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
23 alien-token-init ${alienUserName}
24 #this is a hack! alien-token init seems not enough
25 #but the gclient_env script messes up the LD_LIBRARY_PATH
28 done < <(grep -v "LD_LIBRARY_PATH" /tmp/gclient_env_${UID})
39 #be paranoid and make some full paths
40 [[ ! -f ${inputList} ]] && echo "no input list: ${inputList}" && return 1
41 inputList=$(get_realpath ${inputList})
42 mkdir -p ${workingDirectory}
43 workingDirectory=$(workingDirectory=${workingDirectory%/}; cd ${workingDirectory%/*}; echo "${PWD}/${workingDirectory##*/}")
44 if [[ ! -d ${workingDirectory} ]]; then
45 echo "working dir $workingDirectory does not exist and cannot be created"
48 cd ${workingDirectory}
51 echo inputList=$inputList
52 echo outputDirectory=$outputDirectory
55 dateString=$(date +%Y-%m-%d-%H-%M)
56 echo "Start time QA process: $dateString"
59 mkdir -p $logDirectory
60 [[ ! -d $logDirectory ]] && echo "no log dir $logDirectory" && return 1
61 logFile="$logDirectory/${0##*/}.${dateString}.log"
63 [[ ! -f ${logFile} ]] && echo "cannot write logfile $logfile" && return 1
64 echo "logFile = $logFile"
67 lockFile=${logDirectory}/runQA.lock
68 [[ -f ${lockFile} ]] && echo "lock ${lockFile} exists!" | tee ${logFile} && return 1
70 [[ ! -f ${lockFile} ]] && echo "cannot lock $lockFile" | tee ${logFile} && return 1
74 ################################################################
76 for detectorScript in $ALICE_ROOT/PWGPP/QA/detectorQAscripts/*; do
78 echo "##############################################"
80 [[ ! ${detectorScript} =~ .*\.sh$ ]] && continue
81 detector=${detectorScript%.sh}
82 detector=${detector##*/}
85 if [[ "${excludeDetectors}" =~ ${detector} ]]; then
86 echo "${detector} is excluded in config, skipping..."
90 #if includeDetectors set, only process thoe detectors specified there
91 if [[ -n ${includeDetectors} && ! "${includeDetectors}" =~ ${detector} ]]; then
92 echo "${detector} not included in includeDetectors, skipping..."
96 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
97 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
98 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}-${dateString}
99 if ! mkdir -p ${tmpDetectorRunDir}; then
100 echo "cannot create the temp dir $tmpDetectorRunDir"
103 cd ${tmpDetectorRunDir}
105 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
106 echo "running QA for ${detector}"
107 echo " outputDir=$outputDir"
108 echo " tmpPrefix=$tmpPrefix"
111 unset -f periodLevelQA
112 unset -f runLevelHighPtTreeQA
113 unset -f periodLevelHighPtTreeQA
114 source ${detectorScript}
116 #################################################################
117 #produce the QA and trending tree for each file (run)
118 unset arrOfTouchedProductions
119 declare -A arrOfTouchedProductions
120 while read qaFile; do
123 #first check if input file exists
124 [[ ! -f ${qaFile%\#*} ]] && echo "file ${qaFile%\#*} not accessible" && continue
126 if ! guessRunData ${qaFile}; then
127 echo "could not guess run data from ${qaFile}"
131 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
132 tmpRunDir=${tmpProductionDir}/000${runNumber}
133 mkdir -p ${tmpRunDir}
136 #by default we expect to have everything in the same archive
139 #maybe the input is not an archive, but a file
140 [[ "${qaFile}" =~ QAresults.root$ ]] && highPtTree=""
141 [[ "${qaFile}" =~ FilterEvents_Trees.root$ ]] && qaFile=""
143 #it is possible we get the highPt trees from somewhere else
144 #search the list of high pt trees for the proper run number
145 if [[ -n ${inputListHighPtTrees} ]]; then
146 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
147 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
151 echo highPtTree=$highPtTree
153 #what if we have a zip archive?
154 if [[ "$qaFile" =~ .*.zip$ ]]; then
155 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
156 qaFile="${qaFile}#QAresults.root"
161 if [[ "$highPtTree" =~ .*.zip$ ]]; then
162 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
163 highPtTree="${highPtTree}#FilterEvents_Trees.root"
169 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
170 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
171 runLevelQA "${qaFile}" &> runLevelQA.log
172 #perform some default actions:
173 #if trending.root not created, create a default one
174 if [[ ! -f trending.root ]]; then
175 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
177 if [[ -f trending.root ]]; then
178 arrOfTouchedProductions[${tmpProductionDir}]=1
180 echo "trending.root not created"
183 #expert QA based on high pt trees
184 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
185 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
186 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
187 arrOfTouchedProductions[${tmpProductionDir}]=1
190 cd ${tmpDetectorRunDir}
194 #################################################################
195 #cache which productions were (re)done
196 echo "list of processed productions:"
197 echo " ${!arrOfTouchedProductions[@]}"
200 #################################################################
201 #(re)do the merging/trending
202 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
203 cd ${tmpProductionDir}
205 echo "running period level stuff in ${tmpProductionDir}"
207 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
208 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
210 mkdir -p ${productionDir}
211 if [[ ! -d ${productionDir} ]]; then
212 echo "cannot make productionDir $productionDir" && continue
215 #move runs to final destination
216 for dir in ${tmpProductionDir}/000*; do
218 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
219 if ! guessRunData "${dir}/dummyName"; then
220 echo "could not guess run data from ${dir}"
224 #before moving - VALIDATE!!!
225 if ! validate ${dir}; then
229 if [[ -d ${oldRunDir} ]]; then
230 echo "removing old ${oldRunDir}"
233 echo "moving new ${runNumber} to ${productionDir}"
234 mv -f ${dir} ${productionDir}
237 #go to a temp dir to do the period level stuff in a completely clean dir
238 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
240 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
241 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
242 cd ${tmpPeriodLevelQAdir}
244 #link the final list of per-run dirs here, just the dirs
245 #to have a clean working directory
247 declare -a linkedStuff
248 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
250 #merge trending files if any
251 if /bin/ls 000*/trending.root &>/dev/null; then
252 hadd trending.root 000*/trending.root &> periodLevelQA.log
255 #run the period level trending/QA
256 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
257 echo running ${detector} periodLevelQA for production ${period}/${pass}
258 periodLevelQA trending.root &>> periodLevelQA.log
260 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
263 if ! validate ${PWD}; then continue; fi
265 #here we are validated so move the produced QA to the final place
266 #clean up linked stuff first
267 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
268 #some of the output could be a directory, so handle that
269 #TODO: maybe use rsync?
270 for x in ${tmpPeriodLevelQAdir}/*; do
271 if [[ -d ${x} ]]; then
272 echo "removing ${productionDir}/${x##*/}"
273 rm -rf ${productionDir}/${x##*/}
274 echo "moving ${x} to ${productionDir}"
275 mv ${x} ${productionDir}
277 if [[ -f ${x} ]]; then
278 echo "moving ${x} to ${productionDir}"
279 mv -f ${x} ${productionDir}
284 rm -rf ${tmpPeriodLevelQAdir}
288 cd ${workingDirectory}
290 if [[ -z ${planB} ]]; then
292 echo removing ${tmpDetectorRunDir}
293 rm -rf ${tmpDetectorRunDir}
297 done #end of detector loop
305 #in case of emergency
306 if [[ -n ${MAILTO} ]]; then
308 echo "trouble detected, sending email to ${MAILTO}"
310 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
316 summarizeLogs ${1} >> ${logSummary}
318 if [[ ${logStatus} -ne 0 ]]; then
319 echo "WARNING not validated: ${1}"
329 [[ ! -d ${dir} ]] && dir=${PWD}
331 #print a summary of logs
340 for log in ${dir}/${logFiles[*]}; do
341 finallog=${PWD%/}/${log}
342 [[ ! -f ${log} ]] && continue
343 errorSummary=$(validateLog ${log})
345 [[ validationStatus -ne 0 ]] && logstatus=1
346 if [[ ${validationStatus} -eq 0 ]]; then
347 #in pretend mode randomly report an error in rec.log some cases
348 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
349 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
351 echo "${finallog} OK"
353 elif [[ ${validationStatus} -eq 1 ]]; then
354 echo "${finallog} BAD ${errorSummary}"
355 elif [[ ${validationStatus} -eq 2 ]]; then
356 echo "${finallog} OK MWAH ${errorSummary}"
364 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
365 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
376 'error while loading shared libraries'
379 'Thread [0-9]* (Thread'
382 '\.C.*error:.*\.h: No such file'
384 'Interpreter error recovered'
392 local errorSummary=""
393 local warningSummary=""
395 for ((i=0; i<${#errorConditions[@]};i++)); do
396 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
397 [[ -n ${tmp} ]] && tmp+=" : "
401 for ((i=0; i<${#warningConditions[@]};i++)); do
402 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
403 [[ -n ${tmp} ]] && tmp+=" : "
404 warningSummary+=${tmp}
407 if [[ -n ${errorSummary} ]]; then
408 echo "${errorSummary}"
412 if [[ -n ${warningSummary} ]]; then
413 echo "${warningSummary}"
424 #where to search for qa files
427 workingDirectory="${PWD}"
428 #where to place the final qa plots
429 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
430 outputDirectory="${workingDirectory}/%DET"
431 #filter out detector option
432 excludeDetectors="EXAMPLE"
434 logDirectory=${workingDirectory}/logs
436 #ocdbStorage="raw://"
438 #MAILTO="fbellini@cern.ch"
440 #first, check if the config file is configured
441 #is yes - source it so that other options can override it
444 if [[ ${opt} =~ configFile=.* ]]; then
446 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
447 source "${configFile}"
452 #then, parse the options as they override the options from file
453 while [[ -n ${1} ]]; do
455 if [[ ${var} =~ .*=.* ]]; then
458 echo "badly formatted option ${var}, should be: option=value, stopping..."
467 #guess the period from the path, pick the rightmost one
472 legoTrainRunNumber=""
475 local shortRunNumber=""
477 declare -a path=( $1 )
478 local dirDepth=$(( ${#path[*]}-1 ))
480 for ((x=${dirDepth};x>=0;x--)); do
482 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
483 local field=${path[${x}]}
484 local fieldNext=${path[$((x+1))]}
486 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
487 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
488 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
489 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
490 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
491 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
492 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
495 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
496 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
498 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
499 if [[ -z ${runNumber}} ]];
509 substituteDetectorName()
513 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
514 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
522 if cd "$(echo "${1%/*}")" &>/dev/null
524 # file *may* not be local
525 # exception is ./file.ext
526 # try 'cd .; cd -;' *works!*
530 # file *must* be local
534 # file *cannot* exist
537 # reassemble realpath
538 echo "$tmppwd"/"${1##*/}"