6 echo " ${0##*/} option=value [option=value]"
7 echo " at least one option, either inputList or configFile should be specified,"
8 echo " options override config file (if any), e.g.:"
9 echo " ${0##*/} configFile=runQA.config inputList=file.list outputDirectory=%det"
13 if ! parseConfig $@; then
18 [[ -z $ALICE_ROOT ]] && source ${alirootEnv}
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 inputList=$(readlink -f ${inputList})
36 [[ ! -f ${inputList} ]] && echo "no input list: ${inputList}" && return 1
37 workingDirectory=$(readlink -f ${workingDirectory})
38 mkdir -p ${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 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
83 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
84 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}
85 if ! mkdir -p ${tmpDetectorRunDir}; then
86 echo "cannot create the temp dir $tmpDetectorRunDir"
89 cd ${tmpDetectorRunDir}
91 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
93 echo "##############################################"
94 echo "running QA for ${detector}"
95 echo " outputDir=$outputDir"
96 echo " tmpPrefix=$tmpPrefix"
99 unset -f periodLevelQA
100 source ${detectorScript}
102 #################################################################
103 #produce the QA and trending tree for each file (run)
104 unset arrOfTouchedProductions
105 declare -A arrOfTouchedProductions
106 while read qaFile; do
109 if ! guessRunData ${qaFile}; then
110 echo "could not guess run data from ${qaFile}"
114 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
115 arrOfTouchedProductions[${tmpProductionDir}]=1
116 tmpRunDir=${tmpProductionDir}/000${runNumber}
117 mkdir -p ${tmpRunDir}
120 #handle the case of a zip archive
121 [[ "$qaFile" =~ .*.zip$ ]] && qaFile="${qaFile}#QAresults.root"
122 [[ "$qaFile" =~ .*.zip$ ]] && highPtTree="${qaFile}#FilterEvents_Trees.root"
124 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
125 runLevelQA ${qaFile} &> runLevelQA.log
127 #perform some default actions:
128 #if trending.root not created, create a default one
129 if [[ ! -f trending.root ]]; then
130 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" &>> runLevelQA.log
132 cd ${tmpDetectorRunDir}
136 #################################################################
137 #cache which productions were (re)done
138 echo "list of processed productions:"
139 echo " ${!arrOfTouchedProductions[@]}"
142 #################################################################
143 #(re)do the merging/trending in the final destination
144 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
146 echo "running period level stuff in ${tmpProductionDir}"
148 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
150 mkdir -p ${productionDir}
151 if [[ ! -d ${productionDir} ]]; then
152 echo "cannot make productionDir $productionDir" && continue
156 #move to final destination
157 for dir in ${tmpProductionDir}/*; do
158 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
159 if ! guessRunData "${dir}/dummyName"; then
160 echo "could not guess run data from ${dir}"
164 #before moving - VALIDATE!!!
165 if ! validate ${dir}; then continue; fi
167 if [[ -d ${oldRunDir} ]]; then
168 echo "removing old ${oldRunDir}"
171 echo "moving new ${runNumber} to ${productionDir}"
172 mv -f ${dir} ${productionDir}
175 echo running ${detector} periodLevelQA for production ${period}/${pass}
178 #merge trending files if any
179 if /bin/ls 000*/trending.root &>/dev/null; then
180 hadd trending.root 000*/trending.root &> periodLevelQA.log
181 periodLevelQA trending.root &>> periodLevelQA.log
184 if ! validate ${PWD}; then continue; fi
186 cd ${tmpDetectorRunDir}
190 cd ${workingDirectory}
192 if [[ -z ${planB} ]]; then
194 echo removing ${tmpDetectorRunDir}
195 rm -rf ${tmpDetectorRunDir}
207 #in case of emergency
208 if [[ -n ${MAILTO} ]]; then
210 echo "trouble detected, sending email to ${MAILTO}"
212 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
218 summarizeLogs ${1} >> ${logSummary}
220 if [[ ${logStatus} -ne 0 ]]; then
221 echo "WARNING not validated: ${1}"
231 [[ ! -d ${dir} ]] && dir=${PWD}
233 #print a summary of logs
242 for log in ${dir}/${logFiles[*]}; do
243 finallog=${PWD%/}/${log}
244 [[ ! -f ${log} ]] && continue
245 errorSummary=$(validateLog ${log})
247 [[ validationStatus -ne 0 ]] && logstatus=1
248 if [[ ${validationStatus} -eq 0 ]]; then
249 #in pretend mode randomly report an error in rec.log some cases
250 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
251 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
253 echo "${finallog} OK"
255 elif [[ ${validationStatus} -eq 1 ]]; then
256 echo "${finallog} BAD ${errorSummary}"
257 elif [[ ${validationStatus} -eq 2 ]]; then
258 echo "${finallog} OK MWAH ${errorSummary}"
266 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
267 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
278 'error while loading shared libraries'
281 'Thread [0-9]* (Thread'
284 '\.C.*error:.*\.h: No such file'
293 local errorSummary=""
294 local warningSummary=""
296 for ((i=0; i<${#errorConditions[@]};i++)); do
297 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
298 [[ -n ${tmp} ]] && tmp+=" : "
302 for ((i=0; i<${#warningConditions[@]};i++)); do
303 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
304 [[ -n ${tmp} ]] && tmp+=" : "
305 warningSummary+=${tmp}
308 if [[ -n ${errorSummary} ]]; then
309 echo "${errorSummary}"
313 if [[ -n ${warningSummary} ]]; then
314 echo "${warningSummary}"
325 #where to search for qa files
328 workingDirectory="${PWD}"
329 #where to place the final qa plots
330 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
331 outputDirectory="${workingDirectory}/%DET"
332 #filter out detector option
333 excludeDetectors="EXAMPLE"
335 logDirectory=${workingDirectory}/logs
337 #alirootEnv="/home/mkrzewic/alisoft/balice_master.sh"
339 #ocdbStorage="raw://"
341 #MAILTO="fbellini@cern.ch"
343 #first, check if the config file is configured
344 #is yes - source it so that other options can override it
347 if [[ ${opt} =~ configFile=.* ]]; then
349 configFile=$(readlink -f ${configFile})
350 source "${configFile}"
355 #then, parse the options as they override the options from file
356 while [[ -n ${1} ]]; do
358 if [[ ${var} =~ .*=.* ]]; then
361 echo "badly formatted option ${var}, should be: option=value, stopping..."
370 #guess the period from the path, pick the rightmost one
375 legoTrainRunNumber=""
378 local shortRunNumber=""
380 declare -a path=( $1 )
381 local dirDepth=$(( ${#path[*]}-1 ))
383 for ((x=${dirDepth};x>=0;x--)); do
385 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
386 local field=${path[${x}]}
387 local fieldNext=${path[$((x+1))]}
389 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
390 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
391 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
392 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
393 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
394 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
395 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
398 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
399 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
401 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
402 if [[ -z ${runNumber}} ]];
412 substituteDetectorName()
416 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
417 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}