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})
45 #be paranoid and make some full paths
46 [[ ! -f ${inputList} ]] && echo "no input list: ${inputList}" && return 1
47 inputList=$(get_realpath ${inputList})
48 mkdir -p ${workingDirectory}
49 workingDirectory=$(workingDirectory=${workingDirectory%/}; cd ${workingDirectory%/*}; echo "${PWD}/${workingDirectory##*/}")
50 if [[ ! -d ${workingDirectory} ]]; then
51 echo "working dir $workingDirectory does not exist and cannot be created"
54 cd ${workingDirectory}
57 echo inputList=$inputList
58 echo outputDirectory=$outputDirectory
61 dateString=$(date +%Y-%m-%d-%H-%M-%S-%N)
62 echo "Start time QA process: $dateString"
65 mkdir -p $logDirectory
66 [[ ! -d $logDirectory ]] && echo "no log dir $logDirectory" && return 1
67 logFile="$logDirectory/${0##*/}.${dateString}.log"
69 [[ ! -f ${logFile} ]] && echo "cannot write logfile $logfile" && return 1
70 echo "logFile = $logFile"
73 lockFile=${workingDirectory}/runQA.lock
74 [[ -f ${lockFile} ]] && echo "lock ${lockFile} exists!" | tee ${logFile} && return 1
76 [[ ! -f ${lockFile} ]] && echo "cannot lock $lockFile" | tee ${logFile} && return 1
80 ################################################################
82 for detectorScript in $ALICE_ROOT/PWGPP/QA/detectorQAscripts/*; do
84 echo "##############################################"
87 [[ ! ${detectorScript} =~ .*\.sh$ ]] && continue
88 detector=${detectorScript%.sh}
89 detector=${detector##*/}
90 #by default we expect the container in the QA root file to de named like
92 detectorQAcontainerName=${detector}
95 if [[ "${excludeDetectors}" =~ ${detector} ]]; then
96 echo "${detector} is excluded in config, skipping..."
100 #if includeDetectors set, only process thoe detectors specified there
101 if [[ -n ${includeDetectors} && ! "${includeDetectors}" =~ ${detector} ]]; then
102 echo "${detector} not included in includeDetectors, skipping..."
106 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
107 hostInfo >> ${logSummary}
108 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
109 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}-${dateString}
110 if ! mkdir -p ${tmpDetectorRunDir}; then
111 echo "cannot create the temp dir $tmpDetectorRunDir"
114 cd ${tmpDetectorRunDir}
116 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
117 echo "running QA for ${detector}"
118 echo " outputDir=$outputDir"
119 echo " tmpPrefix=$tmpPrefix"
121 #unset the detector functions from previous iterations (detectors)
123 unset -f periodLevelQA
124 unset -f runLevelHighPtTreeQA
125 unset -f periodLevelHighPtTreeQA
126 source ${detectorScript}
128 #################################################################
129 #produce the QA and trending tree for each file (run)
130 unset arrOfTouchedProductions
131 declare -A arrOfTouchedProductions
132 while read qaFile; do
136 #first check if input file exists
137 [[ ! -f ${qaFile%\#*} ]] && echo "file ${qaFile%\#*} not accessible" && continue
139 if ! guessRunData ${qaFile}; then
140 echo "could not guess run data from ${qaFile}"
143 echo "anchorYear for ${originalPeriod} is: ${anchorYear}"
145 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
146 tmpRunDir=${tmpProductionDir}/000${runNumber}
147 mkdir -p ${tmpRunDir}
150 #by default we expect to have everything in the same archive
153 #maybe the input is not an archive, but a file
154 [[ "${qaFile}" =~ QAresults.root$ ]] && highPtTree=""
155 [[ "${qaFile}" =~ FilterEvents_Trees.root$ ]] && qaFile=""
157 #it is possible we get the highPt trees from somewhere else
158 #search the list of high pt trees for the proper run number
159 if [[ -n ${inputListHighPtTrees} ]]; then
160 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
161 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
165 echo highPtTree=$highPtTree
166 echo ocdbStorage=${ocdbStorage}
169 #what if we have a zip archive?
170 if [[ "$qaFile" =~ .*.zip$ ]]; then
171 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
172 qaFile="${qaFile}#QAresults.root"
173 elif unzip -l ${qaFile} | egrep "QAresults_barrel.root" &>/dev/null; then
174 qaFile="${qaFile}#QAresults_barrel.root"
179 if [[ "$highPtTree" =~ .*.zip$ ]]; then
180 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
181 highPtTree="${highPtTree}#FilterEvents_Trees.root"
187 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
188 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
189 runLevelQA "${qaFile}" &> runLevelQA.log
190 #perform some default actions:
191 #if trending.root not created, create a default one
192 if [[ ! -f trending.root ]]; then
193 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detectorQAcontainerName}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
195 if [[ -f trending.root ]]; then
196 #cache the touched production + an example file to guarantee consistent run data parsing
197 arrOfTouchedProductions[${tmpProductionDir}]="${qaFile%\#*}"
199 echo "trending.root not created"
202 #expert QA based on high pt trees
203 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
204 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
205 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
206 arrOfTouchedProductions[${tmpProductionDir}]=1
209 cd ${tmpDetectorRunDir}
213 #################################################################
214 #cache which productions were (re)done
215 echo "list of processed productions:"
216 echo " ${!arrOfTouchedProductions[@]}"
219 #################################################################
220 #(re)do the merging/trending
221 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
222 cd ${tmpProductionDir}
224 echo "running period level stuff in ${tmpProductionDir}"
227 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
228 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
230 mkdir -p ${productionDir}
231 if [[ ! -d ${productionDir} ]]; then
232 echo "cannot make productionDir $productionDir" && continue
235 #move runs to final destination
236 for dir in ${tmpProductionDir}/000*; do
238 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
239 if ! guessRunData "${arrOfTouchedProductions[${tmpProductionDir}]}"; then
240 echo "could not guess run data from ${dir}"
244 #before moving - VALIDATE!!!
245 if ! validate ${dir}; then
249 #moving a dir is an atomic operation, no locking necessary
250 if [[ -d ${oldRunDir} ]]; then
251 echo "removing old ${oldRunDir}"
254 echo "moving new ${runNumber} to ${productionDir}"
255 mv -f ${dir} ${productionDir}
258 #go to a temp dir to do the period level stuff in a completely clean dir
259 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
261 echo tmpPeriodLevelQAdir="${tmpPeriodLevelQAdir}"
262 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
263 cd ${tmpPeriodLevelQAdir}
265 #link the final list of per-run dirs here, just the dirs
266 #to have a clean working directory
268 declare -a linkedStuff
269 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
271 #merge trending files if any
272 if /bin/ls 000*/trending.root &>/dev/null; then
273 hadd trending.root 000*/trending.root &> periodLevelQA.log
276 #run the period level trending/QA
277 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
278 echo running ${detector} periodLevelQA for production ${period}/${pass}
279 periodLevelQA trending.root &>> periodLevelQA.log
281 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
284 if ! validate ${PWD}; then continue; fi
286 #here we are validated so move the produced QA to the final place
287 #clean up linked stuff first
288 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
289 periodLevelLock=${productionDir}/runQA.lock
290 if [[ ! -f ${periodLevelLock} ]]; then
291 #some of the output could be a directory, so handle that
292 #TODO: maybe use rsync?
293 #lock to avoid conflicts:
294 echo "${HOSTNAME} ${dateString}" > ${periodLevelLock}
295 for x in ${tmpPeriodLevelQAdir}/*; do
296 if [[ -d ${x} ]]; then
297 echo "removing ${productionDir}/${x##*/}"
298 rm -rf ${productionDir}/${x##*/}
299 echo "moving ${x} to ${productionDir}"
300 mv ${x} ${productionDir}
302 if [[ -f ${x} ]]; then
303 echo "moving ${x} to ${productionDir}"
304 mv -f ${x} ${productionDir}
307 rm -f ${periodLevelLock}
309 rm -rf ${tmpPeriodLevelQAdir}
311 echo "ERROR: cannot move to destination" >> ${logSummary}
312 echo "production dir ${productionDir} locked!" >> ${logSummary}
313 echo "check and maybe manually do:" >> ${logSummary}
314 echo " rm ${periodLevelLock}" >> ${logSummary}
315 echo " rsync -av ${tmpPeriodLevelQAdir}/ ${productionDir}/" >> ${logSummary}
321 cd ${workingDirectory}
323 if [[ -z ${planB} ]]; then
325 echo removing ${tmpDetectorRunDir}
326 rm -rf ${tmpDetectorRunDir}
330 done #end of detector loop
339 #in case of emergency
340 #first check if we have the email of the detector expert defined,
341 #if yes, append to the mailing list
342 local mailTo=${MAILTO}
343 local detExpertEmailVar="MAILTO_${detector}"
344 [[ -n "${!detExpertEmailVar}" ]] && mailTo+=" ${!detExpertEmailVar}"
345 if [[ -n ${mailTo} ]]; then
347 echo "trouble detected, sending email to ${mailTo}"
348 cat ${logSummary} | mail -s "${detector} QA in need of assistance" ${mailTo}
355 summarizeLogs ${1} >> ${logSummary}
357 if [[ ${logStatus} -ne 0 ]]; then
358 echo "WARNING not validated: ${1}"
368 [[ ! -d ${dir} ]] && dir=${PWD}
370 #print a summary of logs
379 for log in ${dir}/${logFiles[*]}; do
380 [[ ! -f ${log} ]] && continue
381 errorSummary=$(validateLog ${log})
383 [[ validationStatus -ne 0 ]] && logstatus=1
384 if [[ ${validationStatus} -eq 0 ]]; then
385 #in pretend mode randomly report an error in rec.log some cases
386 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
387 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${log} BAD random error" || echo "${log} OK"
391 elif [[ ${validationStatus} -eq 1 ]]; then
392 echo "${log} BAD ${errorSummary}"
393 elif [[ ${validationStatus} -eq 2 ]]; then
394 echo "${log} OK MWAH ${errorSummary}"
402 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
403 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
414 'error while loading shared libraries'
417 'Thread [0-9]* (Thread'
420 '\.C.*error:.*\.h: No such file'
422 'Interpreter error recovered'
430 local errorSummary=""
431 local warningSummary=""
433 for ((i=0; i<${#errorConditions[@]};i++)); do
434 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
435 [[ -n ${tmp} ]] && tmp+=" : "
439 for ((i=0; i<${#warningConditions[@]};i++)); do
440 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
441 [[ -n ${tmp} ]] && tmp+=" : "
442 warningSummary+=${tmp}
445 if [[ -n ${errorSummary} ]]; then
446 echo "${errorSummary}"
450 if [[ -n ${warningSummary} ]]; then
451 echo "${warningSummary}"
464 #where to search for qa files
467 workingDirectory="${PWD}"
468 #where to place the final qa plots
469 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
470 outputDirectory="${workingDirectory}/%DET"
471 #filter out detector option
472 excludeDetectors="EXAMPLE"
474 logDirectory=${workingDirectory}/logs
478 #MAILTO="fbellini@cern.ch"
480 #first, check if the config file is configured
481 #is yes - source it so that other options can override it
483 for opt in "${args[@]}"; do
484 if [[ ${opt} =~ configFile=.* ]]; then
486 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
487 echo "using config file: ${configFile}"
488 source "${configFile}"
493 #then, parse the options as they override the options from file
494 for opt in "${args[@]}"; do
495 if [[ ! "${opt}" =~ .*=.* ]]; then
496 echo "badly formatted option ${var}, should be: option=value, stopping..."
499 local var="${opt%%=*}"
500 local value="${opt#*=}"
501 echo "${var}=${value}"
502 export ${var}="${value}"
509 #guess the period from the path, pick the rightmost one
514 legoTrainRunNumber=""
523 declare -a path=( $1 )
525 local dirDepth=$(( ${#path[*]}-1 ))
527 for ((x=${dirDepth};x>=0;x--)); do
529 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
530 local field=${path[${x}]}
531 local fieldNext=${path[$((x+1))]}
533 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
534 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
535 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*} && originalPeriod=${field}
536 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
537 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
538 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
539 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
543 [[ -n ${shortRunNumber} && "${legoTrainRunNumber}" =~ ${shortRunNumber} ]] && legoTrainRunNumber=""
544 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
545 [[ "${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
546 [[ -n ${legoTrainRunNumber} ]] && pass+="_lego${legoTrainRunNumber}"
548 #modify the OCDB: set the year
549 if [[ ${dataType} =~ sim ]]; then
550 anchorYear=$(run2year $runNumber)
551 if [[ -z "${anchorYear}" ]]; then
552 echo "WARNING: anchorYear not available for this production: ${originalPeriod}, runNumber: ${runNumber}. Cannot set the OCDB."
555 ocdbStorage=$(setYear ${anchorYear} ${ocdbStorage})
557 ocdbStorage=$(setYear ${year} ${ocdbStorage})
560 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
561 if [[ -z ${runNumber} ]]
573 #for a given run print the year.
574 #the run-year table is ${runMap} (a string)
575 #defined in the config file
576 #one line per year, format: year runMin runMax
578 [[ -z ${run} ]] && return 1
582 while read year runMin runMax; do
583 [[ -z ${year} || -z ${runMin} || -z ${runMax} ]] && continue
584 [[ ${run} -ge ${runMin} && ${run} -le ${runMax} ]] && echo ${year} && break
585 done < <(echo "${runMap}")
589 substituteDetectorName()
593 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
594 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
603 if cd "$(echo "${1%/*}")" &>/dev/null
605 # file *may* not be local
606 # exception is ./file.ext
607 # try 'cd .; cd -;' *works!*
611 # file *must* be local
615 # file *cannot* exist
618 # reassemble realpath
619 echo "$tmppwd"/"${1##*/}"
626 # ${1} - year to be set
627 # ${2} - where to set the year
628 local year1=$(guessYear ${1})
629 local year2=$(guessYear ${2})
631 [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
638 #guess the year from the path, pick the rightmost one
640 declare -a pathArray=( ${1} )
643 for field in ${pathArray[@]}; do
644 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
652 # Hallo world - Print AliRoot/Root/Alien system info
658 echo --------------------------------------
662 echo HOSTINFO HOSTNAME" "$HOSTNAME
663 echo HOSTINFO DATE" "`date`
664 echo HOSTINFO gccpath" "`which gcc`
665 echo HOSTINFO gcc version" "`gcc --version | grep gcc`
666 echo --------------------------------------
671 echo --------------------------------------
675 echo ROOTINFO ROOT" "`which root`
676 echo ROOTINFO VERSION" "`root-config --version`
678 echo --------------------------------------
684 echo --------------------------------------
688 echo ALIROOTINFO ALIROOT" "`which aliroot`
689 echo ALIROOTINFO VERSION" "`echo $ALICE_LEVEL`
690 echo ALIROOTINFO TARGET" "`echo $ALICE_TARGET`
692 echo --------------------------------------
697 #echo --------------------------------------
700 #for a in `alien --printenv`; do echo ALIENINFO $a; done
702 #echo --------------------------------------