11 |
|
|
12 |
|
my %opt; |
13 |
|
Getopt::Long::Configure ("bundling"); |
14 |
< |
GetOptions (\%opt, "prefix|p=s", "weight|w=s", "help|h"); |
14 |
> |
GetOptions (\%opt, "luminosity|l=s", "prefix|p=s", "weight|w=s", "help|h"); |
15 |
|
|
16 |
|
printHelp () if $opt{"help"} || !$opt{"prefix"}; |
17 |
|
my $files = processArgs (\@ARGV); |
18 |
|
my @rootFiles; |
19 |
|
my @weights; |
20 |
< |
my @goodJobs; |
21 |
< |
my @badJobs; |
22 |
< |
my %runList; |
20 |
> |
my $nGoodJobs = 0; |
21 |
> |
my $nBadJobs = 0; |
22 |
|
my $counting = 0; |
23 |
+ |
my %exitCodes; |
24 |
+ |
my %crossSections; |
25 |
+ |
my $integratedLuminosity = 10000; |
26 |
+ |
$integratedLuminosity = $opt{"luminosity"} if $opt{"luminosity"}; |
27 |
|
foreach my $file (@$files) |
28 |
|
{ |
29 |
|
next if $file eq "."; |
30 |
|
next if $file eq ".."; |
31 |
< |
if ($file =~ m/^.*\/condor_.*\.log$/) |
31 |
> |
my $dir = $file; |
32 |
> |
$dir =~ s/^(.*)\/[^\/]*$/$1/; |
33 |
> |
if ($file =~ m/^.*\/condor_[^_]*\.log$/) |
34 |
|
{ |
35 |
|
my $jobNumber = $file; |
36 |
|
$jobNumber =~ s/^.*\/condor_([^_]*)\.log$/$1/; |
40 |
|
my $fileContents = join ("", @fileContents); |
41 |
|
$fileContents =~ s/\n/ /g; |
42 |
|
$fileContents =~ s/.*\(return value ([^)]*)\).*/$1/g; |
43 |
< |
push (@goodJobs, $jobNumber) if $fileContents == 0; |
43 |
> |
$nGoodJobs++; |
44 |
|
if ($fileContents != 0) |
45 |
|
{ |
46 |
< |
push (@badJobs, $jobNumber); |
46 |
> |
$nBadJobs++; |
47 |
|
print "Skipping job $jobNumber. (return value $fileContents)\n"; |
48 |
|
} |
49 |
+ |
$exitCodes{$dir}{$jobNumber} = $fileContents; |
50 |
+ |
$counting = 1; |
51 |
|
} |
52 |
< |
if ($file =~ m/^.*\/runList\.py$/) |
52 |
> |
if ($file =~ m/^.*\/crossSectionInPicobarn\.txt$/) |
53 |
|
{ |
54 |
< |
my $directory = $file; |
55 |
< |
$directory =~ s/^(.*)\/runList\.py$/$1/; |
56 |
< |
$runList{$directory} = getRunList ($file); |
57 |
< |
$counting = 1; |
54 |
> |
open (CROSS_SECTION, "<$file"); |
55 |
> |
my $crossSection = <CROSS_SECTION>; |
56 |
> |
close (CROSS_SECTION); |
57 |
> |
$crossSections{$dir} = $crossSection; |
58 |
|
} |
59 |
|
} |
60 |
< |
my $nJobs = @goodJobs; |
54 |
< |
$nJobs += @badJobs; |
55 |
< |
my $goodEvents = 0; |
56 |
< |
my $goodLumis = 0; |
57 |
< |
my $goodRuns = 0; |
58 |
< |
my $badEvents = 0; |
59 |
< |
my $badLumis = 0; |
60 |
< |
my $badRuns = 0; |
60 |
> |
my $nTotalEvents = 0; |
61 |
|
foreach my $file (@$files) |
62 |
|
{ |
63 |
|
next if $file eq "."; |
64 |
|
next if $file eq ".."; |
65 |
+ |
my $dir = $file; |
66 |
+ |
$dir =~ s/^(.*)\/[^\/]*$/$1/; |
67 |
|
my $badJob = 0; |
68 |
|
if ($file =~ m/^.*_[^_]*\.root$/) |
69 |
|
{ |
70 |
|
my $jobNumber = $file; |
69 |
– |
my $directory = $file; |
71 |
|
$jobNumber =~ s/^.*_([^_]*)\.root$/$1/; |
72 |
< |
$directory =~ s/^(.*)\/[^\/]*\.root$/$1/; |
73 |
< |
foreach my $badJobNumber (@badJobs) |
74 |
< |
{ |
75 |
< |
$badJob = 1 if $jobNumber = $badJobNumber; |
76 |
< |
} |
77 |
< |
countEvents ($runList{$directory}, $jobNumber, $nJobs, \$goodEvents, \$goodLumis, \$goodRuns) if !$badJob && defined $runList{$directory}; |
78 |
< |
countEvents ($runList{$directory}, $jobNumber, $nJobs, \$badEvents, \$badLumis, \$badRuns) if $badJob && defined $runList{$directory}; |
72 |
> |
$badJob = defined $exitCodes{$dir} && defined $exitCodes{$dir}{$jobNumber} && $exitCodes{$dir}{$jobNumber}; |
73 |
> |
} |
74 |
> |
next if $badJob; |
75 |
> |
if ($file =~ m/^.*\.root$/) |
76 |
> |
{ |
77 |
> |
my $nEvents = countEvents ($file); |
78 |
> |
$nTotalEvents = -1 if $nTotalEvents < 0 || $nEvents < 0; |
79 |
> |
$nTotalEvents += $nEvents if !($nTotalEvents < 0 || $nEvents < 0); |
80 |
> |
} |
81 |
> |
} |
82 |
> |
foreach my $file (@$files) |
83 |
> |
{ |
84 |
> |
next if $file eq "."; |
85 |
> |
next if $file eq ".."; |
86 |
> |
my $dir = $file; |
87 |
> |
$dir =~ s/^(.*)\/[^\/]*$/$1/; |
88 |
> |
my $badJob = 0; |
89 |
> |
if ($file =~ m/^.*_[^_]*\.root$/) |
90 |
> |
{ |
91 |
> |
my $jobNumber = $file; |
92 |
> |
$jobNumber =~ s/^.*_([^_]*)\.root$/$1/; |
93 |
> |
$badJob = defined $exitCodes{$dir} && defined $exitCodes{$dir}{$jobNumber} && $exitCodes{$dir}{$jobNumber}; |
94 |
|
} |
95 |
|
next if $badJob; |
96 |
|
if ($file =~ m/^.*\.root$/) |
97 |
|
{ |
98 |
|
push (@rootFiles, $file); |
99 |
|
push (@weights, $opt{"weight"}) if $opt{"weight"}; |
100 |
< |
push (@weights, 1.0) if !$opt{"weight"}; |
100 |
> |
push (@weights, ($crossSections{$dir} * $integratedLuminosity) / $nTotalEvents) if !$opt{"weight"} && defined $crossSections{$dir}; |
101 |
> |
push (@weights, 1.0) if !$opt{"weight"} && !(defined $crossSections{$dir}); |
102 |
|
} |
103 |
|
} |
87 |
– |
my $nGoodJobs = @goodJobs; |
88 |
– |
my $nBadJobs = @badJobs; |
89 |
– |
print "$nGoodJobs ran successfully over $goodEvents events, $goodLumis lumis, $goodRuns runs\n" if $counting; |
90 |
– |
print "$nBadJobs failed to run over $badEvents events, $badLumis lumis, $badRuns runs\n" if $counting; |
104 |
|
if (!@rootFiles) |
105 |
|
{ |
106 |
|
print "Found no ROOT files to merge!\n"; |
110 |
|
my $weights = join (",", @weights); |
111 |
|
system ("mergeTFileServiceHistograms -i $rootFiles -o $opt{'prefix'}.root -w $weights"); |
112 |
|
system ("cutFlowTable $opt{'prefix'}.root cutFlow >& $opt{'prefix'}.tex"); |
113 |
+ |
my $goodEvents = countEvents ("$opt{'prefix'}.root"); |
114 |
+ |
print "$nGoodJobs jobs ran successfully over $nTotalEvents ($goodEvents weighted) events.\n" if $counting; |
115 |
+ |
print "$nBadJobs jobs failed to run.\n" if $counting; |
116 |
|
|
117 |
|
sub |
118 |
|
processArgs |
159 |
|
print "Usage: $exeName -p PREFIX [OPTION]... DIRECTORIES_AND_FILES\n"; |
160 |
|
print "Merges ROOT files containing histograms and produces a cutflow table in the\n"; |
161 |
|
print "form of a LaTeX document from the histogram named \"cutFlow\". If there are\n"; |
162 |
< |
print "Condor logs in the specified directories, checks for nonzero return values.\n"; |
162 |
> |
print "Condor logs in the specified directories, checks for nonzero return values. If\n"; |
163 |
> |
print "the directories where created by \"osusub\", uses the cross section from the\n"; |
164 |
> |
print "database to weight all histograms.\n"; |
165 |
|
print "\n"; |
166 |
|
print "Mandatory arguments to long options are mandatory for short options too.\n"; |
167 |
|
printf "%-29s%s\n", " -h, --help", "print this help message"; |
168 |
+ |
printf "%-29s%s\n", " -l, --luminosity", "integrated luminosity to which the histograms are"; |
169 |
+ |
printf "%-29s%s\n", " ", "weighted (default: 10000/pb)"; |
170 |
|
printf "%-29s%s\n", " -p, --prefix PREFIX", "output files are named PREFIX.root and PREFIX.tex"; |
171 |
< |
printf "%-29s%s\n", " -w, --weight WEIGHT", "scale the output by WEIGHT"; |
171 |
> |
printf "%-29s%s\n", " -w, --weight WEIGHT", "scale the output by WEIGHT, overriding the"; |
172 |
> |
printf "%-29s%s\n", " ", "automatic weighting using the cross section from"; |
173 |
> |
printf "%-29s%s\n", " ", "the database"; |
174 |
|
|
175 |
|
exit; |
176 |
|
} |
197 |
|
sub |
198 |
|
countEvents |
199 |
|
{ |
200 |
< |
my $runList = shift; |
201 |
< |
my $jobNumber = shift; |
202 |
< |
my $nJobs = shift; |
203 |
< |
my $events = shift; |
182 |
< |
my $lumis = shift; |
183 |
< |
my $runs = shift; |
184 |
< |
|
185 |
< |
my $filesPerJob = ceil (@$runList / $nJobs); |
186 |
< |
print "Job $jobNumber ran successfully on $filesPerJob files.\n"; |
187 |
< |
my @subRunList = @$runList[($jobNumber * $filesPerJob)..($jobNumber * $filesPerJob + $filesPerJob - 1)]; |
188 |
< |
foreach my $file (@subRunList) |
200 |
> |
my $file = shift; |
201 |
> |
|
202 |
> |
my $output = `getEventsFromCutFlow $file cutFlow`; |
203 |
> |
if ($output =~ m/Did not find a histogram named/) |
204 |
|
{ |
205 |
< |
my @output = `edmFileUtil $file`; |
206 |
< |
my $output = join (" ", @output); |
192 |
< |
$output =~ s/\n//g; |
193 |
< |
my $eventsStr = $output; |
194 |
< |
my $lumisStr = $output; |
195 |
< |
my $runsStr = $output; |
196 |
< |
$eventsStr =~ s/^.*\([^ ]* runs, [^ ]* lumis, ([^ ]*) events, [^ ]* bytes\).*$/$1/; |
197 |
< |
$lumisStr =~ s/^.*\([^ ]* runs, ([^ ]*) lumis, [^ ]* events, [^ ]* bytes\).*$/$1/; |
198 |
< |
$runsStr =~ s/^.*\(([^ ]*) runs, [^ ]* lumis, [^ ]* events, [^ ]* bytes\).*$/$1/; |
199 |
< |
$$events += $eventsStr; |
200 |
< |
$$lumis += $lumisStr; |
201 |
< |
$$runs += $runsStr; |
205 |
> |
print $output; |
206 |
> |
return -1; |
207 |
|
} |
208 |
+ |
$output =~ s/^.*: (.*)$/$1/; |
209 |
+ |
$output =~ s/\n//g; |
210 |
+ |
|
211 |
+ |
return $output; |
212 |
|
} |