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
34 #be paranoid and make some full paths
35 [[ ! -f ${inputList} ]] && echo "no input list: ${inputList}" && return 1
36 inputList=$(get_realpath ${inputList})
37 mkdir -p ${workingDirectory}
38 workingDirectory=$(workingDirectory=${workingDirectory%/}; cd ${workingDirectory%/*}; echo "${PWD}/${workingDirectory##*/}")
39 if [[ ! -d ${workingDirectory} ]]; then
40 echo "working dir $workingDirectory does not exist and cannot be created"
43 cd ${workingDirectory}
46 echo inputList=$inputList
47 echo outputDirectory=$outputDirectory
50 dateString=$(date +%Y-%m-%d-%H-%M)
51 echo "Start time QA process: $dateString"
54 mkdir -p $logDirectory
55 [[ ! -d $logDirectory ]] && echo "no log dir $logDirectory" && return 1
56 logFile="$logDirectory/${0##*/}.${dateString}.log"
58 [[ ! -f ${logFile} ]] && echo "cannot write logfile $logfile" && return 1
59 echo "logFile = $logFile"
63 lockFile=${logDirectory}/runQA.lock
64 [[ -f ${lockFile} ]] && echo "lock ${lockFile} exists!" && return 1
66 [[ ! -f ${lockFile} ]] && echo "cannot lock $lockFile" && return 1
68 ################################################################
70 for detectorScript in $ALICE_ROOT/PWGPP/QA/detectorQAscripts/*; do
72 [[ ! ${detectorScript} =~ .*\.sh ]] && continue
73 detector=${detectorScript%.sh}
74 detector=${detector##*/}
77 if [[ "${excludeDetectors}" =~ ${detector} ]]; then
78 echo "${detector} is excluded in config, skipping..."
82 #if includeDetectors set, only process thoe detectors specified there
83 if [[ -n ${includeDetectors} && ! "${includeDetectors}" =~ ${detector} ]]; then
84 echo "${detector} not included in includeDetectors, skipping..."
88 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
89 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
90 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}
91 if ! mkdir -p ${tmpDetectorRunDir}; then
92 echo "cannot create the temp dir $tmpDetectorRunDir"
95 cd ${tmpDetectorRunDir}
97 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
99 echo "##############################################"
100 echo "running QA for ${detector}"
101 echo " outputDir=$outputDir"
102 echo " tmpPrefix=$tmpPrefix"
105 unset -f periodLevelQA
106 unset -f runLevelHighPtTreeQA
107 unset -f periodLevelHighPtTreeQA
108 source ${detectorScript}
110 #################################################################
111 #produce the QA and trending tree for each file (run)
112 unset arrOfTouchedProductions
113 declare -A arrOfTouchedProductions
114 while read qaFile; do
117 if ! guessRunData ${qaFile}; then
118 echo "could not guess run data from ${qaFile}"
122 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
123 tmpRunDir=${tmpProductionDir}/000${runNumber}
124 mkdir -p ${tmpRunDir}
127 #by default we expect to have everything in the same archive
130 #maybe the input is not an archive, but a file
131 [[ "${qaFile}" =~ "QAresults.root" ]] && highPtTree=""
132 [[ "${qaFile}" =~ "FilterEvents_Trees.root" ]] && qaFile=""
134 #it is possible we get the highPt trees from somewhere else
135 #search the list of high pt trees for the proper run number
136 if [[ -n ${inputListHighPtTrees} ]]; then
137 highPtTree=$(egrep -m1 ${runNumber} ${inputListHighPtTrees})
138 echo "loaded the highPtTree ${highPtTree} from external file ${inputListHighPtTrees}"
142 echo highPtTree=$highPtTree
144 #what if we have a zip archive?
145 if [[ "$qaFile" =~ .*.zip$ ]]; then
146 if unzip -l ${qaFile} | egrep "QAresults.root" &>/dev/null; then
147 qaFile="${qaFile}#QAresults.root"
152 if [[ "$highPtTree" =~ .*.zip$ ]]; then
153 if unzip -l ${highPtTree} | egrep "FilterEvents_Trees.root" &>/dev/null; then
154 highPtTree="${highPtTree}#FilterEvents_Trees.root"
160 if [[ -n ${qaFile} && $(type -t runLevelQA) =~ "function" ]]; then
161 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
162 runLevelQA "${qaFile}" &> runLevelQA.log
163 #perform some default actions:
164 #if trending.root not created, create a default one
165 if [[ ! -f trending.root ]]; then
166 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" &>> runLevelQA.log
168 arrOfTouchedProductions[${tmpProductionDir}]=1
170 #expert QA based on high pt trees
171 if [[ -n ${highPtTree} && $(type -t runLevelHighPtTreeQA) =~ "function" ]]; then
172 echo running ${detector} runLevelHighPtTreeQA for run ${runNumber} from ${highPtTree}
173 runLevelHighPtTreeQA "${highPtTree}" &> runLevelHighPtTreeQA.log
174 arrOfTouchedProductions[${tmpProductionDir}]=1
177 cd ${tmpDetectorRunDir}
181 #################################################################
182 #cache which productions were (re)done
183 echo "list of processed productions:"
184 echo " ${!arrOfTouchedProductions[@]}"
187 #################################################################
188 #(re)do the merging/trending in the final destination
189 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
191 echo "running period level stuff in ${tmpProductionDir}"
193 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
195 mkdir -p ${productionDir}
196 if [[ ! -d ${productionDir} ]]; then
197 echo "cannot make productionDir $productionDir" && continue
201 #move to final destination
202 for dir in ${tmpProductionDir}/*; do
203 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
204 if ! guessRunData "${dir}/dummyName"; then
205 echo "could not guess run data from ${dir}"
209 #before moving - VALIDATE!!!
210 if ! validate ${dir}; then continue; fi
212 if [[ -d ${oldRunDir} ]]; then
213 echo "removing old ${oldRunDir}"
216 echo "moving new ${runNumber} to ${productionDir}"
217 mv -f ${dir} ${productionDir}
222 #merge trending files if any
223 if /bin/ls 000*/trending.root &>/dev/null; then
224 hadd trending.root 000*/trending.root &> periodLevelQA.log
227 if [[ -f "trending.root" && $(type -t periodLevelQA) =~ "function" ]]; then
228 echo running ${detector} periodLevelQA for production ${period}/${pass}
229 periodLevelQA trending.root &>> periodLevelQA.log
231 echo "WARNING: not running ${detector} periodLevelQA for production ${period}/${pass}, no trending.root"
235 if ! validate ${PWD}; then continue; fi
237 cd ${tmpDetectorRunDir}
241 cd ${workingDirectory}
243 if [[ -z ${planB} ]]; then
245 echo removing ${tmpDetectorRunDir}
246 rm -rf ${tmpDetectorRunDir}
258 #in case of emergency
259 if [[ -n ${MAILTO} ]]; then
261 echo "trouble detected, sending email to ${MAILTO}"
263 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
269 summarizeLogs ${1} >> ${logSummary}
271 if [[ ${logStatus} -ne 0 ]]; then
272 echo "WARNING not validated: ${1}"
282 [[ ! -d ${dir} ]] && dir=${PWD}
284 #print a summary of logs
293 for log in ${dir}/${logFiles[*]}; do
294 finallog=${PWD%/}/${log}
295 [[ ! -f ${log} ]] && continue
296 errorSummary=$(validateLog ${log})
298 [[ validationStatus -ne 0 ]] && logstatus=1
299 if [[ ${validationStatus} -eq 0 ]]; then
300 #in pretend mode randomly report an error in rec.log some cases
301 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
302 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
304 echo "${finallog} OK"
306 elif [[ ${validationStatus} -eq 1 ]]; then
307 echo "${finallog} BAD ${errorSummary}"
308 elif [[ ${validationStatus} -eq 2 ]]; then
309 echo "${finallog} OK MWAH ${errorSummary}"
317 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
318 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
329 'error while loading shared libraries'
332 'Thread [0-9]* (Thread'
335 '\.C.*error:.*\.h: No such file'
337 'Interpreter error recovered'
345 local errorSummary=""
346 local warningSummary=""
348 for ((i=0; i<${#errorConditions[@]};i++)); do
349 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
350 [[ -n ${tmp} ]] && tmp+=" : "
354 for ((i=0; i<${#warningConditions[@]};i++)); do
355 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
356 [[ -n ${tmp} ]] && tmp+=" : "
357 warningSummary+=${tmp}
360 if [[ -n ${errorSummary} ]]; then
361 echo "${errorSummary}"
365 if [[ -n ${warningSummary} ]]; then
366 echo "${warningSummary}"
377 #where to search for qa files
380 workingDirectory="${PWD}"
381 #where to place the final qa plots
382 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
383 outputDirectory="${workingDirectory}/%DET"
384 #filter out detector option
385 excludeDetectors="EXAMPLE"
387 logDirectory=${workingDirectory}/logs
389 #alirootEnv="/home/mkrzewic/alisoft/balice_master.sh"
391 #ocdbStorage="raw://"
393 #MAILTO="fbellini@cern.ch"
395 #first, check if the config file is configured
396 #is yes - source it so that other options can override it
399 if [[ ${opt} =~ configFile=.* ]]; then
401 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
402 source "${configFile}"
407 #then, parse the options as they override the options from file
408 while [[ -n ${1} ]]; do
410 if [[ ${var} =~ .*=.* ]]; then
413 echo "badly formatted option ${var}, should be: option=value, stopping..."
422 #guess the period from the path, pick the rightmost one
427 legoTrainRunNumber=""
430 local shortRunNumber=""
432 declare -a path=( $1 )
433 local dirDepth=$(( ${#path[*]}-1 ))
435 for ((x=${dirDepth};x>=0;x--)); do
437 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
438 local field=${path[${x}]}
439 local fieldNext=${path[$((x+1))]}
441 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
442 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
443 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
444 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
445 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
446 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
447 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
450 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
451 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
453 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
454 if [[ -z ${runNumber}} ]];
464 substituteDetectorName()
468 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
469 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
477 if cd "$(echo "${1%/*}")" &>/dev/null
479 # file *may* not be local
480 # exception is ./file.ext
481 # try 'cd .; cd -;' *works!*
485 # file *must* be local
489 # file *cannot* exist
492 # reassemble realpath
493 echo "$tmppwd"/"${1##*/}"