7 |
|
|
8 |
|
sub getDataset; |
9 |
|
sub dbUpdate; |
10 |
+ |
sub dbUpdateOther; |
11 |
|
sub dbDelete; |
12 |
+ |
sub dbDeleteOther; |
13 |
|
sub addSlashes; |
14 |
|
sub uploadRelease; |
15 |
+ |
sub datasetExists; |
16 |
|
|
17 |
|
our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped"; |
18 |
|
|
19 |
|
my %opt; |
20 |
|
Getopt::Long::Configure ("bundling"); |
21 |
< |
GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "lumiSummary|s=s", "location|l=s", "fileList|t=s", "release|r=s", "help|h"); |
21 |
> |
GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "lumiSummary|s=s", "location|l=s", "fileList|t=s", "release|r=s", "other|o", "help|h"); |
22 |
|
my $argc = @ARGV; |
23 |
|
|
24 |
|
printHelp ($ARGV[0]) if $opt{"help"}; |
25 |
< |
printHelp () if $argc != 2; |
26 |
< |
printHelp () if $ARGV[0] ne "create" && $ARGV[0] ne "update" && $ARGV[0] ne "finish" && $ARGV[0] ne "deprecate" && $ARGV[0] ne "uploadRelease" && $ARGV[0] ne "deleteEntry"; |
25 |
> |
printHelp () if $argc != 2 && $ARGV[0] ne "createOther"; |
26 |
> |
printHelp () if $ARGV[0] ne "create" && $ARGV[0] ne "createOther" && $ARGV[0] ne "update" && $ARGV[0] ne "finish" && $ARGV[0] ne "deprecate" && $ARGV[0] ne "uploadRelease" && $ARGV[0] ne "deleteEntry"; |
27 |
> |
if ($ARGV[0] eq "create" && datasetExists ($ARGV[1])) |
28 |
> |
{ |
29 |
> |
print "Dataset name already exists in the database!\n"; |
30 |
> |
exit; |
31 |
> |
} |
32 |
|
if (($ARGV[0] eq "create" || $ARGV[0] eq "finish") && !$opt{"location"}) |
33 |
|
{ |
34 |
|
print "The directory containing the ntuples must be given!\n"; |
39 |
|
print "Both the Python and the CMSSW release must be given!\n"; |
40 |
|
exit; |
41 |
|
} |
42 |
< |
if ($ARGV[0] ne "uploadRelease") |
35 |
< |
{ |
36 |
< |
my $id = -1; |
37 |
< |
my $fullDataset; |
38 |
< |
($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create"; |
39 |
< |
$fullDataset = $ARGV[1] if $id < 0; |
40 |
< |
$ARGV[0] = "create" if $id < 0; |
41 |
< |
my $status = "present"; |
42 |
< |
$status = "" if $ARGV[0] eq "update"; |
43 |
< |
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
44 |
< |
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
45 |
< |
dbUpdate ($id, $fullDataset, $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}); |
46 |
< |
dbDelete ($id) if $ARGV[0] eq "deleteEntry"; |
47 |
< |
} |
48 |
< |
else |
42 |
> |
if ($ARGV[0] eq "uploadRelease") |
43 |
|
{ |
44 |
|
my $parentDir = "./$opt{'release'}"; |
45 |
|
$parentDir =~ s/CMSSW_[^\/]*//g; |
50 |
|
$opt{"format"} = "BEAN" if !$opt{"format"}; |
51 |
|
uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], $ENV{"USER"}, $opt{"comment"}); |
52 |
|
} |
53 |
+ |
elsif ($ARGV[0] eq "createOther") |
54 |
+ |
{ |
55 |
+ |
my @listOfFiles = @ARGV; |
56 |
+ |
@listOfFiles = reverse (@listOfFiles); |
57 |
+ |
pop (@listOfFiles); |
58 |
+ |
@listOfFiles = reverse (@listOfFiles); |
59 |
+ |
dbOtherCreate ($ENV{"USER"}, \@listOfFiles, $opt{"comment"}); |
60 |
+ |
} |
61 |
+ |
else |
62 |
+ |
{ |
63 |
+ |
my $id = -1; |
64 |
+ |
my $fullDataset; |
65 |
+ |
($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create" && ($ARGV[0] ne "update" || !$opt{"other"}) && ($ARGV[0] ne "deleteEntry" || !$opt{"other"}); |
66 |
+ |
$id = $ARGV[1] if ($ARGV[0] eq "update" && $opt{"other"}) || ($ARGV[0] eq "deleteEntry" && $opt{"other"}); |
67 |
+ |
$fullDataset = $ARGV[1] if $id < 0; |
68 |
+ |
$ARGV[0] = "create" if $id < 0; |
69 |
+ |
my $status = "present"; |
70 |
+ |
$status = "" if $ARGV[0] eq "update"; |
71 |
+ |
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
72 |
+ |
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
73 |
+ |
dbUpdate ($id, $fullDataset, $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}) if !$opt{"other"}; |
74 |
+ |
dbUpdateOther ($id, $opt{"comment"}) if $opt{"other"}; |
75 |
+ |
dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"}; |
76 |
+ |
dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"}; |
77 |
+ |
} |
78 |
|
|
79 |
|
sub |
80 |
|
addSlashes |
99 |
|
my $queryDataset = $dataset; |
100 |
|
$queryDataset =~ s/\*/%/g; |
101 |
|
$queryDataset =~ s/(.*)/%$1%/g; |
102 |
< |
my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by lastUpdateTime"; |
102 |
> |
my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by creationTime"; |
103 |
|
$db->selectdb ("ntuple"); |
104 |
|
$results = $db->query ($query); |
105 |
|
if ($results->numrows () == 1) |
254 |
|
} |
255 |
|
} |
256 |
|
($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList); |
257 |
< |
my $fullLocation = "$ENV{'PWD'}/$location"; |
257 |
> |
my $fullLocation = $location; |
258 |
> |
$fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//); |
259 |
|
|
260 |
|
$dataset = addSlashes ($dataset); |
261 |
|
$user = addSlashes ($user); |
312 |
|
} |
313 |
|
|
314 |
|
sub |
315 |
+ |
dbUpdateOther |
316 |
+ |
{ |
317 |
+ |
my $id = shift; |
318 |
+ |
my $comment = shift; |
319 |
+ |
|
320 |
+ |
$comment = addSlashes ($comment); |
321 |
+ |
|
322 |
+ |
my $query = "update other set lastUpdateTime=now(), comment='$comment' where id=$id"; |
323 |
+ |
$db->selectdb ("ntuple"); |
324 |
+ |
my $results = $db->query ($query); |
325 |
+ |
|
326 |
+ |
return $results; |
327 |
+ |
} |
328 |
+ |
|
329 |
+ |
sub |
330 |
|
dbDelete |
331 |
|
{ |
332 |
|
my $id = shift; |
333 |
|
|
299 |
– |
return if $id < 0; |
334 |
|
my $query = "delete from ntuple where id=$id"; |
335 |
|
$db->selectdb ("ntuple"); |
336 |
|
my $results = $db->query ($query); |
337 |
|
} |
338 |
|
|
339 |
|
sub |
340 |
+ |
dbDeleteOther |
341 |
+ |
{ |
342 |
+ |
my $id = shift; |
343 |
+ |
|
344 |
+ |
my $query = "delete from other where id=$id"; |
345 |
+ |
$db->selectdb ("ntuple"); |
346 |
+ |
my $results = $db->query ($query); |
347 |
+ |
} |
348 |
+ |
|
349 |
+ |
sub |
350 |
|
printHelp |
351 |
|
{ |
352 |
|
my $command = shift; |
370 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
371 |
|
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
372 |
|
} |
373 |
+ |
elsif ($command eq "createOther") |
374 |
+ |
{ |
375 |
+ |
print "Usage: $exeName [OPTION]... createOther DIRECTORIES_AND_FILES\n"; |
376 |
+ |
print "Creates an entry in the database for non-ntuple data.\n"; |
377 |
+ |
print "\n"; |
378 |
+ |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
379 |
+ |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
380 |
+ |
} |
381 |
|
elsif ($command eq "update") |
382 |
|
{ |
383 |
|
print "Usage: $exeName [OPTION]... update NAME\n"; |
389 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format"; |
390 |
|
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
391 |
|
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
392 |
+ |
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
393 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
394 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
395 |
|
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
407 |
|
} |
408 |
|
elsif ($command eq "deleteEntry") |
409 |
|
{ |
410 |
< |
print "Usage: $exeName deleteEntry NAME\n"; |
410 |
> |
print "Usage: $exeName [OPTION]... deleteEntry NAME\n"; |
411 |
|
print "Deletes the database entry for dataset NAME. This is intended primarily for\n"; |
412 |
|
print "mistaken database entries. If you wish to actually delete a set of ntuples,\n"; |
413 |
|
print "please use the \"deprecate\" command instead.\n"; |
414 |
+ |
print "\n"; |
415 |
+ |
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
416 |
|
} |
417 |
|
elsif ($command eq "deprecate") |
418 |
|
{ |
446 |
|
print "\n"; |
447 |
|
print "COMMAND may be one of the following:\n"; |
448 |
|
printf "%-29s%s\n", " create", "creates the entry"; |
449 |
+ |
printf "%-29s%s\n", " create", "creates an entry for non-ntuple data"; |
450 |
|
printf "%-29s%s\n", " update", "updates the entry"; |
451 |
|
printf "%-29s%s\n", " finish", "finalizes the database entry"; |
452 |
|
printf "%-29s%s\n", " deleteEntry", "removes the database entry"; |
535 |
|
$db->selectdb ("ntuple"); |
536 |
|
my $results = $db->query ($query); |
537 |
|
} |
538 |
+ |
|
539 |
+ |
sub |
540 |
+ |
datasetExists |
541 |
+ |
{ |
542 |
+ |
my $dataset = shift; |
543 |
+ |
|
544 |
+ |
my $query = "select id from ntuple where dataset='$dataset'"; |
545 |
+ |
$db->selectdb ("ntuple"); |
546 |
+ |
my $results = $db->query ($query); |
547 |
+ |
|
548 |
+ |
return $results->numrows (); |
549 |
+ |
} |
550 |
+ |
|
551 |
+ |
sub |
552 |
+ |
dbOtherCreate |
553 |
+ |
{ |
554 |
+ |
my $user = shift; |
555 |
+ |
my $listOfFiles = shift; |
556 |
+ |
my $comment = shift; |
557 |
+ |
|
558 |
+ |
my $size = 0.0; |
559 |
+ |
my $nFiles = 0.0; |
560 |
+ |
for (my $i = 0; $i < @$listOfFiles; $i++) |
561 |
+ |
{ |
562 |
+ |
if (!(-e $$listOfFiles[$i])) |
563 |
+ |
{ |
564 |
+ |
print "$$listOfFiles[$i] does not exist!\n"; |
565 |
+ |
exit; |
566 |
+ |
} |
567 |
+ |
$nFiles += `ls -R $$listOfFiles[$i] | grep -v ':\$' | grep -v '^\$' | wc -l`; |
568 |
+ |
my $fileSize = `du -s $$listOfFiles[$i]`; |
569 |
+ |
$fileSize =~ s/([^ ]*) .*/$1/; |
570 |
+ |
$fileSize /= 1024 * 1024; |
571 |
+ |
$size += $fileSize; |
572 |
+ |
$$listOfFiles[$i] = "$ENV{'PWD'}/$$listOfFiles[$i]" if !($$listOfFiles[$i] =~ m/^\//); |
573 |
+ |
} |
574 |
+ |
$size = sprintf "%.2f", $size; |
575 |
+ |
my $location = join ("<br />", @$listOfFiles); |
576 |
+ |
|
577 |
+ |
my $query = "select max(id) from other"; |
578 |
+ |
$db->selectdb ("ntuple"); |
579 |
+ |
my $results = $db->query ($query); |
580 |
+ |
my @row = $results->fetchrow (); |
581 |
+ |
my $id = 1; |
582 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
583 |
+ |
|
584 |
+ |
$user = addSlashes ($user); |
585 |
+ |
$location = addSlashes ($location); |
586 |
+ |
$comment = addSlashes ($comment); |
587 |
+ |
|
588 |
+ |
my $query = "insert into other (id, creationTime, lastUpdateTime, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$location', $nFiles, $size, '$comment')"; |
589 |
+ |
$db->selectdb ("ntuple"); |
590 |
+ |
my $results = $db->query ($query); |
591 |
+ |
|
592 |
+ |
print "ID $id\n"; |
593 |
+ |
} |