File indexing completed on 2023-03-17 11:16:27
0001
0002 use warnings;
0003 use strict;
0004 use threads;
0005 use threads::shared;
0006
0007 my $dir = $ENV{'CMSSW_BASE'} . "/src/PhysicsTools/PatAlgos/test";
0008 chdir $dir or die "Can't chdir to $dir.\n Check that CMSSW_BASE variable is set correcly, and that you have checked out PhysicsTools/PatAlgos.\n";
0009
0010 my %done :shared = ();
0011 my $fake :shared = 0;
0012 my $repdef :shared = "";
0013
0014 use Getopt::Long;
0015 my ($help,$base,$extra,$all,$shy,$obj);
0016 my @summary :shared;
0017 GetOptions( 'h|?|help' => \$help,
0018 'n|dry-run' => \$fake,
0019 'b|base' => \$base,
0020 'o|obj' => \$obj,
0021 'a|all' => \$all,
0022 'e|extra' => \$extra,
0023 's|summary=s' => \@summary,
0024 'q|quiet' => \$shy);
0025 @summary = split(/,/, join(',',@summary));
0026 if ($help) {
0027 my $name = `basename $0`; chomp $name;
0028 print "Usage: perl $name [-n|--dry-run] [cfg.pys]\n" .
0029 " -n or --dry-run: just read the output, don't run cmsRun\n".
0030 " -h or --help: print this help\n".
0031 " -b or --base: add base standard PAT config files to the jobs to run\n".
0032 " -o or --obj: add PAT config files for single physics objecs to the jobs to run\n".
0033 " -e or --extra: add the extra standard PAT config files to the jobs to run (that is, those not in base)\n".
0034 " -a or --all: add all standard PAT config files to the jobs to run\n".
0035 " -s or --summary: print summary table of objects (argument can be 'aod', 'allLayer1', 'selectedLayer1', ...)\n".
0036 " -q or --quiet: print summary tables only if there are warnings/errors in that table.\n";
0037 exit(0);
0038 }
0039 if ($fake) {
0040 print "=== NOT ACTUALLLY RUNNING cmsRun, JUST READING OUTPUT LOGS ===\n";
0041 }
0042
0043 my @CFGs = map({$_ =~ /\.py$|\*$/ ? $_ : "*$_*"} @ARGV);
0044
0045
0046 my @anyCFGs = glob("pat*[._]cfg.py");
0047 my @baseCFGs = grep($_ =~ /standard|fastSim|data|PF2PAT/, @anyCFGs);
0048 my @objCFGs = grep($_ =~ /only/, @anyCFGs);
0049 my @extraCFGs = grep($_ =~ /add|metUncertainties|userData/, @anyCFGs);
0050 if ($base ) { push @CFGs, @baseCFGs; }
0051 if ($obj ) { push @CFGs, @objCFGs; }
0052 if ($all ) { push @CFGs, @anyCFGs; }
0053 if ($extra) { push @CFGs, @extraCFGs; }
0054 if (@CFGs) {
0055
0056 my %allCFGs = ();
0057 foreach my $cfg (@CFGs) {
0058 foreach my $cfgfile (grep(/cfg\.py$/, glob($cfg))) { $allCFGs{$cfgfile} = 1; }
0059 }
0060 @CFGs = sort(keys(%allCFGs));
0061 } else {
0062 print STDERR "Please specify a cfg, or use --one, --base, --all, --extra to select the standard ones\n"; exit(0);
0063 }
0064
0065 print "Will run " . scalar(@CFGs) . " config files: " . join(' ', @CFGs) . "\n\n";
0066
0067 foreach my $cfg (@CFGs) {
0068 unless (-f $cfg) { die "Config file $cfg does not exist in $dir\n"; }
0069 }
0070
0071 sub cmsRun {
0072 my ($f, $o) = ($_[0], $_[1]);
0073 unless ($fake) {
0074 system("sh -c 'cmsRun $f > $o 2>&1 '");
0075 } else {
0076
0077 system("sh -c 'sleep 1'");
0078 }
0079 $done{$f} = time();
0080 }
0081
0082 my %info = ();
0083
0084 my @txt = ("Jobs starting:");
0085 foreach my $f (@CFGs) {
0086 my $o = $f; $o =~ s/[\._]cfg\.py$/.log/;
0087
0088 my $max = -1;
0089 open CFG, $f;
0090 foreach(<CFG>) {
0091 and $max = 0;
0092 if ($max == 0) { and $max = $1; }
0093 if ($max == -1) {
0094 and $max = 0;
0095 if ($max == 0) { and $max = $1; }
0096 }
0097 }
0098 close CFG;
0099
0100 push @txt, " \e[32;1m$f\e[37;0m: starting (on $max events total)";
0101 $info{$f} = { 'out' => $o, 'start' => time(), 'max'=>$max };
0102 my $thr = threads->create(\&cmsRun, $f, $o);
0103 }
0104 print join("\n", @txt), "\n";
0105
0106 sub printDone {
0107 my $f = shift(@_);
0108 my $lines = 0; my $last = 0;
0109 my ($excep, $exbody) = (0,"");
0110 open LOG, $info{$f}->{'out'};
0111 while (<LOG>) {
0112 $lines++;
0113 and $last = $1;
0114 if () {
0115 my $exname = $1;
0116 $excep++;
0117 if ($excep == 1) { $exbody .= "\t" . $_; }
0118 while ($_ = <LOG>) {
0119 $lines++;
0120 if ($excep == 1) { $exbody .= "\t" . $_; }
0121 last if ();
0122 }
0123 }
0124 };
0125 close LOG;
0126
0127 $info{$f}->{'last'} = $last;
0128 $info{$f}->{'lines'} = $lines;
0129 $info{$f}->{'excep'} = $excep;
0130 $info{$f}->{'exbody'}= $exbody;
0131 return "\e[32;1m$f\e[37;0m: \e[;;1mdone\e[m events " . $info{$f}->{'last'} . "/" . $info{$f}->{'max'} .
0132 ", total time " . ($done{$f} - $info{$f}->{'start'}) . "s, " .
0133 $info{$f}->{'lines'} . " output lines, " .
0134 ($info{$f}->{'excep'} ? "\e[1;31m" . $info{$f}->{'excep'} . " exceptions\e[0m" : "\e[32mno exceptions\e[0m" );
0135 }
0136
0137 sub printRunning {
0138 my $f = shift(@_);
0139 my $lines = 0; my $last = 0;
0140 my ($excep, $exbody) = (0,"");
0141 open LOG, $info{$f}->{'out'};
0142 while (<LOG>) {
0143 $lines++;
0144 and $last = $1;
0145 if () {
0146 my $exname = $1;
0147 $excep++;
0148 if ($excep == 1) { $exbody .= "\t" . $_; }
0149 while ($_ = <LOG>) {
0150 $lines++;
0151 if ($excep == 1) { $exbody .= "\t" . $_; }
0152 last if ();
0153 }
0154 }
0155 };
0156 close LOG;
0157
0158 my $secs = time() - $info{$f}->{'start'};
0159 $info{$f}->{'time'} = $secs;
0160 $info{$f}->{'last'} = $last;
0161 $info{$f}->{'lines'} = $lines;
0162 $info{$f}->{'excep'} = $excep;
0163 $info{$f}->{'exbody'}= $exbody;
0164 return "\e[32;1m$f\e[37;0m: event $last/" . $info{$f}->{'max'} ." (time ${secs}s, ${lines} output lines, " .
0165 ($excep ? "\e[1;31m$excep exceptions\e[0m" : "\e[32mno exceptions yet\e[0m" ) . ")...";
0166 }
0167
0168 while (scalar(keys(%done)) < scalar(@CFGs)) {
0169 sleep 1;
0170
0171 foreach my $f (@txt) { print "\e[F\e[M"; }; @txt = ();
0172
0173 my @run = (); my @done = ();
0174 foreach my $f (@CFGs) {
0175 if (defined($done{$f}) and defined($info{$f}->{'last'})) {
0176 push @done, " " . printDone($f);
0177 } else {
0178 push @run, " " . printRunning($f);
0179 }
0180 }
0181 push @txt, ("Jobs running:", @run);
0182 if (@done) { push @txt, ("Jobs done:", @done) };
0183 push @txt, "";
0184 print join("\n", @txt), "\n";
0185 }
0186
0187 foreach my $f (@txt) { print "\e[F\e[M"; }
0188
0189 print "All jobs done.\n";
0190
0191 sub redIf($$) {
0192 return ($_[1] ? "\e[1;31m E> " . $_[0] . "\e[0m" : " ".$_[0]);
0193 }
0194 foreach my $f (@CFGs) {
0195 print printDone ($f), "\n";
0196 if ($info{$f}->{'excep'}) { print "\e[1;31m" . $info{$f}->{'exbody'} . "\e[0m"; }
0197
0198 open LOG, $info{$f}->{'out'}; my @log = <LOG>; close LOG;
0199 my $log = join('',@log);
0200 foreach my $table (@summary) {
0201 if ($log =~ ) {
0202 my $info = $1;
0203 $info =~ s/^ (.*present\s+\d+\s+\(\s*(\d+\.?\d*)\s*%\).*)$/redIf($1,$2 ne '100')/meg;
0204 $info =~ s/^ (.*total\s+0\s.*)$/\e[1;31m E> $1\e[0m/mg;
0205 if (!$shy or ($info =~ /\e\[1;31m E>/)) {
0206 print " ".$info;
0207 }
0208 }
0209 }
0210 foreach my $l (grep(/TrigReport Events total =/, @log)) { print " \e[1m$l\e[0m"; }
0211
0212 print "\n";
0213 }