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 source ${detectorScript}
108 #################################################################
109 #produce the QA and trending tree for each file (run)
110 unset arrOfTouchedProductions
111 declare -A arrOfTouchedProductions
112 while read qaFile; do
115 if ! guessRunData ${qaFile}; then
116 echo "could not guess run data from ${qaFile}"
120 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
121 arrOfTouchedProductions[${tmpProductionDir}]=1
122 tmpRunDir=${tmpProductionDir}/000${runNumber}
123 mkdir -p ${tmpRunDir}
126 #handle the case of a zip archive
127 [[ "$qaFile" =~ .*.zip$ ]] && qaFile="${qaFile}#QAresults.root"
128 [[ "$qaFile" =~ .*.zip$ ]] && highPtTree="${qaFile}#FilterEvents_Trees.root"
130 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
131 runLevelQA ${qaFile} &> runLevelQA.log
133 #perform some default actions:
134 #if trending.root not created, create a default one
135 if [[ ! -f trending.root ]]; then
136 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" &>> runLevelQA.log
138 cd ${tmpDetectorRunDir}
142 #################################################################
143 #cache which productions were (re)done
144 echo "list of processed productions:"
145 echo " ${!arrOfTouchedProductions[@]}"
148 #################################################################
149 #(re)do the merging/trending in the final destination
150 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
152 echo "running period level stuff in ${tmpProductionDir}"
154 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
156 mkdir -p ${productionDir}
157 if [[ ! -d ${productionDir} ]]; then
158 echo "cannot make productionDir $productionDir" && continue
162 #move to final destination
163 for dir in ${tmpProductionDir}/*; do
164 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
165 if ! guessRunData "${dir}/dummyName"; then
166 echo "could not guess run data from ${dir}"
170 #before moving - VALIDATE!!!
171 if ! validate ${dir}; then continue; fi
173 if [[ -d ${oldRunDir} ]]; then
174 echo "removing old ${oldRunDir}"
177 echo "moving new ${runNumber} to ${productionDir}"
178 mv -f ${dir} ${productionDir}
181 echo running ${detector} periodLevelQA for production ${period}/${pass}
184 #merge trending files if any
185 if /bin/ls 000*/trending.root &>/dev/null; then
186 hadd trending.root 000*/trending.root &> periodLevelQA.log
187 periodLevelQA trending.root &>> periodLevelQA.log
190 if ! validate ${PWD}; then continue; fi
192 cd ${tmpDetectorRunDir}
196 cd ${workingDirectory}
198 if [[ -z ${planB} ]]; then
200 echo removing ${tmpDetectorRunDir}
201 rm -rf ${tmpDetectorRunDir}
213 #in case of emergency
214 if [[ -n ${MAILTO} ]]; then
216 echo "trouble detected, sending email to ${MAILTO}"
218 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
224 summarizeLogs ${1} >> ${logSummary}
226 if [[ ${logStatus} -ne 0 ]]; then
227 echo "WARNING not validated: ${1}"
237 [[ ! -d ${dir} ]] && dir=${PWD}
239 #print a summary of logs
248 for log in ${dir}/${logFiles[*]}; do
249 finallog=${PWD%/}/${log}
250 [[ ! -f ${log} ]] && continue
251 errorSummary=$(validateLog ${log})
253 [[ validationStatus -ne 0 ]] && logstatus=1
254 if [[ ${validationStatus} -eq 0 ]]; then
255 #in pretend mode randomly report an error in rec.log some cases
256 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
257 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
259 echo "${finallog} OK"
261 elif [[ ${validationStatus} -eq 1 ]]; then
262 echo "${finallog} BAD ${errorSummary}"
263 elif [[ ${validationStatus} -eq 2 ]]; then
264 echo "${finallog} OK MWAH ${errorSummary}"
272 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
273 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
284 'error while loading shared libraries'
287 'Thread [0-9]* (Thread'
290 '\.C.*error:.*\.h: No such file'
299 local errorSummary=""
300 local warningSummary=""
302 for ((i=0; i<${#errorConditions[@]};i++)); do
303 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
304 [[ -n ${tmp} ]] && tmp+=" : "
308 for ((i=0; i<${#warningConditions[@]};i++)); do
309 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
310 [[ -n ${tmp} ]] && tmp+=" : "
311 warningSummary+=${tmp}
314 if [[ -n ${errorSummary} ]]; then
315 echo "${errorSummary}"
319 if [[ -n ${warningSummary} ]]; then
320 echo "${warningSummary}"
331 #where to search for qa files
334 workingDirectory="${PWD}"
335 #where to place the final qa plots
336 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
337 outputDirectory="${workingDirectory}/%DET"
338 #filter out detector option
339 excludeDetectors="EXAMPLE"
341 logDirectory=${workingDirectory}/logs
343 #alirootEnv="/home/mkrzewic/alisoft/balice_master.sh"
345 #ocdbStorage="raw://"
347 #MAILTO="fbellini@cern.ch"
349 #first, check if the config file is configured
350 #is yes - source it so that other options can override it
353 if [[ ${opt} =~ configFile=.* ]]; then
355 [[ ! -f ${configFile} ]] && echo "configFile ${configFile} not found, exiting..." && return 1
356 source "${configFile}"
361 #then, parse the options as they override the options from file
362 while [[ -n ${1} ]]; do
364 if [[ ${var} =~ .*=.* ]]; then
367 echo "badly formatted option ${var}, should be: option=value, stopping..."
376 #guess the period from the path, pick the rightmost one
381 legoTrainRunNumber=""
384 local shortRunNumber=""
386 declare -a path=( $1 )
387 local dirDepth=$(( ${#path[*]}-1 ))
389 for ((x=${dirDepth};x>=0;x--)); do
391 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
392 local field=${path[${x}]}
393 local fieldNext=${path[$((x+1))]}
395 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
396 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
397 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
398 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
399 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
400 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
401 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
404 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
405 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
407 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
408 if [[ -z ${runNumber}} ]];
418 substituteDetectorName()
422 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
423 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}
431 if cd "$(echo "${1%/*}")" &>/dev/null
433 # file *may* not be local
434 # exception is ./file.ext
435 # try 'cd .; cd -;' *works!*
439 # file *must* be local
443 # file *cannot* exist
446 # reassemble realpath
447 echo "$tmppwd"/"${1##*/}"