2 if [ ${BASH_VERSINFO} -lt 4 ]; then
3 echo "bash version >= 4 needed, you have ${BASH_VERSION}, exiting..."
11 echo " ${0##*/} option=value [option=value]"
12 echo " at least inputList should be specified, or configFile containing it:"
13 echo " ${0##*/} inputList=file.list"
14 echo " options override config file (if any), e.g.:"
15 echo " ${0##*/} configFile=runQA.config inputList=file.list outputDirectory=%det"
19 if ! parseConfig "$@"; then
24 [[ -z $ALICE_ROOT ]] && echo "ALICE_ROOT not defined" && return 1
27 if [[ ${ocdbStorage} =~ ${ocdbregex} ]]; then
28 alien-token-init ${alienUserName}
29 #this is a hack! alien-token init seems not enough
30 #but the gclient_env script messes up the LD_LIBRARY_PATH
33 done < <(grep -v "LD_LIBRARY_PATH" /tmp/gclient_env_${UID})
44 #be paranoid and make some full paths
45 [[ ! -f ${inputList} ]] && echo "no input list: ${inputList}" && return 1
46 inputList=$(get_realpath ${inputList})
47 mkdir -p ${workingDirectory}
48 workingDirectory=$(workingDirectory=${workingDirectory%/}; cd ${workingDirectory%/*}; echo "${PWD}/${workingDirectory##*/}")
49 if [[ ! -d ${workingDirectory} ]]; then
50 echo "working dir $workingDirectory does not exist and cannot be created"
53 cd ${workingDirectory}
56 echo inputList=$inputList
57 echo outputDirectory=$outputDirectory
60 dateString=$(date +%Y-%m-%d-%H-%M-%S-%N)
61 echo "Start time QA process: $dateString"
64 mkdir -p $logDirectory
65 [[ ! -d $logDirectory ]] && echo "no log dir $logDirectory" && return 1
66 logFile="$logDirectory/${0##*/}.${dateString}.log"
68 [[ ! -f ${logFile} ]] && echo "cannot write logfile $logfile" && return 1
69 echo "logFile = $logFile"
72 lockFile=${workingDirectory}/runQA.lock
73 [[ -f ${lockFile} ]] && echo "lock ${lockFile} exists!" | tee ${logFile} && return 1
75 [[ ! -f ${lockFile} ]] && echo "cannot lock $lockFile" | tee ${logFile} && return 1
79 ################################################################
81 for detectorScript in $ALICE_ROOT/PWGPP/QA/detectorQAscripts/*; do
83 echo "##############################################"
86 [[ ! ${detectorScript} =~ .*\.sh$ ]] && continue
87 detector=${detectorScript%.sh}
88 detector=${detector##*/}
91 if [[ "${excludeDetectors}" =~ ${detector} ]]; then
92 echo "${detector} is excluded in config, skipping..."
96 #if includeDetectors set, only process thoe detectors specified there
97 if [[ -n ${includeDetectors} && ! "${includeDetectors}" =~ ${detector} ]]; then
98 echo "${detector} not included in includeDetectors, skipping..."
102 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
103 hostInfo >> ${logSummary}
104 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
105 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}-${dateString}
106 if ! mkdir -p ${tmpDetectorRunDir}; then
107 echo "cannot create the temp dir $tmpDetectorRunDir"
110 cd ${tmpDetectorRunDir}
112 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
113 echo "running QA for ${detector}"
114 echo " outputDir=$outputDir"
115 echo " tmpPrefix=$tmpPrefix"
117 #unset the detector functions from previous iterations (detectors)
119 unset -f periodLevelQA
120 unset -f runLevelHighPtTreeQA
121 unset -f periodLevelHighPtTreeQA
122 source ${detectorScript}
124 #################################################################
125 #produce the QA and trending tree for each file (run)
126 unset arrOfTouchedProductions
127 declare -A arrOfTouchedProductions
128 while read qaFile; do
132 #first check if input file exists
133 [[ ! -f ${qaFile%\#*} ]] && echo "file ${qaFile%\#*} not accessible" && continue
135 if ! guessRunData ${qaFile}; then
136 echo "could not guess run data from ${qaFile}"
139 echo "anchorYear for ${originalPeriod} is: ${anchorYear}"
141 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
142 tmpRunDir=${tmpProductionDir}/000${runNumber}
143 mkdir -p ${tmpRunDir}
146 #by default we expect to have everything in the same archive
149 #maybe the input is not an archive, but a file
150 [[ "${qaFile}" =~ QAresults.root$ ]] && highPtTree=""
151 [[ "${qaFile}" =~ FilterEvents_Trees.root$ ]] && qaFile=""
153 #it is possible we get the highPt trees from somewhere else
154 #search the list of high pt trees for the proper run number
155 if [[ -n ${inputListHighPtTrees} ]]; then
156 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
157 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
161 echo highPtTree=$highPtTree
162 echo ocdbStorage=${ocdbStorage}
165 #what if we have a zip archive?
166 if [[ "$qaFile" =~ .*.zip$ ]]; then
167 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
168 qaFile="${qaFile}#QAresults.root"
169 elif unzip -l ${qaFile} | egrep "QAresults_barrel.root" &>/dev/null; then
170 qaFile="${qaFile}#QAresults_barrel.root"
175 if [[ "$highPtTree" =~ .*.zip$ ]]; then
176 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
177 highPtTree="${highPtTree}#FilterEvents_Trees.root"
183 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
184 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
185 runLevelQA "${qaFile}" &> runLevelQA.log
186 #perform some default actions:
187 #if trending.root not created, create a default one
188 if [[ ! -f trending.root ]]; then
189 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
191 if [[ -f trending.root ]]; then
192 #cache the touched production + an example file to guarantee consistent run data parsing
193 arrOfTouchedProductions[${tmpProductionDir}]="${qaFile%\#*}"
195 echo "trending.root not created"
198 #expert QA based on high pt trees
199 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
200 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
201 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
202 arrOfTouchedProductions[${tmpProductionDir}]=1
205 cd ${tmpDetectorRunDir}
209 #################################################################
210 #cache which productions were (re)done
211 echo "list of processed productions:"
212 echo " ${!arrOfTouchedProductions[@]}"
215 #################################################################
216 #(re)do the merging/trending
217 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
218 cd ${tmpProductionDir}
220 echo "running period level stuff in ${tmpProductionDir}"
223 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
224 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
226 mkdir -p ${productionDir}
227 if [[ ! -d ${productionDir} ]]; then
228 echo "cannot make productionDir $productionDir" && continue
231 #move runs to final destination
232 for dir in ${tmpProductionDir}/000*; do
234 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
235 if ! guessRunData "${arrOfTouchedProductions[${tmpProductionDir}]}"; then
236 echo "could not guess run data from ${dir}"
240 #before moving - VALIDATE!!!
241 if ! validate ${dir}; then
245 #moving a dir is an atomic operation, no locking necessary
246 if [[ -d ${oldRunDir} ]]; then
247 echo "removing old ${oldRunDir}"
250 echo "moving new ${runNumber} to ${productionDir}"
251 mv -f ${dir} ${productionDir}
254 #go to a temp dir to do the period level stuff in a completely clean dir
255 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
257 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
258 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
259 cd ${tmpPeriodLevelQAdir}
261 #link the final list of per-run dirs here, just the dirs
262 #to have a clean working directory
264 declare -a linkedStuff
265 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
267 #merge trending files if any
268 if /bin/ls 000*/trending.root &>/dev/null; then
269 hadd trending.root 000*/trending.root &> periodLevelQA.log
272 #run the period level trending/QA
273 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
274 echo running ${detector} periodLevelQA for production ${period}/${pass}
275 periodLevelQA trending.root &>> periodLevelQA.log
277 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
280 if ! validate ${PWD}; then continue; fi
282 #here we are validated so move the produced QA to the final place
283 #clean up linked stuff first
284 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
285 periodLevelLock=${productionDir}/runQA.lock
286 if [[ ! -f ${periodLevelLock} ]]; then
287 #some of the output could be a directory, so handle that
288 #TODO: maybe use rsync?
289 #lock to avoid conflicts:
290 echo "${HOSTNAME} ${dateString}" > ${periodLevelLock}
291 for x in ${tmpPeriodLevelQAdir}/*; do
292 if [[ -d ${x} ]]; then
293 echo "removing ${productionDir}/${x##*/}"
294 rm -rf ${productionDir}/${x##*/}
295 echo "moving ${x} to ${productionDir}"
296 mv ${x} ${productionDir}
298 if [[ -f ${x} ]]; then
299 echo "moving ${x} to ${productionDir}"
300 mv -f ${x} ${productionDir}
303 rm -f ${periodLevelLock}
305 rm -rf ${tmpPeriodLevelQAdir}
307 echo "ERROR: cannot move to destination" >> ${logSummary}
308 echo "production dir ${productionDir} locked!" >> ${logSummary}
309 echo "check and maybe manually do:" >> ${logSummary}
310 echo " rm ${periodLevelLock}" >> ${logSummary}
311 echo " rsync -av ${tmpPeriodLevelQAdir}/ ${productionDir}/" >> ${logSummary}
317 cd ${workingDirectory}
319 if [[ -z ${planB} ]]; then
321 echo removing ${tmpDetectorRunDir}
322 rm -rf ${tmpDetectorRunDir}
326 done #end of detector loop
334 #in case of emergency
335 if [[ -n ${MAILTO} ]]; then
337 echo "trouble detected, sending email to ${MAILTO}"
338 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
344 summarizeLogs ${1} >> ${logSummary}
346 if [[ ${logStatus} -ne 0 ]]; then
347 echo "WARNING not validated: ${1}"
357 [[ ! -d ${dir} ]] && dir=${PWD}
359 #print a summary of logs
368 for log in ${dir}/${logFiles[*]}; do
369 [[ ! -f ${log} ]] && continue
370 errorSummary=$(validateLog ${log})
372 [[ validationStatus -ne 0 ]] && logstatus=1
373 if [[ ${validationStatus} -eq 0 ]]; then
374 #in pretend mode randomly report an error in rec.log some cases
375 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
376 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${log} BAD random error" || echo "${log} OK"
380 elif [[ ${validationStatus} -eq 1 ]]; then
381 echo "${log} BAD ${errorSummary}"
382 elif [[ ${validationStatus} -eq 2 ]]; then
383 echo "${log} OK MWAH ${errorSummary}"
391 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
392 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
403 'error while loading shared libraries'
406 'Thread [0-9]* (Thread'
409 '\.C.*error:.*\.h: No such file'
411 'Interpreter error recovered'
419 local errorSummary=""
420 local warningSummary=""
422 for ((i=0; i<${#errorConditions[@]};i++)); do
423 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
424 [[ -n ${tmp} ]] && tmp+=" : "
428 for ((i=0; i<${#warningConditions[@]};i++)); do
429 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
430 [[ -n ${tmp} ]] && tmp+=" : "
431 warningSummary+=${tmp}
434 if [[ -n ${errorSummary} ]]; then
435 echo "${errorSummary}"
439 if [[ -n ${warningSummary} ]]; then
440 echo "${warningSummary}"
453 #where to search for qa files
456 workingDirectory="${PWD}"
457 #where to place the final qa plots
458 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
459 outputDirectory="${workingDirectory}/%DET"
460 #filter out detector option
461 excludeDetectors="EXAMPLE"
463 logDirectory=${workingDirectory}/logs
467 #MAILTO="fbellini@cern.ch"
469 #first, check if the config file is configured
470 #is yes - source it so that other options can override it
472 for opt in "${args[@]}"; do
473 if [[ ${opt} =~ configFile=.* ]]; then
475 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
476 echo "using config file: ${configFile}"
477 source "${configFile}"
482 #then, parse the options as they override the options from file
483 for opt in "${args[@]}"; do
484 if [[ ! "${opt}" =~ .*=.* ]]; then
485 echo "badly formatted option ${var}, should be: option=value, stopping..."
488 local var="${opt%%=*}"
489 local value="${opt#*=}"
490 echo "${var}=${value}"
491 export ${var}="${value}"
497 #guess the period from the path, pick the rightmost one
502 legoTrainRunNumber=""
511 declare -a path=( $1 )
513 local dirDepth=$(( ${#path[*]}-1 ))
515 for ((x=${dirDepth};x>=0;x--)); do
517 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
518 local field=${path[${x}]}
519 local fieldNext=${path[$((x+1))]}
521 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
522 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
523 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*} && originalPeriod=${field}
524 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
525 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
526 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
527 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
531 [[ -n ${shortRunNumber} && "${legoTrainRunNumber}" =~ ${shortRunNumber} ]] && legoTrainRunNumber=""
532 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
533 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber} && originalPass="" #for MC not from lego, the runnumber is identified as lego train number, thus needs to be nulled
534 [[ -n ${legoTrainRunNumber} ]] && pass+="_lego${legoTrainRunNumber}"
536 #modify the OCDB: set the year
537 if [[ ${dataType} =~ sim ]]; then
538 anchorYear=$(run2year $runNumber)
539 if [[ -z "${anchorYear}" ]]; then
540 echo "WARNING: anchorYear not available for this production: ${originalPeriod}, runNumber: ${runNumber}. Cannot set the OCDB."
543 ocdbStorage=$(setYear ${anchorYear} ${ocdbStorage})
545 ocdbStorage=$(setYear ${year} ${ocdbStorage})
548 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
549 if [[ -z ${runNumber} ]]
561 #for a given run print the year.
562 #the run-year table is ${runMap} (a string)
563 #defined in the config file
564 #one line per year, format: year runMin runMax
566 [[ -z ${run} ]] && return 1
570 while read year runMin runMax; do
571 [[ -z ${year} || -z ${runMin} || -z ${runMax} ]] && continue
572 [[ ${run} -ge ${runMin} && ${run} -le ${runMax} ]] && echo ${year} && break
573 done < <(echo "${runMap}")
577 substituteDetectorName()
581 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
582 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
590 if cd "$(echo "${1%/*}")" &>/dev/null
592 # file *may* not be local
593 # exception is ./file.ext
594 # try 'cd .; cd -;' *works!*
598 # file *must* be local
602 # file *cannot* exist
605 # reassemble realpath
606 echo "$tmppwd"/"${1##*/}"
613 # ${1} - year to be set
614 # ${2} - where to set the year
615 local year1=$(guessYear ${1})
616 local year2=$(guessYear ${2})
618 [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
625 #guess the year from the path, pick the rightmost one
627 declare -a pathArray=( ${1} )
630 for field in ${pathArray[@]}; do
631 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
639 # Hallo world - Print AliRoot/Root/Alien system info
645 echo --------------------------------------
649 echo HOSTINFO HOSTNAME" "$HOSTNAME
650 echo HOSTINFO DATE" "`date`
651 echo HOSTINFO gccpath" "`which gcc`
652 echo HOSTINFO gcc version" "`gcc --version | grep gcc`
653 echo --------------------------------------
658 echo --------------------------------------
662 echo ROOTINFO ROOT" "`which root`
663 echo ROOTINFO VERSION" "`root-config --version`
665 echo --------------------------------------
671 echo --------------------------------------
675 echo ALIROOTINFO ALIROOT" "`which aliroot`
676 echo ALIROOTINFO VERSION" "`echo $ALICE_LEVEL`
677 echo ALIROOTINFO TARGET" "`echo $ALICE_TARGET`
679 echo --------------------------------------
684 #echo --------------------------------------
687 #for a in `alien --printenv`; do echo ALIENINFO $a; done
689 #echo --------------------------------------