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.13 by ahart, Mon Oct 22 13:50:25 2012 UTC vs.
Revision 1.22 by ahart, Wed Feb 6 00:35:57 2013 UTC

# Line 14 | Line 14 | 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");
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 ($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";
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";
# Line 35 | Line 37 | if ($ARGV[0] eq "uploadRelease" && (!$op
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'}";
# Line 50 | Line 57 | 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'}", \@listOfFiles, $opt{"comment"});
70 >    dbOtherCreate ("$ENV{'USER'}\@$ENV{'HOSTNAME'}", \@listOfFiles, $opt{"comment"});
71    }
72   else
73    {
# Line 70 | Line 81 | else
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 <    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 >    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"};
# Line 163 | 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 $name = shift;
186    my $fileListName = shift;
187    my $status = shift;
188    my $comment = shift;
# Line 174 | Line 191 | dbUpdate
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;
# Line 242 | Line 264 | dbUpdate
264        close (LUMI_SUMMARY);
265        $lumiSummary = join ("", @lumiSummary);
266      }
267 <  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 <    }
267 >  $release .= ".$configName" if $configName;
268    ($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList);
269    my $fullLocation = $location;
270    $fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//);
# Line 265 | Line 277 | dbUpdate
277    $jsonFile = addSlashes ($jsonFile);
278    $lumiSummary = addSlashes ($lumiSummary);
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 +      $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 281 | 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, 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')";
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;
# Line 303 | Line 344 | dbUpdate
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 366 | Line 408 | printHelp
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";
# Line 389 | Line 433 | printHelp
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";
# Line 399 | Line 446 | printHelp
446    elsif ($command eq "finish")
447      {
448        print "Usage: $exeName -l DIRECTORY finish NAME\n";
402
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";
# Line 447 | Line 493 | printHelp
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";
# Line 465 | Line 521 | printHelp
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;
# Line 530 | Line 587 | uploadRelease
587        print "$recipeName does not exist!\n";
588        exit;
589      }
590 <  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
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);
# Line 574 | Line 631 | downloadRelease
631        print "Ntuple release \"$release\" not found!\n";
632        exit;
633      }
577  if (!(-e "/home/hart/public_html/releases/$release.tar.gz"))
578    {
579      print "Release is in the database but no package exists!\n";
580      exit;
581    }
634    if ($pyConfigName)
635      {
636        my @row = $results->fetchrow ();
# Line 586 | Line 638 | downloadRelease
638        print PY_CONFIG $row[1];
639        close (PY_CONFIG);
640      }
641 <  copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz");
641 >  `wget "http://cmshead.mps.ohio-state.edu/~osucms/releases/$release.tar.gz"`;
642   }
643  
644   sub
645   dbOtherCreate
646   {
647 <  my $user = shift;
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++)
# Line 626 | Line 681 | dbOtherCreate
681    $location = addSlashes ($location);
682    $comment = addSlashes ($comment);
683  
684 <  my $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$user', '$location', $nFiles, $size, '$comment')";
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 <  my $results = $db->query ($query);
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