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##*/}
78 for excluded in ${excludeDetectors}; do
79 if [[ ${detector} =~ ${excluded} ]]; then
80 echo "${detector} is excluded in config, skipping..."
85 [[ ${skipDetector} -eq 1 ]] && continue
87 logSummary=${logDirectory}/summary-${detector}-${dateString}.log
88 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
89 tmpDetectorRunDir=${workingDirectory}/tmpQAtmpRunDir${detector}
90 if ! mkdir -p ${tmpDetectorRunDir}; then
91 echo "cannot create the temp dir $tmpDetectorRunDir"
94 cd ${tmpDetectorRunDir}
96 tmpPrefix=${tmpDetectorRunDir}/${outputDir}
98 echo "##############################################"
99 echo "running QA for ${detector}"
100 echo " outputDir=$outputDir"
101 echo " tmpPrefix=$tmpPrefix"
104 unset -f periodLevelQA
105 source ${detectorScript}
107 #################################################################
108 #produce the QA and trending tree for each file (run)
109 unset arrOfTouchedProductions
110 declare -A arrOfTouchedProductions
111 while read qaFile; do
114 if ! guessRunData ${qaFile}; then
115 echo "could not guess run data from ${qaFile}"
119 tmpProductionDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}
120 arrOfTouchedProductions[${tmpProductionDir}]=1
121 tmpRunDir=${tmpProductionDir}/000${runNumber}
122 mkdir -p ${tmpRunDir}
125 #handle the case of a zip archive
126 [[ "$qaFile" =~ .*.zip$ ]] && qaFile="${qaFile}#QAresults.root"
128 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
129 runLevelQA ${qaFile} &> runLevelQA.log
131 #perform some default actions:
132 #if trending.root not created, create a default one
133 if [[ ! -f trending.root ]]; then
134 aliroot -b -q -l "$ALICE_ROOT/PWGPP/macros/simpleTrending.C(\"${qaFile}\",${runNumber},\"${detector}\",\"trending.root\",\"trending\",\"recreate\")" &>> runLevelQA.log
136 cd ${tmpDetectorRunDir}
140 #################################################################
141 #cache which productions were (re)done
142 echo "list of processed productions:"
143 echo " ${!arrOfTouchedProductions[@]}"
146 #################################################################
147 #(re)do the merging/trending in the final destination
148 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
150 echo "running period level stuff in ${tmpProductionDir}"
152 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
154 mkdir -p ${productionDir}
155 if [[ ! -d ${productionDir} ]]; then
156 echo "cannot make productionDir $productionDir" && continue
160 #move to final destination
161 for dir in ${tmpProductionDir}/*; do
162 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
163 if ! guessRunData "${dir}/dummyName"; then
164 echo "could not guess run data from ${dir}"
168 #before moving - VALIDATE!!!
169 if ! validate ${dir}; then continue; fi
171 if [[ -d ${oldRunDir} ]]; then
172 echo "removing old ${oldRunDir}"
175 echo "moving new ${runNumber} to ${productionDir}"
176 mv -f ${dir} ${productionDir}
179 echo running ${detector} periodLevelQA for production ${period}/${pass}
182 #merge trending files if any
183 if /bin/ls 000*/trending.root &>/dev/null; then
184 hadd trending.root 000*/trending.root &> periodLevelQA.log
185 periodLevelQA trending.root &>> periodLevelQA.log
188 if ! validate ${PWD}; then continue; fi
190 cd ${tmpDetectorRunDir}
194 cd ${workingDirectory}
196 if [[ -z ${planB} ]]; then
198 echo removing ${tmpDetectorRunDir}
199 rm -rf ${tmpDetectorRunDir}
211 #in case of emergency
212 if [[ -n ${MAILTO} ]]; then
214 echo "trouble detected, sending email to ${MAILTO}"
216 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
222 summarizeLogs ${1} >> ${logSummary}
224 if [[ ${logStatus} -ne 0 ]]; then
225 echo "WARNING not validated: ${1}"
235 [[ ! -d ${dir} ]] && dir=${PWD}
237 #print a summary of logs
246 for log in ${dir}/${logFiles[*]}; do
247 finallog=${PWD%/}/${log}
248 [[ ! -f ${log} ]] && continue
249 errorSummary=$(validateLog ${log})
251 [[ validationStatus -ne 0 ]] && logstatus=1
252 if [[ ${validationStatus} -eq 0 ]]; then
253 #in pretend mode randomly report an error in rec.log some cases
254 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
255 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
257 echo "${finallog} OK"
259 elif [[ ${validationStatus} -eq 1 ]]; then
260 echo "${finallog} BAD ${errorSummary}"
261 elif [[ ${validationStatus} -eq 2 ]]; then
262 echo "${finallog} OK MWAH ${errorSummary}"
270 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
271 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
282 'error while loading shared libraries'
285 'Thread [0-9]* (Thread'
288 '\.C.*error:.*\.h: No such file'
297 local errorSummary=""
298 local warningSummary=""
300 for ((i=0; i<${#errorConditions[@]};i++)); do
301 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
302 [[ -n ${tmp} ]] && tmp+=" : "
306 for ((i=0; i<${#warningConditions[@]};i++)); do
307 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
308 [[ -n ${tmp} ]] && tmp+=" : "
309 warningSummary+=${tmp}
312 if [[ -n ${errorSummary} ]]; then
313 echo "${errorSummary}"
317 if [[ -n ${warningSummary} ]]; then
318 echo "${warningSummary}"
329 #where to search for qa files
332 workingDirectory="${PWD}"
333 #where to place the final qa plots
334 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
335 outputDirectory="${workingDirectory}/%DET"
336 #filter out detector option
337 excludeDetectors="EXAMPLE"
339 logDirectory=${workingDirectory}/logs
341 #alirootEnv="/home/mkrzewic/alisoft/balice_master.sh"
343 #ocdbStorage="raw://"
345 #MAILTO="fbellini@cern.ch"
347 #first, check if the config file is configured
348 #is yes - source it so that other options can override it
351 if [[ ${opt} =~ configFile=.* ]]; then
353 configFile=$(readlink -f ${configFile})
354 source "${configFile}"
359 #then, parse the options as they override the options from file
360 while [[ -n ${1} ]]; do
362 if [[ ${var} =~ .*=.* ]]; then
365 echo "badly formatted option ${var}, should be: option=value, stopping..."
374 #guess the period from the path, pick the rightmost one
379 legoTrainRunNumber=""
382 local shortRunNumber=""
384 declare -a path=( $1 )
385 local dirDepth=$(( ${#path[*]}-1 ))
387 for ((x=${dirDepth};x>=0;x--)); do
389 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
390 local field=${path[${x}]}
391 local fieldNext=${path[$((x+1))]}
393 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
394 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
395 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
396 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
397 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
398 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
399 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
402 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
403 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
405 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
406 if [[ -z ${runNumber}} ]];
416 substituteDetectorName()
420 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
421 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}