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; |
20 |
|
|
21 |
|
my %opt; |
22 |
|
Getopt::Long::Configure ("bundling"); |
23 |
< |
GetOptions (\%opt, "label|l=s", "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"}; |
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); |
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; |
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 |
|
|
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 |
|
} |
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") |
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); |
137 |
< |
closedir (LOCATION); |
138 |
< |
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): "; |
164 |
|
$response =~ s/\n//g; |
165 |
|
exit if !$response || lc ($response) ne "y"; |
166 |
|
} |
146 |
– |
elsif ($isLocation) |
147 |
– |
{ |
148 |
– |
$nFiles = @files - 2; |
149 |
– |
} |
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 |
> |
next if !($files[$i] =~ m/\.root$/); |
174 |
> |
print RUNLIST "'file:" . abs_path ("$location/$files[$i]") . "'"; |
175 |
|
print RUNLIST "," if $i + 1 != @files; |
176 |
|
print RUNLIST "\n"; |
177 |
|
} |
202 |
|
if ($results->numrows () == 1) |
203 |
|
{ |
204 |
|
my @row = $results->fetchrow (); |
205 |
< |
return ($row[3], $row[4], $row[5], $row[7]) if $row[7]; |
206 |
< |
return ($row[3], $row[4], $row[5], $row[6]) if !$row[7]; |
205 |
> |
$row[7] += 0; |
206 |
> |
return ($row[3], $row[4], $row[5], $row[7]) if $row[7] > 0; |
207 |
> |
return ($row[3], $row[4], $row[5], $row[6]) if $row[7] <= 0; |
208 |
|
} |
209 |
|
if ($results->numrows () == 0) |
210 |
|
{ |
301 |
|
my $exeName = $0; |
302 |
|
$exeName =~ s/^.*\/([^\/]*)$/$1/; |
303 |
|
|
304 |
< |
print "Usage: $exeName [OPTION]... [DATASET | LOCATION] CONFIG DIRECTORY NJOBS\n"; |
304 |
> |
print "Usage: $exeName [OPTION]... [DATASET | LOCATION | LIST] CONFIG DIRECTORY NJOBS\n"; |
305 |
|
print "Submits CMSSW jobs to the OSU Tier 3 compute nodes using Condor.\n"; |
306 |
|
print "\n"; |
307 |
+ |
printf "%-29s%s\n", " -d, --dataset DATASET", "override the dataset name"; |
308 |
|
printf "%-29s%s\n", " -h, --help", "print this help message"; |
309 |
|
printf "%-29s%s\n", " -l, --label LABEL", "give the dataset a short label"; |
310 |
|
printf "%-29s%s\n", " -m, --maxEvents N", "only run over N events in the dataset; default is"; |
311 |
+ |
printf "%-29s%s\n", " -p, --process PROCESS", "suffix for the process name"; |
312 |
|
printf "%-29s%s\n", " ", "to run over all events"; |
313 |
|
print "\n"; |
314 |
|
print "The optional first argument must be either a DATASET registered in the Tier 3\n"; |
315 |
< |
print "ntuple database or a LOCATION which exists on disk. CONFIG must be a valid\n"; |
316 |
< |
print "CMSSW python configuration which can be used with cmsRun. DIRECTORY is a\n"; |
317 |
< |
print "working directory that is created and in which all output, both from the CMSSW\n"; |
318 |
< |
print "jobs and from Condor, is placed. Finally, NJOBS is the number of Condor jobs\n"; |
319 |
< |
print "that will be created.\n"; |
315 |
> |
print "ntuple database, a LOCATION which exists on disk, or a text file containing a\n"; |
316 |
> |
print "LIST of files to run over. CONFIG must be a valid CMSSW python configuration\n"; |
317 |
> |
print "which can be used with cmsRun. DIRECTORY is a working directory that is created\n"; |
318 |
> |
print " and in which all output, both from the CMSSW jobs and from Condor, is placed.\n"; |
319 |
> |
print "Finally, NJOBS is the number of Condor jobs that will be created.\n"; |
320 |
|
|
321 |
|
exit; |
322 |
|
} |