ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osudb
(Generate patch)

Comparing UserCode/OSUT3Analysis/DBTools/scripts/osudb (file contents):
Revision 1.3 by ahart, Thu Jun 14 17:42:30 2012 UTC vs.
Revision 1.15 by ahart, Fri Nov 30 18:20:59 2012 UTC

# Line 3 | Line 3
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'}\@$ENV{'HOSTNAME'}", \@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
# Line 43 | Line 102 | 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
# Line 96 | Line 173 | dbUpdate
173   {
174    my $id = shift;
175    my $dataset = shift;
176 <  my $user = shift;
176 >  my $userAndHost = 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 $user = $userAndHost;
189 +  $user =~ s/@.*$//g;
190  
191 +  my $fileList;
192    my $pset;
193    my $crabCfg;
194    my $jsonFile;
195    my $lumiSummary;
196    my $size = 0;
197    my $nFiles = 0;
198 +  if ($fileListName)
199 +    {
200 +      if (!(-e $fileListName))
201 +        {
202 +          print "$fileListName does not exist!\n";
203 +          exit;
204 +        }
205 +      open (FILE_LIST, "<$fileListName");
206 +      my @fileList = <FILE_LIST>;
207 +      close (FILE_LIST);
208 +      $fileList = join ("", @fileList);
209 +    }
210    if ($psetName)
211      {
212        if (!(-e $psetName))
# Line 161 | Line 255 | dbUpdate
255        close (LUMI_SUMMARY);
256        $lumiSummary = join ("", @lumiSummary);
257      }
258 <  if ($location)
259 <  {
260 <    if (!(-e $location))
261 <      {
262 <        print "$location does not exist!\n";
263 <        exit;
264 <      }
265 <     $nFiles = `ls $location | wc -l`;
266 <     $size = `du -s $location`;
267 <    $size =~ s/([^ ]*) .*/$1/;
268 <    $size /= 1024 * 1024;
269 <    $size = sprintf "%.2f", $size;
270 <  }
258 >  if ($release)
259 >    {
260 >      my $query = "select id from ntupleRelease where name='$release'";
261 >      $db->selectdb ("ntuple");
262 >      my $results = $db->query ($query);
263 >      if ($results->numrows () != 1)
264 >        {
265 >          print "Ntuple release \"$release\" not found!\n";
266 >          exit;
267 >        }
268 >    }
269 >  ($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList);
270 >  my $fullLocation = $location;
271 >  $fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//);
272  
273    $dataset = addSlashes ($dataset);
274    $user = addSlashes ($user);
# Line 182 | Line 277 | dbUpdate
277    $crabCfg = addSlashes ($crabCfg);
278    $jsonFile = addSlashes ($jsonFile);
279    $lumiSummary = addSlashes ($lumiSummary);
280 <  $location = addSlashes ($location);
281 <  $remoteLocation = addSlashes ($remoteLocation);
280 >  $fullLocation = addSlashes ($fullLocation);
281 >  $fileList = addSlashes ($fileList);
282    $status = addSlashes ($status);
283    $comment = addSlashes ($comment);
284 +  $release = addSlashes ($release);
285  
286    my $results;
287    my $query;
288    if ($id < 0)
289      {
194      $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User");
290        $query = "select max(id) from ntuple";
291        $db->selectdb ("ntuple");
292        $results = $db->query ($query);
# Line 199 | Line 294 | dbUpdate
294        my $id = 1;
295        $id = $row[0] + 1 if $results->numrows ();
296  
297 <      $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')";
297 >      $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')";
298      }
299    if ($id > 0)
300      {
# Line 208 | Line 303 | dbUpdate
303  
304        $values .= ", dataset='$dataset'" if $dataset;
305        $values .= ", lastUpdateTime=now()";
306 +      $values .= ", lastUpdateUser='$user'";
307        $values .= ", format='$format'" if $format;
308 <      $values .= ", location='$location'" if $location;
309 <      $values .= ", remoteLocation='$remoteLocation'" if $remoteLocation;
310 <      $values .= ", nFiles=$nFiles" if $location;
311 <      $values .= ", sizeInGB=$size" if $location;
308 >      $values .= ", location='$fullLocation'" if $location;
309 >      $values .= ", fileList='$fileList'" if $fileList;
310 >      $values .= ", nFiles=$nFiles" if $nFiles;
311 >      $values .= ", sizeInGB=$size" if $size;
312        $values .= ", status='$status'" if $status;
313        $values .= ", comment='$comment'" if $comment;
314        $values .= ", pset='$pset'" if $pset;
315        $values .= ", crabCfg='$crabCfg'" if $crabCfg;
316        $values .= ", jsonFile='$jsonFile'" if $jsonFile;
317        $values .= ", lumiSummary='$lumiSummary'" if $lumiSummary;
318 +      $values .= ", version='$release'" if $release;
319  
320        $values =~ s/^, //;
321        $query = "update ntuple set $values where id=$id";
# Line 229 | Line 326 | dbUpdate
326   }
327  
328   sub
329 + dbUpdateOther
330 + {
331 +  my $id = shift;
332 +  my $comment = shift;
333 +  my $user = shift;
334 +
335 +  $comment = addSlashes ($comment);
336 +
337 +  my $query = "update other set lastUpdateTime=now(), lastUpdateUser='$user', comment='$comment'  where id=$id";
338 +  $db->selectdb ("ntuple");
339 +  my $results = $db->query ($query);
340 +
341 +  return $results;
342 + }
343 +
344 + sub
345 + dbDelete
346 + {
347 +  my $id = shift;
348 +
349 +  my $query = "delete from ntuple where id=$id";
350 +  $db->selectdb ("ntuple");
351 +  my $results = $db->query ($query);
352 + }
353 +
354 + sub
355 + dbDeleteOther
356 + {
357 +  my $id = shift;
358 +
359 +  my $query = "delete from other where id=$id";
360 +  $db->selectdb ("ntuple");
361 +  my $results = $db->query ($query);
362 + }
363 +
364 + sub
365   printHelp
366   {
367 +  my $command = shift;
368 +
369    my $exeName = $0;
370    $exeName =~ s/^.*\/([^\/]*)$/$1/;
371  
372 <  print "Usage: $exeName [OPTION]... COMMAND DATASET\n";
373 <  print "Manipulates entries in the OSU Tier 3 ntuple database.\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 file used to submit the ntuple jobs";
377 <  printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for this 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 to ntuplize the dataset";
380 <  printf "%-29s%s\n", "  -h, --help", "print this help message";
381 <  printf "%-29s%s\n", "  -l, --location DIRECTORY", "location on the Tier 3";
382 <  printf "%-29s%s\n", "  -p, --pyConfig FILE", "python config used to ntuplize the dataset";
383 <  printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json returned by CRAB";
384 <  print "\n";
385 <  print "COMMAND may be one of the following:\n";
386 <  printf "%-29s%s\n", "  create", "creates the entry (assumes the dataset is present)";
387 <  printf "%-29s%s\n", "  update", "updates the entry";
388 <  printf "%-29s%s\n", "  finish", "finalizes the database entry";
389 <  printf "%-29s%s\n", "  deprecate", "marks the dataset for deletion";
372 >  if ($command eq "create")
373 >    {
374 >      print "Usage: $exeName -l DIRECTORY [OPTION]... create NAME\n";
375 >      print "Creates an entry in the database for dataset NAME. The ntuples are assumed to\n";
376 >      print "be present on the Tier 3, with the status being set accordingly.\n";
377 >      print "\n";
378 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
379 >      printf "%-29s%s\n", "  -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs";
380 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
381 >      printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
382 >      printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
383 >      printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
384 >      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
385 >      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
386 >      printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
387 >    }
388 >  elsif ($command eq "createOther")
389 >    {
390 >      print "Usage: $exeName [OPTION]... createOther DIRECTORIES_AND_FILES\n";
391 >      print "Creates an entry in the database for non-ntuple data.\n";
392 >      print "\n";
393 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
394 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
395 >    }
396 >  elsif ($command eq "update")
397 >    {
398 >      print "Usage: $exeName [OPTION]... update NAME\n";
399 >      print "Updates an existing database entry for dataset NAME.\n";
400 >      print "\n";
401 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
402 >      printf "%-29s%s\n", "  -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs";
403 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
404 >      printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format";
405 >      printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
406 >      printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
407 >      printf "%-29s%s\n", "  -o, --other", "update an entry in the non-ntuple database";
408 >      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
409 >      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
410 >      printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
411 >    }
412 >  elsif ($command eq "finish")
413 >    {
414 >      print "Usage: $exeName -l DIRECTORY finish NAME\n";
415 >      print "Finalizes the database entry for dataset NAME, changing its status to\n";
416 >      print "\"present\".  This is intended to be the final step in command-line based ntuple\n";
417 >      print "production.\n";
418 >      print "\n";
419 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
420 >      printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
421 >    }
422 >  elsif ($command eq "deleteEntry")
423 >    {
424 >      print "Usage: $exeName [OPTION]... deleteEntry NAME\n";
425 >      print "Deletes the database entry for dataset NAME. This is intended primarily for\n";
426 >      print "mistaken database entries. If you wish to actually delete a set of ntuples,\n";
427 >      print "please use the \"deprecate\" command instead.\n";
428 >      print "\n";
429 >      printf "%-29s%s\n", "  -o, --other", "update an entry in the non-ntuple database";
430 >    }
431 >  elsif ($command eq "deprecate")
432 >    {
433 >      print "Usage: $exeName deprecate NAME\n";
434 >      print "Marks the dataset NAME for deletion. WARNING: The dataset will be deleted from\n";
435 >      print "the Tier 3 within one week of this action. If you wish to simply delete a\n";
436 >      print "mistaken database entry, use the \"deleteEntry\" command instead.\n";
437 >    }
438 >  elsif ($command eq "uploadRelease")
439 >    {
440 >      print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
441 >      print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n";
442 >      print "database entry for it, with NAME being the name of the release. An ntuple\n";
443 >      print "release is a CMSSW release with all the necessary packages added for creating\n";
444 >      print "ntuples, along with a default Python config file.\n";
445 >      print "\n";
446 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
447 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
448 >      printf "%-29s%s\n", "  -e, --recipe FILE", "file containing the recipe for the release";
449 >      printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
450 >      printf "%-29s%s\n", "  -p, --pyConfig FILE", "default Python config for the release";
451 >      printf "%-29s%s\n", "  -r, --release DIRECTORY", "CMSSW release containing ntuple packages";
452 >    }
453 >  elsif ($command eq "downloadRelease")
454 >    {
455 >      print "Usage: $exeName [OPTION]... downloadRelease NAME\n";
456 >      print "Copies an ntuple release to the current directory on the Tier 3. Optionally\n";
457 >      print "copies the corresponding Python configuration file registered in the database.\n";
458 >      print "\n";
459 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
460 >      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python configuration file name";
461 >    }
462 >  elsif ($command eq "uploadConfig")
463 >    {
464 >      print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadConfig NAME\n";
465 >      print "Creates an entry in the database for a customized Python configuration file.\n";
466 >      print "\n";
467 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
468 >      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
469 >      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config file";
470 >      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release with which to use this config";
471 >    }
472 >  else
473 >    {
474 >      print "Usage: $exeName [OPTION]... COMMAND NAME\n";
475 >      print "Manipulates entry in the OSU Tier 3 ntuple database given by NAME.\n";
476 >      print "\n";
477 >      print "Mandatory arguments to long options are mandatory for short options too.\n";
478 >      printf "%-29s%s\n", "  -h, --help", "print help. If COMMAND is present, print help";
479 >      printf "%-29s%s\n", " ", "specific to COMMAND.";
480 >      print "\n";
481 >      print "COMMAND may be one of the following:\n";
482 >      printf "%-29s%s\n", "  create", "creates the entry";
483 >      printf "%-29s%s\n", "  createOther", "creates an entry for non-ntuple data";
484 >      printf "%-29s%s\n", "  update", "updates the entry";
485 >      printf "%-29s%s\n", "  finish", "finalizes the database entry";
486 >      printf "%-29s%s\n", "  deleteEntry", "removes the database entry";
487 >      printf "%-29s%s\n", "  deprecate", "marks the dataset for deletion";
488 >      printf "%-29s%s\n", "  uploadRelease", "upload an ntuple release";
489 >      printf "%-29s%s\n", "  downloadRelease", "download an ntuple release";
490 >      printf "%-29s%s\n", "  uploadConfig", "upload an ntuple config";
491 >    }
492  
493    exit;
494   }
495 +
496 + sub
497 + sizeOfDataset
498 + {
499 +  my $dataset = shift;
500 +  my $location = shift;
501 +  my $fileList = shift;
502 +
503 +  my $size = 0.0;
504 +  my $nFiles = 0;
505 +  if ($location && !$fileList)
506 +    {
507 +      if (!(-e $location))
508 +        {
509 +          print "$location does not exist!\n";
510 +          exit;
511 +        }
512 +      $nFiles = `ls $location | wc -l`;
513 +      $size = `du -s $location`;
514 +      $size =~ s/([^ ]*) .*/$1/;
515 +      $size /= 1024 * 1024;
516 +      $size = sprintf "%.2f", $size;
517 +    }
518 +  elsif ($fileList)
519 +    {
520 +      foreach my $file (split (/\n/, $fileList))
521 +        {
522 +          $nFiles++;
523 +          my $fileSize = `du -s $file`;
524 +          $fileSize =~ s/([^ ]*) .*/$1/;
525 +          $size += $fileSize;
526 +        }
527 +      $size /= 1024 * 1024;
528 +      $size = sprintf "%.2f", $size;
529 +    }
530 +
531 +  return ($nFiles, $size);
532 + }
533 +
534 + sub
535 + uploadRelease
536 + {
537 +  my $format = shift;
538 +  my $cmsswRelease = shift;
539 +  my $release = shift;
540 +  my $psetName = shift;
541 +  my $name = shift;
542 +  my $user = shift;
543 +  my $comment = shift;
544 +  my $recipeName = shift;
545 +
546 +  if (!(-e $psetName))
547 +    {
548 +      print "$psetName does not exist!\n";
549 +      exit;
550 +    }
551 +  if (!(-e $recipeName))
552 +    {
553 +      print "$recipeName does not exist!\n";
554 +      exit;
555 +    }
556 +  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
557 +  open (PY_CONFIG, "<$psetName");
558 +  my @pset = <PY_CONFIG>;
559 +  close (PY_CONFIG);
560 +  my $pset = join ("", @pset);
561 +  open (RECIPE, "<$recipeName");
562 +  my @recipe = <RECIPE>;
563 +  close (RECIPE);
564 +  my $recipe = join ("\n", @recipe);
565 +
566 +  my $query = "select max(id) from ntupleRelease";
567 +  $db->selectdb ("ntuple");
568 +  my $results = $db->query ($query);
569 +  my @row = $results->fetchrow ();
570 +  my $id = 1;
571 +  $id = $row[0] + 1 if $results->numrows ();
572 +
573 +  $name = addSlashes ($name);
574 +  $pset = addSlashes ($pset);
575 +  $user = addSlashes ($user);
576 +  $format = addSlashes ($format);
577 +  $cmsswRelease = addSlashes ($cmsswRelease);
578 +  $comment = addSlashes ($comment);
579 +  $recipe = addSlashes ($recipe);
580 +
581 +  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')";
582 +  $db->selectdb ("ntuple");
583 +  my $results = $db->query ($query);
584 + }
585 +
586 + sub
587 + downloadRelease
588 + {
589 +  my $release = shift;
590 +  my $pyConfigName = shift;
591 +
592 +  my $query = "select id,pset from ntupleRelease where name='$release'";
593 +  $db->selectdb ("ntuple");
594 +  my $results = $db->query ($query);
595 +  if ($results->numrows () != 1)
596 +    {
597 +      print "Ntuple release \"$release\" not found!\n";
598 +      exit;
599 +    }
600 +  if (!(-e "/home/hart/public_html/releases/$release.tar.gz"))
601 +    {
602 +      print "Release is in the database but no package exists!\n";
603 +      exit;
604 +    }
605 +  if ($pyConfigName)
606 +    {
607 +      my @row = $results->fetchrow ();
608 +      open (PY_CONFIG, ">$pyConfigName");
609 +      print PY_CONFIG $row[1];
610 +      close (PY_CONFIG);
611 +    }
612 +  copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz");
613 + }
614 +
615 + sub
616 + dbOtherCreate
617 + {
618 +  my $userAndHost = shift;
619 +  my $listOfFiles = shift;
620 +  my $comment = shift;
621 +
622 +  my $user = $userAndHost;
623 +  $user =~ s/@.*$//g;
624 +
625 +  my $size = 0.0;
626 +  my $nFiles = 0.0;
627 +  for (my $i = 0; $i < @$listOfFiles; $i++)
628 +    {
629 +      if (!(-e $$listOfFiles[$i]))
630 +        {
631 +          print "$$listOfFiles[$i] does not exist!\n";
632 +          exit;
633 +        }
634 +      $nFiles += `ls -R $$listOfFiles[$i] | grep -v ':\$' | grep -v '^\$' | wc -l`;
635 +      my $fileSize = `du -s $$listOfFiles[$i]`;
636 +      $fileSize =~ s/([^ ]*) .*/$1/;
637 +      $fileSize /= 1024 * 1024;
638 +      $size += $fileSize;
639 +      $$listOfFiles[$i] = "$ENV{'PWD'}/$$listOfFiles[$i]" if !($$listOfFiles[$i] =~ m/^\//);
640 +    }
641 +  $size = sprintf "%.2f", $size;
642 +  my $location = join ("<br />", @$listOfFiles);
643 +
644 +  my $query = "select max(id) from other";
645 +  $db->selectdb ("ntuple");
646 +  my $results = $db->query ($query);
647 +  my @row = $results->fetchrow ();
648 +  my $id = 1;
649 +  $id = $row[0] + 1 if $results->numrows ();
650 +
651 +  $user = addSlashes ($user);
652 +  $location = addSlashes ($location);
653 +  $comment = addSlashes ($comment);
654 +
655 +  $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$userAndHost', '$user', '$location', $nFiles, $size, '$comment')";
656 +  $db->selectdb ("ntuple");
657 +  $results = $db->query ($query);
658 +
659 +  print "ID $id\n";
660 + }
661 +
662 + sub
663 + uploadConfig
664 + {
665 +  my $name = shift;
666 +  my $user = shift;
667 +  my $psetName = shift;
668 +  my $release = shift;
669 +  my $comment = shift;
670 +
671 +  if (!(-e $psetName))
672 +    {
673 +      print "$psetName does not exist!\n";
674 +      exit;
675 +    }
676 +  if ($release)
677 +    {
678 +      my $query = "select id from ntupleRelease where name='$release'";
679 +      $db->selectdb ("ntuple");
680 +      my $results = $db->query ($query);
681 +      if ($results->numrows () != 1)
682 +        {
683 +          print "Ntuple release \"$release\" not found!\n";
684 +          exit;
685 +        }
686 +    }
687 +  open (PSET, "<$psetName");
688 +  my @pset = <PSET>;
689 +  close (PSET);
690 +  my $pset = join ("", @pset);
691 +
692 +  my $query = "select max(id) from ntupleConfig";
693 +  $db->selectdb ("ntuple");
694 +  my $results = $db->query ($query);
695 +  my @row = $results->fetchrow ();
696 +  my $id = 1;
697 +  $id = $row[0] + 1 if $results->numrows ();
698 +
699 +  $name = addSlashes ($name);
700 +  $user = addSlashes ($user);
701 +  $pset = addSlashes ($pset);
702 +  $release = addSlashes ($release);
703 +  $comment = addSlashes ($comment);
704 +
705 +  my $query = "insert into ntupleConfig (id, name, pset, user, pending, ntupleRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$release', '$comment')";
706 +  $db->selectdb ("ntuple");
707 +  $results = $db->query ($query);
708 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines