ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osudb
Revision: 1.16
Committed: Sat Jan 19 06:56:01 2013 UTC (12 years, 3 months ago) by ahart
Branch: MAIN
Changes since 1.15: +46 -0 lines
Log Message:
Do not register duplicate locations and warn of duplicate datasets.

File Contents

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