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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines