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"
168 if [[ "$highPtTree" =~ .*.zip$ ]]; then
169 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
170 highPtTree="${highPtTree}#FilterEvents_Trees.root"
176 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
177 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
178 runLevelQA "${qaFile}" &> runLevelQA.log
179 #perform some default actions:
180 #if trending.root not created, create a default one
181 if [[ ! -f trending.root ]]; then
182 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
184 if [[ -f trending.root ]]; then
185 arrOfTouchedProductions[${tmpProductionDir}]=1
187 echo "trending.root not created"
190 #expert QA based on high pt trees
191 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
192 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
193 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
194 arrOfTouchedProductions[${tmpProductionDir}]=1
197 cd ${tmpDetectorRunDir}
201 #################################################################
202 #cache which productions were (re)done
203 echo "list of processed productions:"
204 echo " ${!arrOfTouchedProductions[@]}"
207 #################################################################
208 #(re)do the merging/trending
209 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
210 cd ${tmpProductionDir}
212 echo "running period level stuff in ${tmpProductionDir}"
215 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
216 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
218 mkdir -p ${productionDir}
219 if [[ ! -d ${productionDir} ]]; then
220 echo "cannot make productionDir $productionDir" && continue
223 #move runs to final destination
224 for dir in ${tmpProductionDir}/000*; do
226 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
227 if ! guessRunData "${dir}/dummyName"; then
228 echo "could not guess run data from ${dir}"
232 #before moving - VALIDATE!!!
233 if ! validate ${dir}; then
237 #moving a dir is an atomic operation, no locking necessary
238 if [[ -d ${oldRunDir} ]]; then
239 echo "removing old ${oldRunDir}"
242 echo "moving new ${runNumber} to ${productionDir}"
243 mv -f ${dir} ${productionDir}
246 #go to a temp dir to do the period level stuff in a completely clean dir
247 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
249 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
250 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
251 cd ${tmpPeriodLevelQAdir}
253 #link the final list of per-run dirs here, just the dirs
254 #to have a clean working directory
256 declare -a linkedStuff
257 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
259 #merge trending files if any
260 if /bin/ls 000*/trending.root &>/dev/null; then
261 hadd trending.root 000*/trending.root &> periodLevelQA.log
264 #run the period level trending/QA
265 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
266 echo running ${detector} periodLevelQA for production ${period}/${pass}
267 periodLevelQA trending.root &>> periodLevelQA.log
269 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
272 if ! validate ${PWD}; then continue; fi
274 #here we are validated so move the produced QA to the final place
275 #clean up linked stuff first
276 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
277 periodLevelLock=${productionDir}/runQA.lock
278 if [[ ! -f ${periodLevelLock} ]]; then
279 #some of the output could be a directory, so handle that
280 #TODO: maybe use rsync?
281 #lock to avoid conflicts:
282 echo "${HOSTNAME} ${dateString}" > ${periodLevelLock}
283 for x in ${tmpPeriodLevelQAdir}/*; do
284 if [[ -d ${x} ]]; then
285 echo "removing ${productionDir}/${x##*/}"
286 rm -rf ${productionDir}/${x##*/}
287 echo "moving ${x} to ${productionDir}"
288 mv ${x} ${productionDir}
290 if [[ -f ${x} ]]; then
291 echo "moving ${x} to ${productionDir}"
292 mv -f ${x} ${productionDir}
295 rm -f ${periodLevelLock}
297 rm -rf ${tmpPeriodLevelQAdir}
299 echo "ERROR: cannot move to destination" >> ${logSummary}
300 echo "production dir ${productionDir} locked!" >> ${logSummary}
301 echo "check and maybe manually do:" >> ${logSummary}
302 echo " rm ${periodLevelLock}" >> ${logSummary}
303 echo " rsync -av ${tmpPeriodLevelQAdir}/ ${productionDir}/" >> ${logSummary}
309 cd ${workingDirectory}
311 if [[ -z ${planB} ]]; then
313 echo removing ${tmpDetectorRunDir}
314 rm -rf ${tmpDetectorRunDir}
318 done #end of detector loop
326 #in case of emergency
327 if [[ -n ${MAILTO} ]]; then
329 echo "trouble detected, sending email to ${MAILTO}"
330 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
336 summarizeLogs ${1} >> ${logSummary}
338 if [[ ${logStatus} -ne 0 ]]; then
339 echo "WARNING not validated: ${1}"
349 [[ ! -d ${dir} ]] && dir=${PWD}
351 #print a summary of logs
360 for log in ${dir}/${logFiles[*]}; do
361 [[ ! -f ${log} ]] && continue
362 errorSummary=$(validateLog ${log})
364 [[ validationStatus -ne 0 ]] && logstatus=1
365 if [[ ${validationStatus} -eq 0 ]]; then
366 #in pretend mode randomly report an error in rec.log some cases
367 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
368 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${log} BAD random error" || echo "${log} OK"
372 elif [[ ${validationStatus} -eq 1 ]]; then
373 echo "${log} BAD ${errorSummary}"
374 elif [[ ${validationStatus} -eq 2 ]]; then
375 echo "${log} OK MWAH ${errorSummary}"
383 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
384 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
395 'error while loading shared libraries'
398 'Thread [0-9]* (Thread'
401 '\.C.*error:.*\.h: No such file'
403 'Interpreter error recovered'
411 local errorSummary=""
412 local warningSummary=""
414 for ((i=0; i<${#errorConditions[@]};i++)); do
415 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
416 [[ -n ${tmp} ]] && tmp+=" : "
420 for ((i=0; i<${#warningConditions[@]};i++)); do
421 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
422 [[ -n ${tmp} ]] && tmp+=" : "
423 warningSummary+=${tmp}
426 if [[ -n ${errorSummary} ]]; then
427 echo "${errorSummary}"
431 if [[ -n ${warningSummary} ]]; then
432 echo "${warningSummary}"
445 #where to search for qa files
448 workingDirectory="${PWD}"
449 #where to place the final qa plots
450 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
451 outputDirectory="${workingDirectory}/%DET"
452 #filter out detector option
453 excludeDetectors="EXAMPLE"
455 logDirectory=${workingDirectory}/logs
459 #MAILTO="fbellini@cern.ch"
461 #first, check if the config file is configured
462 #is yes - source it so that other options can override it
464 for opt in "${args[@]}"; do
465 if [[ ${opt} =~ configFile=.* ]]; then
467 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
468 echo "using config file: ${configFile}"
469 source "${configFile}"
474 #then, parse the options as they override the options from file
475 for opt in "${args[@]}"; do
476 if [[ ! "${opt}" =~ .*=.* ]]; then
477 echo "badly formatted option ${var}, should be: option=value, stopping..."
480 local var="${opt%%=*}"
481 local value="${opt#*=}"
482 echo "${var}=${value}"
483 export ${var}="${value}"
489 #guess the period from the path, pick the rightmost one
494 legoTrainRunNumber=""
503 declare -a path=( $1 )
505 local dirDepth=$(( ${#path[*]}-1 ))
507 for ((x=${dirDepth};x>=0;x--)); do
509 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
510 local field=${path[${x}]}
511 local fieldNext=${path[$((x+1))]}
513 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
514 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
515 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*} && originalPeriod=${field}
516 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
517 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
518 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
519 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
523 [[ -n ${shortRunNumber} && "${legoTrainRunNumber}" =~ ${shortRunNumber} ]] && legoTrainRunNumber=""
524 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
525 [[ "${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
526 [[ -n ${legoTrainRunNumber} ]] && pass+="_lego${legoTrainRunNumber}"
528 #modify the OCDB: set the year
529 if [[ ${dataType} =~ sim ]]; then
530 anchorYear=$(for x in $mcProductionMap ; do [[ "${x}" =~ ${originalPeriod} ]] && echo ${x} && break; done)
531 anchorYear=${anchorYear#*=}
532 ocdbStorage=$(setYear ${anchorYear} ${ocdbStorage})
534 ocdbStorage=$(setYear ${year} ${ocdbStorage})
537 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
538 if [[ -z ${runNumber}} ]]
548 substituteDetectorName()
552 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
553 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
561 if cd "$(echo "${1%/*}")" &>/dev/null
563 # file *may* not be local
564 # exception is ./file.ext
565 # try 'cd .; cd -;' *works!*
569 # file *must* be local
573 # file *cannot* exist
576 # reassemble realpath
577 echo "$tmppwd"/"${1##*/}"
584 # ${1} - year to be set
585 # ${2} - where to set the year
586 local year1=$(guessYear ${1})
587 local year2=$(guessYear ${2})
589 [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
596 #guess the year from the path, pick the rightmost one
598 declare -a pathArray=( ${1} )
601 for field in ${pathArray[@]}; do
602 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
610 # Hallo world - Print AliRoot/Root/Alien system info
616 echo --------------------------------------
620 echo HOSTINFO HOSTNAME" "$HOSTNAME
621 echo HOSTINFO DATE" "`date`
622 echo HOSTINFO gccpath" "`which gcc`
623 echo HOSTINFO gcc version" "`gcc --version | grep gcc`
624 echo --------------------------------------
629 echo --------------------------------------
633 echo ROOTINFO ROOT" "`which root`
634 echo ROOTINFO VERSION" "`root-config --version`
636 echo --------------------------------------
642 echo --------------------------------------
646 echo ALIROOTINFO ALIROOT" "`which aliroot`
647 echo ALIROOTINFO VERSION" "`echo $ALICE_LEVEL`
648 echo ALIROOTINFO TARGET" "`echo $ALICE_TARGET`
650 echo --------------------------------------
655 #echo --------------------------------------
658 #for a in `alien --printenv`; do echo ALIENINFO $a; done
660 #echo --------------------------------------