15 |
|
sub downloadRelease; |
16 |
|
sub datasetExists; |
17 |
|
sub uploadConfig; |
18 |
+ |
sub locationExists; |
19 |
+ |
sub getLocation; |
20 |
|
|
21 |
|
our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped"; |
22 |
|
|
23 |
|
my %opt; |
24 |
|
Getopt::Long::Configure ("bundling"); |
25 |
< |
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", "recipe|e=s", "help|h"); |
25 |
> |
GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "lumiSummary|s=s", "location|l=s", "name|n=s", "fileList|t=s", "release|r=s", "other|o", "recipe|e=s", "globalTag|g=s", "configName|i=s", "xSection|x=s", "higherOrderXSec|y=s", "help|h"); |
26 |
|
my $argc = @ARGV; |
27 |
|
|
28 |
|
printHelp ($ARGV[0]) if $opt{"help"}; |
82 |
|
$status = "" if $ARGV[0] eq "update"; |
83 |
|
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
84 |
|
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
85 |
< |
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"}; |
85 |
> |
if ($opt{"location"} && locationExists ($id, $opt{"location"})) |
86 |
> |
{ |
87 |
> |
print "This location is already registered in the database!\n"; |
88 |
> |
exit; |
89 |
> |
} |
90 |
> |
dbUpdate ($id, $fullDataset, "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $opt{"format"}, $opt{"location"}, $opt{"name"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}, $opt{"globalTag"}, $opt{"configName"}, $opt{"xSection"}, $opt{"higherOrderXSec"}) if !$opt{"other"}; |
91 |
|
dbUpdateOther ($id, $opt{"comment"}, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $opt{"other"}; |
92 |
|
dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"}; |
93 |
|
dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"}; |
183 |
|
my $userAndHost = shift; |
184 |
|
my $format = shift; |
185 |
|
my $location = shift; |
186 |
+ |
my $name = shift; |
187 |
|
my $fileListName = shift; |
188 |
|
my $status = shift; |
189 |
|
my $comment = shift; |
192 |
|
my $jsonFileName = shift; |
193 |
|
my $lumiSummaryName = shift; |
194 |
|
my $release = shift; |
195 |
+ |
my $globalTag = shift; |
196 |
+ |
my $configName = shift; |
197 |
+ |
my $xSection = shift; |
198 |
+ |
my $ySection = shift; |
199 |
+ |
|
200 |
+ |
$location = getLocation ($id) if $id > 0 |
201 |
+ |
&& !$crabCfgName |
202 |
+ |
&& !$comment |
203 |
+ |
&& !$format |
204 |
+ |
&& !$globalTag |
205 |
+ |
&& !$configName |
206 |
+ |
&& !$jsonFileName |
207 |
+ |
&& !$location |
208 |
+ |
&& !$name |
209 |
+ |
&& !$psetName |
210 |
+ |
&& !$release |
211 |
+ |
&& !$lumiSummaryName |
212 |
+ |
&& !$xSection |
213 |
+ |
&& !$ySection; |
214 |
|
|
215 |
|
my $user = $userAndHost; |
216 |
|
$user =~ s/@.*$//g; |
282 |
|
close (LUMI_SUMMARY); |
283 |
|
$lumiSummary = join ("", @lumiSummary); |
284 |
|
} |
285 |
< |
if ($release) |
286 |
< |
{ |
260 |
< |
my $query = "select id from ntupleRelease where name='$release'"; |
261 |
< |
$db->selectdb ("ntuple"); |
262 |
< |
my $results = $db->query ($query); |
263 |
< |
if ($results->numrows () != 1) |
264 |
< |
{ |
265 |
< |
print "Ntuple release \"$release\" not found!\n"; |
266 |
< |
exit; |
267 |
< |
} |
268 |
< |
} |
269 |
< |
($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList); |
285 |
> |
$release .= ".$configName" if $configName; |
286 |
> |
($nFiles, $size) = sizeOfDataset ($location, $fileList); |
287 |
|
my $fullLocation = $location; |
288 |
|
$fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//); |
289 |
|
|
295 |
|
$jsonFile = addSlashes ($jsonFile); |
296 |
|
$lumiSummary = addSlashes ($lumiSummary); |
297 |
|
$fullLocation = addSlashes ($fullLocation); |
298 |
+ |
$name = addSlashes ($name); |
299 |
|
$fileList = addSlashes ($fileList); |
300 |
|
$status = addSlashes ($status); |
301 |
|
$comment = addSlashes ($comment); |
302 |
|
$release = addSlashes ($release); |
303 |
+ |
$globalTag = addSlashes ($globalTag); |
304 |
|
|
305 |
|
my $results; |
306 |
|
my $query; |
307 |
|
if ($id < 0) |
308 |
|
{ |
309 |
+ |
$query = "select id from ntuple where dataset='$dataset'"; |
310 |
+ |
$db->selectdb ("ntuple"); |
311 |
+ |
$results = $db->query ($query); |
312 |
+ |
if ($results->numrows ()) |
313 |
+ |
{ |
314 |
+ |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
315 |
+ |
my $response = <STDIN>; |
316 |
+ |
$response =~ s/\n//g; |
317 |
+ |
$response = "n" if !$response; |
318 |
+ |
exit if substr (lc ($response), 0, 1) ne 'y'; |
319 |
+ |
} |
320 |
+ |
|
321 |
|
$query = "select max(id) from ntuple"; |
322 |
|
$db->selectdb ("ntuple"); |
323 |
|
$results = $db->query ($query); |
325 |
|
my $id = 1; |
326 |
|
$id = $row[0] + 1 if $results->numrows (); |
327 |
|
|
328 |
< |
$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(), '$userAndHost', '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release')"; |
328 |
> |
$query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version, globalTag, crossSectionInPicobarn, higherOrderCrossSectionInPicobarn) values ($id, '$dataset', now(), now(), '$userAndHost', '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release', '$globalTag', $xSection, $ySection)"; |
329 |
|
} |
330 |
|
if ($id > 0) |
331 |
|
{ |
332 |
|
my $fields; |
333 |
|
my $values; |
334 |
|
|
335 |
< |
$values .= ", dataset='$dataset'" if $dataset; |
335 |
> |
if ($name) |
336 |
> |
{ |
337 |
> |
$query = "select id from ntuple where dataset='$name'"; |
338 |
> |
$db->selectdb ("ntuple"); |
339 |
> |
$results = $db->query ($query); |
340 |
> |
if ($results->numrows ()) |
341 |
> |
{ |
342 |
> |
print "This dataset already exists in the database. Use this name anyway? (y/N): "; |
343 |
> |
my $response = <STDIN>; |
344 |
> |
$response =~ s/\n//g; |
345 |
> |
$response = "n" if !$response; |
346 |
> |
exit if substr (lc ($response), 0, 1) ne 'y'; |
347 |
> |
} |
348 |
> |
$values .= ", dataset='$name'"; |
349 |
> |
} |
350 |
> |
|
351 |
|
$values .= ", lastUpdateTime=now()"; |
352 |
|
$values .= ", lastUpdateUser='$user'"; |
353 |
|
$values .= ", format='$format'" if $format; |
362 |
|
$values .= ", jsonFile='$jsonFile'" if $jsonFile; |
363 |
|
$values .= ", lumiSummary='$lumiSummary'" if $lumiSummary; |
364 |
|
$values .= ", version='$release'" if $release; |
365 |
+ |
$values .= ", globalTag='$globalTag'" if $globalTag; |
366 |
+ |
$values .= ", crossSectionInPicobarn=$xSection" if $xSection; |
367 |
+ |
$values .= ", higherOrderCrossSectionInPicobarn=$ySection" if $ySection; |
368 |
|
|
369 |
|
$values =~ s/^, //; |
370 |
|
$query = "update ntuple set $values where id=$id"; |
428 |
|
printf "%-29s%s\n", " -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs"; |
429 |
|
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
430 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format (default: BEAN)"; |
431 |
+ |
printf "%-29s%s\n", " -g, --globalTag TAG", "global tag"; |
432 |
+ |
printf "%-29s%s\n", " -i, --configName NAME", "name of config used to produce ntuples"; |
433 |
|
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
434 |
|
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
435 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
436 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
437 |
|
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
438 |
+ |
printf "%-29s%s\n", " -x, --xSection XSEC", "cross section in picobarns for the sample"; |
439 |
+ |
printf "%-29s%s\n", " -y, --higherOrderXSec XSEC", "higher-order cross section in picobarns for the"; |
440 |
+ |
printf "%-29s%s\n", " ", "sample"; |
441 |
|
} |
442 |
|
elsif ($command eq "createOther") |
443 |
|
{ |
450 |
|
elsif ($command eq "update") |
451 |
|
{ |
452 |
|
print "Usage: $exeName [OPTION]... update NAME\n"; |
453 |
< |
print "Updates an existing database entry for dataset NAME.\n"; |
453 |
> |
print "Updates an existing database entry for dataset NAME. If no options are given,\n"; |
454 |
> |
print "updates the number of files and the size on disk of the dataset using the\n"; |
455 |
> |
print "location in the database.\n"; |
456 |
|
print "\n"; |
457 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
458 |
|
printf "%-29s%s\n", " -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs"; |
459 |
|
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
460 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format"; |
461 |
+ |
printf "%-29s%s\n", " -g, --globalTag TAG", "global tag"; |
462 |
+ |
printf "%-29s%s\n", " -i, --configName NAME", "name of config used to produce ntuples"; |
463 |
|
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
464 |
|
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
465 |
+ |
printf "%-29s%s\n", " -n, --name NAME", "rename the entry"; |
466 |
|
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
467 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
468 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
469 |
|
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
470 |
+ |
printf "%-29s%s\n", " -x, --xSection XSEC", "cross section in picobarns for the sample"; |
471 |
+ |
printf "%-29s%s\n", " -y, --higherOrderXSec XSEC", "higher-order cross section in picobarns for the"; |
472 |
+ |
printf "%-29s%s\n", " ", "sample"; |
473 |
|
} |
474 |
|
elsif ($command eq "finish") |
475 |
|
{ |
523 |
|
} |
524 |
|
elsif ($command eq "uploadConfig") |
525 |
|
{ |
526 |
< |
print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadConfig NAME\n"; |
526 |
> |
print "Usage: $exeName -p FILE -r RELEASE [OPTION]... uploadConfig NAME\n"; |
527 |
|
print "Creates an entry in the database for a customized Python configuration file.\n"; |
528 |
|
print "\n"; |
529 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
558 |
|
sub |
559 |
|
sizeOfDataset |
560 |
|
{ |
499 |
– |
my $dataset = shift; |
561 |
|
my $location = shift; |
562 |
|
my $fileList = shift; |
563 |
|
|
614 |
|
print "$recipeName does not exist!\n"; |
615 |
|
exit; |
616 |
|
} |
617 |
< |
move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
617 |
> |
move ($release, "/home/osucms/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
618 |
|
open (PY_CONFIG, "<$psetName"); |
619 |
|
my @pset = <PY_CONFIG>; |
620 |
|
close (PY_CONFIG); |
622 |
|
open (RECIPE, "<$recipeName"); |
623 |
|
my @recipe = <RECIPE>; |
624 |
|
close (RECIPE); |
625 |
< |
my $recipe = join ("\n", @recipe); |
625 |
> |
my $recipe = join ("", @recipe); |
626 |
|
|
627 |
|
my $query = "select max(id) from ntupleRelease"; |
628 |
|
$db->selectdb ("ntuple"); |
658 |
|
print "Ntuple release \"$release\" not found!\n"; |
659 |
|
exit; |
660 |
|
} |
600 |
– |
if (!(-e "/home/hart/public_html/releases/$release.tar.gz")) |
601 |
– |
{ |
602 |
– |
print "Release is in the database but no package exists!\n"; |
603 |
– |
exit; |
604 |
– |
} |
661 |
|
if ($pyConfigName) |
662 |
|
{ |
663 |
|
my @row = $results->fetchrow (); |
665 |
|
print PY_CONFIG $row[1]; |
666 |
|
close (PY_CONFIG); |
667 |
|
} |
668 |
< |
copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz"); |
668 |
> |
`wget "http://cmshead.mps.ohio-state.edu/~osucms/releases/$release.tar.gz"`; |
669 |
|
} |
670 |
|
|
671 |
|
sub |
762 |
|
$db->selectdb ("ntuple"); |
763 |
|
$results = $db->query ($query); |
764 |
|
} |
765 |
+ |
|
766 |
+ |
sub |
767 |
+ |
locationExists |
768 |
+ |
{ |
769 |
+ |
my $id = shift; |
770 |
+ |
my $location = shift; |
771 |
+ |
|
772 |
+ |
$location =~ s/^(.*)\/+$/$1/; |
773 |
+ |
my $query = "select id from ntuple where location like '$location%' and id!=$id"; |
774 |
+ |
$db->selectdb ("ntuple"); |
775 |
+ |
my $results = $db->query ($query); |
776 |
+ |
return 1 if $results->numrows (); |
777 |
+ |
|
778 |
+ |
if ($location =~ m/^\/store\/.*$/) |
779 |
+ |
{ |
780 |
+ |
$location =~ s/^\/store\/(.*)$/\/data\/se\/store\/$1/; |
781 |
+ |
} |
782 |
+ |
elsif ($location =~ m/^\/data\/se\/store\/.*$/) |
783 |
+ |
{ |
784 |
+ |
$location =~ s/^\/data\/se\/store\/(.*)$/\/store\/$1/; |
785 |
+ |
} |
786 |
+ |
|
787 |
+ |
my $query = "select id from ntuple where location like '$location%' and id!=$id"; |
788 |
+ |
$db->selectdb ("ntuple"); |
789 |
+ |
my $results = $db->query ($query); |
790 |
+ |
return 1 if $results->numrows (); |
791 |
+ |
|
792 |
+ |
return 0; |
793 |
+ |
} |
794 |
+ |
|
795 |
+ |
sub |
796 |
+ |
getLocation |
797 |
+ |
{ |
798 |
+ |
my $id = shift; |
799 |
+ |
|
800 |
+ |
my $query = "select location from ntuple where id=$id"; |
801 |
+ |
$db->selectdb ("ntuple"); |
802 |
+ |
my $results = $db->query ($query); |
803 |
+ |
my @row = $results->fetchrow (); |
804 |
+ |
|
805 |
+ |
return $row[0]; |
806 |
+ |
} |