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}"
134 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
135 tmpRunDir=${tmpProductionDir}/000${runNumber}
136 mkdir -p ${tmpRunDir}
139 #by default we expect to have everything in the same archive
142 #maybe the input is not an archive, but a file
143 [[ "${qaFile}" =~ QAresults.root$ ]] && highPtTree=""
144 [[ "${qaFile}" =~ FilterEvents_Trees.root$ ]] && qaFile=""
146 #it is possible we get the highPt trees from somewhere else
147 #search the list of high pt trees for the proper run number
148 if [[ -n ${inputListHighPtTrees} ]]; then
149 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
150 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
154 echo highPtTree=$highPtTree
155 echo ocdbStorage=${ocdbStorage}
158 #what if we have a zip archive?
159 if [[ "$qaFile" =~ .*.zip$ ]]; then
160 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
161 qaFile="${qaFile}#QAresults.root"
166 if [[ "$highPtTree" =~ .*.zip$ ]]; then
167 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
168 highPtTree="${highPtTree}#FilterEvents_Trees.root"
174 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
175 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
176 runLevelQA "${qaFile}" &> runLevelQA.log
177 #perform some default actions:
178 #if trending.root not created, create a default one
179 if [[ ! -f trending.root ]]; then
180 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
182 if [[ -f trending.root ]]; then
183 arrOfTouchedProductions[${tmpProductionDir}]=1
185 echo "trending.root not created"
188 #expert QA based on high pt trees
189 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
190 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
191 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
192 arrOfTouchedProductions[${tmpProductionDir}]=1
195 cd ${tmpDetectorRunDir}
199 #################################################################
200 #cache which productions were (re)done
201 echo "list of processed productions:"
202 echo " ${!arrOfTouchedProductions[@]}"
205 #################################################################
206 #(re)do the merging/trending
207 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
208 cd ${tmpProductionDir}
210 echo "running period level stuff in ${tmpProductionDir}"
213 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
214 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
216 mkdir -p ${productionDir}
217 if [[ ! -d ${productionDir} ]]; then
218 echo "cannot make productionDir $productionDir" && continue
221 #move runs to final destination
222 for dir in ${tmpProductionDir}/000*; do
224 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
225 if ! guessRunData "${dir}/dummyName"; then
226 echo "could not guess run data from ${dir}"
230 #before moving - VALIDATE!!!
231 if ! validate ${dir}; then
235 #moving a dir is an atomic operation, no locking necessary
236 if [[ -d ${oldRunDir} ]]; then
237 echo "removing old ${oldRunDir}"
240 echo "moving new ${runNumber} to ${productionDir}"
241 mv -f ${dir} ${productionDir}
244 #go to a temp dir to do the period level stuff in a completely clean dir
245 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
247 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
248 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
249 cd ${tmpPeriodLevelQAdir}
251 #link the final list of per-run dirs here, just the dirs
252 #to have a clean working directory
254 declare -a linkedStuff
255 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
257 #merge trending files if any
258 if /bin/ls 000*/trending.root &>/dev/null; then
259 hadd trending.root 000*/trending.root &> periodLevelQA.log
262 #run the period level trending/QA
263 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
264 echo running ${detector} periodLevelQA for production ${period}/${pass}
265 periodLevelQA trending.root &>> periodLevelQA.log
267 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
270 if ! validate ${PWD}; then continue; fi
272 #here we are validated so move the produced QA to the final place
273 #clean up linked stuff first
274 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
275 periodLevelLock=${productionDir}/runQA.lock
276 if [[ ! -f ${periodLevelLock} ]]; then
277 #some of the output could be a directory, so handle that
278 #TODO: maybe use rsync?
279 #lock to avoid conflicts:
280 echo "${HOSTNAME} ${dateString}" > ${periodLevelLock}
281 for x in ${tmpPeriodLevelQAdir}/*; do
282 if [[ -d ${x} ]]; then
283 echo "removing ${productionDir}/${x##*/}"
284 rm -rf ${productionDir}/${x##*/}
285 echo "moving ${x} to ${productionDir}"
286 mv ${x} ${productionDir}
288 if [[ -f ${x} ]]; then
289 echo "moving ${x} to ${productionDir}"
290 mv -f ${x} ${productionDir}
293 rm -f ${periodLevelLock}
295 rm -rf ${tmpPeriodLevelQAdir}
297 echo "ERROR: cannot move to destination" >> ${logSummary}
298 echo "production dir ${productionDir} locked!" >> ${logSummary}
299 echo "check and maybe manually do:" >> ${logSummary}
300 echo " rm ${periodLevelLock}" >> ${logSummary}
301 echo " rsync -av ${tmpPeriodLevelQAdir}/ ${productionDir}/" >> ${logSummary}
307 cd ${workingDirectory}
309 if [[ -z ${planB} ]]; then
311 echo removing ${tmpDetectorRunDir}
312 rm -rf ${tmpDetectorRunDir}
316 done #end of detector loop
324 #in case of emergency
325 if [[ -n ${MAILTO} ]]; then
327 echo "trouble detected, sending email to ${MAILTO}"
329 grep BAD ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
335 summarizeLogs ${1} >> ${logSummary}
337 if [[ ${logStatus} -ne 0 ]]; then
338 echo "WARNING not validated: ${1}"
348 [[ ! -d ${dir} ]] && dir=${PWD}
350 #print a summary of logs
359 for log in ${dir}/${logFiles[*]}; do
360 finallog=${PWD%/}/${log}
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 "${finallog} BAD random error" || echo "${finallog} OK"
370 echo "${finallog} OK"
372 elif [[ ${validationStatus} -eq 1 ]]; then
373 echo "${finallog} BAD ${errorSummary}"
374 elif [[ ${validationStatus} -eq 2 ]]; then
375 echo "${finallog} 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=""
500 local shortRunNumber=""
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 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
524 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber} && originalPass=""
525 [[ -n ${legoTrainRunNumber} ]] && pass+="_lego${legoTrainRunNumber}"
527 #modify the OCDB: set the year
528 if [[ ${dataType} =~ sim && -n ${mcProductionMap} ]]; then
529 anchorYear=${mcProductionMap[${originalPeriod}]}
530 ocdbStorage=$(setYear ${anchorYear} ${ocdbStorage})
532 ocdbStorage=$(setYear ${year} ${ocdbStorage})
535 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
536 if [[ -z ${runNumber}} ]]
546 substituteDetectorName()
550 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
551 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
559 if cd "$(echo "${1%/*}")" &>/dev/null
561 # file *may* not be local
562 # exception is ./file.ext
563 # try 'cd .; cd -;' *works!*
567 # file *must* be local
571 # file *cannot* exist
574 # reassemble realpath
575 echo "$tmppwd"/"${1##*/}"
582 # ${1} - year to be set
583 # ${2} - where to set the year
584 local year1=$(guessYear ${1})
585 local year2=$(guessYear ${2})
587 [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
594 #guess the year from the path, pick the rightmost one
596 declare -a pathArray=( ${1} )
599 for field in ${pathArray[@]}; do
600 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}