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 |
< |
my $nFiles = outputRunList ($ARGV[0], $ARGV[2]); |
55 |
< |
my $nJobs = $ARGV[3]; |
56 |
< |
my $realNJobs = ceil ($nFiles / ceil ($nFiles / $nJobs)); |
57 |
< |
outputPset ($ARGV[2]); |
58 |
< |
outputCondor ($ARGV[2], $realNJobs, $ARGV[0]); |
59 |
< |
copy ($ARGV[1], "$ARGV[2]/userConfig_cfg.py"); |
60 |
< |
chdir $ARGV[2]; |
61 |
< |
print "Submitting $realNJobs jobs to run on $nFiles files.\n"; |
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 |
|
|
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); |
103 |
|
my $dataset = shift; |
104 |
|
my $workingDir = shift; |
105 |
|
|
106 |
+ |
return 0 if !$dataset; |
107 |
|
my $location; |
108 |
|
my $nFiles; |
109 |
|
my $status; |
215 |
|
sub |
216 |
|
outputCondor |
217 |
|
{ |
218 |
+ |
my $condorFileName = shift; |
219 |
|
my $workingDir = shift; |
220 |
|
my $nJobs = shift; |
221 |
|
my $dataset = shift; |
222 |
|
|
223 |
|
my $cmsRun = `which cmsRun`; |
224 |
< |
open (SUB, ">$workingDir/condor.sub"); |
224 |
> |
my $condorFile = ""; |
225 |
|
|
226 |
< |
print SUB "Executable = $cmsRun\n"; |
227 |
< |
print SUB "Universe = vanilla\n"; |
228 |
< |
print SUB "Getenv = True\n"; |
229 |
< |
print SUB "Arguments = config_cfg.py True $nJobs \$(Process) $dataset\n"; |
230 |
< |
print SUB "\n"; |
231 |
< |
print SUB "Output = condor_\$(Process).out\n"; |
232 |
< |
print SUB "Error = condor_\$(Process).err\n"; |
233 |
< |
print SUB "Log = condor_\$(Process).log\n"; |
234 |
< |
print SUB "\n"; |
235 |
< |
print SUB "+IsLocalJob = true\n"; |
236 |
< |
print SUB "Rank = TARGET.IsLocalSlot\n"; |
237 |
< |
print SUB "\n"; |
238 |
< |
print SUB "Queue $nJobs\n"; |
226 |
> |
if (!(-e $condorFileName)) |
227 |
> |
{ |
228 |
> |
$condorFile .= "Executable = $cmsRun\n"; |
229 |
> |
$condorFile .= "Universe = vanilla\n"; |
230 |
> |
$condorFile .= "Getenv = True\n"; |
231 |
> |
$condorFile .= "Arguments = config_cfg.py True $nJobs \$(Process) $dataset\n" if $dataset; |
232 |
> |
$condorFile .= "Arguments = config_cfg.py True $nJobs \$(Process) NULL\n" if !$dataset; |
233 |
> |
$condorFile .= "\n"; |
234 |
> |
$condorFile .= "Output = condor_\$(Process).out\n"; |
235 |
> |
$condorFile .= "Error = condor_\$(Process).err\n"; |
236 |
> |
$condorFile .= "Log = condor_\$(Process).log\n"; |
237 |
> |
$condorFile .= "\n"; |
238 |
> |
$condorFile .= "+IsLocalJob = true\n"; |
239 |
> |
$condorFile .= "Rank = TARGET.IsLocalSlot\n"; |
240 |
> |
$condorFile .= "\n"; |
241 |
> |
$condorFile .= "Queue $nJobs\n"; |
242 |
> |
} |
243 |
> |
else |
244 |
> |
{ |
245 |
> |
open (SUB, "<$condorFileName"); |
246 |
> |
my @condorFile = <SUB>; |
247 |
> |
close (SUB); |
248 |
> |
$condorFile = join ("", @condorFile); |
249 |
> |
$condorFile =~ s/\$cmsRun/$cmsRun/g; |
250 |
> |
$condorFile =~ s/\$nJobs/$nJobs/g; |
251 |
> |
$condorFile =~ s/\$dataset/$dataset/g if $dataset; |
252 |
> |
$condorFile =~ s/\$dataset/NULL/g if !$dataset; |
253 |
> |
} |
254 |
|
|
255 |
+ |
open (SUB, ">$workingDir/condor.sub"); |
256 |
+ |
print SUB $condorFile; |
257 |
|
close (SUB); |
258 |
|
} |
259 |
|
|
263 |
|
my $exeName = $0; |
264 |
|
$exeName =~ s/^.*\/([^\/]*)$/$1/; |
265 |
|
|
266 |
< |
print "Usage: $exeName [OPTION]... DATASET CONFIG DIRECTORY NJOBS\n"; |
219 |
< |
print " or: $exeName [OPTION]... LOCATION CONFIG DIRECTORY NJOBS\n"; |
266 |
> |
print "Usage: $exeName [OPTION]... [DATASET | LOCATION] CONFIG DIRECTORY NJOBS\n"; |
267 |
|
print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n"; |
268 |
|
print "\n"; |
269 |
|
printf "%-29s%s\n", " -h, --help", "print this help message"; |
270 |
+ |
printf "%-29s%s\n", " -m, --maxEvents N", "only run over N events in the dataset; default is"; |
271 |
+ |
printf "%-29s%s\n", " ", "to run over all events"; |
272 |
|
print "\n"; |
273 |
< |
print "The first argument must be either a DATASET registered in the Tier 3 ntuple\n"; |
274 |
< |
print "database or a LOCATION which exists on disk. CONFIG must be a valid CMSSW\n"; |
275 |
< |
print "python configuration which can be used with cmsRun. DIRECTORY is a working\n"; |
276 |
< |
print "directory that is created and in which all output, both from the CMSSW jobs and\n"; |
277 |
< |
print "from Condor, is placed. Finally, NJOBS is the number of Condor jobs that will\n"; |
278 |
< |
print "be created.\n"; |
273 |
> |
print "The optional first argument must be either a DATASET registered in the Tier 3\n"; |
274 |
> |
print "ntuple database or a LOCATION which exists on disk. CONFIG must be a valid\n"; |
275 |
> |
print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a\n"; |
276 |
> |
print "working directory that is created and in which all output, both from the CMSSW\n"; |
277 |
> |
print "jobs and from Condor, is placed. Finally, NJOBS is the number of Condor jobs\n"; |
278 |
> |
print "that will be created.\n"; |
279 |
|
|
280 |
|
exit; |
281 |
|
} |