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", "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 ($opt{"location"} && locationExists ($opt{"location"})) |
46 |
> |
{ |
47 |
> |
print "This location is already registered in the database!\n"; |
48 |
|
exit; |
49 |
|
} |
50 |
|
if ($ARGV[0] eq "uploadRelease") |
56 |
|
$cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/; |
57 |
|
`tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`; |
58 |
|
$opt{"format"} = "BEAN" if !$opt{"format"}; |
59 |
< |
uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}", $opt{"comment"}); |
59 |
> |
uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}", $opt{"comment"}, $opt{"recipe"}); |
60 |
|
} |
61 |
|
elsif ($ARGV[0] eq "downloadRelease") |
62 |
|
{ |
63 |
|
downloadRelease ($ARGV[1], $opt{"pyConfig"}); |
64 |
|
} |
65 |
+ |
elsif ($ARGV[0] eq "uploadConfig") |
66 |
+ |
{ |
67 |
+ |
uploadConfig ($ARGV[1], $ENV{"USER"}, $opt{"pyConfig"}, $opt{"release"}, $opt{"comment"}); |
68 |
+ |
} |
69 |
|
elsif ($ARGV[0] eq "createOther") |
70 |
|
{ |
71 |
|
my @listOfFiles = @ARGV; |
72 |
|
@listOfFiles = reverse (@listOfFiles); |
73 |
|
pop (@listOfFiles); |
74 |
|
@listOfFiles = reverse (@listOfFiles); |
75 |
< |
dbOtherCreate ("$ENV{'USER'}", \@listOfFiles, $opt{"comment"}); |
75 |
> |
dbOtherCreate ("$ENV{'USER'}\@$ENV{'HOSTNAME'}", \@listOfFiles, $opt{"comment"}); |
76 |
|
} |
77 |
|
else |
78 |
|
{ |
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 $fileListName = shift; |
191 |
|
my $lumiSummaryName = shift; |
192 |
|
my $release = shift; |
193 |
|
|
194 |
+ |
my $user = $userAndHost; |
195 |
+ |
$user =~ s/@.*$//g; |
196 |
+ |
|
197 |
|
my $fileList; |
198 |
|
my $pset; |
199 |
|
my $crabCfg; |
293 |
|
my $query; |
294 |
|
if ($id < 0) |
295 |
|
{ |
296 |
+ |
$query = "select id from ntuple where dataset='$dataset'"; |
297 |
+ |
$db->selectdb ("ntuple"); |
298 |
+ |
$results = $db->query ($query); |
299 |
+ |
if ($results->numrows ()) |
300 |
+ |
{ |
301 |
+ |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
302 |
+ |
my $response = <STDIN>; |
303 |
+ |
$response =~ s/\n//g; |
304 |
+ |
$response = "n" if !$response; |
305 |
+ |
exit if substr (lc ($response), 0, 1) ne 'y'; |
306 |
+ |
} |
307 |
+ |
|
308 |
|
$query = "select max(id) from ntuple"; |
309 |
|
$db->selectdb ("ntuple"); |
310 |
|
$results = $db->query ($query); |
312 |
|
my $id = 1; |
313 |
|
$id = $row[0] + 1 if $results->numrows (); |
314 |
|
|
315 |
< |
$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')"; |
315 |
> |
$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')"; |
316 |
|
} |
317 |
|
if ($id > 0) |
318 |
|
{ |
430 |
|
elsif ($command eq "finish") |
431 |
|
{ |
432 |
|
print "Usage: $exeName -l DIRECTORY finish NAME\n"; |
402 |
– |
|
433 |
|
print "Finalizes the database entry for dataset NAME, changing its status to\n"; |
434 |
|
print "\"present\". This is intended to be the final step in command-line based ntuple\n"; |
435 |
|
print "production.\n"; |
455 |
|
} |
456 |
|
elsif ($command eq "uploadRelease") |
457 |
|
{ |
458 |
< |
print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n"; |
458 |
> |
print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n"; |
459 |
|
print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n"; |
460 |
|
print "database entry for it, with NAME being the name of the release. An ntuple\n"; |
461 |
|
print "release is a CMSSW release with all the necessary packages added for creating\n"; |
463 |
|
print "\n"; |
464 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
465 |
|
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
466 |
+ |
printf "%-29s%s\n", " -e, --recipe FILE", "file containing the recipe for the release"; |
467 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format (default: BEAN)"; |
468 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "default Python config for the release"; |
469 |
|
printf "%-29s%s\n", " -r, --release DIRECTORY", "CMSSW release containing ntuple packages"; |
477 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
478 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python configuration file name"; |
479 |
|
} |
480 |
+ |
elsif ($command eq "uploadConfig") |
481 |
+ |
{ |
482 |
+ |
print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadConfig NAME\n"; |
483 |
+ |
print "Creates an entry in the database for a customized Python configuration file.\n"; |
484 |
+ |
print "\n"; |
485 |
+ |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
486 |
+ |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
487 |
+ |
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config file"; |
488 |
+ |
printf "%-29s%s\n", " -r, --release NAME", "ntuple release with which to use this config"; |
489 |
+ |
} |
490 |
|
else |
491 |
|
{ |
492 |
|
print "Usage: $exeName [OPTION]... COMMAND NAME\n"; |
505 |
|
printf "%-29s%s\n", " deprecate", "marks the dataset for deletion"; |
506 |
|
printf "%-29s%s\n", " uploadRelease", "upload an ntuple release"; |
507 |
|
printf "%-29s%s\n", " downloadRelease", "download an ntuple release"; |
508 |
+ |
printf "%-29s%s\n", " uploadConfig", "upload an ntuple config"; |
509 |
|
} |
510 |
|
|
511 |
|
exit; |
559 |
|
my $name = shift; |
560 |
|
my $user = shift; |
561 |
|
my $comment = shift; |
562 |
+ |
my $recipeName = shift; |
563 |
|
|
521 |
– |
move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
564 |
|
if (!(-e $psetName)) |
565 |
|
{ |
566 |
|
print "$psetName does not exist!\n"; |
567 |
|
exit; |
568 |
|
} |
569 |
+ |
if (!(-e $recipeName)) |
570 |
+ |
{ |
571 |
+ |
print "$recipeName does not exist!\n"; |
572 |
+ |
exit; |
573 |
+ |
} |
574 |
+ |
move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
575 |
|
open (PY_CONFIG, "<$psetName"); |
576 |
|
my @pset = <PY_CONFIG>; |
577 |
|
close (PY_CONFIG); |
578 |
|
my $pset = join ("", @pset); |
579 |
+ |
open (RECIPE, "<$recipeName"); |
580 |
+ |
my @recipe = <RECIPE>; |
581 |
+ |
close (RECIPE); |
582 |
+ |
my $recipe = join ("\n", @recipe); |
583 |
|
|
584 |
|
my $query = "select max(id) from ntupleRelease"; |
585 |
|
$db->selectdb ("ntuple"); |
594 |
|
$format = addSlashes ($format); |
595 |
|
$cmsswRelease = addSlashes ($cmsswRelease); |
596 |
|
$comment = addSlashes ($comment); |
597 |
+ |
$recipe = addSlashes ($recipe); |
598 |
|
|
599 |
< |
my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment')"; |
599 |
> |
my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')"; |
600 |
|
$db->selectdb ("ntuple"); |
601 |
|
my $results = $db->query ($query); |
602 |
|
} |
633 |
|
sub |
634 |
|
dbOtherCreate |
635 |
|
{ |
636 |
< |
my $user = shift; |
636 |
> |
my $userAndHost = shift; |
637 |
|
my $listOfFiles = shift; |
638 |
|
my $comment = shift; |
639 |
|
|
640 |
+ |
my $user = $userAndHost; |
641 |
+ |
$user =~ s/@.*$//g; |
642 |
+ |
|
643 |
|
my $size = 0.0; |
644 |
|
my $nFiles = 0.0; |
645 |
|
for (my $i = 0; $i < @$listOfFiles; $i++) |
670 |
|
$location = addSlashes ($location); |
671 |
|
$comment = addSlashes ($comment); |
672 |
|
|
673 |
< |
my $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$user', '$location', $nFiles, $size, '$comment')"; |
673 |
> |
$query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$userAndHost', '$user', '$location', $nFiles, $size, '$comment')"; |
674 |
|
$db->selectdb ("ntuple"); |
675 |
< |
my $results = $db->query ($query); |
675 |
> |
$results = $db->query ($query); |
676 |
|
|
677 |
|
print "ID $id\n"; |
678 |
|
} |
679 |
+ |
|
680 |
+ |
sub |
681 |
+ |
uploadConfig |
682 |
+ |
{ |
683 |
+ |
my $name = shift; |
684 |
+ |
my $user = shift; |
685 |
+ |
my $psetName = shift; |
686 |
+ |
my $release = shift; |
687 |
+ |
my $comment = shift; |
688 |
+ |
|
689 |
+ |
if (!(-e $psetName)) |
690 |
+ |
{ |
691 |
+ |
print "$psetName does not exist!\n"; |
692 |
+ |
exit; |
693 |
+ |
} |
694 |
+ |
if ($release) |
695 |
+ |
{ |
696 |
+ |
my $query = "select id from ntupleRelease where name='$release'"; |
697 |
+ |
$db->selectdb ("ntuple"); |
698 |
+ |
my $results = $db->query ($query); |
699 |
+ |
if ($results->numrows () != 1) |
700 |
+ |
{ |
701 |
+ |
print "Ntuple release \"$release\" not found!\n"; |
702 |
+ |
exit; |
703 |
+ |
} |
704 |
+ |
} |
705 |
+ |
open (PSET, "<$psetName"); |
706 |
+ |
my @pset = <PSET>; |
707 |
+ |
close (PSET); |
708 |
+ |
my $pset = join ("", @pset); |
709 |
+ |
|
710 |
+ |
my $query = "select max(id) from ntupleConfig"; |
711 |
+ |
$db->selectdb ("ntuple"); |
712 |
+ |
my $results = $db->query ($query); |
713 |
+ |
my @row = $results->fetchrow (); |
714 |
+ |
my $id = 1; |
715 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
716 |
+ |
|
717 |
+ |
$name = addSlashes ($name); |
718 |
+ |
$user = addSlashes ($user); |
719 |
+ |
$pset = addSlashes ($pset); |
720 |
+ |
$release = addSlashes ($release); |
721 |
+ |
$comment = addSlashes ($comment); |
722 |
+ |
|
723 |
+ |
my $query = "insert into ntupleConfig (id, name, pset, user, pending, ntupleRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$release', '$comment')"; |
724 |
+ |
$db->selectdb ("ntuple"); |
725 |
+ |
$results = $db->query ($query); |
726 |
+ |
} |
727 |
+ |
|
728 |
+ |
sub |
729 |
+ |
locationExists |
730 |
+ |
{ |
731 |
+ |
my $location = shift; |
732 |
+ |
|
733 |
+ |
$location =~ s/^(.*)\/+$/$1/; |
734 |
+ |
my $query = "select id from ntuple where location like '$location%'"; |
735 |
+ |
$db->selectdb ("ntuple"); |
736 |
+ |
my $results = $db->query ($query); |
737 |
+ |
return 1 if $results->numrows (); |
738 |
+ |
|
739 |
+ |
if ($location =~ m/^\/store\/.*$/) |
740 |
+ |
{ |
741 |
+ |
$location =~ s/^\/store\/(.*)$/\/data\/se\/store\/$1/; |
742 |
+ |
} |
743 |
+ |
elsif ($location =~ m/^\/data\/se\/store\/.*$/) |
744 |
+ |
{ |
745 |
+ |
$location =~ s/^\/data\/se\/store\/(.*)$/\/store\/$1/; |
746 |
+ |
} |
747 |
+ |
|
748 |
+ |
my $query = "select id from ntuple where location like '$location%'"; |
749 |
+ |
$db->selectdb ("ntuple"); |
750 |
+ |
my $results = $db->query ($query); |
751 |
+ |
return 1 if $results->numrows (); |
752 |
+ |
|
753 |
+ |
return 0; |
754 |
+ |
} |