14 |
|
sub uploadRelease; |
15 |
|
sub downloadRelease; |
16 |
|
sub datasetExists; |
17 |
+ |
sub uploadConfig; |
18 |
+ |
sub locationExists; |
19 |
|
|
20 |
|
our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped"; |
21 |
|
|
22 |
|
my %opt; |
23 |
|
Getopt::Long::Configure ("bundling"); |
24 |
< |
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"); |
24 |
> |
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", "help|h"); |
25 |
|
my $argc = @ARGV; |
26 |
|
|
27 |
|
printHelp ($ARGV[0]) if $opt{"help"}; |
28 |
|
printHelp () if $argc != 2 && $ARGV[0] ne "createOther"; |
29 |
< |
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 "downloadRelease" && $ARGV[0] ne "deleteEntry"; |
29 |
> |
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 "downloadRelease" && $ARGV[0] ne "deleteEntry" && $ARGV[0] ne "uploadConfig"; |
30 |
|
if (($ARGV[0] eq "create" || $ARGV[0] eq "finish") && !$opt{"location"}) |
31 |
|
{ |
32 |
|
print "The directory containing the ntuples must be given!\n"; |
33 |
|
exit; |
34 |
|
} |
35 |
< |
if ($ARGV[0] eq "uploadRelease" && !$opt{"pyConfig"} && !$opt{"release"}) |
35 |
> |
if ($ARGV[0] eq "uploadRelease" && (!$opt{"pyConfig"} || !$opt{"release"} || !$opt{"recipe"})) |
36 |
|
{ |
37 |
< |
print "Both the Python and the CMSSW release must be given!\n"; |
37 |
> |
print "The Python config, CMSSW release directory, and recipe file must be given!\n"; |
38 |
> |
exit; |
39 |
> |
} |
40 |
> |
if ($ARGV[0] eq "uploadConfig" && (!$opt{"pyConfig"} || !$opt{"release"})) |
41 |
> |
{ |
42 |
> |
print "The Python config and ntuple release must be given!\n"; |
43 |
|
exit; |
44 |
|
} |
45 |
|
if ($ARGV[0] eq "uploadRelease") |
51 |
|
$cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/; |
52 |
|
`tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`; |
53 |
|
$opt{"format"} = "BEAN" if !$opt{"format"}; |
54 |
< |
uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}", $opt{"comment"}); |
54 |
> |
uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}", $opt{"comment"}, $opt{"recipe"}); |
55 |
|
} |
56 |
|
elsif ($ARGV[0] eq "downloadRelease") |
57 |
|
{ |
58 |
|
downloadRelease ($ARGV[1], $opt{"pyConfig"}); |
59 |
|
} |
60 |
+ |
elsif ($ARGV[0] eq "uploadConfig") |
61 |
+ |
{ |
62 |
+ |
uploadConfig ($ARGV[1], $ENV{"USER"}, $opt{"pyConfig"}, $opt{"release"}, $opt{"comment"}); |
63 |
+ |
} |
64 |
|
elsif ($ARGV[0] eq "createOther") |
65 |
|
{ |
66 |
|
my @listOfFiles = @ARGV; |
67 |
|
@listOfFiles = reverse (@listOfFiles); |
68 |
|
pop (@listOfFiles); |
69 |
|
@listOfFiles = reverse (@listOfFiles); |
70 |
< |
dbOtherCreate ("$ENV{'USER'}", \@listOfFiles, $opt{"comment"}); |
70 |
> |
dbOtherCreate ("$ENV{'USER'}\@$ENV{'HOSTNAME'}", \@listOfFiles, $opt{"comment"}); |
71 |
|
} |
72 |
|
else |
73 |
|
{ |
81 |
|
$status = "" if $ARGV[0] eq "update"; |
82 |
|
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
83 |
|
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
84 |
< |
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"}; |
84 |
> |
if ($opt{"location"} && locationExists ($id, $opt{"location"})) |
85 |
> |
{ |
86 |
> |
print "This location is already registered in the database!\n"; |
87 |
> |
exit; |
88 |
> |
} |
89 |
> |
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"}) if !$opt{"other"}; |
90 |
|
dbUpdateOther ($id, $opt{"comment"}, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $opt{"other"}; |
91 |
|
dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"}; |
92 |
|
dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"}; |
179 |
|
{ |
180 |
|
my $id = shift; |
181 |
|
my $dataset = shift; |
182 |
< |
my $user = shift; |
182 |
> |
my $userAndHost = shift; |
183 |
|
my $format = shift; |
184 |
|
my $location = shift; |
185 |
+ |
my $name = shift; |
186 |
|
my $fileListName = shift; |
187 |
|
my $status = shift; |
188 |
|
my $comment = shift; |
192 |
|
my $lumiSummaryName = shift; |
193 |
|
my $release = shift; |
194 |
|
|
195 |
+ |
my $user = $userAndHost; |
196 |
+ |
$user =~ s/@.*$//g; |
197 |
+ |
|
198 |
|
my $fileList; |
199 |
|
my $pset; |
200 |
|
my $crabCfg; |
285 |
|
$jsonFile = addSlashes ($jsonFile); |
286 |
|
$lumiSummary = addSlashes ($lumiSummary); |
287 |
|
$fullLocation = addSlashes ($fullLocation); |
288 |
+ |
$name = addSlashes ($name); |
289 |
|
$fileList = addSlashes ($fileList); |
290 |
|
$status = addSlashes ($status); |
291 |
|
$comment = addSlashes ($comment); |
295 |
|
my $query; |
296 |
|
if ($id < 0) |
297 |
|
{ |
298 |
+ |
$query = "select id from ntuple where dataset='$dataset'"; |
299 |
+ |
$db->selectdb ("ntuple"); |
300 |
+ |
$results = $db->query ($query); |
301 |
+ |
if ($results->numrows ()) |
302 |
+ |
{ |
303 |
+ |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
304 |
+ |
my $response = <STDIN>; |
305 |
+ |
$response =~ s/\n//g; |
306 |
+ |
$response = "n" if !$response; |
307 |
+ |
exit if substr (lc ($response), 0, 1) ne 'y'; |
308 |
+ |
} |
309 |
+ |
|
310 |
|
$query = "select max(id) from ntuple"; |
311 |
|
$db->selectdb ("ntuple"); |
312 |
|
$results = $db->query ($query); |
314 |
|
my $id = 1; |
315 |
|
$id = $row[0] + 1 if $results->numrows (); |
316 |
|
|
317 |
< |
$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')"; |
317 |
> |
$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')"; |
318 |
|
} |
319 |
|
if ($id > 0) |
320 |
|
{ |
321 |
|
my $fields; |
322 |
|
my $values; |
323 |
|
|
324 |
< |
$values .= ", dataset='$dataset'" if $dataset; |
324 |
> |
if ($name) |
325 |
> |
{ |
326 |
> |
$query = "select id from ntuple where dataset='$name'"; |
327 |
> |
$db->selectdb ("ntuple"); |
328 |
> |
$results = $db->query ($query); |
329 |
> |
if ($results->numrows ()) |
330 |
> |
{ |
331 |
> |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
332 |
> |
my $response = <STDIN>; |
333 |
> |
$response =~ s/\n//g; |
334 |
> |
$response = "n" if !$response; |
335 |
> |
exit if substr (lc ($response), 0, 1) ne 'y'; |
336 |
> |
} |
337 |
> |
$values .= ", dataset='$name'"; |
338 |
> |
} |
339 |
> |
|
340 |
|
$values .= ", lastUpdateTime=now()"; |
341 |
|
$values .= ", lastUpdateUser='$user'"; |
342 |
|
$values .= ", format='$format'" if $format; |
439 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format"; |
440 |
|
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
441 |
|
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
442 |
+ |
printf "%-29s%s\n", " -n, --name NAME", "rename the entry"; |
443 |
|
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
444 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
445 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
448 |
|
elsif ($command eq "finish") |
449 |
|
{ |
450 |
|
print "Usage: $exeName -l DIRECTORY finish NAME\n"; |
402 |
– |
|
451 |
|
print "Finalizes the database entry for dataset NAME, changing its status to\n"; |
452 |
|
print "\"present\". This is intended to be the final step in command-line based ntuple\n"; |
453 |
|
print "production.\n"; |
473 |
|
} |
474 |
|
elsif ($command eq "uploadRelease") |
475 |
|
{ |
476 |
< |
print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n"; |
476 |
> |
print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n"; |
477 |
|
print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n"; |
478 |
|
print "database entry for it, with NAME being the name of the release. An ntuple\n"; |
479 |
|
print "release is a CMSSW release with all the necessary packages added for creating\n"; |
481 |
|
print "\n"; |
482 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
483 |
|
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
484 |
+ |
printf "%-29s%s\n", " -e, --recipe FILE", "file containing the recipe for the release"; |
485 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format (default: BEAN)"; |
486 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "default Python config for the release"; |
487 |
|
printf "%-29s%s\n", " -r, --release DIRECTORY", "CMSSW release containing ntuple packages"; |
495 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
496 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python configuration file name"; |
497 |
|
} |
498 |
+ |
elsif ($command eq "uploadConfig") |
499 |
+ |
{ |
500 |
+ |
print "Usage: $exeName -p FILE -r RELEASE [OPTION]... uploadConfig NAME\n"; |
501 |
+ |
print "Creates an entry in the database for a customized Python configuration file.\n"; |
502 |
+ |
print "\n"; |
503 |
+ |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
504 |
+ |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
505 |
+ |
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config file"; |
506 |
+ |
printf "%-29s%s\n", " -r, --release NAME", "ntuple release with which to use this config"; |
507 |
+ |
} |
508 |
|
else |
509 |
|
{ |
510 |
|
print "Usage: $exeName [OPTION]... COMMAND NAME\n"; |
523 |
|
printf "%-29s%s\n", " deprecate", "marks the dataset for deletion"; |
524 |
|
printf "%-29s%s\n", " uploadRelease", "upload an ntuple release"; |
525 |
|
printf "%-29s%s\n", " downloadRelease", "download an ntuple release"; |
526 |
+ |
printf "%-29s%s\n", " uploadConfig", "upload an ntuple config"; |
527 |
|
} |
528 |
|
|
529 |
|
exit; |
577 |
|
my $name = shift; |
578 |
|
my $user = shift; |
579 |
|
my $comment = shift; |
580 |
+ |
my $recipeName = shift; |
581 |
|
|
521 |
– |
move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
582 |
|
if (!(-e $psetName)) |
583 |
|
{ |
584 |
|
print "$psetName does not exist!\n"; |
585 |
|
exit; |
586 |
|
} |
587 |
+ |
if (!(-e $recipeName)) |
588 |
+ |
{ |
589 |
+ |
print "$recipeName does not exist!\n"; |
590 |
+ |
exit; |
591 |
+ |
} |
592 |
+ |
move ($release, "/home/osucms/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
593 |
|
open (PY_CONFIG, "<$psetName"); |
594 |
|
my @pset = <PY_CONFIG>; |
595 |
|
close (PY_CONFIG); |
596 |
|
my $pset = join ("", @pset); |
597 |
+ |
open (RECIPE, "<$recipeName"); |
598 |
+ |
my @recipe = <RECIPE>; |
599 |
+ |
close (RECIPE); |
600 |
+ |
my $recipe = join ("\n", @recipe); |
601 |
|
|
602 |
|
my $query = "select max(id) from ntupleRelease"; |
603 |
|
$db->selectdb ("ntuple"); |
612 |
|
$format = addSlashes ($format); |
613 |
|
$cmsswRelease = addSlashes ($cmsswRelease); |
614 |
|
$comment = addSlashes ($comment); |
615 |
+ |
$recipe = addSlashes ($recipe); |
616 |
|
|
617 |
< |
my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment')"; |
617 |
> |
my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')"; |
618 |
|
$db->selectdb ("ntuple"); |
619 |
|
my $results = $db->query ($query); |
620 |
|
} |
633 |
|
print "Ntuple release \"$release\" not found!\n"; |
634 |
|
exit; |
635 |
|
} |
565 |
– |
if (!(-e "/home/hart/public_html/releases/$release.tar.gz")) |
566 |
– |
{ |
567 |
– |
print "Release is in the database but no package exists!\n"; |
568 |
– |
exit; |
569 |
– |
} |
636 |
|
if ($pyConfigName) |
637 |
|
{ |
638 |
|
my @row = $results->fetchrow (); |
640 |
|
print PY_CONFIG $row[1]; |
641 |
|
close (PY_CONFIG); |
642 |
|
} |
643 |
< |
copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz"); |
643 |
> |
`wget "http://cmshead.mps.ohio-state.edu/~osucms/releases/$release.tar.gz"`; |
644 |
|
} |
645 |
|
|
646 |
|
sub |
647 |
|
dbOtherCreate |
648 |
|
{ |
649 |
< |
my $user = shift; |
649 |
> |
my $userAndHost = shift; |
650 |
|
my $listOfFiles = shift; |
651 |
|
my $comment = shift; |
652 |
|
|
653 |
+ |
my $user = $userAndHost; |
654 |
+ |
$user =~ s/@.*$//g; |
655 |
+ |
|
656 |
|
my $size = 0.0; |
657 |
|
my $nFiles = 0.0; |
658 |
|
for (my $i = 0; $i < @$listOfFiles; $i++) |
683 |
|
$location = addSlashes ($location); |
684 |
|
$comment = addSlashes ($comment); |
685 |
|
|
686 |
< |
my $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$user', '$location', $nFiles, $size, '$comment')"; |
686 |
> |
$query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$userAndHost', '$user', '$location', $nFiles, $size, '$comment')"; |
687 |
|
$db->selectdb ("ntuple"); |
688 |
< |
my $results = $db->query ($query); |
688 |
> |
$results = $db->query ($query); |
689 |
|
|
690 |
|
print "ID $id\n"; |
691 |
|
} |
692 |
+ |
|
693 |
+ |
sub |
694 |
+ |
uploadConfig |
695 |
+ |
{ |
696 |
+ |
my $name = shift; |
697 |
+ |
my $user = shift; |
698 |
+ |
my $psetName = shift; |
699 |
+ |
my $release = shift; |
700 |
+ |
my $comment = shift; |
701 |
+ |
|
702 |
+ |
if (!(-e $psetName)) |
703 |
+ |
{ |
704 |
+ |
print "$psetName does not exist!\n"; |
705 |
+ |
exit; |
706 |
+ |
} |
707 |
+ |
if ($release) |
708 |
+ |
{ |
709 |
+ |
my $query = "select id from ntupleRelease where name='$release'"; |
710 |
+ |
$db->selectdb ("ntuple"); |
711 |
+ |
my $results = $db->query ($query); |
712 |
+ |
if ($results->numrows () != 1) |
713 |
+ |
{ |
714 |
+ |
print "Ntuple release \"$release\" not found!\n"; |
715 |
+ |
exit; |
716 |
+ |
} |
717 |
+ |
} |
718 |
+ |
open (PSET, "<$psetName"); |
719 |
+ |
my @pset = <PSET>; |
720 |
+ |
close (PSET); |
721 |
+ |
my $pset = join ("", @pset); |
722 |
+ |
|
723 |
+ |
my $query = "select max(id) from ntupleConfig"; |
724 |
+ |
$db->selectdb ("ntuple"); |
725 |
+ |
my $results = $db->query ($query); |
726 |
+ |
my @row = $results->fetchrow (); |
727 |
+ |
my $id = 1; |
728 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
729 |
+ |
|
730 |
+ |
$name = addSlashes ($name); |
731 |
+ |
$user = addSlashes ($user); |
732 |
+ |
$pset = addSlashes ($pset); |
733 |
+ |
$release = addSlashes ($release); |
734 |
+ |
$comment = addSlashes ($comment); |
735 |
+ |
|
736 |
+ |
my $query = "insert into ntupleConfig (id, name, pset, user, pending, ntupleRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$release', '$comment')"; |
737 |
+ |
$db->selectdb ("ntuple"); |
738 |
+ |
$results = $db->query ($query); |
739 |
+ |
} |
740 |
+ |
|
741 |
+ |
sub |
742 |
+ |
locationExists |
743 |
+ |
{ |
744 |
+ |
my $id = shift; |
745 |
+ |
my $location = shift; |
746 |
+ |
|
747 |
+ |
$location =~ s/^(.*)\/+$/$1/; |
748 |
+ |
my $query = "select id from ntuple where location like '$location%' and id!=$id"; |
749 |
+ |
$db->selectdb ("ntuple"); |
750 |
+ |
my $results = $db->query ($query); |
751 |
+ |
return 1 if $results->numrows (); |
752 |
+ |
|
753 |
+ |
if ($location =~ m/^\/store\/.*$/) |
754 |
+ |
{ |
755 |
+ |
$location =~ s/^\/store\/(.*)$/\/data\/se\/store\/$1/; |
756 |
+ |
} |
757 |
+ |
elsif ($location =~ m/^\/data\/se\/store\/.*$/) |
758 |
+ |
{ |
759 |
+ |
$location =~ s/^\/data\/se\/store\/(.*)$/\/store\/$1/; |
760 |
+ |
} |
761 |
+ |
|
762 |
+ |
my $query = "select id from ntuple where location like '$location%' and id!=$id"; |
763 |
+ |
$db->selectdb ("ntuple"); |
764 |
+ |
my $results = $db->query ($query); |
765 |
+ |
return 1 if $results->numrows (); |
766 |
+ |
|
767 |
+ |
return 0; |
768 |
+ |
} |