2 # runEMCALQA.pl v.0.5 A.SHABETAI alexandre.shabetai@cern.ch
6 use File::Path qw(mkpath );
13 ##########################################################
14 # What this script is doing and how to use it
18 print STDERR << "EOF";
19 This script runs the EMCAL QA macros on selected runs.
21 usage: $0 --period <PERIOD> --pass <PASS> [ --gridprefix <GRIDPREFIX> ] [--extraGridPath <EXTRAGRIDPATH> ] [ --runlist <runlist.txt> ] [ --col <pp||PbPb> ]
23 -h --help : shows this (help) messag
25 The following parameters are mendatory:
26 --period : the running period to consider (ex: LHC1XX )
27 --pass : the production pass to use (use "simu" for simulated data) (ex: pass1 )
29 You may specify the following options if you want to change their default values:
30 --runlist : a text file with the list of runs to consider - one run by line (default: <period>-<pass>-runlist.txt ) (ex: MyLHC13arunlist.txt )
31 --extraGridPath : extra grid path to use (default: none ) (ex: ESDs/QA68 )
32 --localpath : path where the existing local QAresults files are stored (default: <period>/<pass> ) (ex: <a_prefix> )
33 --savePlots : save the plots as image files (0: no ; 1:png ; 2: png + pdf) (default: 1 (png) ) (ex: 0 )
34 --debug : debug flag (0 or 1) (default; 0 ) (ex: 1 )
35 --gridQAname : basename QA filename on the grid (without the .root suffix) (default: QAresults ) (ex: QAresults )
36 --gridTimeOut : timeOut for grid acces (default: 10 s ) (ex: 10 )
37 --gridprefix : the begining of the grid path to use (default: /alice/data/<year>/<period> - or .../sim/... if pass=simu) (ex: /alice/data/201X/LHC1XX )
38 --filter : filter the input file (default: 0 (no) ) (ex: 1 )
39 --treeSelections: filename of file containing additional cuts on the trending tree (default: none ) (ex: MySelection.C )
40 --trigger : force to use the specified trigger name (default: trigger names are automaticly read from the input files ) (ex: trigEMC )
41 --col : force the type of colisions pp or PbPb (default: pp - or PbPb if period ends with "h" ) (ex: PbPb )
43 NB: all switches can be abreviated ex: --period is valid as well as -pe
45 example: $0 --period LHC13a --pass pass1
52 #############################################################################
53 # the values above should not be changed (please use the command lune options instead)
68 my $gridQAname = "QAresults";
69 my $treeSelections = "";
71 #############################################################################
76 "period=s" => \$period, # string
77 "pass=s" => \$pass, # string
78 "gridprefix=s" => \$gridprefix, #string
79 "localpath=s" => \$localpath, #string
80 "runlist=s" => \$runlist, #string
81 "col=s" => \$col, #string
82 "extraGridPath=s" => \$extragridPath, #string
83 "savePlots=i" => \$savePlots, #int
84 "debug=i" => \$debug, #int
85 "filter=i" => \$filter, #bool
86 "triggerForced=s" => \$trigger,
87 "gridTimeOut=i" => \$GridTimeOut, #int
88 "gridQAname=s" => \$gridQAname, #string
89 "treeSelections=s" => \$treeSelections) #string
90 or die("Error in command line arguments\n");
92 die "Missing --period! (you can get help with $0 -h)" unless $period;
93 die "Missing --pass! (you can get help with $0 -h)" unless $pass;
95 if ($pass eq "sim") {$pass= "simu";}
96 if (!(defined($runlist))) {$runlist = "$period-$pass-runlist.txt";}
97 if (!(defined($col)) && index($period, 'h') != -1) {$col = "PbPb";}
98 if (!(defined($col))) {$col = "pp";}
100 if (!(defined($gridprefix))) {
101 my $year=sprintf("20%s",substr($period, 3, 2));
102 if ($pass ne "simu") {$gridprefix = "/alice/data/$year/$period";} else {$gridprefix = "/alice/sim/$year/$period";}
104 if (!(defined($extragridPath))) {
105 if (($pass ne "simu") && (index($pass, 'c') != -1)) { $extragridPath = $pass;}
106 elsif ($pass ne "simu") { $extragridPath = "ESDs/$pass";}
107 else {$extragridPath = "";}
110 ##############################################################################
111 # the values above should not be changed
113 my $macroDir = abs_path(dirname($0));
114 my $locDir = "$period/$pass";
115 $ENV{QAPATH} = "$locDir/";
116 my $processedrunlist = "$locDir/processed.txt";
117 my $notprocessedrunlist = "$locDir/notprocessed.txt";
121 my @gridsuffixes = qw(.root);
122 if (index($pass, 'c') != -1) {@gridsuffixes = qw(_barrel.root _outer.root);}
123 if (!(defined($localpath))) {$localpath = $locDir;} else {$localpath = $localpath."/";}
125 ###############################################################################
128 if (! -e $locDir) {mkpath($locDir);}
129 if ((defined(glob("$locDir/*data.txt")))) {unlink(glob("$locDir/*data.txt"));}
130 my $includePath = qx{aliroot -b -l << EOF
134 if (index($includePath,"$ENV{ALICE_ROOT}/include") == -1)
135 {print "Please add \$ALICE_ROOT/include to your include path using a rootlogon.C of .rootrc "; exit;}
137 my $ALIEN_ROOT = $ENV{'ALIEN_ROOT'};
138 if (!(defined($ALIEN_ROOT))) {die "ALIEN_ROOT not defined!";}
139 my $proxyValidity = qx{$ALIEN_ROOT/api/bin/xrdgsiproxy info 2>&1 | grep "time left" | cut -d " " -f 6 | cut -d: -f1}; chomp($proxyValidity);
140 if (!(defined($proxyValidity)) || $proxyValidity eq "0h") { die "No valid proxy found (or proxy valid for less that one hour). Nothing done!"};
141 my $isValidToken = qx{$ALIEN_ROOT/api/bin/alien-token-info | grep -c "Token is still valid"};
142 if ($isValidToken==0) { die "No valid token found. Nothing done!";}
143 #############################################################################t
146 open(STDOUT, "| tee -i \"$locDir/$period\_$pass\_EMCALQA.log\"");
147 open(STDERR, '>&STDOUT');
148 open(FIN, $runlist) or die "Could not open $runlist: $! please specify --runlist of create $runlist";
149 open(FOUT, ">$processedrunlist") or die "Could not open $processedrunlist: $!";
150 open(FOUT2, ">$notprocessedrunlist") or die "Could not open $notprocessedrunlist: $!";
152 print "\n Executing $0";
153 foreach (@ARGV) { print " $_";}
158 while( my $line = <FIN>) {
160 my @fields = split(/,/, $line);
163 @runs = sort { $a <=> $b } @runs;
165 # create the directory structure and copy the output of the QA train from the grid
166 foreach my $run (@runs) {
168 if($pass ne "simu") {$run = sprintf("%09d", $run);}
169 print "\nProcessing run $run...\n";
170 foreach my $suffix (@gridsuffixes) {
171 my $gridFile = "alien://$gridprefix/$run/$extragridPath/$gridQAname$suffix";
172 my $shortrun = $run; $shortrun =~ s/^0+//; $shortrun =~ s/ +$//;
173 my $locFileName = "$shortrun$suffix";
175 print "\n Processing file $locFileName...\n";
177 if (! -e "$locDir/$run") {mkdir("$locDir/$run");} #
179 if ($localpath eq $locDir) {
180 for (my $trial = 1; $trial <= 2; $trial++)
183 system("root -b -l -q \'$macroDir/CopyQAFile.C+g\(\"$gridFile\",\"$localpath\",kFALSE,\"$locFileName\",$GridTimeOut\)\'");
186 if (! $exit_code) { print "\nFile $gridQAname$suffix processed succesfully (run $shortrun, try $trial)\n";last} else { print "\nThe processing of file $gridQAname$suffix (run $shortrun) failed! (try $trial)\n";};
187 if ($exit_code eq 252 || $exit_code eq 253) {unlink("$localpath/$locFileName"); }
190 # run the run level QA for the runs that were selected (i.e in the runlist and that do have a valid local QA output filie).
194 if (-e "$localpath/$locFileName" ) {
196 system("aliroot -b -q \'$macroDir/CreateEMCALRunQA.C+g\(\"$localpath/$locFileName\",\"$run\",\"$period\",\"$pass\",$savePlots,$filter,\"$trigger\",\"$col\",\"$calo\"\)\'");
199 if (! $exit_code) { print FOUT "$shortrun\n"; print "\nCreateEMCALRunQA() for file $gridQAname$suffix processed succesfully (run $shortrun)\n";} else { print FOUT2 "$shortrun\n" ; print "\nThe processing of CreateEMCALRunQA() for file $gridQAname$suffix failed! (run $shortrun)\n";};
201 if ($suffix ne ".root") { move("$locDir/$run/trending.root", "$locDir/$run/trending$suffix"); move("$locDir/$run/${period}_${pass}_${shortrun}_QAplots.root","$locDir/$run/${period}_${pass}_${shortrun}_QAplots$suffix");}
203 } else { print " File not found: $localpath/$locFileName";} }
212 #################################################################################
215 if ((! $exit_code) && defined(glob("$locDir/*/trendin*.root")) && (-e glob("$locDir/*/trendin*.root")))
218 print "\nMerging....\n";
220 system("hadd -v 1 -f $locDir/trending.root $locDir/*/trendin*.root");
223 if (! $debug) { system("rm $locDir/*/trendin*.root"); }
226 ################################################################################
227 # process and plot the period level QA
231 if ((! $exit_code) && (-e "$locDir/trending.root")) { system("root -b -l -q \'$macroDir/PlotEMCALQATrendingTree.C(\"$locDir/trending.root\",$savePlots,\"$treeSelections\",\"$trigger\"\)\'"); }
234 if (! $exit_code) { print "\nPlotEMCALQATrendingTree() processed succesfully\n";} else { print "\nThe processing of PlotEMCALQATrendingTree() failed!\n";};
236 ################################################################################
239 move($processedrunlist,"$locDir/runlist.txt") or die "Cannot move the runlist to the correct local directory : $!";
240 move("$locDir/trendingPlots.root","$locDir/$period"."_$pass"."_trendingPlots.root");
242 ################################################################################
245 if ((! $exit_code) && defined(glob("$locDir/*/${period}_${pass}_*_QAplot*.root $locDir/${period}_${pass}_trendingPlots.root $locDir/trending.root")) && (-e glob("$locDir/*/${period}_${pass}_*_QAplot*.root $locDir/${period}_${pass}_trendingPlots.root $locDir/trending.root")))
248 print "\n Final Merging....\n";
250 system("hadd -v 1 -f $locDir/${period}_${pass}_EMCALQA.root $locDir/*/${period}_${pass}_*_QAplot*.root $locDir/${period}_${pass}_trendingPlots.root $locDir/trending.root");
252 if (! $debug) {system("rm -f $locDir/*/${period}_${pass}_*_QAplot*.root $locDir/${period}_${pass}_trendingPlots.root"); }
256 ###############################################################################
257 # cleanup some files used for debugging
259 if (! $debug && (defined(glob("$locDir/*/*.txt")))) {unlink(glob("$locDir/*/*.txt"));}
260 if (! $debug && (defined(glob("$locDir/*.txt")))) {unlink(glob("$locDir/*.txt"));}
261 if (! $debug && ! $savePlots && (defined(glob("$locDir/*/")))) {system("rmdir --ignore-fail-on-non-empty $locDir/*/");}
264 ##############################################################################
267 if ((! $exit_code) && -e "$locDir/${period}_${pass}_EMCALQA.root") { system("root -b -l -q \'$macroDir/MakeQAPdf.C+g(\"$locDir/${period}_${pass}_EMCALQA.root\"\)\'"); }
270 ##############################################################################