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.4 by ahart, Thu Aug 9 06:36:17 2012 UTC vs.
Revision 1.12 by ahart, Mon Feb 4 04:14:43 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 19 | Line 20 | GetOptions (\%opt, "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 = 0;
56 > $realNJobs = ceil ($nFiles / ceil ($nFiles / $nJobs)) if $nFiles;
57 > outputPset ($directory, $dataset);
58 > outputCondor ($directory, $realNJobs, $nJobs, $dataset);
59 > copy ($config, "$directory/userConfig_cfg.py");
60 > chdir $directory;
61 > print "Submitting $realNJobs jobs to run on $nFiles files.\n";
62   system ("condor_submit condor.sub");
63  
64   sub
65   outputPset
66   {
67    my $workingDir = shift;
68 +  my $dataset = shift;
69  
70    open (PSET, ">$workingDir/config_cfg.py");
71  
# Line 57 | Line 80 | outputPset
80    print PSET "fileName = re.sub (r'^(.*)\\.([^\\.]*)\$', r'\\1_' + str (osusub.jobNumber) + r'.\\2', fileName)\n";
81    print PSET "pset.process.TFileService.fileName = fileName\n";
82    print PSET "\n";
83 <  print PSET "pset.process.source.fileNames = cms.untracked.vstring (osusub.runList)\n";
84 <  print PSET "pset.process.maxEvents.input = cms.untracked.int32 (-1)\n";
83 >  if ($dataset)
84 >    {
85 >      print PSET "pset.process.source.fileNames = cms.untracked.vstring (osusub.runList)\n";
86 >      print PSET "pset.process.maxEvents.input = cms.untracked.int32 (-1)\n";
87 >    }
88    print PSET "process = pset.process\n";
89  
90    close (PSET);
# Line 70 | Line 96 | outputRunList
96    my $dataset = shift;
97    my $workingDir = shift;
98  
99 <  my ($location, $nFiles, $status) = getLocation ($dataset);
100 <  if ($status ne "present")
101 <    {
102 <      print "This dataset is not marked as present on the Tier 3!\n";
103 <      exit;
99 >  return 0 if !$dataset;
100 >  my $location;
101 >  my $nFiles;
102 >  my $status;
103 >  my $crossSection;
104 >  my $isLocation = 0;
105 >  $isLocation = 1 if -e $dataset;
106 >  if (!$isLocation)
107 >    {
108 >      ($location, $nFiles, $status, $crossSection) = getLocation ($dataset);
109 >      if ($status ne "present")
110 >        {
111 >          print "This dataset is not marked as present on the Tier 3!\n";
112 >          print "Continue anyway? (y/N): ";
113 >          my $response = <STDIN>;
114 >          $response =~ s/\n//g;
115 >          exit if !$response || lc ($response) ne "y";
116 >        }
117 >      if (!(-e $location))
118 >        {
119 >          print "The database does not know where this dataset is!\n";
120 >          exit;
121 >        }
122      }
123 <  if (!(-e $location))
123 >  else
124      {
125 <      print "The database does not know where this dataset is!\n";
82 <      exit;
125 >      $location = $dataset;
126      }
127    opendir (LOCATION, $location);
128    my @files = readdir (LOCATION);
129    closedir (LOCATION);
130 <  if (@files - 2 != $nFiles)
130 >  if (!$isLocation && @files - 2 != $nFiles)
131      {
132        print "Number of files does not match database entry!\n";
133 <      exit;
133 >      print "Continue anyway? (y/N): ";
134 >      my $response = <STDIN>;
135 >      $response =~ s/\n//g;
136 >      exit if !$response || lc ($response) ne "y";
137 >    }
138 >  elsif ($isLocation)
139 >    {
140 >      $nFiles = @files - 2;
141      }
142    open (RUNLIST, ">$workingDir/runList.py");
143    print RUNLIST "runList = [\n";
# Line 101 | Line 151 | outputRunList
151      }
152    print RUNLIST "]";
153    close (RUNLIST);
154 +  if ($crossSection && $crossSection >= 0.0)
155 +    {
156 +      open (CROSS_SECTION, ">$workingDir/crossSectionInPicobarn.txt");
157 +      print CROSS_SECTION "$crossSection\n";
158 +      close (CROSS_SECTION);
159 +    }
160 +
161 +  return $nFiles;
162   }
163  
164   sub
# Line 112 | Line 170 | getLocation
170    my $queryDataset = $dataset;
171    $queryDataset =~ s/\*/%/g;
172    $queryDataset =~ s/(.*)/%$1%/g;
173 <  my $query = "select dataset,user,creationTime,location,nFiles,status from ntuple where dataset like '$queryDataset' and status='present' order by creationTime";
173 >  my $query = "select dataset,user,creationTime,location,nFiles,status,crossSectionInPicobarn from ntuple where dataset like '$queryDataset' order by creationTime";
174    $db->selectdb ("ntuple");
175    $results = $db->query ($query);
176    if ($results->numrows () == 1)
177      {
178        my @row = $results->fetchrow ();
179 <      return ($row[3], $row[4], $row[5]);
179 >      return ($row[3], $row[4], $row[5], $row[6]);
180      }
181    if ($results->numrows () == 0)
182      {
# Line 131 | Line 189 | getLocation
189    for (my $i = 1; $i <= $results->numrows (); $i++)
190      {
191        my @row = $results->fetchrow ();
192 <      $map{"$i"} = [$row[3], $row[4], $row[5]];
192 >      $map{"$i"} = [$row[3], $row[4], $row[5], $row[6]];
193        printf "(%2d) $row[0]\n", $i;
194        print "     created by $row[1] on $row[2]\n";
195      }
# Line 144 | Line 202 | getLocation
202        exit;
203      }
204  
205 <  return ($map{$response}[0], $map{$response}[1], $map{$response}[2]);
205 >  return ($map{$response}[0], $map{$response}[1], $map{$response}[2], $map{$response}[3]);
206   }
207  
208   sub
209   outputCondor
210   {
211    my $workingDir = shift;
212 +  my $realNJobs = shift;
213    my $nJobs = shift;
214 +  my $dataset = shift;
215  
216    my $cmsRun = `which cmsRun`;
217    open (SUB, ">$workingDir/condor.sub");
# Line 159 | Line 219 | outputCondor
219    print SUB "Executable              = $cmsRun\n";
220    print SUB "Universe                = vanilla\n";
221    print SUB "Getenv                  = True\n";
222 <  print SUB "Arguments               = config_cfg.py $nJobs \$(Process)\n";
222 >  print SUB "Arguments               = config_cfg.py True $realNJobs \$(Process) $dataset\n" if $dataset;
223 >  print SUB "Arguments               = config_cfg.py True $realNJobs \$(Process) NULL\n" if !$dataset;
224    print SUB "\n";
225    print SUB "Output                  = condor_\$(Process).out\n";
226    print SUB "Error                   = condor_\$(Process).err\n";
227    print SUB "Log                     = condor_\$(Process).log\n";
228    print SUB "\n";
229 +  print SUB "+IsLocalJob             = true\n";
230 +  print SUB "Rank                    = TARGET.IsLocalSlot\n";
231 +  print SUB "\n";
232    print SUB "Queue $nJobs\n";
233  
234    close (SUB);
# Line 176 | Line 240 | printHelp
240    my $exeName = $0;
241    $exeName =~ s/^.*\/([^\/]*)$/$1/;
242  
243 <  print "Usage: $exeName [OPTION]... DATASET CONFIG DIRECTORY NJOBS\n";
243 >  print "Usage: $exeName [OPTION]... [DATASET | LOCATION] CONFIG DIRECTORY NJOBS\n";
244    print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n";
245    print "\n";
246    printf "%-29s%s\n", "  -h, --help", "print this help message";
247    print "\n";
248 <  print "The DATASET must exist in the Tier 3 ntuple database, and CONFIG must be a valid\n";
249 <  print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a working\n";
250 <  print "directory that is created and in which all output, both from the CMSSW jobs and\n";
251 <  print "from Condor, is placed. Finally, NJOBS is the number of Condor jobs that will\n";
252 <  print "be created.\n";
248 >  print "The optional first argument must be either a DATASET registered in the Tier 3\n";
249 >  print "ntuple database or a LOCATION which exists on disk. CONFIG must be a valid\n";
250 >  print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a\n";
251 >  print "working directory that is created and in which all output, both from the CMSSW\n";
252 >  print "jobs and from Condor, is placed. Finally, NJOBS is the number of Condor jobs\n";
253 >  print "that will be created.\n";
254  
255    exit;
256   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines