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.12 by ahart, Mon Oct 22 12:50:07 2012 UTC vs.
Revision 1.23 by ahart, Thu Feb 7 09:04:47 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", "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", "xSection|x=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";
33      exit;
34    }
35 < if ($ARGV[0] eq "uploadRelease" && !$opt{"pyConfig"} && !$opt{"release"})
35 > if ($ARGV[0] eq "uploadRelease" && (!$opt{"pyConfig"} || !$opt{"release"} || !$opt{"recipe"}))
36    {
37 <    print "Both the Python and the CMSSW release must be given!\n";
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")
# Line 44 | Line 51 | if ($ARGV[0] eq "uploadRelease")
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"});
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'}", \@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"}, $opt{"xSection"}) 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 +  my $xSection = shift;
197 +
198 +  my $user = $userAndHost;
199 +  $user =~ s/@.*$//g;
200  
201    my $fileList;
202    my $pset;
# Line 242 | Line 265 | dbUpdate
265        close (LUMI_SUMMARY);
266        $lumiSummary = join ("", @lumiSummary);
267      }
268 <  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 <    }
268 >  $release .= ".$configName" if $configName;
269    ($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList);
270    my $fullLocation = $location;
271    $fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//);
# Line 265 | Line 278 | dbUpdate
278    $jsonFile = addSlashes ($jsonFile);
279    $lumiSummary = addSlashes ($lumiSummary);
280    $fullLocation = addSlashes ($fullLocation);
281 +  $name = addSlashes ($name);
282    $fileList = addSlashes ($fileList);
283    $status = addSlashes ($status);
284    $comment = addSlashes ($comment);
285    $release = addSlashes ($release);
286 +  $globalTag = addSlashes ($globalTag);
287  
288    my $results;
289    my $query;
290    if ($id < 0)
291      {
292 +      $query = "select id from ntuple where dataset='$dataset'";
293 +      $db->selectdb ("ntuple");
294 +      $results = $db->query ($query);
295 +      if ($results->numrows ())
296 +        {
297 +          print "This dataset already exists in the database. Create anyway? (y/N): ";
298 +          my $response = <STDIN>;
299 +          $response =~ s/\n//g;
300 +          $response = "n" if !$response;
301 +          exit if substr (lc ($response), 0, 1) ne 'y';
302 +        }
303 +
304        $query = "select max(id) from ntuple";
305        $db->selectdb ("ntuple");
306        $results = $db->query ($query);
# Line 281 | Line 308 | dbUpdate
308        my $id = 1;
309        $id = $row[0] + 1 if $results->numrows ();
310  
311 <      $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')";
311 >      $query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version, globalTag, crossSectionInPicobarn) values ($id, '$dataset', now(), now(), '$userAndHost', '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release', '$globalTag', $xSection)";
312      }
313    if ($id > 0)
314      {
315        my $fields;
316        my $values;
317  
318 <      $values .= ", dataset='$dataset'" if $dataset;
318 >      if ($name)
319 >        {
320 >          $query = "select id from ntuple where dataset='$name'";
321 >          $db->selectdb ("ntuple");
322 >          $results = $db->query ($query);
323 >          if ($results->numrows ())
324 >            {
325 >              print "This dataset already exists in the database. Create anyway? (y/N): ";
326 >              my $response = <STDIN>;
327 >              $response =~ s/\n//g;
328 >              $response = "n" if !$response;
329 >              exit if substr (lc ($response), 0, 1) ne 'y';
330 >            }
331 >          $values .= ", dataset='$name'";
332 >        }
333 >
334        $values .= ", lastUpdateTime=now()";
335        $values .= ", lastUpdateUser='$user'";
336        $values .= ", format='$format'" if $format;
# Line 303 | Line 345 | dbUpdate
345        $values .= ", jsonFile='$jsonFile'" if $jsonFile;
346        $values .= ", lumiSummary='$lumiSummary'" if $lumiSummary;
347        $values .= ", version='$release'" if $release;
348 +      $values .= ", globalTag='$globalTag'" if $globalTag;
349 +      $values .= ", crossSectionInPicobarn=$xSection" if $xSection;
350  
351        $values =~ s/^, //;
352        $query = "update ntuple set $values where id=$id";
# Line 366 | Line 410 | printHelp
410        printf "%-29s%s\n", "  -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs";
411        printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
412        printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
413 +      printf "%-29s%s\n", "  -g, --globalTag TAG", "global tag";
414 +      printf "%-29s%s\n", "  -i, --configName NAME", "name of config used to produce ntuples";
415        printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
416        printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
417        printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
418        printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
419        printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
420 +      printf "%-29s%s\n", "  -x, --xSection XSEC", "cross section in picobarns for the sample";
421      }
422    elsif ($command eq "createOther")
423      {
# Line 389 | Line 436 | printHelp
436        printf "%-29s%s\n", "  -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs";
437        printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
438        printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format";
439 +      printf "%-29s%s\n", "  -g, --globalTag TAG", "global tag";
440 +      printf "%-29s%s\n", "  -i, --configName NAME", "name of config used to produce ntuples";
441        printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
442        printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
443 +      printf "%-29s%s\n", "  -n, --name NAME", "rename the entry";
444        printf "%-29s%s\n", "  -o, --other", "update an entry in the non-ntuple database";
445        printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
446        printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
447        printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
448 +      printf "%-29s%s\n", "  -x, --xSection XSEC", "cross section in picobarns for the sample";
449      }
450    elsif ($command eq "finish")
451      {
452        print "Usage: $exeName -l DIRECTORY finish NAME\n";
402
453        print "Finalizes the database entry for dataset NAME, changing its status to\n";
454        print "\"present\".  This is intended to be the final step in command-line based ntuple\n";
455        print "production.\n";
# Line 425 | Line 475 | printHelp
475      }
476    elsif ($command eq "uploadRelease")
477      {
478 <      print "Usage: $exeName -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
478 >      print "Usage: $exeName -e FILE -p FILE -r DIRECTORY [OPTION]... uploadRelease NAME\n";
479        print "Copies an ntuple release to the appropriate area on the Tier 3, and creates a\n";
480        print "database entry for it, with NAME being the name of the release. An ntuple\n";
481        print "release is a CMSSW release with all the necessary packages added for creating\n";
# Line 433 | Line 483 | printHelp
483        print "\n";
484        print "Mandatory arguments to long options are mandatory for short options too.\n";
485        printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
486 +      printf "%-29s%s\n", "  -e, --recipe FILE", "file containing the recipe for the release";
487        printf "%-29s%s\n", "  -f, --format FORMAT", "ntuple format (default: BEAN)";
488        printf "%-29s%s\n", "  -p, --pyConfig FILE", "default Python config for the release";
489        printf "%-29s%s\n", "  -r, --release DIRECTORY", "CMSSW release containing ntuple packages";
# Line 446 | Line 497 | printHelp
497        print "Mandatory arguments to long options are mandatory for short options too.\n";
498        printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python configuration file name";
499      }
500 +  elsif ($command eq "uploadConfig")
501 +    {
502 +      print "Usage: $exeName -p FILE -r RELEASE [OPTION]... uploadConfig NAME\n";
503 +      print "Creates an entry in the database for a customized Python configuration file.\n";
504 +      print "\n";
505 +      print "Mandatory arguments to long options are mandatory for short options too.\n";
506 +      printf "%-29s%s\n", "  -c, --comment COMMENT", "comment for the database entry";
507 +      printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config file";
508 +      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release with which to use this config";
509 +    }
510    else
511      {
512        print "Usage: $exeName [OPTION]... COMMAND NAME\n";
# Line 464 | Line 525 | printHelp
525        printf "%-29s%s\n", "  deprecate", "marks the dataset for deletion";
526        printf "%-29s%s\n", "  uploadRelease", "upload an ntuple release";
527        printf "%-29s%s\n", "  downloadRelease", "download an ntuple release";
528 +      printf "%-29s%s\n", "  uploadConfig", "upload an ntuple config";
529      }
530  
531    exit;
# Line 517 | Line 579 | uploadRelease
579    my $name = shift;
580    my $user = shift;
581    my $comment = shift;
582 +  my $recipeName = shift;
583  
521  move ($release, "/home/hart/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
584    if (!(-e $psetName))
585      {
586        print "$psetName does not exist!\n";
587        exit;
588      }
589 +  if (!(-e $recipeName))
590 +    {
591 +      print "$recipeName does not exist!\n";
592 +      exit;
593 +    }
594 +  move ($release, "/home/osucms/public_html/releases/$name.tar.gz") or die "Ntuple releases may only be uploaded on the Tier 3, stopped";
595    open (PY_CONFIG, "<$psetName");
596    my @pset = <PY_CONFIG>;
597    close (PY_CONFIG);
598    my $pset = join ("", @pset);
599 +  open (RECIPE, "<$recipeName");
600 +  my @recipe = <RECIPE>;
601 +  close (RECIPE);
602 +  my $recipe = join ("\n", @recipe);
603  
604    my $query = "select max(id) from ntupleRelease";
605    $db->selectdb ("ntuple");
# Line 542 | Line 614 | uploadRelease
614    $format = addSlashes ($format);
615    $cmsswRelease = addSlashes ($cmsswRelease);
616    $comment = addSlashes ($comment);
617 +  $recipe = addSlashes ($recipe);
618  
619 <  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment')";
619 >  my $query = "insert into ntupleRelease (id, name, pset, user, pending, format, cmsswRelease, comment, recipe) values ($id, '$name', '$pset', '$user', 1, '$format', '$cmsswRelease', '$comment', '$recipe')";
620    $db->selectdb ("ntuple");
621    my $results = $db->query ($query);
622   }
# Line 562 | Line 635 | downloadRelease
635        print "Ntuple release \"$release\" not found!\n";
636        exit;
637      }
565  if (!(-e "/home/hart/public_html/releases/$release.tar.gz"))
566    {
567      print "Release is in the database but no package exists!\n";
568      exit;
569    }
638    if ($pyConfigName)
639      {
640        my @row = $results->fetchrow ();
# Line 574 | Line 642 | downloadRelease
642        print PY_CONFIG $row[1];
643        close (PY_CONFIG);
644      }
645 <  copy ("/home/hart/public_html/releases/$release.tar.gz", "$release.tar.gz");
645 >  `wget "http://cmshead.mps.ohio-state.edu/~osucms/releases/$release.tar.gz"`;
646   }
647  
648   sub
649   dbOtherCreate
650   {
651 <  my $user = shift;
651 >  my $userAndHost = shift;
652    my $listOfFiles = shift;
653    my $comment = shift;
654  
655 +  my $user = $userAndHost;
656 +  $user =~ s/@.*$//g;
657 +
658    my $size = 0.0;
659    my $nFiles = 0.0;
660    for (my $i = 0; $i < @$listOfFiles; $i++)
# Line 614 | Line 685 | dbOtherCreate
685    $location = addSlashes ($location);
686    $comment = addSlashes ($comment);
687  
688 <  my $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$user', '$user', '$location', $nFiles, $size, '$comment')";
688 >  $query = "insert into other (id, creationTime, lastUpdateTime, lastUpdateUser, user, location, nFiles, sizeInGB, comment) values ($id, now(), now(), '$userAndHost', '$user', '$location', $nFiles, $size, '$comment')";
689    $db->selectdb ("ntuple");
690 <  my $results = $db->query ($query);
690 >  $results = $db->query ($query);
691  
692    print "ID $id\n";
693   }
694 +
695 + sub
696 + uploadConfig
697 + {
698 +  my $name = shift;
699 +  my $user = shift;
700 +  my $psetName = shift;
701 +  my $release = shift;
702 +  my $comment = shift;
703 +
704 +  if (!(-e $psetName))
705 +    {
706 +      print "$psetName does not exist!\n";
707 +      exit;
708 +    }
709 +  if ($release)
710 +    {
711 +      my $query = "select id from ntupleRelease where name='$release'";
712 +      $db->selectdb ("ntuple");
713 +      my $results = $db->query ($query);
714 +      if ($results->numrows () != 1)
715 +        {
716 +          print "Ntuple release \"$release\" not found!\n";
717 +          exit;
718 +        }
719 +    }
720 +  open (PSET, "<$psetName");
721 +  my @pset = <PSET>;
722 +  close (PSET);
723 +  my $pset = join ("", @pset);
724 +
725 +  my $query = "select max(id) from ntupleConfig";
726 +  $db->selectdb ("ntuple");
727 +  my $results = $db->query ($query);
728 +  my @row = $results->fetchrow ();
729 +  my $id = 1;
730 +  $id = $row[0] + 1 if $results->numrows ();
731 +
732 +  $name = addSlashes ($name);
733 +  $user = addSlashes ($user);
734 +  $pset = addSlashes ($pset);
735 +  $release = addSlashes ($release);
736 +  $comment = addSlashes ($comment);
737 +
738 +  my $query = "insert into ntupleConfig (id, name, pset, user, pending, ntupleRelease, comment) values ($id, '$name', '$pset', '$user', 1, '$release', '$comment')";
739 +  $db->selectdb ("ntuple");
740 +  $results = $db->query ($query);
741 + }
742 +
743 + sub
744 + locationExists
745 + {
746 +  my $id = shift;
747 +  my $location = shift;
748 +
749 +  $location =~ s/^(.*)\/+$/$1/;
750 +  my $query = "select id from ntuple where location like '$location%' and id!=$id";
751 +  $db->selectdb ("ntuple");
752 +  my $results = $db->query ($query);
753 +  return 1 if $results->numrows ();
754 +
755 +  if ($location =~ m/^\/store\/.*$/)
756 +    {
757 +      $location =~ s/^\/store\/(.*)$/\/data\/se\/store\/$1/;
758 +    }
759 +  elsif ($location =~ m/^\/data\/se\/store\/.*$/)
760 +    {
761 +      $location =~ s/^\/data\/se\/store\/(.*)$/\/store\/$1/;
762 +    }
763 +
764 +  my $query = "select id from ntuple where location like '$location%' and id!=$id";
765 +  $db->selectdb ("ntuple");
766 +  my $results = $db->query ($query);
767 +  return 1 if $results->numrows ();
768 +
769 +  return 0;
770 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines