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.23 by ahart, Thu Feb 7 09:04:47 2013 UTC vs.
Revision 1.26 by ahart, Thu May 23 20:39:16 2013 UTC

# Line 4 | Line 4 | use strict;
4   use Mysql;
5   use Getopt::Long;
6   use File::Copy;
7 + use Term::ANSIColor;
8  
9   sub getDataset;
10   sub dbUpdate;
# Line 16 | Line 17 | sub downloadRelease;
17   sub datasetExists;
18   sub uploadConfig;
19   sub locationExists;
20 + sub getLocation;
21  
22   our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped";
23  
24   my %opt;
25   Getopt::Long::Configure ("bundling");
26 < 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");
26 > 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", "higherOrderXSec|y=s", "help|h");
27   my $argc = @ARGV;
28  
29   printHelp ($ARGV[0]) if $opt{"help"};
# Line 86 | Line 88 | else
88          print "This location is already registered in the database!\n";
89          exit;
90        }
91 <    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"};
92 <    dbUpdateOther ($id, $opt{"comment"}, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $opt{"other"};
91 >    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"}, $opt{"higherOrderXSec"}) if $ARGV[0] ne "deleteEntry" && !$opt{"other"};
92 >    dbUpdateOther ($id, $opt{"comment"}, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $ARGV[0] ne "deleteEntry" && $opt{"other"};
93      dbDelete ($id) if $ARGV[0] eq "deleteEntry" && !$opt{"other"};
94      dbDeleteOther ($id) if $ARGV[0] eq "deleteEntry" && $opt{"other"};
95    }
# Line 115 | Line 117 | getDataset
117    my $queryDataset = $dataset;
118    $queryDataset =~ s/\*/%/g;
119    $queryDataset =~ s/(.*)/%$1%/g;
120 <  my $query = "select id,dataset,user,creationTime from ntuple where dataset like '$queryDataset' order by creationTime";
120 >  my $query = "select id,dataset,user,creationTime,status from ntuple where dataset like '$queryDataset' order by creationTime";
121    $db->selectdb ("ntuple");
122    $results = $db->query ($query);
123    if ($results->numrows () == 1)
# Line 148 | Line 150 | getDataset
150    for (my $i = 1; $i <= $results->numrows (); $i++)
151      {
152        my @row = $results->fetchrow ();
153 +      $row[3] =~ s/([^ ]*) [^ ]*/$1/g;
154        $id{"$i"} = $row[0];
155        $fullDataset{"$i"} = $row[1];
156        printf "(%2d) $row[1]\n", $i;
157 <      print "     created by $row[2] on $row[3]\n";
157 >      print "     (";
158 >      print color "green" if $row[4] eq "present";
159 >      print color "bold yellow" if $row[4] eq "submitted";
160 >      print color "bold red" if $row[4] eq "created" or $row[4] eq "cancelled" or $row[4] eq "deprecated";
161 >      print $row[4];
162 >      print color "reset";
163 >      print ") created by $row[2] on $row[3]\n";
164      }
165    print "\nWhich entry would you like to modify?";
166    if ($command ne "deleteEntry" && $command ne "deprecate")
# Line 194 | Line 203 | dbUpdate
203    my $globalTag = shift;
204    my $configName = shift;
205    my $xSection = shift;
206 +  my $ySection = shift;
207 +
208 +  $location = getLocation ($id) if $id > 0
209 +                               && !$crabCfgName
210 +                               && !$comment
211 +                               && !$format
212 +                               && !$globalTag
213 +                               && !$configName
214 +                               && !$jsonFileName
215 +                               && !$location
216 +                               && !$name
217 +                               && !$psetName
218 +                               && !$release
219 +                               && !$lumiSummaryName
220 +                               && !$xSection
221 +                               && !$ySection;
222  
223    my $user = $userAndHost;
224    $user =~ s/@.*$//g;
# Line 266 | Line 291 | dbUpdate
291        $lumiSummary = join ("", @lumiSummary);
292      }
293    $release .= ".$configName" if $configName;
294 <  ($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList);
294 >  ($nFiles, $size) = sizeOfDataset ($location, $fileList);
295    my $fullLocation = $location;
296    $fullLocation = "$ENV{'PWD'}/$location" if !($location =~ m/^\//);
297  
# Line 308 | Line 333 | dbUpdate
333        my $id = 1;
334        $id = $row[0] + 1 if $results->numrows ();
335  
336 <      $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)";
336 >      my $columns = "(id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version, globalTag";
337 >      $columns .= ", crossSectionInPicobarn" if $xSection;
338 >      $columns .= ", higherOrderCrossSectionInPicobarn" if $ySection;
339 >      $columns .= ")";
340 >      my $values = "($id, '$dataset', now(), now(), '$userAndHost', '$user', '$format', '$fullLocation', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release', '$globalTag'";
341 >      $values .= ", $xSection" if $xSection;
342 >      $values .= ", $ySection" if $ySection;
343 >      $values .= ")";
344 >      $query = "insert into ntuple $columns values $values";
345      }
346    if ($id > 0)
347      {
# Line 322 | Line 355 | dbUpdate
355            $results = $db->query ($query);
356            if ($results->numrows ())
357              {
358 <              print "This dataset already exists in the database. Create anyway? (y/N): ";
358 >              print "This dataset already exists in the database. Use this name anyway? (y/N): ";
359                my $response = <STDIN>;
360                $response =~ s/\n//g;
361                $response = "n" if !$response;
# Line 347 | Line 380 | dbUpdate
380        $values .= ", version='$release'" if $release;
381        $values .= ", globalTag='$globalTag'" if $globalTag;
382        $values .= ", crossSectionInPicobarn=$xSection" if $xSection;
383 +      $values .= ", higherOrderCrossSectionInPicobarn=$ySection" if $ySection;
384  
385        $values =~ s/^, //;
386        $query = "update ntuple set $values where id=$id";
# Line 418 | Line 452 | printHelp
452        printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
453        printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
454        printf "%-29s%s\n", "  -x, --xSection XSEC", "cross section in picobarns for the sample";
455 +      printf "%-29s%s\n", "  -y, --higherOrderXSec XSEC", "higher-order cross section in picobarns for the";
456 +      printf "%-29s%s\n", "                            ", "sample";
457      }
458    elsif ($command eq "createOther")
459      {
# Line 430 | Line 466 | printHelp
466    elsif ($command eq "update")
467      {
468        print "Usage: $exeName [OPTION]... update NAME\n";
469 <      print "Updates an existing database entry for dataset NAME.\n";
469 >      print "Updates an existing database entry for dataset NAME. If no options are given,\n";
470 >      print "updates the number of files and the size on disk of the dataset using the\n";
471 >      print "location in the database.\n";
472        print "\n";
473        print "Mandatory arguments to long options are mandatory for short options too.\n";
474        printf "%-29s%s\n", "  -b, --crabCfg FILE", "CRAB config used to submit ntuple jobs";
# Line 446 | Line 484 | printHelp
484        printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
485        printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
486        printf "%-29s%s\n", "  -x, --xSection XSEC", "cross section in picobarns for the sample";
487 +      printf "%-29s%s\n", "  -y, --higherOrderXSec XSEC", "higher-order cross section in picobarns for the";
488 +      printf "%-29s%s\n", "                            ", "sample";
489      }
490    elsif ($command eq "finish")
491      {
# Line 534 | Line 574 | printHelp
574   sub
575   sizeOfDataset
576   {
537  my $dataset = shift;
577    my $location = shift;
578    my $fileList = shift;
579  
# Line 599 | Line 638 | uploadRelease
638    open (RECIPE, "<$recipeName");
639    my @recipe = <RECIPE>;
640    close (RECIPE);
641 <  my $recipe = join ("\n", @recipe);
641 >  my $recipe = join ("", @recipe);
642  
643    my $query = "select max(id) from ntupleRelease";
644    $db->selectdb ("ntuple");
# Line 768 | Line 807 | locationExists
807  
808    return 0;
809   }
810 +
811 + sub
812 + getLocation
813 + {
814 +  my $id = shift;
815 +
816 +  my $query = "select location from ntuple where id=$id";
817 +  $db->selectdb ("ntuple");
818 +  my $results = $db->query ($query);
819 +  my @row = $results->fetchrow ();
820 +
821 +  return $row[0];
822 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines