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 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
99 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}-${dateString}
100 if ! mkdir -p ${tmpDetectorRunDir}; then
101 echo "cannot create the temp dir $tmpDetectorRunDir"
104 cd ${tmpDetectorRunDir}
106 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
107 echo "running QA for ${detector}"
108 echo " outputDir=$outputDir"
109 echo " tmpPrefix=$tmpPrefix"
111 #unset the detector functions from previous iterations (detectors)
113 unset -f periodLevelQA
114 unset -f runLevelHighPtTreeQA
115 unset -f periodLevelHighPtTreeQA
116 source ${detectorScript}
118 #################################################################
119 #produce the QA and trending tree for each file (run)
120 unset arrOfTouchedProductions
121 declare -A arrOfTouchedProductions
122 while read qaFile; do
126 #first check if input file exists
127 [[ ! -f ${qaFile%\#*} ]] && echo "file ${qaFile%\#*} not accessible" && continue
129 if ! guessRunData ${qaFile}; then
130 echo "could not guess run data from ${qaFile}"
133 echo "anchorYear for ${originalPeriod} is: ${anchorYear}"
135 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
136 tmpRunDir=${tmpProductionDir}/000${runNumber}
137 mkdir -p ${tmpRunDir}
140 #by default we expect to have everything in the same archive
143 #maybe the input is not an archive, but a file
144 [[ "${qaFile}" =~ QAresults.root$ ]] && highPtTree=""
145 [[ "${qaFile}" =~ FilterEvents_Trees.root$ ]] && qaFile=""
147 #it is possible we get the highPt trees from somewhere else
148 #search the list of high pt trees for the proper run number
149 if [[ -n ${inputListHighPtTrees} ]]; then
150 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
151 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
155 echo highPtTree=$highPtTree
156 echo ocdbStorage=${ocdbStorage}
159 #what if we have a zip archive?
160 if [[ "$qaFile" =~ .*.zip$ ]]; then
161 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
162 qaFile="${qaFile}#QAresults.root"
167 if [[ "$highPtTree" =~ .*.zip$ ]]; then
168 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
169 highPtTree="${highPtTree}#FilterEvents_Trees.root"
175 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
176 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
177 runLevelQA "${qaFile}" &> runLevelQA.log
178 #perform some default actions:
179 #if trending.root not created, create a default one
180 if [[ ! -f trending.root ]]; then
181 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
183 if [[ -f trending.root ]]; then
184 arrOfTouchedProductions[${tmpProductionDir}]=1
186 echo "trending.root not created"
189 #expert QA based on high pt trees
190 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
191 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
192 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
193 arrOfTouchedProductions[${tmpProductionDir}]=1
196 cd ${tmpDetectorRunDir}
200 #################################################################
201 #cache which productions were (re)done
202 echo "list of processed productions:"
203 echo " ${!arrOfTouchedProductions[@]}"
206 #################################################################
207 #(re)do the merging/trending
208 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
209 cd ${tmpProductionDir}
211 echo "running period level stuff in ${tmpProductionDir}"
214 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
215 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
217 mkdir -p ${productionDir}
218 if [[ ! -d ${productionDir} ]]; then
219 echo "cannot make productionDir $productionDir" && continue
222 #move runs to final destination
223 for dir in ${tmpProductionDir}/000*; do
225 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
226 if ! guessRunData "${dir}/dummyName"; then
227 echo "could not guess run data from ${dir}"
231 #before moving - VALIDATE!!!
232 if ! validate ${dir}; then
236 #moving a dir is an atomic operation, no locking necessary
237 if [[ -d ${oldRunDir} ]]; then
238 echo "removing old ${oldRunDir}"
241 echo "moving new ${runNumber} to ${productionDir}"
242 mv -f ${dir} ${productionDir}
245 #go to a temp dir to do the period level stuff in a completely clean dir
246 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
248 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
249 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
250 cd ${tmpPeriodLevelQAdir}
252 #link the final list of per-run dirs here, just the dirs
253 #to have a clean working directory
255 declare -a linkedStuff
256 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
258 #merge trending files if any
259 if /bin/ls 000*/trending.root &>/dev/null; then
260 hadd trending.root 000*/trending.root &> periodLevelQA.log
263 #run the period level trending/QA
264 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
265 echo running ${detector} periodLevelQA for production ${period}/${pass}
266 periodLevelQA trending.root &>> periodLevelQA.log
268 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
271 if ! validate ${PWD}; then continue; fi
273 #here we are validated so move the produced QA to the final place
274 #clean up linked stuff first
275 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
276 periodLevelLock=${productionDir}/runQA.lock
277 if [[ ! -f ${periodLevelLock} ]]; then
278 #some of the output could be a directory, so handle that
279 #TODO: maybe use rsync?
280 #lock to avoid conflicts:
281 echo "${HOSTNAME} ${dateString}" > ${periodLevelLock}
282 for x in ${tmpPeriodLevelQAdir}/*; do
283 if [[ -d ${x} ]]; then
284 echo "removing ${productionDir}/${x##*/}"
285 rm -rf ${productionDir}/${x##*/}
286 echo "moving ${x} to ${productionDir}"
287 mv ${x} ${productionDir}
289 if [[ -f ${x} ]]; then
290 echo "moving ${x} to ${productionDir}"
291 mv -f ${x} ${productionDir}
294 rm -f ${periodLevelLock}
296 rm -rf ${tmpPeriodLevelQAdir}
298 echo "ERROR: cannot move to destination" >> ${logSummary}
299 echo "production dir ${productionDir} locked!" >> ${logSummary}
300 echo "check and maybe manually do:" >> ${logSummary}
301 echo " rm ${periodLevelLock}" >> ${logSummary}
302 echo " rsync -av ${tmpPeriodLevelQAdir}/ ${productionDir}/" >> ${logSummary}
308 cd ${workingDirectory}
310 if [[ -z ${planB} ]]; then
312 echo removing ${tmpDetectorRunDir}
313 rm -rf ${tmpDetectorRunDir}
317 done #end of detector loop
325 #in case of emergency
326 if [[ -n ${MAILTO} ]]; then
328 echo "trouble detected, sending email to ${MAILTO}"
330 grep BAD ${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 finallog=${PWD%/}/${log}
362 [[ ! -f ${log} ]] && continue
363 errorSummary=$(validateLog ${log})
365 [[ validationStatus -ne 0 ]] && logstatus=1
366 if [[ ${validationStatus} -eq 0 ]]; then
367 #in pretend mode randomly report an error in rec.log some cases
368 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
369 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
371 echo "${finallog} OK"
373 elif [[ ${validationStatus} -eq 1 ]]; then
374 echo "${finallog} BAD ${errorSummary}"
375 elif [[ ${validationStatus} -eq 2 ]]; then
376 echo "${finallog} OK MWAH ${errorSummary}"
384 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
385 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
396 'error while loading shared libraries'
399 'Thread [0-9]* (Thread'
402 '\.C.*error:.*\.h: No such file'
404 'Interpreter error recovered'
412 local errorSummary=""
413 local warningSummary=""
415 for ((i=0; i<${#errorConditions[@]};i++)); do
416 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
417 [[ -n ${tmp} ]] && tmp+=" : "
421 for ((i=0; i<${#warningConditions[@]};i++)); do
422 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
423 [[ -n ${tmp} ]] && tmp+=" : "
424 warningSummary+=${tmp}
427 if [[ -n ${errorSummary} ]]; then
428 echo "${errorSummary}"
432 if [[ -n ${warningSummary} ]]; then
433 echo "${warningSummary}"
446 #where to search for qa files
449 workingDirectory="${PWD}"
450 #where to place the final qa plots
451 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
452 outputDirectory="${workingDirectory}/%DET"
453 #filter out detector option
454 excludeDetectors="EXAMPLE"
456 logDirectory=${workingDirectory}/logs
460 #MAILTO="fbellini@cern.ch"
462 #first, check if the config file is configured
463 #is yes - source it so that other options can override it
465 for opt in "${args[@]}"; do
466 if [[ ${opt} =~ configFile=.* ]]; then
468 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
469 echo "using config file: ${configFile}"
470 source "${configFile}"
475 #then, parse the options as they override the options from file
476 for opt in "${args[@]}"; do
477 if [[ ! "${opt}" =~ .*=.* ]]; then
478 echo "badly formatted option ${var}, should be: option=value, stopping..."
481 local var="${opt%%=*}"
482 local value="${opt#*=}"
483 echo "${var}=${value}"
484 export ${var}="${value}"
490 #guess the period from the path, pick the rightmost one
495 legoTrainRunNumber=""
504 declare -a path=( $1 )
506 local dirDepth=$(( ${#path[*]}-1 ))
508 for ((x=${dirDepth};x>=0;x--)); do
510 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
511 local field=${path[${x}]}
512 local fieldNext=${path[$((x+1))]}
514 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
515 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
516 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*} && originalPeriod=${field}
517 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
518 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
519 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
520 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
524 [[ -n ${shortRunNumber} && "${legoTrainRunNumber}" =~ ${shortRunNumber} ]] && legoTrainRunNumber=""
525 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
526 [[ "${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
527 [[ -n ${legoTrainRunNumber} ]] && pass+="_lego${legoTrainRunNumber}"
529 #modify the OCDB: set the year
530 if [[ ${dataType} =~ sim ]]; then
531 anchorYear=$(for x in $mcProductionMap ; do [[ "${x}" =~ ${originalPeriod} ]] && echo ${x} && break; done)
532 anchorYear=${anchorYear#*=}
533 ocdbStorage=$(setYear ${anchorYear} ${ocdbStorage})
535 ocdbStorage=$(setYear ${year} ${ocdbStorage})
538 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
539 if [[ -z ${runNumber}} ]]
549 substituteDetectorName()
553 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
554 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
562 if cd "$(echo "${1%/*}")" &>/dev/null
564 # file *may* not be local
565 # exception is ./file.ext
566 # try 'cd .; cd -;' *works!*
570 # file *must* be local
574 # file *cannot* exist
577 # reassemble realpath
578 echo "$tmppwd"/"${1##*/}"
585 # ${1} - year to be set
586 # ${2} - where to set the year
587 local year1=$(guessYear ${1})
588 local year2=$(guessYear ${2})
590 [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
597 #guess the year from the path, pick the rightmost one
599 declare -a pathArray=( ${1} )
602 for field in ${pathArray[@]}; do
603 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}