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