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)
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=${logDirectory}/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
156 #what if we have a zip archive?
157 if [[ "$qaFile" =~ .*.zip$ ]]; then
158 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
159 qaFile="${qaFile}#QAresults.root"
164 if [[ "$highPtTree" =~ .*.zip$ ]]; then
165 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
166 highPtTree="${highPtTree}#FilterEvents_Trees.root"
172 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
173 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
174 runLevelQA "${qaFile}" &> runLevelQA.log
175 #perform some default actions:
176 #if trending.root not created, create a default one
177 if [[ ! -f trending.root ]]; then
178 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" 2>&1 | tee -a runLevelQA.log
180 if [[ -f trending.root ]]; then
181 arrOfTouchedProductions[${tmpProductionDir}]=1
183 echo "trending.root not created"
186 #expert QA based on high pt trees
187 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
188 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
189 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
190 arrOfTouchedProductions[${tmpProductionDir}]=1
193 cd ${tmpDetectorRunDir}
197 #################################################################
198 #cache which productions were (re)done
199 echo "list of processed productions:"
200 echo " ${!arrOfTouchedProductions[@]}"
203 #################################################################
204 #(re)do the merging/trending
205 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
206 cd ${tmpProductionDir}
208 echo "running period level stuff in ${tmpProductionDir}"
211 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
212 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
214 mkdir -p ${productionDir}
215 if [[ ! -d ${productionDir} ]]; then
216 echo "cannot make productionDir $productionDir" && continue
219 #move runs to final destination
220 for dir in ${tmpProductionDir}/000*; do
222 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
223 if ! guessRunData "${dir}/dummyName"; then
224 echo "could not guess run data from ${dir}"
228 #before moving - VALIDATE!!!
229 if ! validate ${dir}; then
233 #moving a dir is an atomic operation, no locking necessary
234 if [[ -d ${oldRunDir} ]]; then
235 echo "removing old ${oldRunDir}"
238 echo "moving new ${runNumber} to ${productionDir}"
239 mv -f ${dir} ${productionDir}
242 #go to a temp dir to do the period level stuff in a completely clean dir
243 tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
245 echo tmpPeriodLevelQAdir="${tmpProductionDir}/periodLevelQA"
246 if ! mkdir -p ${tmpPeriodLevelQAdir}; then continue; fi
247 cd ${tmpPeriodLevelQAdir}
249 #link the final list of per-run dirs here, just the dirs
250 #to have a clean working directory
252 declare -a linkedStuff
253 for x in ${productionDir}/000*; do [[ -d $x ]] && ln -s $x && linkedStuff+=(${x##*/}); done
255 #merge trending files if any
256 if /bin/ls 000*/trending.root &>/dev/null; then
257 hadd trending.root 000*/trending.root &> periodLevelQA.log
260 #run the period level trending/QA
261 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
262 echo running ${detector} periodLevelQA for production ${period}/${pass}
263 periodLevelQA trending.root &>> periodLevelQA.log
265 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
268 if ! validate ${PWD}; then continue; fi
270 #here we are validated so move the produced QA to the final place
271 #clean up linked stuff first
272 [[ -n ${linkedStuff[@]} ]] && rm ${linkedStuff[@]}
273 periodLevelLock=${productionDir}/runQA.lock
274 if [[ ! -f ${periodLevelLock} ]]; then
275 #some of the output could be a directory, so handle that
276 #TODO: maybe use rsync?
277 #lock to avoid conflicts:
278 echo "${HOSTNAME} ${dateString}" > ${periodLevelLock}
279 for x in ${tmpPeriodLevelQAdir}/*; do
280 if [[ -d ${x} ]]; then
281 echo "removing ${productionDir}/${x##*/}"
282 rm -rf ${productionDir}/${x##*/}
283 echo "moving ${x} to ${productionDir}"
284 mv ${x} ${productionDir}
286 if [[ -f ${x} ]]; then
287 echo "moving ${x} to ${productionDir}"
288 mv -f ${x} ${productionDir}
291 rm -f ${periodLevelLock}
293 rm -rf ${tmpPeriodLevelQAdir}
295 echo "locked! cannot move to destination"
296 echo "check and maybe manually do:"
297 echo " rm ${periodLevelLock}"
298 echo " rsync -av ${tmpPeriodLevelQAdir}/ ${productionDir}/"
303 cd ${workingDirectory}
305 if [[ -z ${planB} ]]; then
307 echo removing ${tmpDetectorRunDir}
308 rm -rf ${tmpDetectorRunDir}
312 done #end of detector loop
320 #in case of emergency
321 if [[ -n ${MAILTO} ]]; then
323 echo "trouble detected, sending email to ${MAILTO}"
325 grep BAD ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
331 summarizeLogs ${1} >> ${logSummary}
333 if [[ ${logStatus} -ne 0 ]]; then
334 echo "WARNING not validated: ${1}"
344 [[ ! -d ${dir} ]] && dir=${PWD}
346 #print a summary of logs
355 for log in ${dir}/${logFiles[*]}; do
356 finallog=${PWD%/}/${log}
357 [[ ! -f ${log} ]] && continue
358 errorSummary=$(validateLog ${log})
360 [[ validationStatus -ne 0 ]] && logstatus=1
361 if [[ ${validationStatus} -eq 0 ]]; then
362 #in pretend mode randomly report an error in rec.log some cases
363 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
364 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
366 echo "${finallog} OK"
368 elif [[ ${validationStatus} -eq 1 ]]; then
369 echo "${finallog} BAD ${errorSummary}"
370 elif [[ ${validationStatus} -eq 2 ]]; then
371 echo "${finallog} OK MWAH ${errorSummary}"
379 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
380 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
391 'error while loading shared libraries'
394 'Thread [0-9]* (Thread'
397 '\.C.*error:.*\.h: No such file'
399 'Interpreter error recovered'
407 local errorSummary=""
408 local warningSummary=""
410 for ((i=0; i<${#errorConditions[@]};i++)); do
411 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
412 [[ -n ${tmp} ]] && tmp+=" : "
416 for ((i=0; i<${#warningConditions[@]};i++)); do
417 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
418 [[ -n ${tmp} ]] && tmp+=" : "
419 warningSummary+=${tmp}
422 if [[ -n ${errorSummary} ]]; then
423 echo "${errorSummary}"
427 if [[ -n ${warningSummary} ]]; then
428 echo "${warningSummary}"
441 #where to search for qa files
444 workingDirectory="${PWD}"
445 #where to place the final qa plots
446 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
447 outputDirectory="${workingDirectory}/%DET"
448 #filter out detector option
449 excludeDetectors="EXAMPLE"
451 logDirectory=${workingDirectory}/logs
455 #MAILTO="fbellini@cern.ch"
457 #first, check if the config file is configured
458 #is yes - source it so that other options can override it
460 for opt in "${args[@]}"; do
461 if [[ ${opt} =~ configFile=.* ]]; then
463 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
464 echo "using config file: ${configFile}"
465 source "${configFile}"
470 #then, parse the options as they override the options from file
471 for opt in "${args[@]}"; do
472 if [[ ! "${opt}" =~ .*=.* ]]; then
473 echo "badly formatted option ${var}, should be: option=value, stopping..."
476 local var="${opt%%=*}"
477 local value="${opt#*=}"
478 echo "${var} = ${value}"
479 export ${var}="${value}"
485 #guess the period from the path, pick the rightmost one
490 legoTrainRunNumber=""
493 local shortRunNumber=""
495 declare -a path=( $1 )
496 local dirDepth=$(( ${#path[*]}-1 ))
498 for ((x=${dirDepth};x>=0;x--)); do
500 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
501 local field=${path[${x}]}
502 local fieldNext=${path[$((x+1))]}
504 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
505 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
506 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
507 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
508 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
509 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
510 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
513 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
514 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
516 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
517 if [[ -z ${runNumber}} ]];
527 substituteDetectorName()
531 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
532 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
540 if cd "$(echo "${1%/*}")" &>/dev/null
542 # file *may* not be local
543 # exception is ./file.ext
544 # try 'cd .; cd -;' *works!*
548 # file *must* be local
552 # file *cannot* exist
555 # reassemble realpath
556 echo "$tmppwd"/"${1##*/}"