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" || $ARGV[0] eq "finish") && !$opt{"location"}) |
28 |
|
{ |
29 |
|
print "The directory containing the ntuples must be given!\n"; |
34 |
|
print "Both the Python and the CMSSW release must be given!\n"; |
35 |
|
exit; |
36 |
|
} |
37 |
< |
if ($ARGV[0] ne "uploadRelease") |
37 |
> |
if ($ARGV[0] eq "uploadRelease") |
38 |
> |
{ |
39 |
> |
my $parentDir = "./$opt{'release'}"; |
40 |
> |
$parentDir =~ s/CMSSW_[^\/]*//g; |
41 |
> |
$parentDir =~ s/\/\/*/\//g; |
42 |
> |
my $cmsswRelease = $opt{'release'}; |
43 |
> |
$cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/; |
44 |
> |
`tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`; |
45 |
> |
$opt{"format"} = "BEAN" if !$opt{"format"}; |
46 |
> |
uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $opt{"comment"}); |
47 |
> |
} |
48 |
> |
elsif ($ARGV[0] eq "createOther") |
49 |
> |
{ |
50 |
> |
my @listOfFiles = @ARGV; |
51 |
> |
@listOfFiles = reverse (@listOfFiles); |
52 |
> |
pop (@listOfFiles); |
53 |
> |
@listOfFiles = reverse (@listOfFiles); |
54 |
> |
dbOtherCreate ("$ENV{'USER'}\@$ENV{'HOSTNAME'}", \@listOfFiles, $opt{"comment"}); |
55 |
> |
} |
56 |
> |
else |
57 |
|
{ |
58 |
|
my $id = -1; |
59 |
|
my $fullDataset; |
60 |
< |
($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create"; |
60 |
> |
($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create" && ($ARGV[0] ne "update" || !$opt{"other"}) && ($ARGV[0] ne "deleteEntry" || !$opt{"other"}); |
61 |
> |
$id = $ARGV[1] if ($ARGV[0] eq "update" && $opt{"other"}) || ($ARGV[0] eq "deleteEntry" && $opt{"other"}); |
62 |
|
$fullDataset = $ARGV[1] if $id < 0; |
63 |
|
$ARGV[0] = "create" if $id < 0; |
64 |
|
my $status = "present"; |
65 |
|
$status = "" if $ARGV[0] eq "update"; |
66 |
|
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
67 |
|
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
68 |
< |
dbUpdate ($id, $fullDataset, $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}); |
69 |
< |
dbDelete ($id) if $ARGV[0] eq "deleteEntry"; |
70 |
< |
} |
71 |
< |
else |
49 |
< |
{ |
50 |
< |
my $parentDir = "./$opt{'release'}"; |
51 |
< |
$parentDir =~ s/CMSSW_[^\/]*//g; |
52 |
< |
$parentDir =~ s/\/\/*/\//g; |
53 |
< |
my $cmsswRelease = $opt{'release'}; |
54 |
< |
$cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/; |
55 |
< |
`tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`; |
56 |
< |
$opt{"format"} = "BEAN" if !$opt{"format"}; |
57 |
< |
uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], $ENV{"USER"}, $opt{"comment"}); |
68 |
> |
dbUpdate ($id, $fullDataset, "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}) if !$opt{"other"}; |
69 |
> |
dbUpdateOther ($id, $opt{"comment"}, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $opt{"other"}; |
70 |
> |
dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"}; |
71 |
> |
dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"}; |
72 |
|
} |
73 |
|
|
74 |
|
sub |
94 |
|
my $queryDataset = $dataset; |
95 |
|
$queryDataset =~ s/\*/%/g; |
96 |
|
$queryDataset =~ s/(.*)/%$1%/g; |
97 |
< |
my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by lastUpdateTime"; |
97 |
> |
my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by creationTime"; |
98 |
|
$db->selectdb ("ntuple"); |
99 |
|
$results = $db->query ($query); |
100 |
|
if ($results->numrows () == 1) |
249 |
|
} |
250 |
|
} |
251 |
|
($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList); |
252 |
< |
my $fullLocation = "$ENV{'PWD'}/$location"; |
252 |
> |
my $fullLocation = $location; |
253 |
> |
$fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//); |
254 |
|
|
255 |
|
$dataset = addSlashes ($dataset); |
256 |
|
$user = addSlashes ($user); |
276 |
|
my $id = 1; |
277 |
|
$id = $row[0] + 1 if $results->numrows (); |
278 |
|
|
279 |
< |
$query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version) values ($id, '$dataset', now(), now(), '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release')"; |
279 |
> |
$query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version) values ($id, '$dataset', now(), now(), '$user', '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release')"; |
280 |
|
} |
281 |
|
if ($id > 0) |
282 |
|
{ |
285 |
|
|
286 |
|
$values .= ", dataset='$dataset'" if $dataset; |
287 |
|
$values .= ", lastUpdateTime=now()"; |
288 |
+ |
$values .= ", lastUpdateUser='$user'"; |
289 |
|
$values .= ", format='$format'" if $format; |
290 |
|
$values .= ", location='$fullLocation'" if $location; |
291 |
|
$values .= ", fileList='$fileList'" if $fileList; |
308 |
|
} |
309 |
|
|
310 |
|
sub |
311 |
+ |
dbUpdateOther |
312 |
+ |
{ |
313 |
+ |
my $id = shift; |
314 |
+ |
my $comment = shift; |
315 |
+ |
my $user = shift; |
316 |
+ |
|
317 |
+ |
$comment = addSlashes ($comment); |
318 |
+ |
|
319 |
+ |
my $query = "update other set lastUpdateTime=now(), lastUpdateUser='$user', comment='$comment' where id=$id"; |
320 |
+ |
$db->selectdb ("ntuple"); |
321 |
+ |
my $results = $db->query ($query); |
322 |
+ |
|
323 |
+ |
return $results; |
324 |
+ |
} |
325 |
+ |
|
326 |
+ |
sub |
327 |
|
dbDelete |
328 |
|
{ |
329 |
|
my $id = shift; |
330 |
|
|
299 |
– |
return if $id < 0; |
331 |
|
my $query = "delete from ntuple where id=$id"; |
332 |
|
$db->selectdb ("ntuple"); |
333 |
|
my $results = $db->query ($query); |
334 |
|
} |
335 |
|
|
336 |
|
sub |
337 |
+ |
dbDeleteOther |
338 |
+ |
{ |
339 |
+ |
my $id = shift; |
340 |
+ |
|
341 |
+ |
my $query = "delete from other where id=$id"; |
342 |
+ |
$db->selectdb ("ntuple"); |
343 |
+ |
my $results = $db->query ($query); |
344 |
+ |
} |
345 |
+ |
|
346 |
+ |
sub |
347 |
|
printHelp |
348 |
|
{ |
349 |
|
my $command = shift; |
367 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
368 |
|
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
369 |
|
} |
370 |
+ |
elsif ($command eq "createOther") |
371 |
+ |
{ |
372 |
+ |
print "Usage: $exeName [OPTION]... createOther DIRECTORIES_AND_FILES\n"; |
373 |
+ |
print "Creates an entry in the database for non-ntuple data.\n"; |
374 |
+ |
print "\n"; |
375 |
+ |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
376 |
+ |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
377 |
+ |
} |
378 |
|
elsif ($command eq "update") |
379 |
|
{ |
380 |
|
print "Usage: $exeName [OPTION]... update NAME\n"; |
386 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format"; |
387 |
|
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
388 |
|
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
389 |
+ |
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
390 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
391 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
392 |
|
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
404 |
|
} |
405 |
|
elsif ($command eq "deleteEntry") |
406 |
|
{ |
407 |
< |
print "Usage: $exeName deleteEntry NAME\n"; |
407 |
> |
print "Usage: $exeName [OPTION]... deleteEntry NAME\n"; |
408 |
|
print "Deletes the database entry for dataset NAME. This is intended primarily for\n"; |
409 |
|
print "mistaken database entries. If you wish to actually delete a set of ntuples,\n"; |
410 |
|
print "please use the \"deprecate\" command instead.\n"; |
411 |
+ |
print "\n"; |
412 |
+ |
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
413 |
|
} |
414 |
|
elsif ($command eq "deprecate") |
415 |
|
{ |
443 |
|
print "\n"; |
444 |
|
print "COMMAND may be one of the following:\n"; |
445 |
|
printf "%-29s%s\n", " create", "creates the entry"; |
446 |
+ |
printf "%-29s%s\n", " create", "creates an entry for non-ntuple data"; |
447 |
|
printf "%-29s%s\n", " update", "updates the entry"; |
448 |
|
printf "%-29s%s\n", " finish", "finalizes the database entry"; |
449 |
|
printf "%-29s%s\n", " deleteEntry", "removes the database entry"; |
532 |
|
$db->selectdb ("ntuple"); |
533 |
|
my $results = $db->query ($query); |
534 |
|
} |
535 |
+ |
|
536 |
+ |
sub |
537 |
+ |
dbOtherCreate |
538 |
+ |
{ |
539 |
+ |
my $user = shift; |
540 |
+ |
my $listOfFiles = shift; |
541 |
+ |
my $comment = shift; |
542 |
+ |
|
543 |
+ |
my $size = 0.0; |
544 |
+ |
my $nFiles = 0.0; |
545 |
+ |
for (my $i = 0; $i < @$listOfFiles; $i++) |
546 |
+ |
{ |
547 |
+ |
if (!(-e $$listOfFiles[$i])) |
548 |
+ |
{ |
549 |
+ |
print "$$listOfFiles[$i] does not exist!\n"; |
550 |
+ |
exit; |
551 |
+ |
} |
552 |
+ |
$nFiles += `ls -R $$listOfFiles[$i] | grep -v ':\$' | grep -v '^\$' | wc -l`; |
553 |
+ |
my $fileSize = `du -s $$listOfFiles[$i]`; |
554 |
+ |
$fileSize =~ s/([^ ]*) .*/$1/; |
555 |
+ |
$fileSize /= 1024 * 1024; |
556 |
+ |
$size += $fileSize; |
557 |
+ |
$$listOfFiles[$i] = "$ENV{'PWD'}/$$listOfFiles[$i]" if !($$listOfFiles[$i] =~ m/^\//); |
558 |
+ |
} |
559 |
+ |
$size = sprintf "%.2f", $size; |
560 |
+ |
my $location = join ("<br />", @$listOfFiles); |
561 |
+ |
|
562 |
+ |
my $query = "select max(id) from other"; |
563 |
+ |
$db->selectdb ("ntuple"); |
564 |
+ |
my $results = $db->query ($query); |
565 |
+ |
my @row = $results->fetchrow (); |
566 |
+ |
my $id = 1; |
567 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
568 |
+ |
|
569 |
+ |
$user = addSlashes ($user); |
570 |
+ |
$location = addSlashes ($location); |
571 |
+ |
$comment = addSlashes ($comment); |
572 |
+ |
|
573 |
+ |
my $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$user', '$location', $nFiles, $size, '$comment')"; |
574 |
+ |
$db->selectdb ("ntuple"); |
575 |
+ |
my $results = $db->query ($query); |
576 |
+ |
|
577 |
+ |
print "ID $id\n"; |
578 |
+ |
} |