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", "recipe|e=s", "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", "globalTag|g=s", "configName|i=s", "help|h"); |
25 |
|
my $argc = @ARGV; |
26 |
|
|
27 |
|
printHelp ($ARGV[0]) if $opt{"help"}; |
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"}, $opt{"globalTag"}, $opt{"configName"}) 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"}; |
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; |
191 |
|
my $jsonFileName = shift; |
192 |
|
my $lumiSummaryName = shift; |
193 |
|
my $release = shift; |
194 |
+ |
my $globalTag = shift; |
195 |
+ |
my $configName = shift; |
196 |
|
|
197 |
|
my $user = $userAndHost; |
198 |
|
$user =~ s/@.*$//g; |
264 |
|
close (LUMI_SUMMARY); |
265 |
|
$lumiSummary = join ("", @lumiSummary); |
266 |
|
} |
267 |
< |
if ($release) |
259 |
< |
{ |
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 |
< |
} |
267 |
> |
$release .= ".$configName" if $configName; |
268 |
|
($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList); |
269 |
|
my $fullLocation = $location; |
270 |
|
$fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//); |
277 |
|
$jsonFile = addSlashes ($jsonFile); |
278 |
|
$lumiSummary = addSlashes ($lumiSummary); |
279 |
|
$fullLocation = addSlashes ($fullLocation); |
280 |
+ |
$name = addSlashes ($name); |
281 |
|
$fileList = addSlashes ($fileList); |
282 |
|
$status = addSlashes ($status); |
283 |
|
$comment = addSlashes ($comment); |
284 |
|
$release = addSlashes ($release); |
285 |
+ |
$globalTag = addSlashes ($globalTag); |
286 |
|
|
287 |
|
my $results; |
288 |
|
my $query; |
289 |
|
if ($id < 0) |
290 |
|
{ |
291 |
+ |
$query = "select id from ntuple where dataset='$dataset'"; |
292 |
+ |
$db->selectdb ("ntuple"); |
293 |
+ |
$results = $db->query ($query); |
294 |
+ |
if ($results->numrows ()) |
295 |
+ |
{ |
296 |
+ |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
297 |
+ |
my $response = <STDIN>; |
298 |
+ |
$response =~ s/\n//g; |
299 |
+ |
$response = "n" if !$response; |
300 |
+ |
exit if substr (lc ($response), 0, 1) ne 'y'; |
301 |
+ |
} |
302 |
+ |
|
303 |
|
$query = "select max(id) from ntuple"; |
304 |
|
$db->selectdb ("ntuple"); |
305 |
|
$results = $db->query ($query); |
307 |
|
my $id = 1; |
308 |
|
$id = $row[0] + 1 if $results->numrows (); |
309 |
|
|
310 |
< |
$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')"; |
310 |
> |
$query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version, globalTag) values ($id, '$dataset', now(), now(), '$userAndHost', '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release', '$globalTag')"; |
311 |
|
} |
312 |
|
if ($id > 0) |
313 |
|
{ |
314 |
|
my $fields; |
315 |
|
my $values; |
316 |
|
|
317 |
< |
$values .= ", dataset='$dataset'" if $dataset; |
317 |
> |
if ($name) |
318 |
> |
{ |
319 |
> |
$query = "select id from ntuple where dataset='$name'"; |
320 |
> |
$db->selectdb ("ntuple"); |
321 |
> |
$results = $db->query ($query); |
322 |
> |
if ($results->numrows ()) |
323 |
> |
{ |
324 |
> |
print "This dataset already exists in the database. Create anyway? (y/N): "; |
325 |
> |
my $response = <STDIN>; |
326 |
> |
$response =~ s/\n//g; |
327 |
> |
$response = "n" if !$response; |
328 |
> |
exit if substr (lc ($response), 0, 1) ne 'y'; |
329 |
> |
} |
330 |
> |
$values .= ", dataset='$name'"; |
331 |
> |
} |
332 |
> |
|
333 |
|
$values .= ", lastUpdateTime=now()"; |
334 |
|
$values .= ", lastUpdateUser='$user'"; |
335 |
|
$values .= ", format='$format'" if $format; |
344 |
|
$values .= ", jsonFile='$jsonFile'" if $jsonFile; |
345 |
|
$values .= ", lumiSummary='$lumiSummary'" if $lumiSummary; |
346 |
|
$values .= ", version='$release'" if $release; |
347 |
+ |
$values .= ", globalTag='$globalTag'" if $globalTag; |
348 |
|
|
349 |
|
$values =~ s/^, //; |
350 |
|
$query = "update ntuple set $values where id=$id"; |
408 |
|
printf "%-29s%s\n", " -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs"; |
409 |
|
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
410 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format (default: BEAN)"; |
411 |
+ |
printf "%-29s%s\n", " -g, --globalTag TAG", "global tag"; |
412 |
+ |
printf "%-29s%s\n", " -i, --configName NAME", "name of config used to produce ntuples"; |
413 |
|
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
414 |
|
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
415 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
433 |
|
printf "%-29s%s\n", " -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs"; |
434 |
|
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
435 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format"; |
436 |
+ |
printf "%-29s%s\n", " -g, --globalTag TAG", "global tag"; |
437 |
+ |
printf "%-29s%s\n", " -i, --configName NAME", "name of config used to produce ntuples"; |
438 |
|
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
439 |
|
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
440 |
+ |
printf "%-29s%s\n", " -n, --name NAME", "rename the entry"; |
441 |
|
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
442 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
443 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
495 |
|
} |
496 |
|
elsif ($command eq "uploadConfig") |
497 |
|
{ |
498 |
< |
print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadConfig NAME\n"; |
498 |
> |
print "Usage: $exeName -p FILE -r RELEASE [OPTION]... uploadConfig NAME\n"; |
499 |
|
print "Creates an entry in the database for a customized Python configuration file.\n"; |
500 |
|
print "\n"; |
501 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
587 |
|
print "$recipeName does not exist!\n"; |
588 |
|
exit; |
589 |
|
} |
590 |
< |
move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
590 |
> |
move ($release, "/home/osucms/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
591 |
|
open (PY_CONFIG, "<$psetName"); |
592 |
|
my @pset = <PY_CONFIG>; |
593 |
|
close (PY_CONFIG); |
631 |
|
print "Ntuple release \"$release\" not found!\n"; |
632 |
|
exit; |
633 |
|
} |
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 |
– |
} |
634 |
|
if ($pyConfigName) |
635 |
|
{ |
636 |
|
my @row = $results->fetchrow (); |
638 |
|
print PY_CONFIG $row[1]; |
639 |
|
close (PY_CONFIG); |
640 |
|
} |
641 |
< |
copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz"); |
641 |
> |
`wget "http://cmshead.mps.ohio-state.edu/~osucms/releases/$release.tar.gz"`; |
642 |
|
} |
643 |
|
|
644 |
|
sub |
735 |
|
$db->selectdb ("ntuple"); |
736 |
|
$results = $db->query ($query); |
737 |
|
} |
738 |
+ |
|
739 |
+ |
sub |
740 |
+ |
locationExists |
741 |
+ |
{ |
742 |
+ |
my $id = shift; |
743 |
+ |
my $location = shift; |
744 |
+ |
|
745 |
+ |
$location =~ s/^(.*)\/+$/$1/; |
746 |
+ |
my $query = "select id from ntuple where location like '$location%' and id!=$id"; |
747 |
+ |
$db->selectdb ("ntuple"); |
748 |
+ |
my $results = $db->query ($query); |
749 |
+ |
return 1 if $results->numrows (); |
750 |
+ |
|
751 |
+ |
if ($location =~ m/^\/store\/.*$/) |
752 |
+ |
{ |
753 |
+ |
$location =~ s/^\/store\/(.*)$/\/data\/se\/store\/$1/; |
754 |
+ |
} |
755 |
+ |
elsif ($location =~ m/^\/data\/se\/store\/.*$/) |
756 |
+ |
{ |
757 |
+ |
$location =~ s/^\/data\/se\/store\/(.*)$/\/store\/$1/; |
758 |
+ |
} |
759 |
+ |
|
760 |
+ |
my $query = "select id from ntuple where location like '$location%' and id!=$id"; |
761 |
+ |
$db->selectdb ("ntuple"); |
762 |
+ |
my $results = $db->query ($query); |
763 |
+ |
return 1 if $results->numrows (); |
764 |
+ |
|
765 |
+ |
return 0; |
766 |
+ |
} |