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.17 by ahart, Wed May 1 19:47:56 2013 UTC vs.
Revision 1.20 by ahart, Wed Jun 19 13:40:44 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   sub printHelp;
12   sub outputPset;
# Line 16 | Line 18 | our $db = Mysql->connect ("cmshead", "nt
18  
19   my %opt;
20   Getopt::Long::Configure ("bundling");
21 < GetOptions (\%opt, "label|l=s", "maxEvents|m=s", "help|h");
21 > GetOptions (\%opt, "dataset|d=s", "label|l=s", "maxEvents|m=s", "process|p=s", "help|h");
22   my $argc = @ARGV;
23  
24   printHelp () if $opt{"help"};
# Line 57 | Line 59 | $realNJobs = ceil ($nFiles / ceil ($nFil
59   my $eventsPerJob = -1;
60   $eventsPerJob = ceil ($opt{"maxEvents"} / $realNJobs) if $opt{"maxEvents"} && $opt{"maxEvents"} >= 0;
61   my $realMaxEvents = $eventsPerJob * $realNJobs;
62 < outputPset ($directory, $dataset, $opt{"maxEvents"}, $eventsPerJob);
62 > outputPset ($directory, $dataset, $opt{"maxEvents"}, $eventsPerJob, $opt{"process"});
63 > $dataset = $opt{"dataset"} if $opt{"dataset"};
64   outputCondor ("$ENV{'CMSSW_BASE'}/src/OSUT3Analysis/DBTools/data/condor.sub", $directory, $realNJobs, $dataset, $opt{"label"});
65   copy ($config, "$directory/userConfig_cfg.py");
66   chdir $directory;
67   print "Submitting $realNJobs jobs to run on $realMaxEvents events in $nFiles files.\n" if $realMaxEvents >= 0;
68   print "Submitting $realNJobs jobs to run on all events in $nFiles files.\n" if $realMaxEvents < 0;
69 < system ("condor_submit condor.sub");
69 > system ("LD_LIBRARY_PATH=/usr/lib64/condor:\$LD_LIBRARY_PATH condor_submit condor.sub");
70  
71   sub
72   outputPset
# Line 72 | Line 75 | outputPset
75    my $dataset = shift;
76    my $nEvents = shift;
77    my $eventsPerJob = shift;
78 +  my $process = shift;
79 +
80 +  $process =~ s/[^[:alnum:]]//g;
81  
82    open (PSET, ">$workingDir/config_cfg.py");
83  
# Line 93 | Line 99 | outputPset
99      }
100    print PSET "pset.process.maxEvents.input = cms.untracked.int32 ($eventsPerJob)\n" if $eventsPerJob >= 0;
101    print PSET "process = pset.process\n";
102 +  print PSET "process.setName_ (process.name_ () + '$process')\n" if $process;
103  
104    close (PSET);
105   }
# Line 109 | Line 116 | outputRunList
116    my $status;
117    my $crossSection;
118    my $isLocation = 0;
119 <  $isLocation = 1 if -e $dataset;
120 <  if (!$isLocation)
119 >  my $isRunList = 0;
120 >  $isLocation = 1 if -d $dataset;
121 >  $isRunList = 1 if -f $dataset;
122 >  $location = $dataset if $isLocation;
123 >  if (!$isLocation && !$isRunList)
124      {
125        ($location, $nFiles, $status, $crossSection) = getLocation ($dataset);
126        if ($status ne "present")
# Line 127 | Line 137 | outputRunList
137            exit;
138          }
139      }
140 +  my @files;
141 +  if (!$isRunList)
142 +    {
143 +      opendir (LOCATION, $location);
144 +      @files = readdir (LOCATION);
145 +      closedir (LOCATION);
146 +    }
147    else
148      {
149 <      $location = $dataset;
149 >      open (RUNLIST, $dataset);
150 >      while (my $file = <RUNLIST>)
151 >        {
152 >          push (@files, abs_path ($file));
153 >        }
154 >      close (RUNLIST);
155      }
156 <  opendir (LOCATION, $location);
157 <  my @files = readdir (LOCATION);
136 <  closedir (LOCATION);
137 <  if (!$isLocation && @files - 2 != $nFiles)
156 >  $nFiles = @files - 2 if $isLocation || $isRunList;
157 >  if (@files - 2 != $nFiles)
158      {
159        print "Number of files does not match database entry!\n";
160        print "Continue anyway? (y/N): ";
# Line 142 | Line 162 | outputRunList
162        $response =~ s/\n//g;
163        exit if !$response || lc ($response) ne "y";
164      }
145  elsif ($isLocation)
146    {
147      $nFiles = @files - 2;
148    }
165    open (RUNLIST, ">$workingDir/runList.py");
166    print RUNLIST "runList = [\n";
167    for (my $i = 0; $i < @files; $i++)
168      {
169        next if $files[$i] eq ".";
170        next if $files[$i] eq "..";
171 <      print RUNLIST "'file:$location/$files[$i]'";
171 >      print RUNLIST "'file:" . abs_path ("$location/$files[$i]") . "'";
172        print RUNLIST "," if $i + 1 != @files;
173        print RUNLIST "\n";
174      }
# Line 197 | Line 213 | getLocation
213    for (my $i = 1; $i <= $results->numrows (); $i++)
214      {
215        my @row = $results->fetchrow ();
216 +      $row[2] =~ s/([^ ]*) [^ ]*/$1/g;
217        $map{"$i"} = [$row[3], $row[4], $row[5], $row[7]] if $row[7];
218        $map{"$i"} = [$row[3], $row[4], $row[5], $row[6]] if !$row[7];
219        printf "(%2d) $row[0]\n", $i;
220 <      print "     created by $row[1] on $row[2]\n";
220 >      print "     (";
221 >      print color "green" if $row[5] eq "present";
222 >      print color "bold yellow" if $row[5] eq "submitted";
223 >      print color "bold red" if $row[5] eq "created" or $row[5] eq "cancelled" or $row[5] eq "deprecated";
224 >      print $row[5];
225 >      print color "reset";
226 >      print ") created by $row[1] on $row[2]\n";
227      }
228    print "\nWhich dataset would you like to use?: ";
229    my $response = <STDIN>;
# Line 274 | Line 297 | printHelp
297    my $exeName = $0;
298    $exeName =~ s/^.*\/([^\/]*)$/$1/;
299  
300 <  print "Usage: $exeName [OPTION]... [DATASET | LOCATION] CONFIG DIRECTORY NJOBS\n";
300 >  print "Usage: $exeName [OPTION]... [DATASET | LOCATION | LIST] CONFIG DIRECTORY NJOBS\n";
301    print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n";
302    print "\n";
303 +  printf "%-29s%s\n", "  -d, --dataset DATASET", "override the dataset name";
304    printf "%-29s%s\n", "  -h, --help", "print this help message";
305    printf "%-29s%s\n", "  -l, --label LABEL", "give the dataset a short label";
306    printf "%-29s%s\n", "  -m, --maxEvents N", "only run over N events in the dataset; default is";
307 +  printf "%-29s%s\n", "  -p, --process PROCESS", "suffix for the process name";
308    printf "%-29s%s\n", " ", "to run over all events";
309    print "\n";
310    print "The optional first argument must be either a DATASET registered in the Tier 3\n";
311 <  print "ntuple database or a LOCATION which exists on disk. CONFIG must be a valid\n";
312 <  print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a\n";
313 <  print "working directory that is created and in which all output, both from the CMSSW\n";
314 <  print "jobs and from Condor, is placed. Finally, NJOBS is the number of Condor jobs\n";
315 <  print "that will be created.\n";
311 >  print "ntuple database, a LOCATION which exists on disk, or a text file containing a\n";
312 >  print "LIST of files to run over. CONFIG must be a valid CMSSW python configuration\n";
313 >  print "which can be used with cmsRun. DIRECTORY is a working directory that is created\n";
314 >  print "  and in which all output, both from the CMSSW jobs and from Condor, is placed.\n";
315 >  print "Finally, NJOBS is the number of Condor jobs that will be created.\n";
316  
317    exit;
318   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines