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.4 by ahart, Tue Jul 31 14:12:19 2012 UTC vs.
Revision 1.5 by ahart, Tue Jul 31 14:55:05 2012 UTC

# Line 34 | Line 34 | if ($ARGV[0] eq "uploadRelease" && !$opt
34   if ($ARGV[0] ne "uploadRelease")
35    {
36      my $id = -1;
37 <    $id = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create";
37 >    my $fullDataset;
38 >    ($id, $fullDataset) = getDataset ($ARGV[0], $ARGV[1]) if $ARGV[0] ne "create";
39 >    $fullDataset = $ARGV[1] if $id < 0;
40      $ARGV[0] = "create" if $id < 0;
41      my $status = "present";
42      $status = "" if $ARGV[0] eq "update";
43      $status = "deprecated" if $ARGV[0] eq "deprecate";
44      $opt{"format"} = "BEAN" if $ARGV[0] eq "create" && !$opt{"format"};
45      $opt{"location"} = "$ENV{'PWD'}/$opt{'location'}" if !($opt{"location"} =~ m/^\//);
46 <    dbUpdate ($id, $ARGV[1], $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"});
46 >    dbUpdate ($id, $fullDataset, $ENV{"USER"}, $opt{"format"}, $opt{"location"}, $opt{"fileList"}, $status, $opt{"comment"}, $opt{"pyConfig"}, $opt{"crabCfg"}, $opt{"jsonFile"}, $opt{"lumiSummary"}, $opt{"release"});
47      dbDelete ($id) if $ARGV[0] eq "deleteEntry";
48    }
49   else
# Line 85 | Line 87 | getDataset
87    if ($results->numrows () == 1)
88      {
89        my @row = $results->fetchrow ();
90 <      return $row[0];
90 >      return ($row[0], $row[1]);
91      }
92    if ($results->numrows () == 0)
93      {
# Line 96 | Line 98 | getDataset
98            $response =~ s/\n//g;
99            $response = "y" if !$response;
100            exit if substr (lc ($response), 0, 1) ne 'y';
101 <          return -1;
101 >          return (-1, "");
102          }
103        else
104          {
# Line 104 | Line 106 | getDataset
106            exit;
107          }
108      }
109 <  my %map;
109 >  my %id;
110 >  my %fullDataset;
111    print "Found multiple database entries matching\n";
112    print "\"$dataset\":\n";
113    print "( 0) new\n" if $command ne "deleteEntry" && $command ne "deprecate";
114    for (my $i = 1; $i <= $results->numrows (); $i++)
115      {
116        my @row = $results->fetchrow ();
117 <      $map{"$i"} = $row[0];
117 >      $id{"$i"} = $row[0];
118 >      $fullDataset{"$i"} = $row[1];
119        printf "(%2d) $row[1]\n", $i;
120        print "     created by $row[2] on $row[3]\n";
121      }
# Line 126 | Line 130 | getDataset
130      }
131    my $response = <STDIN>;
132    $response =~ s/[ \t\n]//g;
133 <  return -1 if $response == 0 && $command ne "deleteEntry" && $command ne "deprecate";
134 <  if (!(exists $map{$response}))
133 >  return (-1, "") if $response == 0 && $command ne "deleteEntry" && $command ne "deprecate";
134 >  if (!(exists $id{$response}))
135      {
136        print "Your selection \"$response\" was not a valid option! Quitting.\n";
137        exit;
138      }
139  
140 <  return $map{$response};
140 >  return ($id{$response}, $fullDataset{$response});
141   }
142  
143   sub
# Line 151 | Line 155 | dbUpdate
155    my $crabCfgName = shift;
156    my $jsonFileName = shift;
157    my $lumiSummaryName = shift;
158 +  my $release = shift;
159  
160    my $fileList;
161    my $pset;
# Line 219 | Line 224 | dbUpdate
224        close (LUMI_SUMMARY);
225        $lumiSummary = join ("", @lumiSummary);
226      }
227 +  if ($release)
228 +    {
229 +      my $query = "select id from ntupleRelease where name='$release'";
230 +      $db->selectdb ("ntuple");
231 +      my $results = $db->query ($query);
232 +      if ($results->numrows () != 1)
233 +        {
234 +          print "Ntuple release \"$release\" not found!\n";
235 +          exit;
236 +        }
237 +    }
238    ($nFiles, $size) = sizeOfDataset ($dataset, $location, $fileList);
239  
240    $dataset = addSlashes ($dataset);
# Line 232 | Line 248 | dbUpdate
248    $fileList = addSlashes ($fileList);
249    $status = addSlashes ($status);
250    $comment = addSlashes ($comment);
251 +  $release = addSlashes ($release);
252  
253    my $results;
254    my $query;
# Line 244 | Line 261 | dbUpdate
261        my $id = 1;
262        $id = $row[0] + 1 if $results->numrows ();
263  
264 <      $query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary) values ($id, '$dataset', now(), now(), '$user', '$format', '$location', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary')";
264 >      $query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, user, format, location, fileList, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, lumiSummary, version) values ($id, '$dataset', now(), now(), '$user', '$format', '$location', '$fileList', $nFiles, $size, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$lumiSummary', '$release')";
265      }
266    if ($id > 0)
267      {
# Line 264 | Line 281 | dbUpdate
281        $values .= ", crabCfg='$crabCfg'" if $crabCfg;
282        $values .= ", jsonFile='$jsonFile'" if $jsonFile;
283        $values .= ", lumiSummary='$lumiSummary'" if $lumiSummary;
284 +      $values .= ", version='$release'" if $release;
285  
286        $values =~ s/^, //;
287        $query = "update ntuple set $values where id=$id";
# Line 305 | Line 323 | printHelp
323        printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
324        printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
325        printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
326 +      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
327        printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
328      }
329    elsif ($command eq "update")
# Line 319 | Line 338 | printHelp
338        printf "%-29s%s\n", "  -j, --jsonFile FILE", "JSON file used for this dataset";
339        printf "%-29s%s\n", "  -l, --location DIRECTORY", "directory containing the ntuples";
340        printf "%-29s%s\n", "  -p, --pyConfig FILE", "Python config used to produce ntuples";
341 +      printf "%-29s%s\n", "  -r, --release NAME", "ntuple release used to produce ntuples";
342        printf "%-29s%s\n", "  -s, --lumiSummary FILE", "lumiSummary.json reported by CRAB";
343      }
344    elsif ($command eq "finish")

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines