ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/DBTools/scripts/osusub
(Generate patch)

Comparing UserCode/OSUT3Analysis/DBTools/scripts/osusub (file contents):
Revision 1.13 by ahart, Fri Feb 8 09:17:45 2013 UTC vs.
Revision 1.21 by ahart, Tue Jul 2 23:41:12 2013 UTC

# Line 5 | Line 5 | use Mysql;
5   use File::Copy;
6   use Getopt::Long;
7   use POSIX;
8 + use Term::ANSIColor;
9 + use Cwd 'abs_path';
10 +
11 + select ((select (STDOUT), $| = 1)[0]);
12  
13   sub printHelp;
14   sub outputPset;
# Line 16 | Line 20 | our $db = Mysql->connect ("cmshead", "nt
20  
21   my %opt;
22   Getopt::Long::Configure ("bundling");
23 < GetOptions (\%opt, "maxEvents|m=s", "help|h");
23 > GetOptions (\%opt, "dataset|d=s", "label|l=s", "maxEvents|m=s", "process|p=s", "help|h");
24   my $argc = @ARGV;
25  
26   printHelp () if $opt{"help"};
# Line 57 | Line 61 | $realNJobs = ceil ($nFiles / ceil ($nFil
61   my $eventsPerJob = -1;
62   $eventsPerJob = ceil ($opt{"maxEvents"} / $realNJobs) if $opt{"maxEvents"} && $opt{"maxEvents"} >= 0;
63   my $realMaxEvents = $eventsPerJob * $realNJobs;
64 < outputPset ($directory, $dataset, $opt{"maxEvents"}, $eventsPerJob);
65 < outputCondor ($directory, $realNJobs, $dataset);
64 > outputPset ($directory, $dataset, $opt{"maxEvents"}, $eventsPerJob, $opt{"process"});
65 > $dataset = $opt{"dataset"} if $opt{"dataset"};
66 > outputCondor ("$ENV{'CMSSW_BASE'}/src/OSUT3Analysis/DBTools/data/condor.sub", $directory, $realNJobs, $dataset, $opt{"label"});
67   copy ($config, "$directory/userConfig_cfg.py");
68   chdir $directory;
69   print "Submitting $realNJobs jobs to run on $realMaxEvents events in $nFiles files.\n" if $realMaxEvents >= 0;
70   print "Submitting $realNJobs jobs to run on all events in $nFiles files.\n" if $realMaxEvents < 0;
71 < system ("condor_submit condor.sub");
71 > system ("LD_LIBRARY_PATH=/usr/lib64/condor:\$LD_LIBRARY_PATH condor_submit condor.sub");
72  
73   sub
74   outputPset
# Line 72 | Line 77 | outputPset
77    my $dataset = shift;
78    my $nEvents = shift;
79    my $eventsPerJob = shift;
80 +  my $process = shift;
81 +
82 +  $process =~ s/[^[:alnum:]]//g;
83  
84    open (PSET, ">$workingDir/config_cfg.py");
85  
# Line 93 | Line 101 | outputPset
101      }
102    print PSET "pset.process.maxEvents.input = cms.untracked.int32 ($eventsPerJob)\n" if $eventsPerJob >= 0;
103    print PSET "process = pset.process\n";
104 +  print PSET "process.setName_ (process.name_ () + '$process')\n" if $process;
105  
106    close (PSET);
107   }
# Line 109 | Line 118 | outputRunList
118    my $status;
119    my $crossSection;
120    my $isLocation = 0;
121 <  $isLocation = 1 if -e $dataset;
122 <  if (!$isLocation)
121 >  my $isRunList = 0;
122 >  $isLocation = 1 if -d $dataset;
123 >  $isRunList = 1 if -f $dataset;
124 >  $location = $dataset if $isLocation;
125 >  if (!$isLocation && !$isRunList)
126      {
127        ($location, $nFiles, $status, $crossSection) = getLocation ($dataset);
128        if ($status ne "present")
# Line 127 | Line 139 | outputRunList
139            exit;
140          }
141      }
142 +  my @files;
143 +  if (!$isRunList)
144 +    {
145 +      opendir (LOCATION, $location);
146 +      @files = readdir (LOCATION);
147 +      closedir (LOCATION);
148 +    }
149    else
150      {
151 <      $location = $dataset;
151 >      open (RUNLIST, $dataset);
152 >      while (my $file = <RUNLIST>)
153 >        {
154 >          push (@files, abs_path ($file));
155 >        }
156 >      close (RUNLIST);
157      }
158 <  opendir (LOCATION, $location);
159 <  my @files = readdir (LOCATION);
136 <  closedir (LOCATION);
137 <  if (!$isLocation && @files - 2 != $nFiles)
158 >  $nFiles = @files - 2 if $isLocation || $isRunList;
159 >  if (@files - 2 != $nFiles)
160      {
161        print "Number of files does not match database entry!\n";
162        print "Continue anyway? (y/N): ";
# Line 142 | Line 164 | outputRunList
164        $response =~ s/\n//g;
165        exit if !$response || lc ($response) ne "y";
166      }
145  elsif ($isLocation)
146    {
147      $nFiles = @files - 2;
148    }
167    open (RUNLIST, ">$workingDir/runList.py");
168    print RUNLIST "runList = [\n";
169    for (my $i = 0; $i < @files; $i++)
170      {
171        next if $files[$i] eq ".";
172        next if $files[$i] eq "..";
173 <      print RUNLIST "'file:$location/$files[$i]'";
173 >      print RUNLIST "'file:" . abs_path ("$location/$files[$i]") . "'";
174        print RUNLIST "," if $i + 1 != @files;
175        print RUNLIST "\n";
176      }
# Line 177 | Line 195 | getLocation
195    my $queryDataset = $dataset;
196    $queryDataset =~ s/\*/%/g;
197    $queryDataset =~ s/(.*)/%$1%/g;
198 <  my $query = "select dataset,user,creationTime,location,nFiles,status,crossSectionInPicobarn from ntuple where dataset like '$queryDataset' order by creationTime";
198 >  my $query = "select dataset,user,creationTime,location,nFiles,status,crossSectionInPicobarn,higherOrderCrossSectionInPicobarn from ntuple where dataset like '$queryDataset' order by creationTime";
199    $db->selectdb ("ntuple");
200    $results = $db->query ($query);
201    if ($results->numrows () == 1)
202      {
203        my @row = $results->fetchrow ();
204 <      return ($row[3], $row[4], $row[5], $row[6]);
204 >      $row[7] += 0;
205 >      return ($row[3], $row[4], $row[5], $row[7]) if $row[7] > 0;
206 >      return ($row[3], $row[4], $row[5], $row[6]) if $row[7] <= 0;
207      }
208    if ($results->numrows () == 0)
209      {
# Line 196 | Line 216 | getLocation
216    for (my $i = 1; $i <= $results->numrows (); $i++)
217      {
218        my @row = $results->fetchrow ();
219 <      $map{"$i"} = [$row[3], $row[4], $row[5], $row[6]];
219 >      $row[2] =~ s/([^ ]*) [^ ]*/$1/g;
220 >      $map{"$i"} = [$row[3], $row[4], $row[5], $row[7]] if $row[7];
221 >      $map{"$i"} = [$row[3], $row[4], $row[5], $row[6]] if !$row[7];
222        printf "(%2d) $row[0]\n", $i;
223 <      print "     created by $row[1] on $row[2]\n";
223 >      print "     (";
224 >      print color "green" if $row[5] eq "present";
225 >      print color "bold yellow" if $row[5] eq "submitted";
226 >      print color "bold red" if $row[5] eq "created" or $row[5] eq "cancelled" or $row[5] eq "deprecated";
227 >      print $row[5];
228 >      print color "reset";
229 >      print ") created by $row[1] on $row[2]\n";
230      }
231    print "\nWhich dataset would you like to use?: ";
232    my $response = <STDIN>;
# Line 215 | Line 243 | getLocation
243   sub
244   outputCondor
245   {
246 +  my $condorFileName = shift;
247    my $workingDir = shift;
248    my $nJobs = shift;
249    my $dataset = shift;
250 +  my $label = shift;
251  
252    my $cmsRun = `which cmsRun`;
253 <  open (SUB, ">$workingDir/condor.sub");
253 >  my $condorFile = "";
254  
255 <  print SUB "Executable              = $cmsRun\n";
256 <  print SUB "Universe                = vanilla\n";
257 <  print SUB "Getenv                  = True\n";
258 <  print SUB "Arguments               = config_cfg.py True $nJobs \$(Process) $dataset\n" if $dataset;
259 <  print SUB "Arguments               = config_cfg.py True $nJobs \$(Process) NULL\n" if !$dataset;
260 <  print SUB "\n";
261 <  print SUB "Output                  = condor_\$(Process).out\n";
262 <  print SUB "Error                   = condor_\$(Process).err\n";
263 <  print SUB "Log                     = condor_\$(Process).log\n";
264 <  print SUB "\n";
265 <  print SUB "+IsLocalJob             = true\n";
266 <  print SUB "Rank                    = TARGET.IsLocalSlot\n";
267 <  print SUB "\n";
268 <  print SUB "Queue $nJobs\n";
255 >  if (!(-e $condorFileName))
256 >    {
257 >      my $arguments = "Arguments               = config_cfg.py True $nJobs \$(Process)";
258 >      $arguments .= " $dataset" if $dataset;
259 >      $arguments .= " NULL" if !$dataset;
260 >      $arguments .= " $label" if $label;
261 >      $arguments .= " NULL" if !$label;
262 >      $arguments .= "\n";
263 >
264 >      $condorFile .= "Executable              = $cmsRun\n";
265 >      $condorFile .= "Universe                = vanilla\n";
266 >      $condorFile .= "Getenv                  = True\n";
267 >      $condorFile .= $arguments;
268 >      $condorFile .= "\n";
269 >      $condorFile .= "Output                  = condor_\$(Process).out\n";
270 >      $condorFile .= "Error                   = condor_\$(Process).err\n";
271 >      $condorFile .= "Log                     = condor_\$(Process).log\n";
272 >      $condorFile .= "\n";
273 >      $condorFile .= "+IsLocalJob             = true\n";
274 >      $condorFile .= "Rank                    = TARGET.IsLocalSlot\n";
275 >      $condorFile .= "\n";
276 >      $condorFile .= "Queue $nJobs\n";
277 >    }
278 >  else
279 >    {
280 >      open (SUB, "<$condorFileName");
281 >      my @condorFile = <SUB>;
282 >      close (SUB);
283 >      $condorFile = join ("", @condorFile);
284 >      $condorFile =~ s/\$cmsRun/$cmsRun/g;
285 >      $condorFile =~ s/\$nJobs/$nJobs/g;
286 >      $condorFile =~ s/\$dataset/$dataset/g if $dataset;
287 >      $condorFile =~ s/\$dataset/NULL/g if !$dataset;
288 >      $condorFile =~ s/\$label/$label/g if $label;
289 >      $condorFile =~ s/\$label/NULL/g if !$label;
290 >    }
291  
292 +  open (SUB, ">$workingDir/condor.sub");
293 +  print SUB $condorFile;
294    close (SUB);
295   }
296  
# Line 246 | Line 300 | printHelp
300    my $exeName = $0;
301    $exeName =~ s/^.*\/([^\/]*)$/$1/;
302  
303 <  print "Usage: $exeName [OPTION]... [DATASET | LOCATION] CONFIG DIRECTORY NJOBS\n";
303 >  print "Usage: $exeName [OPTION]... [DATASET | LOCATION | LIST] CONFIG DIRECTORY NJOBS\n";
304    print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n";
305    print "\n";
306 +  printf "%-29s%s\n", "  -d, --dataset DATASET", "override the dataset name";
307    printf "%-29s%s\n", "  -h, --help", "print this help message";
308 +  printf "%-29s%s\n", "  -l, --label LABEL", "give the dataset a short label";
309    printf "%-29s%s\n", "  -m, --maxEvents N", "only run over N events in the dataset; default is";
310 +  printf "%-29s%s\n", "  -p, --process PROCESS", "suffix for the process name";
311    printf "%-29s%s\n", " ", "to run over all events";
312    print "\n";
313    print "The optional first argument must be either a DATASET registered in the Tier 3\n";
314 <  print "ntuple database or a LOCATION which exists on disk. CONFIG must be a valid\n";
315 <  print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a\n";
316 <  print "working directory that is created and in which all output, both from the CMSSW\n";
317 <  print "jobs and from Condor, is placed. Finally, NJOBS is the number of Condor jobs\n";
318 <  print "that will be created.\n";
314 >  print "ntuple database, a LOCATION which exists on disk, or a text file containing a\n";
315 >  print "LIST of files to run over. CONFIG must be a valid CMSSW python configuration\n";
316 >  print "which can be used with cmsRun. DIRECTORY is a working directory that is created\n";
317 >  print "  and in which all output, both from the CMSSW jobs and from Condor, is placed.\n";
318 >  print "Finally, NJOBS is the number of Condor jobs that will be created.\n";
319  
320    exit;
321   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines