3 |
|
use strict; |
4 |
|
use Mysql; |
5 |
|
use Getopt::Long; |
6 |
+ |
use File::Copy; |
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 |
|
|
19 |
< |
our $db; |
19 |
> |
our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped"; |
20 |
|
|
21 |
|
my %opt; |
22 |
|
Getopt::Long::Configure ("bundling"); |
23 |
< |
GetOptions (\%opt, "comment|c=s", "format|f=s", "pyConfig|p=s", "crabCfg|b=s", "jsonFile|j=s", "remoteLocation|r=s", "lumiSummary|s=s", "location|l=s", "help|h"); |
23 |
> |
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 |
|
my $argc = @ARGV; |
25 |
|
|
26 |
< |
printHelp () if $opt{"help"}; |
27 |
< |
printHelp () if $argc != 2; |
28 |
< |
printHelp () if $ARGV[0] != "create" && $ARGV[0] != "update" && $ARGV[0] != "finish" && $ARGV[0] != "deprecate"; |
29 |
< |
my $id = -1; |
30 |
< |
$id = getDataset ($ARGV[1]) if $ARGV[0] ne "create"; |
31 |
< |
$ARGV[0] = "create" if $id < 0; |
32 |
< |
my $status = "present"; |
33 |
< |
$status = "" if $ARGV[0] eq "update"; |
34 |
< |
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
35 |
< |
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
36 |
< |
dbUpdate ($id, $ARGV[1], $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"remoteLocation"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}); |
26 |
> |
printHelp ($ARGV[0]) if $opt{"help"}; |
27 |
> |
printHelp () if $argc != 2 && $ARGV[0] ne "createOther"; |
28 |
> |
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"; |
29 |
> |
if (($ARGV[0] eq "create" || $ARGV[0] eq "finish") && !$opt{"location"}) |
30 |
> |
{ |
31 |
> |
print "The directory containing the ntuples must be given!\n"; |
32 |
> |
exit; |
33 |
> |
} |
34 |
> |
if ($ARGV[0] eq "uploadRelease" && (!$opt{"pyConfig"} || !$opt{"release"} || !$opt{"recipe"})) |
35 |
> |
{ |
36 |
> |
print "The Python config, CMSSW release directory, and recipe file must be given!\n"; |
37 |
> |
exit; |
38 |
> |
} |
39 |
> |
if ($ARGV[0] eq "uploadConfig" && (!$opt{"pyConfig"} || !$opt{"release"})) |
40 |
> |
{ |
41 |
> |
print "The Python config and ntuple release must be given!\n"; |
42 |
> |
exit; |
43 |
> |
} |
44 |
> |
if ($ARGV[0] eq "uploadRelease") |
45 |
> |
{ |
46 |
> |
my $parentDir = "./$opt{'release'}"; |
47 |
> |
$parentDir =~ s/CMSSW_[^\/]*//g; |
48 |
> |
$parentDir =~ s/\/\/*/\//g; |
49 |
> |
my $cmsswRelease = $opt{'release'}; |
50 |
> |
$cmsswRelease =~ s/^.*CMSSW_([^\/]*).*$/CMSSW_$1/; |
51 |
> |
`tar -C $parentDir -czf $ARGV[1].tar.gz $opt{"release"}`; |
52 |
> |
$opt{"format"} = "BEAN" if !$opt{"format"}; |
53 |
> |
uploadRelease ($opt{"format"}, $cmsswRelease, "$ARGV[1].tar.gz", $opt{"pyConfig"}, $ARGV[1], "$ENV{'USER'}", $opt{"comment"}, $opt{"recipe"}); |
54 |
> |
} |
55 |
> |
elsif ($ARGV[0] eq "downloadRelease") |
56 |
> |
{ |
57 |
> |
downloadRelease ($ARGV[1], $opt{"pyConfig"}); |
58 |
> |
} |
59 |
> |
elsif ($ARGV[0] eq "uploadConfig") |
60 |
> |
{ |
61 |
> |
uploadConfig ($ARGV[1], $ENV{"USER"}, $opt{"pyConfig"}, $opt{"release"}, $opt{"comment"}); |
62 |
> |
} |
63 |
> |
elsif ($ARGV[0] eq "createOther") |
64 |
> |
{ |
65 |
> |
my @listOfFiles = @ARGV; |
66 |
> |
@listOfFiles = reverse (@listOfFiles); |
67 |
> |
pop (@listOfFiles); |
68 |
> |
@listOfFiles = reverse (@listOfFiles); |
69 |
> |
dbOtherCreate ("$ENV{'USER'}", \@listOfFiles, $opt{"comment"}); |
70 |
> |
} |
71 |
> |
else |
72 |
> |
{ |
73 |
> |
my $id = -1; |
74 |
> |
my $fullDataset; |
75 |
> |
($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create" && ($ARGV[0] ne "update" || !$opt{"other"}) && ($ARGV[0] ne "deleteEntry" || !$opt{"other"}); |
76 |
> |
$id = $ARGV[1] if ($ARGV[0] eq "update" && $opt{"other"}) || ($ARGV[0] eq "deleteEntry" && $opt{"other"}); |
77 |
> |
$fullDataset = $ARGV[1] if $id < 0; |
78 |
> |
$ARGV[0] = "create" if $id < 0; |
79 |
> |
my $status = "present"; |
80 |
> |
$status = "" if $ARGV[0] eq "update"; |
81 |
> |
$status = "deprecated" if $ARGV[0] eq "deprecate"; |
82 |
> |
$opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"}; |
83 |
> |
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 |
> |
dbUpdateOther ($id, $opt{"comment"}, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $opt{"other"}; |
85 |
> |
dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"}; |
86 |
> |
dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"}; |
87 |
> |
} |
88 |
|
|
89 |
|
sub |
90 |
|
addSlashes |
102 |
|
sub |
103 |
|
getDataset |
104 |
|
{ |
105 |
+ |
my $command = shift; |
106 |
|
my $dataset = shift; |
107 |
|
|
108 |
|
my $results; |
109 |
|
my $queryDataset = $dataset; |
110 |
|
$queryDataset =~ s/\*/%/g; |
111 |
|
$queryDataset =~ s/(.*)/%$1%/g; |
112 |
< |
$db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User"); |
53 |
< |
my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by lastUpdateTime"; |
112 |
> |
my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by creationTime"; |
113 |
|
$db->selectdb ("ntuple"); |
114 |
|
$results = $db->query ($query); |
115 |
|
if ($results->numrows () == 1) |
116 |
|
{ |
117 |
|
my @row = $results->fetchrow (); |
118 |
< |
return $row[0]; |
118 |
> |
return ($row[0], $row[1]); |
119 |
|
} |
120 |
|
if ($results->numrows () == 0) |
121 |
|
{ |
122 |
< |
print "Database entry does not exist. Create it? (Y/n): "; |
123 |
< |
my $response = <STDIN>; |
124 |
< |
$response =~ s/\n//g; |
125 |
< |
$response = "y" if !$response; |
126 |
< |
exit if substr (lc ($response), 0, 1) ne 'y'; |
127 |
< |
return -1; |
122 |
> |
if ($command ne "deleteEntry" && $command ne "deprecate") |
123 |
> |
{ |
124 |
> |
print "Database entry does not exist. Create it? (Y/n): "; |
125 |
> |
my $response = <STDIN>; |
126 |
> |
$response =~ s/\n//g; |
127 |
> |
$response = "y" if !$response; |
128 |
> |
exit if substr (lc ($response), 0, 1) ne 'y'; |
129 |
> |
return (-1, ""); |
130 |
> |
} |
131 |
> |
else |
132 |
> |
{ |
133 |
> |
print "Database entry does not exist.\n"; |
134 |
> |
exit; |
135 |
> |
} |
136 |
|
} |
137 |
< |
my %map; |
137 |
> |
my %id; |
138 |
> |
my %fullDataset; |
139 |
|
print "Found multiple database entries matching\n"; |
140 |
|
print "\"$dataset\":\n"; |
141 |
< |
print "( 0) new\n"; |
141 |
> |
print "( 0) new\n" if $command ne "deleteEntry" && $command ne "deprecate"; |
142 |
|
for (my $i = 1; $i <= $results->numrows (); $i++) |
143 |
|
{ |
144 |
|
my @row = $results->fetchrow (); |
145 |
< |
$map{"$i"} = $row[0]; |
145 |
> |
$id{"$i"} = $row[0]; |
146 |
> |
$fullDataset{"$i"} = $row[1]; |
147 |
|
printf "(%2d) $row[1]\n", $i; |
148 |
|
print " created by $row[2] on $row[3]\n"; |
149 |
|
} |
150 |
< |
print "\nWhich entry would you like to update? (Select 0 to create a new entry): "; |
150 |
> |
print "\nWhich entry would you like to modify?"; |
151 |
> |
if ($command ne "deleteEntry" && $command ne "deprecate") |
152 |
> |
{ |
153 |
> |
print " (Select 0 to create a new entry): " |
154 |
> |
} |
155 |
> |
else |
156 |
> |
{ |
157 |
> |
print ": "; |
158 |
> |
} |
159 |
|
my $response = <STDIN>; |
160 |
|
$response =~ s/[ \t\n]//g; |
161 |
< |
return -1 if $response == 0; |
162 |
< |
if (!(exists $map{$response})) |
161 |
> |
return (-1, "") if $response == 0 && $command ne "deleteEntry" && $command ne "deprecate"; |
162 |
> |
if (!(exists $id{$response})) |
163 |
|
{ |
164 |
|
print "Your selection \"$response\" was not a valid option! Quitting.\n"; |
165 |
|
exit; |
166 |
|
} |
167 |
|
|
168 |
< |
return $map{$response}; |
168 |
> |
return ($id{$response}, $fullDataset{$response}); |
169 |
|
} |
170 |
|
|
171 |
|
sub |
176 |
|
my $user = shift; |
177 |
|
my $format = shift; |
178 |
|
my $location = shift; |
179 |
< |
my $remoteLocation = shift; |
179 |
> |
my $fileListName = shift; |
180 |
|
my $status = shift; |
181 |
|
my $comment = shift; |
182 |
|
my $psetName = shift; |
183 |
|
my $crabCfgName = shift; |
184 |
|
my $jsonFileName = shift; |
185 |
|
my $lumiSummaryName = shift; |
186 |
+ |
my $release = shift; |
187 |
|
|
188 |
+ |
my $fileList; |
189 |
|
my $pset; |
190 |
|
my $crabCfg; |
191 |
|
my $jsonFile; |
192 |
|
my $lumiSummary; |
193 |
|
my $size = 0; |
194 |
|
my $nFiles = 0; |
195 |
+ |
if ($fileListName) |
196 |
+ |
{ |
197 |
+ |
if (!(-e $fileListName)) |
198 |
+ |
{ |
199 |
+ |
print "$fileListName does not exist!\n"; |
200 |
+ |
exit; |
201 |
+ |
} |
202 |
+ |
open (FILE_LIST, "<$fileListName"); |
203 |
+ |
my @fileList = <FILE_LIST>; |
204 |
+ |
close (FILE_LIST); |
205 |
+ |
$fileList = join ("", @fileList); |
206 |
+ |
} |
207 |
|
if ($psetName) |
208 |
|
{ |
209 |
|
if (!(-e $psetName)) |
252 |
|
close (LUMI_SUMMARY); |
253 |
|
$lumiSummary = join ("", @lumiSummary); |
254 |
|
} |
255 |
< |
if ($location) |
256 |
< |
{ |
257 |
< |
if (!(-e $location)) |
258 |
< |
{ |
259 |
< |
print "$location does not exist!\n"; |
260 |
< |
exit; |
261 |
< |
} |
262 |
< |
$nFiles = `ls $location | wc -l`; |
263 |
< |
$size = `du -s $location`; |
264 |
< |
$size =~ s/([^ ]*) .*/$1/; |
265 |
< |
$size /= 1024 * 1024; |
266 |
< |
$size = sprintf "%.2f", $size; |
267 |
< |
} |
255 |
> |
if ($release) |
256 |
> |
{ |
257 |
> |
my $query = "select id from ntupleRelease where name='$release'"; |
258 |
> |
$db->selectdb ("ntuple"); |
259 |
> |
my $results = $db->query ($query); |
260 |
> |
if ($results->numrows () != 1) |
261 |
> |
{ |
262 |
> |
print "Ntuple release \"$release\" not found!\n"; |
263 |
> |
exit; |
264 |
> |
} |
265 |
> |
} |
266 |
> |
($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList); |
267 |
> |
my $fullLocation = $location; |
268 |
> |
$fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//); |
269 |
|
|
270 |
|
$dataset = addSlashes ($dataset); |
271 |
|
$user = addSlashes ($user); |
274 |
|
$crabCfg = addSlashes ($crabCfg); |
275 |
|
$jsonFile = addSlashes ($jsonFile); |
276 |
|
$lumiSummary = addSlashes ($lumiSummary); |
277 |
< |
$location = addSlashes ($location); |
278 |
< |
$remoteLocation = addSlashes ($remoteLocation); |
277 |
> |
$fullLocation = addSlashes ($fullLocation); |
278 |
> |
$fileList = addSlashes ($fileList); |
279 |
|
$status = addSlashes ($status); |
280 |
|
$comment = addSlashes ($comment); |
281 |
+ |
$release = addSlashes ($release); |
282 |
|
|
283 |
|
my $results; |
284 |
|
my $query; |
285 |
|
if ($id < 0) |
286 |
|
{ |
194 |
– |
$db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User"); |
287 |
|
$query = "select max(id) from ntuple"; |
288 |
|
$db->selectdb ("ntuple"); |
289 |
|
$results = $db->query ($query); |
291 |
|
my $id = 1; |
292 |
|
$id = $row[0] + 1 if $results->numrows (); |
293 |
|
|
294 |
< |
$query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, user, format, location, remoteLocation, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary) values ($id, '$dataset', now(), now(), '$user', '$format', '$location', '$remoteLocation', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary')"; |
294 |
> |
$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')"; |
295 |
|
} |
296 |
|
if ($id > 0) |
297 |
|
{ |
300 |
|
|
301 |
|
$values .= ", dataset='$dataset'" if $dataset; |
302 |
|
$values .= ", lastUpdateTime=now()"; |
303 |
+ |
$values .= ", lastUpdateUser='$user'"; |
304 |
|
$values .= ", format='$format'" if $format; |
305 |
< |
$values .= ", location='$location'" if $location; |
306 |
< |
$values .= ", remoteLocation='$remoteLocation'" if $remoteLocation; |
307 |
< |
$values .= ", nFiles=$nFiles" if $location; |
308 |
< |
$values .= ", sizeInGB=$size" if $location; |
305 |
> |
$values .= ", location='$fullLocation'" if $location; |
306 |
> |
$values .= ", fileList='$fileList'" if $fileList; |
307 |
> |
$values .= ", nFiles=$nFiles" if $nFiles; |
308 |
> |
$values .= ", sizeInGB=$size" if $size; |
309 |
|
$values .= ", status='$status'" if $status; |
310 |
|
$values .= ", comment='$comment'" if $comment; |
311 |
|
$values .= ", pset='$pset'" if $pset; |
312 |
|
$values .= ", crabCfg='$crabCfg'" if $crabCfg; |
313 |
|
$values .= ", jsonFile='$jsonFile'" if $jsonFile; |
314 |
|
$values .= ", lumiSummary='$lumiSummary'" if $lumiSummary; |
315 |
+ |
$values .= ", version='$release'" if $release; |
316 |
|
|
317 |
|
$values =~ s/^, //; |
318 |
|
$query = "update ntuple set $values where id=$id"; |
323 |
|
} |
324 |
|
|
325 |
|
sub |
326 |
+ |
dbUpdateOther |
327 |
+ |
{ |
328 |
+ |
my $id = shift; |
329 |
+ |
my $comment = shift; |
330 |
+ |
my $user = shift; |
331 |
+ |
|
332 |
+ |
$comment = addSlashes ($comment); |
333 |
+ |
|
334 |
+ |
my $query = "update other set lastUpdateTime=now(), lastUpdateUser='$user', comment='$comment' where id=$id"; |
335 |
+ |
$db->selectdb ("ntuple"); |
336 |
+ |
my $results = $db->query ($query); |
337 |
+ |
|
338 |
+ |
return $results; |
339 |
+ |
} |
340 |
+ |
|
341 |
+ |
sub |
342 |
+ |
dbDelete |
343 |
+ |
{ |
344 |
+ |
my $id = shift; |
345 |
+ |
|
346 |
+ |
my $query = "delete from ntuple where id=$id"; |
347 |
+ |
$db->selectdb ("ntuple"); |
348 |
+ |
my $results = $db->query ($query); |
349 |
+ |
} |
350 |
+ |
|
351 |
+ |
sub |
352 |
+ |
dbDeleteOther |
353 |
+ |
{ |
354 |
+ |
my $id = shift; |
355 |
+ |
|
356 |
+ |
my $query = "delete from other where id=$id"; |
357 |
+ |
$db->selectdb ("ntuple"); |
358 |
+ |
my $results = $db->query ($query); |
359 |
+ |
} |
360 |
+ |
|
361 |
+ |
sub |
362 |
|
printHelp |
363 |
|
{ |
364 |
+ |
my $command = shift; |
365 |
+ |
|
366 |
|
my $exeName = $0; |
367 |
|
$exeName =~ s/^.*\/([^\/]*)$/$1/; |
368 |
|
|
369 |
< |
print "Usage: $exeName [OPTION]... COMMAND DATASET\n"; |
370 |
< |
print "Manipulates entries in the OSU Tier 3 ntuple database.\n"; |
371 |
< |
print "\n"; |
372 |
< |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
373 |
< |
printf "%-29s%s\n", " -b, --crabCfg FILE", "CRAB config file used to submit the ntuple jobs"; |
374 |
< |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for this database entry"; |
375 |
< |
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format (default: BEAN)"; |
376 |
< |
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used to ntuplize the dataset"; |
377 |
< |
printf "%-29s%s\n", " -h, --help", "print this help message"; |
378 |
< |
printf "%-29s%s\n", " -l, --location DIRECTORY", "location on the Tier 3"; |
379 |
< |
printf "%-29s%s\n", " -p, --pyConfig FILE", "python config used to ntuplize the dataset"; |
380 |
< |
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json returned by CRAB"; |
381 |
< |
print "\n"; |
382 |
< |
print "COMMAND may be one of the following:\n"; |
383 |
< |
printf "%-29s%s\n", " create", "creates the entry (assumes the dataset is present)"; |
384 |
< |
printf "%-29s%s\n", " update", "updates the entry"; |
385 |
< |
printf "%-29s%s\n", " finish", "finalizes the database entry"; |
386 |
< |
printf "%-29s%s\n", " deprecate", "marks the dataset for deletion"; |
369 |
> |
if ($command eq "create") |
370 |
> |
{ |
371 |
> |
print "Usage: $exeName -l DIRECTORY [OPTION]... create NAME\n"; |
372 |
> |
print "Creates an entry in the database for dataset NAME. The ntuples are assumed to\n"; |
373 |
> |
print "be present on the Tier 3, with the status being set accordingly.\n"; |
374 |
> |
print "\n"; |
375 |
> |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
376 |
> |
printf "%-29s%s\n", " -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs"; |
377 |
> |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
378 |
> |
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format (default: BEAN)"; |
379 |
> |
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
380 |
> |
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
381 |
> |
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
382 |
> |
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
383 |
> |
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
384 |
> |
} |
385 |
> |
elsif ($command eq "createOther") |
386 |
> |
{ |
387 |
> |
print "Usage: $exeName [OPTION]... createOther DIRECTORIES_AND_FILES\n"; |
388 |
> |
print "Creates an entry in the database for non-ntuple data.\n"; |
389 |
> |
print "\n"; |
390 |
> |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
391 |
> |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
392 |
> |
} |
393 |
> |
elsif ($command eq "update") |
394 |
> |
{ |
395 |
> |
print "Usage: $exeName [OPTION]... update NAME\n"; |
396 |
> |
print "Updates an existing database entry for dataset NAME.\n"; |
397 |
> |
print "\n"; |
398 |
> |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
399 |
> |
printf "%-29s%s\n", " -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs"; |
400 |
> |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
401 |
> |
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format"; |
402 |
> |
printf "%-29s%s\n", " -j, --jsonFile FILE", "JSON file used for this dataset"; |
403 |
> |
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
404 |
> |
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
405 |
> |
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python config used to produce ntuples"; |
406 |
> |
printf "%-29s%s\n", " -r, --release NAME", "ntuple release used to produce ntuples"; |
407 |
> |
printf "%-29s%s\n", " -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB"; |
408 |
> |
} |
409 |
> |
elsif ($command eq "finish") |
410 |
> |
{ |
411 |
> |
print "Usage: $exeName -l DIRECTORY finish NAME\n"; |
412 |
> |
print "Finalizes the database entry for dataset NAME, changing its status to\n"; |
413 |
> |
print "\"present\". This is intended to be the final step in command-line based ntuple\n"; |
414 |
> |
print "production.\n"; |
415 |
> |
print "\n"; |
416 |
> |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
417 |
> |
printf "%-29s%s\n", " -l, --location DIRECTORY", "directory containing the ntuples"; |
418 |
> |
} |
419 |
> |
elsif ($command eq "deleteEntry") |
420 |
> |
{ |
421 |
> |
print "Usage: $exeName [OPTION]... deleteEntry NAME\n"; |
422 |
> |
print "Deletes the database entry for dataset NAME. This is intended primarily for\n"; |
423 |
> |
print "mistaken database entries. If you wish to actually delete a set of ntuples,\n"; |
424 |
> |
print "please use the \"deprecate\" command instead.\n"; |
425 |
> |
print "\n"; |
426 |
> |
printf "%-29s%s\n", " -o, --other", "update an entry in the non-ntuple database"; |
427 |
> |
} |
428 |
> |
elsif ($command eq "deprecate") |
429 |
> |
{ |
430 |
> |
print "Usage: $exeName deprecate NAME\n"; |
431 |
> |
print "Marks the dataset NAME for deletion. WARNING: The dataset will be deleted from\n"; |
432 |
> |
print "the Tier 3 within one week of this action. If you wish to simply delete a\n"; |
433 |
> |
print "mistaken database entry, use the \"deleteEntry\" command instead.\n"; |
434 |
> |
} |
435 |
> |
elsif ($command eq "uploadRelease") |
436 |
> |
{ |
437 |
> |
print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n"; |
438 |
> |
print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n"; |
439 |
> |
print "database entry for it, with NAME being the name of the release. An ntuple\n"; |
440 |
> |
print "release is a CMSSW release with all the necessary packages added for creating\n"; |
441 |
> |
print "ntuples, along with a default Python config file.\n"; |
442 |
> |
print "\n"; |
443 |
> |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
444 |
> |
printf "%-29s%s\n", " -c, --comment COMMENT", "comment for the database entry"; |
445 |
> |
printf "%-29s%s\n", " -e, --recipe FILE", "file containing the recipe for the release"; |
446 |
> |
printf "%-29s%s\n", " -f, --format FORMAT", "ntuple format (default: BEAN)"; |
447 |
> |
printf "%-29s%s\n", " -p, --pyConfig FILE", "default Python config for the release"; |
448 |
> |
printf "%-29s%s\n", " -r, --release DIRECTORY", "CMSSW release containing ntuple packages"; |
449 |
> |
} |
450 |
> |
elsif ($command eq "downloadRelease") |
451 |
> |
{ |
452 |
> |
print "Usage: $exeName [OPTION]... downloadRelease NAME\n"; |
453 |
> |
print "Copies an ntuple release to the current directory on the Tier 3. Optionally\n"; |
454 |
> |
print "copies the corresponding Python configuration file registered in the database.\n"; |
455 |
> |
print "\n"; |
456 |
> |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
457 |
> |
printf "%-29s%s\n", " -p, --pyConfig FILE", "Python configuration file name"; |
458 |
> |
} |
459 |
> |
elsif ($command eq "uploadConfig") |
460 |
> |
{ |
461 |
> |
print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadConfig NAME\n"; |
462 |
> |
print "Creates an entry in the database for a customized Python configuration file.\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", " -p, --pyConfig FILE", "Python config file"; |
467 |
> |
printf "%-29s%s\n", " -r, --release NAME", "ntuple release with which to use this config"; |
468 |
> |
} |
469 |
> |
else |
470 |
> |
{ |
471 |
> |
print "Usage: $exeName [OPTION]... COMMAND NAME\n"; |
472 |
> |
print "Manipulates entry in the OSU Tier 3 ntuple database given by NAME.\n"; |
473 |
> |
print "\n"; |
474 |
> |
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
475 |
> |
printf "%-29s%s\n", " -h, --help", "print help. If COMMAND is present, print help"; |
476 |
> |
printf "%-29s%s\n", " ", "specific to COMMAND."; |
477 |
> |
print "\n"; |
478 |
> |
print "COMMAND may be one of the following:\n"; |
479 |
> |
printf "%-29s%s\n", " create", "creates the entry"; |
480 |
> |
printf "%-29s%s\n", " createOther", "creates an entry for non-ntuple data"; |
481 |
> |
printf "%-29s%s\n", " update", "updates the entry"; |
482 |
> |
printf "%-29s%s\n", " finish", "finalizes the database entry"; |
483 |
> |
printf "%-29s%s\n", " deleteEntry", "removes the database entry"; |
484 |
> |
printf "%-29s%s\n", " deprecate", "marks the dataset for deletion"; |
485 |
> |
printf "%-29s%s\n", " uploadRelease", "upload an ntuple release"; |
486 |
> |
printf "%-29s%s\n", " downloadRelease", "download an ntuple release"; |
487 |
> |
printf "%-29s%s\n", " uploadConfig", "upload an ntuple config"; |
488 |
> |
} |
489 |
|
|
490 |
|
exit; |
491 |
|
} |
492 |
+ |
|
493 |
+ |
sub |
494 |
+ |
sizeOfDataset |
495 |
+ |
{ |
496 |
+ |
my $dataset = shift; |
497 |
+ |
my $location = shift; |
498 |
+ |
my $fileList = shift; |
499 |
+ |
|
500 |
+ |
my $size = 0.0; |
501 |
+ |
my $nFiles = 0; |
502 |
+ |
if ($location && !$fileList) |
503 |
+ |
{ |
504 |
+ |
if (!(-e $location)) |
505 |
+ |
{ |
506 |
+ |
print "$location does not exist!\n"; |
507 |
+ |
exit; |
508 |
+ |
} |
509 |
+ |
$nFiles = `ls $location | wc -l`; |
510 |
+ |
$size = `du -s $location`; |
511 |
+ |
$size =~ s/([^ ]*) .*/$1/; |
512 |
+ |
$size /= 1024 * 1024; |
513 |
+ |
$size = sprintf "%.2f", $size; |
514 |
+ |
} |
515 |
+ |
elsif ($fileList) |
516 |
+ |
{ |
517 |
+ |
foreach my $file (split (/\n/, $fileList)) |
518 |
+ |
{ |
519 |
+ |
$nFiles++; |
520 |
+ |
my $fileSize = `du -s $file`; |
521 |
+ |
$fileSize =~ s/([^ ]*) .*/$1/; |
522 |
+ |
$size += $fileSize; |
523 |
+ |
} |
524 |
+ |
$size /= 1024 * 1024; |
525 |
+ |
$size = sprintf "%.2f", $size; |
526 |
+ |
} |
527 |
+ |
|
528 |
+ |
return ($nFiles, $size); |
529 |
+ |
} |
530 |
+ |
|
531 |
+ |
sub |
532 |
+ |
uploadRelease |
533 |
+ |
{ |
534 |
+ |
my $format = shift; |
535 |
+ |
my $cmsswRelease = shift; |
536 |
+ |
my $release = shift; |
537 |
+ |
my $psetName = shift; |
538 |
+ |
my $name = shift; |
539 |
+ |
my $user = shift; |
540 |
+ |
my $comment = shift; |
541 |
+ |
my $recipeName = shift; |
542 |
+ |
|
543 |
+ |
if (!(-e $psetName)) |
544 |
+ |
{ |
545 |
+ |
print "$psetName does not exist!\n"; |
546 |
+ |
exit; |
547 |
+ |
} |
548 |
+ |
if (!(-e $recipeName)) |
549 |
+ |
{ |
550 |
+ |
print "$recipeName does not exist!\n"; |
551 |
+ |
exit; |
552 |
+ |
} |
553 |
+ |
move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped"; |
554 |
+ |
open (PY_CONFIG, "<$psetName"); |
555 |
+ |
my @pset = <PY_CONFIG>; |
556 |
+ |
close (PY_CONFIG); |
557 |
+ |
my $pset = join ("", @pset); |
558 |
+ |
open (RECIPE, "<$recipeName"); |
559 |
+ |
my @recipe = <RECIPE>; |
560 |
+ |
close (RECIPE); |
561 |
+ |
my $recipe = join ("\n", @recipe); |
562 |
+ |
|
563 |
+ |
my $query = "select max(id) from ntupleRelease"; |
564 |
+ |
$db->selectdb ("ntuple"); |
565 |
+ |
my $results = $db->query ($query); |
566 |
+ |
my @row = $results->fetchrow (); |
567 |
+ |
my $id = 1; |
568 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
569 |
+ |
|
570 |
+ |
$name = addSlashes ($name); |
571 |
+ |
$pset = addSlashes ($pset); |
572 |
+ |
$user = addSlashes ($user); |
573 |
+ |
$format = addSlashes ($format); |
574 |
+ |
$cmsswRelease = addSlashes ($cmsswRelease); |
575 |
+ |
$comment = addSlashes ($comment); |
576 |
+ |
$recipe = addSlashes ($recipe); |
577 |
+ |
|
578 |
+ |
my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')"; |
579 |
+ |
$db->selectdb ("ntuple"); |
580 |
+ |
my $results = $db->query ($query); |
581 |
+ |
} |
582 |
+ |
|
583 |
+ |
sub |
584 |
+ |
downloadRelease |
585 |
+ |
{ |
586 |
+ |
my $release = shift; |
587 |
+ |
my $pyConfigName = shift; |
588 |
+ |
|
589 |
+ |
my $query = "select id,pset from ntupleRelease where name='$release'"; |
590 |
+ |
$db->selectdb ("ntuple"); |
591 |
+ |
my $results = $db->query ($query); |
592 |
+ |
if ($results->numrows () != 1) |
593 |
+ |
{ |
594 |
+ |
print "Ntuple release \"$release\" not found!\n"; |
595 |
+ |
exit; |
596 |
+ |
} |
597 |
+ |
if (!(-e "/home/hart/public_html/releases/$release.tar.gz")) |
598 |
+ |
{ |
599 |
+ |
print "Release is in the database but no package exists!\n"; |
600 |
+ |
exit; |
601 |
+ |
} |
602 |
+ |
if ($pyConfigName) |
603 |
+ |
{ |
604 |
+ |
my @row = $results->fetchrow (); |
605 |
+ |
open (PY_CONFIG, ">$pyConfigName"); |
606 |
+ |
print PY_CONFIG $row[1]; |
607 |
+ |
close (PY_CONFIG); |
608 |
+ |
} |
609 |
+ |
copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz"); |
610 |
+ |
} |
611 |
+ |
|
612 |
+ |
sub |
613 |
+ |
dbOtherCreate |
614 |
+ |
{ |
615 |
+ |
my $user = shift; |
616 |
+ |
my $listOfFiles = shift; |
617 |
+ |
my $comment = shift; |
618 |
+ |
|
619 |
+ |
my $size = 0.0; |
620 |
+ |
my $nFiles = 0.0; |
621 |
+ |
for (my $i = 0; $i < @$listOfFiles; $i++) |
622 |
+ |
{ |
623 |
+ |
if (!(-e $$listOfFiles[$i])) |
624 |
+ |
{ |
625 |
+ |
print "$$listOfFiles[$i] does not exist!\n"; |
626 |
+ |
exit; |
627 |
+ |
} |
628 |
+ |
$nFiles += `ls -R $$listOfFiles[$i] | grep -v ':\$' | grep -v '^\$' | wc -l`; |
629 |
+ |
my $fileSize = `du -s $$listOfFiles[$i]`; |
630 |
+ |
$fileSize =~ s/([^ ]*) .*/$1/; |
631 |
+ |
$fileSize /= 1024 * 1024; |
632 |
+ |
$size += $fileSize; |
633 |
+ |
$$listOfFiles[$i] = "$ENV{'PWD'}/$$listOfFiles[$i]" if !($$listOfFiles[$i] =~ m/^\//); |
634 |
+ |
} |
635 |
+ |
$size = sprintf "%.2f", $size; |
636 |
+ |
my $location = join ("<br />", @$listOfFiles); |
637 |
+ |
|
638 |
+ |
my $query = "select max(id) from other"; |
639 |
+ |
$db->selectdb ("ntuple"); |
640 |
+ |
my $results = $db->query ($query); |
641 |
+ |
my @row = $results->fetchrow (); |
642 |
+ |
my $id = 1; |
643 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
644 |
+ |
|
645 |
+ |
$user = addSlashes ($user); |
646 |
+ |
$location = addSlashes ($location); |
647 |
+ |
$comment = addSlashes ($comment); |
648 |
+ |
|
649 |
+ |
$query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$user', '$location', $nFiles, $size, '$comment')"; |
650 |
+ |
$db->selectdb ("ntuple"); |
651 |
+ |
$results = $db->query ($query); |
652 |
+ |
|
653 |
+ |
print "ID $id\n"; |
654 |
+ |
} |
655 |
+ |
|
656 |
+ |
sub |
657 |
+ |
uploadConfig |
658 |
+ |
{ |
659 |
+ |
my $name = shift; |
660 |
+ |
my $user = shift; |
661 |
+ |
my $psetName = shift; |
662 |
+ |
my $release = shift; |
663 |
+ |
my $comment = shift; |
664 |
+ |
|
665 |
+ |
if (!(-e $psetName)) |
666 |
+ |
{ |
667 |
+ |
print "$psetName does not exist!\n"; |
668 |
+ |
exit; |
669 |
+ |
} |
670 |
+ |
if ($release) |
671 |
+ |
{ |
672 |
+ |
my $query = "select id from ntupleRelease where name='$release'"; |
673 |
+ |
$db->selectdb ("ntuple"); |
674 |
+ |
my $results = $db->query ($query); |
675 |
+ |
if ($results->numrows () != 1) |
676 |
+ |
{ |
677 |
+ |
print "Ntuple release \"$release\" not found!\n"; |
678 |
+ |
exit; |
679 |
+ |
} |
680 |
+ |
} |
681 |
+ |
open (PSET, "<$psetName"); |
682 |
+ |
my @pset = <PSET>; |
683 |
+ |
close (PSET); |
684 |
+ |
my $pset = join ("", @pset); |
685 |
+ |
|
686 |
+ |
my $query = "select max(id) from ntupleConfig"; |
687 |
+ |
$db->selectdb ("ntuple"); |
688 |
+ |
my $results = $db->query ($query); |
689 |
+ |
my @row = $results->fetchrow (); |
690 |
+ |
my $id = 1; |
691 |
+ |
$id = $row[0] + 1 if $results->numrows (); |
692 |
+ |
|
693 |
+ |
$name = addSlashes ($name); |
694 |
+ |
$user = addSlashes ($user); |
695 |
+ |
$pset = addSlashes ($pset); |
696 |
+ |
$release = addSlashes ($release); |
697 |
+ |
$comment = addSlashes ($comment); |
698 |
+ |
|
699 |
+ |
my $query = "insert into ntupleConfig (id, name, pset, user, pending, ntupleRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$release', '$comment')"; |
700 |
+ |
$db->selectdb ("ntuple"); |
701 |
+ |
$results = $db->query ($query); |
702 |
+ |
} |