6 echo " ${0##*/} option=value [option=value]"
7 echo " at least inputList should be specified, or configFile containing it:"
8 echo " ${0##*/} inputList=file.list"
9 echo " options override config file (if any), e.g.:"
10 echo " ${0##*/} configFile=runQA.config inputList=file.list outputDirectory=%det"
14 if ! parseConfig $@; then
19 [[ -z $ALICE_ROOT ]] && echo "ALICE_ROOT not defined" && return 1
22 if [[ ${ocdbStorage} =~ ${ocdbregex} ]]; then
34 #be paranoid and make some full paths
35 [[ ! -f ${inputList} ]] && echo "no input list: ${inputList}" && return 1
36 inputList=$(get_realpath ${inputList})
37 mkdir -p ${workingDirectory}
38 workingDirectory=$(workingDirectory=${workingDirectory%/}; cd ${workingDirectory%/*}; echo "${PWD}/${workingDirectory##*/}")
39 if [[ ! -d ${workingDirectory} ]]; then
40 echo "working dir $workingDirectory does not exist and cannot be created"
43 cd ${workingDirectory}
46 echo inputList=$inputList
47 echo outputDirectory=$outputDirectory
50 dateString=$(date +%Y-%m-%d-%H-%M)
51 echo "Start time QA process: $dateString"
54 mkdir -p $logDirectory
55 [[ ! -d $logDirectory ]] && echo "no log dir $logDirectory" && return 1
56 logFile="$logDirectory/${0##*/}.${dateString}.log"
58 [[ ! -f ${logFile} ]] && echo "cannot write logfile $logfile" && return 1
59 echo "logFile = $logFile"
62 lockFile=${logDirectory}/runQA.lock
63 [[ -f ${lockFile} ]] && echo "lock ${lockFile} exists!" | tee ${logFile} && return 1
65 [[ ! -f ${lockFile} ]] && echo "cannot lock $lockFile" | tee ${logFile} && return 1
69 ################################################################
71 for detectorScript in $ALICE_ROOT/PWGPP/QA/detectorQAscripts/*; do
73 echo "##############################################"
75 [[ ! ${detectorScript} =~ .*\.sh$ ]] && continue
76 detector=${detectorScript%.sh}
77 detector=${detector##*/}
80 if [[ "${excludeDetectors}" =~ ${detector} ]]; then
81 echo "${detector} is excluded in config, skipping..."
85 #if includeDetectors set, only process thoe detectors specified there
86 if [[ -n ${includeDetectors} && ! "${includeDetectors}" =~ ${detector} ]]; then
87 echo "${detector} not included in includeDetectors, skipping..."
91 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
92 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
93 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}-${dateString}
94 if ! mkdir -p ${tmpDetectorRunDir}; then
95 echo "cannot create the temp dir $tmpDetectorRunDir"
98 cd ${tmpDetectorRunDir}
100 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
101 echo "running QA for ${detector}"
102 echo " outputDir=$outputDir"
103 echo " tmpPrefix=$tmpPrefix"
106 unset -f periodLevelQA
107 unset -f runLevelHighPtTreeQA
108 unset -f periodLevelHighPtTreeQA
109 source ${detectorScript}
111 #################################################################
112 #produce the QA and trending tree for each file (run)
113 unset arrOfTouchedProductions
114 declare -A arrOfTouchedProductions
115 while read qaFile; do
118 #first check if input file exists
119 [[ ! -f ${qaFile%\#*} ]] && echo "file ${qaFile%\#*} not accessible" && continue
121 if ! guessRunData ${qaFile}; then
122 echo "could not guess run data from ${qaFile}"
126 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
127 tmpRunDir=${tmpProductionDir}/000${runNumber}
128 mkdir -p ${tmpRunDir}
131 #by default we expect to have everything in the same archive
134 #maybe the input is not an archive, but a file
135 [[ "${qaFile}" =~ QAresults.root$ ]] && highPtTree=""
136 [[ "${qaFile}" =~ FilterEvents_Trees.root$ ]] && qaFile=""
138 #it is possible we get the highPt trees from somewhere else
139 #search the list of high pt trees for the proper run number
140 if [[ -n ${inputListHighPtTrees} ]]; then
141 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
142 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
146 echo highPtTree=$highPtTree
148 #what if we have a zip archive?
149 if [[ "$qaFile" =~ .*.zip$ ]]; then
150 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
151 qaFile="${qaFile}#QAresults.root"
156 if [[ "$highPtTree" =~ .*.zip$ ]]; then
157 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
158 highPtTree="${highPtTree}#FilterEvents_Trees.root"
164 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
165 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
166 runLevelQA "${qaFile}" &> runLevelQA.log
167 #perform some default actions:
168 #if trending.root not created, create a default one
169 if [[ ! -f trending.root ]]; then
170 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
172 if [[ -f trending.root ]]; then
173 arrOfTouchedProductions[${tmpProductionDir}]=1
175 echo "trending.root not created"
178 #expert QA based on high pt trees
179 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
180 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
181 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
182 arrOfTouchedProductions[${tmpProductionDir}]=1
185 cd ${tmpDetectorRunDir}
189 #################################################################
190 #cache which productions were (re)done
191 echo "list of processed productions:"
192 echo " ${!arrOfTouchedProductions[@]}"
195 #################################################################
196 #(re)do the merging/trending
197 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
198 cd ${tmpProductionDir}
200 echo "running period level stuff in ${tmpProductionDir}"
202 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
203 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
205 mkdir -p ${productionDir}
206 if [[ ! -d ${productionDir} ]]; then
207 echo "cannot make productionDir $productionDir" && continue
210 #move runs to final destination
211 for dir in ${tmpProductionDir}/000*; do
213 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
214 if ! guessRunData "${dir}/dummyName"; then
215 echo "could not guess run data from ${dir}"
219 #before moving - VALIDATE!!!
220 if ! validate ${dir}; then
224 if [[ -d ${oldRunDir} ]]; then
225 echo "removing old ${oldRunDir}"
228 echo "moving new ${runNumber} to ${productionDir}"
229 mv -f ${dir} ${productionDir}
232 #go to a temp dir to do the period level stuff in a completely clean dir
233 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
235 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
236 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
237 cd ${tmpPeriodLevelQAdir}
239 #link the final list of per-run dirs here, just the dirs
240 #to have a clean working directory
242 declare -a linkedStuff
243 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
245 #merge trending files if any
246 if /bin/ls 000*/trending.root &>/dev/null; then
247 hadd trending.root 000*/trending.root &> periodLevelQA.log
250 #run the period level trending/QA
251 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
252 echo running ${detector} periodLevelQA for production ${period}/${pass}
253 periodLevelQA trending.root &>> periodLevelQA.log
255 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
258 if ! validate ${PWD}; then continue; fi
260 #here we are validated so move the produced QA to the final place
261 #clean up linked stuff first
262 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
263 #some of the output could be a directory, so handle that
264 #TODO: maybe use rsync?
265 for x in ${tmpPeriodLevelQAdir}/*; do
266 if [[ -d ${x} ]]; then
267 echo "removing ${productionDir}/${x##*/}"
268 rm -rf ${productionDir}/${x##*/}
269 echo "moving ${x} to ${productionDir}"
270 mv ${x} ${productionDir}
272 if [[ -f ${x} ]]; then
273 echo "moving ${x} to ${productionDir}"
274 mv -f ${x} ${productionDir}
279 rm -rf ${tmpPeriodLevelQAdir}
283 cd ${workingDirectory}
285 if [[ -z ${planB} ]]; then
287 echo removing ${tmpDetectorRunDir}
288 rm -rf ${tmpDetectorRunDir}
292 done #end of detector loop
300 #in case of emergency
301 if [[ -n ${MAILTO} ]]; then
303 echo "trouble detected, sending email to ${MAILTO}"
305 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
311 summarizeLogs ${1} >> ${logSummary}
313 if [[ ${logStatus} -ne 0 ]]; then
314 echo "WARNING not validated: ${1}"
324 [[ ! -d ${dir} ]] && dir=${PWD}
326 #print a summary of logs
335 for log in ${dir}/${logFiles[*]}; do
336 finallog=${PWD%/}/${log}
337 [[ ! -f ${log} ]] && continue
338 errorSummary=$(validateLog ${log})
340 [[ validationStatus -ne 0 ]] && logstatus=1
341 if [[ ${validationStatus} -eq 0 ]]; then
342 #in pretend mode randomly report an error in rec.log some cases
343 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
344 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
346 echo "${finallog} OK"
348 elif [[ ${validationStatus} -eq 1 ]]; then
349 echo "${finallog} BAD ${errorSummary}"
350 elif [[ ${validationStatus} -eq 2 ]]; then
351 echo "${finallog} OK MWAH ${errorSummary}"
359 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
360 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
371 'error while loading shared libraries'
374 'Thread [0-9]* (Thread'
377 '\.C.*error:.*\.h: No such file'
379 'Interpreter error recovered'
387 local errorSummary=""
388 local warningSummary=""
390 for ((i=0; i<${#errorConditions[@]};i++)); do
391 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
392 [[ -n ${tmp} ]] && tmp+=" : "
396 for ((i=0; i<${#warningConditions[@]};i++)); do
397 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
398 [[ -n ${tmp} ]] && tmp+=" : "
399 warningSummary+=${tmp}
402 if [[ -n ${errorSummary} ]]; then
403 echo "${errorSummary}"
407 if [[ -n ${warningSummary} ]]; then
408 echo "${warningSummary}"
419 #where to search for qa files
422 workingDirectory="${PWD}"
423 #where to place the final qa plots
424 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
425 outputDirectory="${workingDirectory}/%DET"
426 #filter out detector option
427 excludeDetectors="EXAMPLE"
429 logDirectory=${workingDirectory}/logs
431 #ocdbStorage="raw://"
433 #MAILTO="fbellini@cern.ch"
435 #first, check if the config file is configured
436 #is yes - source it so that other options can override it
439 if [[ ${opt} =~ configFile=.* ]]; then
441 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
442 source "${configFile}"
447 #then, parse the options as they override the options from file
448 while [[ -n ${1} ]]; do
450 if [[ ${var} =~ .*=.* ]]; then
453 echo "badly formatted option ${var}, should be: option=value, stopping..."
462 #guess the period from the path, pick the rightmost one
467 legoTrainRunNumber=""
470 local shortRunNumber=""
472 declare -a path=( $1 )
473 local dirDepth=$(( ${#path[*]}-1 ))
475 for ((x=${dirDepth};x>=0;x--)); do
477 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
478 local field=${path[${x}]}
479 local fieldNext=${path[$((x+1))]}
481 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
482 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
483 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
484 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
485 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
486 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
487 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
490 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
491 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
493 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
494 if [[ -z ${runNumber}} ]];
504 substituteDetectorName()
508 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
509 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
517 if cd "$(echo "${1%/*}")" &>/dev/null
519 # file *may* not be local
520 # exception is ./file.ext
521 # try 'cd .; cd -;' *works!*
525 # file *must* be local
529 # file *cannot* exist
532 # reassemble realpath
533 echo "$tmppwd"/"${1##*/}"