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-%S-%N)
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=${workingDirectory}/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 "##############################################"
81 [[ ! ${detectorScript} =~ .*\.sh$ ]] && continue
82 detector=${detectorScript%.sh}
83 detector=${detector##*/}
86 if [[ "${excludeDetectors}" =~ ${detector} ]]; then
87 echo "${detector} is excluded in config, skipping..."
91 #if includeDetectors set, only process thoe detectors specified there
92 if [[ -n ${includeDetectors} && ! "${includeDetectors}" =~ ${detector} ]]; then
93 echo "${detector} not included in includeDetectors, skipping..."
97 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
98 hostInfo >> ${logSummary}
99 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
100 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}-${dateString}
101 if ! mkdir -p ${tmpDetectorRunDir}; then
102 echo "cannot create the temp dir $tmpDetectorRunDir"
105 cd ${tmpDetectorRunDir}
107 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
108 echo "running QA for ${detector}"
109 echo " outputDir=$outputDir"
110 echo " tmpPrefix=$tmpPrefix"
112 #unset the detector functions from previous iterations (detectors)
114 unset -f periodLevelQA
115 unset -f runLevelHighPtTreeQA
116 unset -f periodLevelHighPtTreeQA
117 source ${detectorScript}
119 #################################################################
120 #produce the QA and trending tree for each file (run)
121 unset arrOfTouchedProductions
122 declare -A arrOfTouchedProductions
123 while read qaFile; do
127 #first check if input file exists
128 [[ ! -f ${qaFile%\#*} ]] && echo "file ${qaFile%\#*} not accessible" && continue
130 if ! guessRunData ${qaFile}; then
131 echo "could not guess run data from ${qaFile}"
134 echo "anchorYear for ${originalPeriod} is: ${anchorYear}"
136 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
137 tmpRunDir=${tmpProductionDir}/000${runNumber}
138 mkdir -p ${tmpRunDir}
141 #by default we expect to have everything in the same archive
144 #maybe the input is not an archive, but a file
145 [[ "${qaFile}" =~ QAresults.root$ ]] && highPtTree=""
146 [[ "${qaFile}" =~ FilterEvents_Trees.root$ ]] && qaFile=""
148 #it is possible we get the highPt trees from somewhere else
149 #search the list of high pt trees for the proper run number
150 if [[ -n ${inputListHighPtTrees} ]]; then
151 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
152 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
156 echo highPtTree=$highPtTree
157 echo ocdbStorage=${ocdbStorage}
160 #what if we have a zip archive?
161 if [[ "$qaFile" =~ .*.zip$ ]]; then
162 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
163 qaFile="${qaFile}#QAresults.root"
164 elif unzip -l ${qaFile} | egrep "QAresults_barrel.root" &>/dev/null; then
165 qaFile="${qaFile}#QAresults_barrel.root"
170 if [[ "$highPtTree" =~ .*.zip$ ]]; then
171 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
172 highPtTree="${highPtTree}#FilterEvents_Trees.root"
178 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
179 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
180 runLevelQA "${qaFile}" &> runLevelQA.log
181 #perform some default actions:
182 #if trending.root not created, create a default one
183 if [[ ! -f trending.root ]]; then
184 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
186 if [[ -f trending.root ]]; then
187 arrOfTouchedProductions[${tmpProductionDir}]=1
189 echo "trending.root not created"
192 #expert QA based on high pt trees
193 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
194 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
195 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
196 arrOfTouchedProductions[${tmpProductionDir}]=1
199 cd ${tmpDetectorRunDir}
203 #################################################################
204 #cache which productions were (re)done
205 echo "list of processed productions:"
206 echo " ${!arrOfTouchedProductions[@]}"
209 #################################################################
210 #(re)do the merging/trending
211 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
212 cd ${tmpProductionDir}
214 echo "running period level stuff in ${tmpProductionDir}"
217 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
218 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
220 mkdir -p ${productionDir}
221 if [[ ! -d ${productionDir} ]]; then
222 echo "cannot make productionDir $productionDir" && continue
225 #move runs to final destination
226 for dir in ${tmpProductionDir}/000*; do
228 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
229 if ! guessRunData "${dir}/dummyName"; then
230 echo "could not guess run data from ${dir}"
234 #before moving - VALIDATE!!!
235 if ! validate ${dir}; then
239 #moving a dir is an atomic operation, no locking necessary
240 if [[ -d ${oldRunDir} ]]; then
241 echo "removing old ${oldRunDir}"
244 echo "moving new ${runNumber} to ${productionDir}"
245 mv -f ${dir} ${productionDir}
248 #go to a temp dir to do the period level stuff in a completely clean dir
249 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
251 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
252 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
253 cd ${tmpPeriodLevelQAdir}
255 #link the final list of per-run dirs here, just the dirs
256 #to have a clean working directory
258 declare -a linkedStuff
259 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
261 #merge trending files if any
262 if /bin/ls 000*/trending.root &>/dev/null; then
263 hadd trending.root 000*/trending.root &> periodLevelQA.log
266 #run the period level trending/QA
267 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
268 echo running ${detector} periodLevelQA for production ${period}/${pass}
269 periodLevelQA trending.root &>> periodLevelQA.log
271 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
274 if ! validate ${PWD}; then continue; fi
276 #here we are validated so move the produced QA to the final place
277 #clean up linked stuff first
278 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
279 periodLevelLock=${productionDir}/runQA.lock
280 if [[ ! -f ${periodLevelLock} ]]; then
281 #some of the output could be a directory, so handle that
282 #TODO: maybe use rsync?
283 #lock to avoid conflicts:
284 echo "${HOSTNAME} ${dateString}" > ${periodLevelLock}
285 for x in ${tmpPeriodLevelQAdir}/*; do
286 if [[ -d ${x} ]]; then
287 echo "removing ${productionDir}/${x##*/}"
288 rm -rf ${productionDir}/${x##*/}
289 echo "moving ${x} to ${productionDir}"
290 mv ${x} ${productionDir}
292 if [[ -f ${x} ]]; then
293 echo "moving ${x} to ${productionDir}"
294 mv -f ${x} ${productionDir}
297 rm -f ${periodLevelLock}
299 rm -rf ${tmpPeriodLevelQAdir}
301 echo "ERROR: cannot move to destination" >> ${logSummary}
302 echo "production dir ${productionDir} locked!" >> ${logSummary}
303 echo "check and maybe manually do:" >> ${logSummary}
304 echo " rm ${periodLevelLock}" >> ${logSummary}
305 echo " rsync -av ${tmpPeriodLevelQAdir}/ ${productionDir}/" >> ${logSummary}
311 cd ${workingDirectory}
313 if [[ -z ${planB} ]]; then
315 echo removing ${tmpDetectorRunDir}
316 rm -rf ${tmpDetectorRunDir}
320 done #end of detector loop
328 #in case of emergency
329 if [[ -n ${MAILTO} ]]; then
331 echo "trouble detected, sending email to ${MAILTO}"
332 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
338 summarizeLogs ${1} >> ${logSummary}
340 if [[ ${logStatus} -ne 0 ]]; then
341 echo "WARNING not validated: ${1}"
351 [[ ! -d ${dir} ]] && dir=${PWD}
353 #print a summary of logs
362 for log in ${dir}/${logFiles[*]}; do
363 [[ ! -f ${log} ]] && continue
364 errorSummary=$(validateLog ${log})
366 [[ validationStatus -ne 0 ]] && logstatus=1
367 if [[ ${validationStatus} -eq 0 ]]; then
368 #in pretend mode randomly report an error in rec.log some cases
369 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
370 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${log} BAD random error" || echo "${log} OK"
374 elif [[ ${validationStatus} -eq 1 ]]; then
375 echo "${log} BAD ${errorSummary}"
376 elif [[ ${validationStatus} -eq 2 ]]; then
377 echo "${log} OK MWAH ${errorSummary}"
385 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
386 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
397 'error while loading shared libraries'
400 'Thread [0-9]* (Thread'
403 '\.C.*error:.*\.h: No such file'
405 'Interpreter error recovered'
413 local errorSummary=""
414 local warningSummary=""
416 for ((i=0; i<${#errorConditions[@]};i++)); do
417 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
418 [[ -n ${tmp} ]] && tmp+=" : "
422 for ((i=0; i<${#warningConditions[@]};i++)); do
423 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
424 [[ -n ${tmp} ]] && tmp+=" : "
425 warningSummary+=${tmp}
428 if [[ -n ${errorSummary} ]]; then
429 echo "${errorSummary}"
433 if [[ -n ${warningSummary} ]]; then
434 echo "${warningSummary}"
447 #where to search for qa files
450 workingDirectory="${PWD}"
451 #where to place the final qa plots
452 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
453 outputDirectory="${workingDirectory}/%DET"
454 #filter out detector option
455 excludeDetectors="EXAMPLE"
457 logDirectory=${workingDirectory}/logs
461 #MAILTO="fbellini@cern.ch"
463 #first, check if the config file is configured
464 #is yes - source it so that other options can override it
466 for opt in "${args[@]}"; do
467 if [[ ${opt} =~ configFile=.* ]]; then
469 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
470 echo "using config file: ${configFile}"
471 source "${configFile}"
476 #then, parse the options as they override the options from file
477 for opt in "${args[@]}"; do
478 if [[ ! "${opt}" =~ .*=.* ]]; then
479 echo "badly formatted option ${var}, should be: option=value, stopping..."
482 local var="${opt%%=*}"
483 local value="${opt#*=}"
484 echo "${var}=${value}"
485 export ${var}="${value}"
491 #guess the period from the path, pick the rightmost one
496 legoTrainRunNumber=""
505 declare -a path=( $1 )
507 local dirDepth=$(( ${#path[*]}-1 ))
509 for ((x=${dirDepth};x>=0;x--)); do
511 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
512 local field=${path[${x}]}
513 local fieldNext=${path[$((x+1))]}
515 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
516 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
517 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*} && originalPeriod=${field}
518 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
519 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
520 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
521 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
525 [[ -n ${shortRunNumber} && "${legoTrainRunNumber}" =~ ${shortRunNumber} ]] && legoTrainRunNumber=""
526 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
527 [[ "${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
528 [[ -n ${legoTrainRunNumber} ]] && pass+="_lego${legoTrainRunNumber}"
530 #modify the OCDB: set the year
531 if [[ ${dataType} =~ sim ]]; then
532 anchorYear=$(for x in $mcProductionMap ; do [[ "${x}" =~ ${originalPeriod} ]] && echo ${x} && break; done)
533 anchorYear=${anchorYear#*=}
534 ocdbStorage=$(setYear ${anchorYear} ${ocdbStorage})
536 ocdbStorage=$(setYear ${year} ${ocdbStorage})
539 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
540 if [[ -z ${runNumber}} ]]
550 substituteDetectorName()
554 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
555 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
563 if cd "$(echo "${1%/*}")" &>/dev/null
565 # file *may* not be local
566 # exception is ./file.ext
567 # try 'cd .; cd -;' *works!*
571 # file *must* be local
575 # file *cannot* exist
578 # reassemble realpath
579 echo "$tmppwd"/"${1##*/}"
586 # ${1} - year to be set
587 # ${2} - where to set the year
588 local year1=$(guessYear ${1})
589 local year2=$(guessYear ${2})
591 [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
598 #guess the year from the path, pick the rightmost one
600 declare -a pathArray=( ${1} )
603 for field in ${pathArray[@]}; do
604 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
612 # Hallo world - Print AliRoot/Root/Alien system info
618 echo --------------------------------------
622 echo HOSTINFO HOSTNAME" "$HOSTNAME
623 echo HOSTINFO DATE" "`date`
624 echo HOSTINFO gccpath" "`which gcc`
625 echo HOSTINFO gcc version" "`gcc --version | grep gcc`
626 echo --------------------------------------
631 echo --------------------------------------
635 echo ROOTINFO ROOT" "`which root`
636 echo ROOTINFO VERSION" "`root-config --version`
638 echo --------------------------------------
644 echo --------------------------------------
648 echo ALIROOTINFO ALIROOT" "`which aliroot`
649 echo ALIROOTINFO VERSION" "`echo $ALICE_LEVEL`
650 echo ALIROOTINFO TARGET" "`echo $ALICE_TARGET`
652 echo --------------------------------------
657 #echo --------------------------------------
660 #for a in `alien --printenv`; do echo ALIENINFO $a; done
662 #echo --------------------------------------