6 echo " ${0##*/} option=value [option=value]"
7 echo " at least one option, either inputFile 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 tmpRunDir=${workingDirectory}/tmpQArunDir${detector}
90 if ! mkdir -p ${tmpRunDir}; then
91 echo "cannot create the temp dir $tmpRunDir"
96 tmpPrefix=${tmpRunDir}/${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 while read qaFile; do
112 if ! guessRunData ${qaFile}; then
113 echo "could not guess run data from ${qaFile}"
117 runDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}/000${runNumber}
121 #handle the case of a zip archive
122 [[ "$qaFile" =~ .*.zip$ ]] && qaFile="${qaFile}#QAresults.root"
124 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
125 runLevelQA ${qaFile} &> runLevelQA.log
131 #################################################################
132 #cache which productions were (re)done
133 arrOfTouchedProductions=( $(/bin/ls -d ${tmpPrefix}/*/*/*/*) )
134 echo "list of processed productions:"
135 echo " ${arrOfTouchedProductions[@]}"
137 #################################################################
138 #(re)do the merging/trending in the final destination
139 for tmpProductionDir in ${arrOfTouchedProductions[@]}; do
141 echo "running period level stuff in ${tmpProductionDir}"
143 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
145 mkdir -p ${productionDir}
146 if [[ ! -d ${productionDir} ]]; then
147 echo "cannot make productionDir $productionDir" && continue
151 #move to final destination
152 for dir in ${tmpProductionDir}/*; do
153 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
154 if ! guessRunData "${dir}/dummyName"; then
155 echo "could not guess run data from ${dir}"
159 #before moving - VALIDATE!!!
160 if ! validate ${dir}; then continue; fi
162 #summarizeLogs ${dir} >> ${logSummary}
164 #if [[ ${logStatus} -ne 0 ]]; then
165 # echo "WARNING: run not validated: ${dir}"
170 if [[ -d ${oldRunDir} ]]; then
171 echo "removing old ${period}/${pass}/${runNumber}"
174 echo "moving new ${runNumber} to ${productionDir}"
175 mv -f ${dir} ${productionDir}
178 echo running ${detector} periodLevelQA for production ${period}/${pass}
180 hadd trending.root 000*/trending.root &> periodLevelQA.log
181 periodLevelQA trending.root &>> periodLevelQA.log
183 if ! validate ${PWD}; then continue; fi
184 #summarizeLogs ${PWD} >> ${logSummary}
186 #if [[ ${logStatus} -ne 0 ]]; then
187 # echo "WARNING: period ${period} not validated: ${dir}"
196 cd ${workingDirectory}
198 if [[ -z ${planB} ]]; then
200 echo removing ${tmpRunDir}
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 [[ -z ${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 configFile=$(readlink -f ${configFile})
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} ]];
417 substituteDetectorName()
421 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
422 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}