7 |
|
|
8 |
|
sub getDataset; |
9 |
|
sub dbUpdate; |
10 |
+ |
sub dbUpdateOther; |
11 |
|
sub dbDelete; |
12 |
+ |
sub dbDeleteOther; |
13 |
|
sub addSlashes; |
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", "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"}; |
28 |
< |
printHelp () if $argc != 2; |
29 |
< |
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"; |
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" && $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] ne "uploadRelease") |
40 |
> |
if ($ARGV[0] eq "uploadConfig" && (!$opt{"pyConfig"} || !$opt{"release"})) |
41 |
|
{ |
42 |
< |
my $id = -1; |
43 |
< |
my $fullDataset; |
38 |
< |
($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create"; |
39 |
< |
$fullDataset = $ARGV[1] if $id < 0; |
40 |
< |
$ARGV[0] = "create" if $id < 0; |
41 |
< |
my $status = "present"; |
42 |
< |
$status = "" if $ARGV[0] eq "update"; |
43 |
< |
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
44 |
< |
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
45 |
< |
dbUpdate ($id, $fullDataset, $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"}); |
46 |
< |
dbDelete ($id) if $ARGV[0] eq "deleteEntry"; |
42 |
> |
print "The Python config and ntuple release must be given!\n"; |
43 |
> |
exit; |
44 |
|
} |
45 |
< |
else |
45 |
> |
if ($ARGV[0] eq "uploadRelease") |
46 |
|
{ |
47 |
|
my $parentDir = "./$opt{'release'}"; |
48 |
|
$parentDir =~ s/CMSSW_[^\/]*//g; |
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'}\@$ENV{'HOSTNAME'}", \@listOfFiles, $opt{"comment"}); |
71 |
> |
} |
72 |
> |
else |
73 |
> |
{ |
74 |
> |
my $id = -1; |
75 |
> |
my $fullDataset; |
76 |
> |
($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create" && ($ARGV[0] ne "update" || !$opt{"other"}) && ($ARGV[0] ne "deleteEntry" || !$opt{"other"}); |
77 |
> |
$id = $ARGV[1] if ($ARGV[0] eq "update" && $opt{"other"}) || ($ARGV[0] eq "deleteEntry" && $opt{"other"}); |
78 |
> |
$fullDataset = $ARGV[1] if $id < 0; |
79 |
> |
$ARGV[0] = "create" if $id < 0; |
80 |
> |
my $status = "present"; |
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 |
> |
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"}; |
93 |
|
} |
94 |
|
|
95 |
|
sub |
115 |
|
my $queryDataset = $dataset; |
116 |
|
$queryDataset =~ s/\*/%/g; |
117 |
|
$queryDataset =~ s/(.*)/%$1%/g; |
118 |
< |
my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by lastUpdateTime"; |
118 |
> |
my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by creationTime"; |
119 |
|
$db->selectdb ("ntuple"); |
120 |
|
$results = $db->query ($query); |
121 |
|
if ($results->numrows () == 1) |
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; |
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; |
199 |
|
|
200 |
|
my $fileList; |
201 |
|
my $pset; |
264 |
|
close (LUMI_SUMMARY); |
265 |
|
$lumiSummary = join ("", @lumiSummary); |
266 |
|
} |
267 |
< |
if ($release) |
227 |
< |
{ |
228 |
< |
my $query = "select id from ntupleRelease where name='$release'"; |
229 |
< |
$db->selectdb ("ntuple"); |
230 |
< |
my $results = $db->query ($query); |
231 |
< |
if ($results->numrows () != 1) |
232 |
< |
{ |
233 |
< |
print "Ntuple release \"$release\" not found!\n"; |
234 |
< |
exit; |
235 |
< |
} |
236 |
< |
} |
267 |
> |
$release .= ".$configName" if $configName; |
268 |
|
($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList); |
269 |
< |
my $fullLocation = "$ENV{'PWD'}/$location"; |
269 |
> |
my $fullLocation = $location; |
270 |
> |
$fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//); |
271 |
|
|
272 |
|
$dataset = addSlashes ($dataset); |
273 |
|
$user = addSlashes ($user); |
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, 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')"; |
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; |
336 |
|
$values .= ", location='$fullLocation'" if $location; |
337 |
|
$values .= ", fileList='$fileList'" if $fileList; |
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"; |
355 |
|
} |
356 |
|
|
357 |
|
sub |
358 |
+ |
dbUpdateOther |
359 |
+ |
{ |
360 |
+ |
my $id = shift; |
361 |
+ |
my $comment = shift; |
362 |
+ |
my $user = shift; |
363 |
+ |
|
364 |
+ |
$comment = addSlashes ($comment); |
365 |
+ |
|
366 |
+ |
my $query = "update other set lastUpdateTime=now(), lastUpdateUser='$user', comment='$comment' where id=$id"; |
367 |
+ |
$db->selectdb ("ntuple"); |
368 |
+ |
my $results = $db->query ($query); |
369 |
+ |
|
370 |
+ |
return $results; |
371 |
+ |
} |
372 |
+ |
|
373 |
+ |
sub |
374 |
|
dbDelete |
375 |
|
{ |
376 |
|
my $id = shift; |
377 |
|
|
299 |
– |
return if $id < 0; |
378 |
|
my $query = "delete from ntuple where id=$id"; |
379 |
|
$db->selectdb ("ntuple"); |
380 |
|
my $results = $db->query ($query); |
381 |
|
} |
382 |
|
|
383 |
|
sub |
384 |
+ |
dbDeleteOther |
385 |
+ |
{ |
386 |
+ |
my $id = shift; |
387 |
+ |
|
388 |
+ |
my $query = "delete from other where id=$id"; |
389 |
+ |
$db->selectdb ("ntuple"); |
390 |
+ |
my $results = $db->query ($query); |
391 |
+ |
} |
392 |
+ |
|
393 |
+ |
sub |
394 |
|
printHelp |
395 |
|
{ |
396 |
|
my $command = shift; |
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"; |
416 |
|
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
417 |
|
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
418 |
|
} |
419 |
+ |
elsif ($command eq "createOther") |
420 |
+ |
{ |
421 |
+ |
print "Usage: $exeName [OPTION]... createOther DIRECTORIES_AND_FILES\n"; |
422 |
+ |
print "Creates an entry in the database for non-ntuple data.\n"; |
423 |
+ |
print "\n"; |
424 |
+ |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
425 |
+ |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
426 |
+ |
} |
427 |
|
elsif ($command eq "update") |
428 |
|
{ |
429 |
|
print "Usage: $exeName [OPTION]... update NAME\n"; |
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"; |
444 |
|
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
446 |
|
elsif ($command eq "finish") |
447 |
|
{ |
448 |
|
print "Usage: $exeName -l DIRECTORY finish NAME\n"; |
347 |
– |
|
449 |
|
print "Finalizes the database entry for dataset NAME, changing its status to\n"; |
450 |
|
print "\"present\". This is intended to be the final step in command-line based ntuple\n"; |
451 |
|
print "production.\n"; |
455 |
|
} |
456 |
|
elsif ($command eq "deleteEntry") |
457 |
|
{ |
458 |
< |
print "Usage: $exeName deleteEntry NAME\n"; |
458 |
> |
print "Usage: $exeName [OPTION]... deleteEntry NAME\n"; |
459 |
|
print "Deletes the database entry for dataset NAME. This is intended primarily for\n"; |
460 |
|
print "mistaken database entries. If you wish to actually delete a set of ntuples,\n"; |
461 |
|
print "please use the \"deprecate\" command instead.\n"; |
462 |
+ |
print "\n"; |
463 |
+ |
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
464 |
|
} |
465 |
|
elsif ($command eq "deprecate") |
466 |
|
{ |
471 |
|
} |
472 |
|
elsif ($command eq "uploadRelease") |
473 |
|
{ |
474 |
< |
print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n"; |
474 |
> |
print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n"; |
475 |
|
print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n"; |
476 |
|
print "database entry for it, with NAME being the name of the release. An ntuple\n"; |
477 |
|
print "release is a CMSSW release with all the necessary packages added for creating\n"; |
479 |
|
print "\n"; |
480 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
481 |
|
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
482 |
+ |
printf "%-29s%s\n", " -e, --recipe FILE", "file containing the recipe for the release"; |
483 |
|
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format (default: BEAN)"; |
484 |
|
printf "%-29s%s\n", " -p, --pyConfig FILE", "default Python config for the release"; |
485 |
|
printf "%-29s%s\n", " -r, --release DIRECTORY", "CMSSW release containing ntuple packages"; |
486 |
|
} |
487 |
+ |
elsif ($command eq "downloadRelease") |
488 |
+ |
{ |
489 |
+ |
print "Usage: $exeName [OPTION]... downloadRelease NAME\n"; |
490 |
+ |
print "Copies an ntuple release to the current directory on the Tier 3. Optionally\n"; |
491 |
+ |
print "copies the corresponding Python configuration file registered in the database.\n"; |
492 |
+ |
print "\n"; |
493 |
+ |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
494 |
+ |
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python configuration file name"; |
495 |
+ |
} |
496 |
+ |
elsif ($command eq "uploadConfig") |
497 |
+ |
{ |
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"; |
502 |
+ |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
503 |
+ |
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config file"; |
504 |
+ |
printf "%-29s%s\n", " -r, --release NAME", "ntuple release with which to use this config"; |
505 |
+ |
} |
506 |
|
else |
507 |
|
{ |
508 |
|
print "Usage: $exeName [OPTION]... COMMAND NAME\n"; |
514 |
|
print "\n"; |
515 |
|
print "COMMAND may be one of the following:\n"; |
516 |
|
printf "%-29s%s\n", " create", "creates the entry"; |
517 |
+ |
printf "%-29s%s\n", " createOther", "creates an entry for non-ntuple data"; |
518 |
|
printf "%-29s%s\n", " update", "updates the entry"; |
519 |
|
printf "%-29s%s\n", " finish", "finalizes the database entry"; |
520 |
|
printf "%-29s%s\n", " deleteEntry", "removes the database entry"; |
521 |
|
printf "%-29s%s\n", " deprecate", "marks the dataset for deletion"; |
522 |
|
printf "%-29s%s\n", " uploadRelease", "upload an ntuple release"; |
523 |
+ |
printf "%-29s%s\n", " downloadRelease", "download an ntuple release"; |
524 |
+ |
printf "%-29s%s\n", " uploadConfig", "upload an ntuple config"; |
525 |
|
} |
526 |
|
|
527 |
|
exit; |
575 |
|
my $name = shift; |
576 |
|
my $user = shift; |
577 |
|
my $comment = shift; |
578 |
+ |
my $recipeName = shift; |
579 |
|
|
453 |
– |
move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
580 |
|
if (!(-e $psetName)) |
581 |
|
{ |
582 |
|
print "$psetName does not exist!\n"; |
583 |
|
exit; |
584 |
|
} |
585 |
+ |
if (!(-e $recipeName)) |
586 |
+ |
{ |
587 |
+ |
print "$recipeName does not exist!\n"; |
588 |
+ |
exit; |
589 |
+ |
} |
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); |
594 |
|
my $pset = join ("", @pset); |
595 |
+ |
open (RECIPE, "<$recipeName"); |
596 |
+ |
my @recipe = <RECIPE>; |
597 |
+ |
close (RECIPE); |
598 |
+ |
my $recipe = join ("\n", @recipe); |
599 |
|
|
600 |
|
my $query = "select max(id) from ntupleRelease"; |
601 |
|
$db->selectdb ("ntuple"); |
610 |
|
$format = addSlashes ($format); |
611 |
|
$cmsswRelease = addSlashes ($cmsswRelease); |
612 |
|
$comment = addSlashes ($comment); |
613 |
+ |
$recipe = addSlashes ($recipe); |
614 |
|
|
615 |
< |
my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment')"; |
615 |
> |
my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')"; |
616 |
|
$db->selectdb ("ntuple"); |
617 |
|
my $results = $db->query ($query); |
618 |
|
} |
619 |
+ |
|
620 |
+ |
sub |
621 |
+ |
downloadRelease |
622 |
+ |
{ |
623 |
+ |
my $release = shift; |
624 |
+ |
my $pyConfigName = shift; |
625 |
+ |
|
626 |
+ |
my $query = "select id,pset from ntupleRelease where name='$release'"; |
627 |
+ |
$db->selectdb ("ntuple"); |
628 |
+ |
my $results = $db->query ($query); |
629 |
+ |
if ($results->numrows () != 1) |
630 |
+ |
{ |
631 |
+ |
print "Ntuple release \"$release\" not found!\n"; |
632 |
+ |
exit; |
633 |
+ |
} |
634 |
+ |
if ($pyConfigName) |
635 |
+ |
{ |
636 |
+ |
my @row = $results->fetchrow (); |
637 |
+ |
open (PY_CONFIG, ">$pyConfigName"); |
638 |
+ |
print PY_CONFIG $row[1]; |
639 |
+ |
close (PY_CONFIG); |
640 |
+ |
} |
641 |
+ |
`wget "http://cmshead.mps.ohio-state.edu/~osucms/releases/$release.tar.gz"`; |
642 |
+ |
} |
643 |
+ |
|
644 |
+ |
sub |
645 |
+ |
dbOtherCreate |
646 |
+ |
{ |
647 |
+ |
my $userAndHost = shift; |
648 |
+ |
my $listOfFiles = shift; |
649 |
+ |
my $comment = shift; |
650 |
+ |
|
651 |
+ |
my $user = $userAndHost; |
652 |
+ |
$user =~ s/@.*$//g; |
653 |
+ |
|
654 |
+ |
my $size = 0.0; |
655 |
+ |
my $nFiles = 0.0; |
656 |
+ |
for (my $i = 0; $i < @$listOfFiles; $i++) |
657 |
+ |
{ |
658 |
+ |
if (!(-e $$listOfFiles[$i])) |
659 |
+ |
{ |
660 |
+ |
print "$$listOfFiles[$i] does not exist!\n"; |
661 |
+ |
exit; |
662 |
+ |
} |
663 |
+ |
$nFiles += `ls -R $$listOfFiles[$i] | grep -v ':\$' | grep -v '^\$' | wc -l`; |
664 |
+ |
my $fileSize = `du -s $$listOfFiles[$i]`; |
665 |
+ |
$fileSize =~ s/([^ ]*) .*/$1/; |
666 |
+ |
$fileSize /= 1024 * 1024; |
667 |
+ |
$size += $fileSize; |
668 |
+ |
$$listOfFiles[$i] = "$ENV{'PWD'}/$$listOfFiles[$i]" if !($$listOfFiles[$i] =~ m/^\//); |
669 |
+ |
} |
670 |
+ |
$size = sprintf "%.2f", $size; |
671 |
+ |
my $location = join ("<br />", @$listOfFiles); |
672 |
+ |
|
673 |
+ |
my $query = "select max(id) from other"; |
674 |
+ |
$db->selectdb ("ntuple"); |
675 |
+ |
my $results = $db->query ($query); |
676 |
+ |
my @row = $results->fetchrow (); |
677 |
+ |
my $id = 1; |
678 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
679 |
+ |
|
680 |
+ |
$user = addSlashes ($user); |
681 |
+ |
$location = addSlashes ($location); |
682 |
+ |
$comment = addSlashes ($comment); |
683 |
+ |
|
684 |
+ |
$query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$userAndHost', '$user', '$location', $nFiles, $size, '$comment')"; |
685 |
+ |
$db->selectdb ("ntuple"); |
686 |
+ |
$results = $db->query ($query); |
687 |
+ |
|
688 |
+ |
print "ID $id\n"; |
689 |
+ |
} |
690 |
+ |
|
691 |
+ |
sub |
692 |
+ |
uploadConfig |
693 |
+ |
{ |
694 |
+ |
my $name = shift; |
695 |
+ |
my $user = shift; |
696 |
+ |
my $psetName = shift; |
697 |
+ |
my $release = shift; |
698 |
+ |
my $comment = shift; |
699 |
+ |
|
700 |
+ |
if (!(-e $psetName)) |
701 |
+ |
{ |
702 |
+ |
print "$psetName does not exist!\n"; |
703 |
+ |
exit; |
704 |
+ |
} |
705 |
+ |
if ($release) |
706 |
+ |
{ |
707 |
+ |
my $query = "select id from ntupleRelease where name='$release'"; |
708 |
+ |
$db->selectdb ("ntuple"); |
709 |
+ |
my $results = $db->query ($query); |
710 |
+ |
if ($results->numrows () != 1) |
711 |
+ |
{ |
712 |
+ |
print "Ntuple release \"$release\" not found!\n"; |
713 |
+ |
exit; |
714 |
+ |
} |
715 |
+ |
} |
716 |
+ |
open (PSET, "<$psetName"); |
717 |
+ |
my @pset = <PSET>; |
718 |
+ |
close (PSET); |
719 |
+ |
my $pset = join ("", @pset); |
720 |
+ |
|
721 |
+ |
my $query = "select max(id) from ntupleConfig"; |
722 |
+ |
$db->selectdb ("ntuple"); |
723 |
+ |
my $results = $db->query ($query); |
724 |
+ |
my @row = $results->fetchrow (); |
725 |
+ |
my $id = 1; |
726 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
727 |
+ |
|
728 |
+ |
$name = addSlashes ($name); |
729 |
+ |
$user = addSlashes ($user); |
730 |
+ |
$pset = addSlashes ($pset); |
731 |
+ |
$release = addSlashes ($release); |
732 |
+ |
$comment = addSlashes ($comment); |
733 |
+ |
|
734 |
+ |
my $query = "insert into ntupleConfig (id, name, pset, user, pending, ntupleRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$release', '$comment')"; |
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 |
+ |
} |