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.2 by ahart, Thu Jun 14 17:42:30 2012 UTC vs.
Revision 1.15 by ahart, Mon Mar 25 18:26:58 2013 UTC

# Line 4 | Line 4 | use strict;
4   use Mysql;
5   use File::Copy;
6   use Getopt::Long;
7 + use POSIX;
8  
9   sub printHelp;
10   sub outputPset;
# Line 11 | Line 12 | sub outputRunList;
12   sub getLocation;
13   sub outputCondor;
14  
15 < our $db;
15 > our $db = Mysql->connect ("cmshead", "ntuple", "osuT3User");
16  
17   my %opt;
18   Getopt::Long::Configure ("bundling");
19 < GetOptions (\%opt, "help|h");
19 > GetOptions (\%opt, "maxEvents|m=s", "help|h");
20   my $argc = @ARGV;
21  
22   printHelp () if $opt{"help"};
23 < printHelp () if $argc != 4;
24 < if (!(-e $ARGV[1]))
23 > printHelp () if $argc != 3 && $argc != 4;
24 > my $dataset;
25 > my $config;
26 > my $directory;
27 > my $nJobs;
28 > if ($argc == 3)
29    {
30 <    print "\"$ARGV[1]\" does not exist!\n";
30 >    $dataset = "";
31 >    $config = $ARGV[0];
32 >    $directory = $ARGV[1];
33 >    $nJobs = $ARGV[2];
34 >  }
35 > if ($argc == 4)
36 >  {
37 >    $dataset = $ARGV[0];
38 >    $config = $ARGV[1];
39 >    $directory = $ARGV[2];
40 >    $nJobs = $ARGV[3];
41 >  }
42 > if (!(-e $config))
43 >  {
44 >    print "\"$config\" does not exist!\n";
45      exit;
46    }
47 < if (-e $ARGV[2])
47 > if (-e $directory)
48    {
49 <    print "Directory \"$ARGV[2]\" already exists!\n";
49 >    print "Directory \"$directory\" already exists!\n";
50      print "Please delete it or specify another working directory.\n";
51      exit;
52    }
53 < mkdir $ARGV[2];
54 < outputRunList ($ARGV[0], $ARGV[2]);
55 < outputPset ($ARGV[2]);
56 < outputCondor ($ARGV[2], $ARGV[3]);
57 < copy ($ARGV[1], "$ARGV[2]/userConfig_cfg.py");
58 < chdir $ARGV[2];
53 > mkdir $directory;
54 > my $nFiles = outputRunList ($dataset, $directory);
55 > my $realNJobs = $nJobs;
56 > $realNJobs = ceil ($nFiles / ceil ($nFiles / $realNJobs)) if $nFiles;
57 > my $eventsPerJob = -1;
58 > $eventsPerJob = ceil ($opt{"maxEvents"} / $realNJobs) if $opt{"maxEvents"} && $opt{"maxEvents"} >= 0;
59 > my $realMaxEvents = $eventsPerJob * $realNJobs;
60 > outputPset ($directory, $dataset, $opt{"maxEvents"}, $eventsPerJob);
61 > outputCondor ("$ENV{'CMSSW_BASE'}/src/OSUT3Analysis/DBTools/data/condor.sub", $directory, $realNJobs, $dataset);
62 > copy ($config, "$directory/userConfig_cfg.py");
63 > chdir $directory;
64 > print "Submitting $realNJobs jobs to run on $realMaxEvents events in $nFiles files.\n" if $realMaxEvents >= 0;
65 > print "Submitting $realNJobs jobs to run on all events in $nFiles files.\n" if $realMaxEvents < 0;
66   system ("condor_submit condor.sub");
67  
68   sub
69   outputPset
70   {
71    my $workingDir = shift;
72 +  my $dataset = shift;
73 +  my $nEvents = shift;
74 +  my $eventsPerJob = shift;
75  
76    open (PSET, ">$workingDir/config_cfg.py");
77  
# Line 57 | Line 86 | outputPset
86    print PSET "fileName = re.sub (r'^(.*)\\.([^\\.]*)\$', r'\\1_' + str (osusub.jobNumber) + r'.\\2', fileName)\n";
87    print PSET "pset.process.TFileService.fileName = fileName\n";
88    print PSET "\n";
89 <  print PSET "pset.process.source.fileNames = cms.untracked.vstring (osusub.runList)\n";
90 <  print PSET "pset.process.maxEvents.input = cms.untracked.int32 (-1)\n";
89 >  if ($dataset)
90 >    {
91 >      print PSET "pset.process.source.fileNames = cms.untracked.vstring (osusub.runList)\n";
92 >      print PSET "pset.process.maxEvents.input = cms.untracked.int32 ($eventsPerJob)\n" if $eventsPerJob < 0;
93 >    }
94 >  print PSET "pset.process.maxEvents.input = cms.untracked.int32 ($eventsPerJob)\n" if $eventsPerJob >= 0;
95    print PSET "process = pset.process\n";
96  
97    close (PSET);
# Line 70 | Line 103 | outputRunList
103    my $dataset = shift;
104    my $workingDir = shift;
105  
106 <  my ($location, $nFiles, $status) = getLocation ($dataset);
107 <  if ($status ne "present")
106 >  return 0 if !$dataset;
107 >  my $location;
108 >  my $nFiles;
109 >  my $status;
110 >  my $crossSection;
111 >  my $isLocation = 0;
112 >  $isLocation = 1 if -e $dataset;
113 >  if (!$isLocation)
114      {
115 <      print "This dataset is not marked as present on the Tier 3!\n";
116 <      exit;
115 >      ($location, $nFiles, $status, $crossSection) = getLocation ($dataset);
116 >      if ($status ne "present")
117 >        {
118 >          print "This dataset is not marked as present on the Tier 3!\n";
119 >          print "Continue anyway? (y/N): ";
120 >          my $response = <STDIN>;
121 >          $response =~ s/\n//g;
122 >          exit if !$response || lc ($response) ne "y";
123 >        }
124 >      if (!(-e $location))
125 >        {
126 >          print "The database does not know where this dataset is!\n";
127 >          exit;
128 >        }
129      }
130 <  if (!(-e $location))
130 >  else
131      {
132 <      print "The database does not know where this dataset is!\n";
82 <      exit;
132 >      $location = $dataset;
133      }
134    opendir (LOCATION, $location);
135    my @files = readdir (LOCATION);
136    closedir (LOCATION);
137 <  if (@files - 2 != $nFiles)
137 >  if (!$isLocation && @files - 2 != $nFiles)
138      {
139        print "Number of files does not match database entry!\n";
140 <      exit;
140 >      print "Continue anyway? (y/N): ";
141 >      my $response = <STDIN>;
142 >      $response =~ s/\n//g;
143 >      exit if !$response || lc ($response) ne "y";
144 >    }
145 >  elsif ($isLocation)
146 >    {
147 >      $nFiles = @files - 2;
148      }
149    open (RUNLIST, ">$workingDir/runList.py");
150    print RUNLIST "runList = [\n";
# Line 101 | Line 158 | outputRunList
158      }
159    print RUNLIST "]";
160    close (RUNLIST);
161 +  if ($crossSection && $crossSection >= 0.0)
162 +    {
163 +      open (CROSS_SECTION, ">$workingDir/crossSectionInPicobarn.txt");
164 +      print CROSS_SECTION "$crossSection\n";
165 +      close (CROSS_SECTION);
166 +    }
167 +
168 +  return $nFiles;
169   }
170  
171   sub
# Line 112 | Line 177 | getLocation
177    my $queryDataset = $dataset;
178    $queryDataset =~ s/\*/%/g;
179    $queryDataset =~ s/(.*)/%$1%/g;
180 <  $db = Mysql->connect ("cmshead", "ntuple", "osuT3User");
116 <  my $query = "select dataset,user,creationTime,location,nFiles,status from ntuple where dataset like '$queryDataset' order by lastUpdateTime";
180 >  my $query = "select dataset,user,creationTime,location,nFiles,status,crossSectionInPicobarn,higherOrderCrossSectionInPicobarn from ntuple where dataset like '$queryDataset' order by creationTime";
181    $db->selectdb ("ntuple");
182    $results = $db->query ($query);
183    if ($results->numrows () == 1)
184      {
185        my @row = $results->fetchrow ();
186 <      return ($row[3], $row[4], $row[5]);
186 >      return ($row[3], $row[4], $row[5], $row[7]) if $row[7];
187 >      return ($row[3], $row[4], $row[5], $row[6]) if !$row[7];
188      }
189    if ($results->numrows () == 0)
190      {
# Line 132 | Line 197 | getLocation
197    for (my $i = 1; $i <= $results->numrows (); $i++)
198      {
199        my @row = $results->fetchrow ();
200 <      $map{"$i"} = [$row[3], $row[4], $row[5]];
200 >      $map{"$i"} = [$row[3], $row[4], $row[5], $row[7]] if $row[7];
201 >      $map{"$i"} = [$row[3], $row[4], $row[5], $row[6]] if !$row[7];
202        printf "(%2d) $row[0]\n", $i;
203        print "     created by $row[1] on $row[2]\n";
204      }
# Line 145 | Line 211 | getLocation
211        exit;
212      }
213  
214 <  return ($map{$response}[0], $map{$response}[1], $map{$response}[2]);
214 >  return ($map{$response}[0], $map{$response}[1], $map{$response}[2], $map{$response}[3]);
215   }
216  
217   sub
218   outputCondor
219   {
220 +  my $condorFileName = shift;
221    my $workingDir = shift;
222    my $nJobs = shift;
223 +  my $dataset = shift;
224  
225    my $cmsRun = `which cmsRun`;
226 <  open (SUB, ">$workingDir/condor.sub");
226 >  my $condorFile = "";
227  
228 <  print SUB "Executable              = $cmsRun\n";
229 <  print SUB "Universe                = vanilla\n";
230 <  print SUB "Getenv                  = True\n";
231 <  print SUB "Arguments               = config_cfg.py $nJobs \$(Process)\n";
232 <  print SUB "\n";
233 <  print SUB "Output                  = condor_\$(Process).out\n";
234 <  print SUB "Error                   = condor_\$(Process).err\n";
235 <  print SUB "Log                     = condor_\$(Process).log\n";
236 <  print SUB "\n";
237 <  print SUB "Queue $nJobs\n";
228 >  if (!(-e $condorFileName))
229 >    {
230 >      $condorFile .= "Executable              = $cmsRun\n";
231 >      $condorFile .= "Universe                = vanilla\n";
232 >      $condorFile .= "Getenv                  = True\n";
233 >      $condorFile .= "Arguments               = config_cfg.py True $nJobs \$(Process) $dataset\n" if $dataset;
234 >      $condorFile .= "Arguments               = config_cfg.py True $nJobs \$(Process) NULL\n" if !$dataset;
235 >      $condorFile .= "\n";
236 >      $condorFile .= "Output                  = condor_\$(Process).out\n";
237 >      $condorFile .= "Error                   = condor_\$(Process).err\n";
238 >      $condorFile .= "Log                     = condor_\$(Process).log\n";
239 >      $condorFile .= "\n";
240 >      $condorFile .= "+IsLocalJob             = true\n";
241 >      $condorFile .= "Rank                    = TARGET.IsLocalSlot\n";
242 >      $condorFile .= "\n";
243 >      $condorFile .= "Queue $nJobs\n";
244 >    }
245 >  else
246 >    {
247 >      open (SUB, "<$condorFileName");
248 >      my @condorFile = <SUB>;
249 >      close (SUB);
250 >      $condorFile = join ("", @condorFile);
251 >      $condorFile =~ s/\$cmsRun/$cmsRun/g;
252 >      $condorFile =~ s/\$nJobs/$nJobs/g;
253 >      $condorFile =~ s/\$dataset/$dataset/g if $dataset;
254 >      $condorFile =~ s/\$dataset/NULL/g if !$dataset;
255 >    }
256  
257 +  open (SUB, ">$workingDir/condor.sub");
258 +  print SUB $condorFile;
259    close (SUB);
260   }
261  
# Line 177 | Line 265 | printHelp
265    my $exeName = $0;
266    $exeName =~ s/^.*\/([^\/]*)$/$1/;
267  
268 <  print "Usage: $exeName [OPTIONS] DATASET CONFIG DIRECTORY NJOBS\n";
268 >  print "Usage: $exeName [OPTION]... [DATASET | LOCATION] CONFIG DIRECTORY NJOBS\n";
269    print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n";
270    print "\n";
271    printf "%-29s%s\n", "  -h, --help", "print this help message";
272 +  printf "%-29s%s\n", "  -m, --maxEvents N", "only run over N events in the dataset; default is";
273 +  printf "%-29s%s\n", " ", "to run over all events";
274    print "\n";
275 <  print "The DATASET must exist in the Tier 3 ntuple database, and CONFIG must be a valid\n";
276 <  print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a working\n";
277 <  print "directory that is created and in which all output, both from the CMSSW jobs and\n";
278 <  print "from Condor, is placed. Finally, NJOBS is the number of Condor jobs that will\n";
279 <  print "be created.\n";
275 >  print "The optional first argument must be either a DATASET registered in the Tier 3\n";
276 >  print "ntuple database or a LOCATION which exists on disk. CONFIG must be a valid\n";
277 >  print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a\n";
278 >  print "working directory that is created and in which all output, both from the CMSSW\n";
279 >  print "jobs and from Condor, is placed. Finally, NJOBS is the number of Condor jobs\n";
280 >  print "that will be created.\n";
281  
282    exit;
283   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines