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 tmpRunDir=${workingDirectory}/tmpQAtmpRunDir${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 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
135 #################################################################
136 #cache which productions were (re)done
137 echo "list of processed productions:"
138 echo " ${!arrOfTouchedProductions[@]}"
141 #################################################################
142 #(re)do the merging/trending in the final destination
143 for tmpProductionDir in ${!arrOfTouchedProductions[@]}; do
145 echo "running period level stuff in ${tmpProductionDir}"
147 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
149 mkdir -p ${productionDir}
150 if [[ ! -d ${productionDir} ]]; then
151 echo "cannot make productionDir $productionDir" && continue
155 #move to final destination
156 for dir in ${tmpProductionDir}/*; do
157 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
158 if ! guessRunData "${dir}/dummyName"; then
159 echo "could not guess run data from ${dir}"
163 #before moving - VALIDATE!!!
164 if ! validate ${dir}; then continue; fi
166 if [[ -d ${oldRunDir} ]]; then
167 echo "removing old ${period}/${pass}/${runNumber}"
170 echo "moving new ${runNumber} to ${productionDir}"
171 mv -f ${dir} ${productionDir}
174 echo running ${detector} periodLevelQA for production ${period}/${pass}
176 hadd trending.root 000*/trending.root &> periodLevelQA.log
177 periodLevelQA trending.root &>> periodLevelQA.log
179 if ! validate ${PWD}; then continue; fi
185 cd ${workingDirectory}
187 if [[ -z ${planB} ]]; then
189 echo removing ${tmpRunDir}
202 #in case of emergency
203 if [[ -n ${MAILTO} ]]; then
205 echo "trouble detected, sending email to ${MAILTO}"
207 cat ${logSummary} | mail -s "qa in need of assistance" ${MAILTO}
213 summarizeLogs ${1} >> ${logSummary}
215 if [[ ${logStatus} -ne 0 ]]; then
216 echo "WARNING not validated: ${1}"
226 [[ ! -d ${dir} ]] && dir=${PWD}
228 #print a summary of logs
237 for log in ${dir}/${logFiles[*]}; do
238 finallog=${PWD%/}/${log}
239 [[ ! -f ${log} ]] && continue
240 errorSummary=$(validateLog ${log})
242 [[ validationStatus -ne 0 ]] && logstatus=1
243 if [[ ${validationStatus} -eq 0 ]]; then
244 #in pretend mode randomly report an error in rec.log some cases
245 if [[ -n ${pretend} && "${log}" == "rec.log" ]]; then
246 [[ $(( ${RANDOM}%2 )) -ge 1 ]] && echo "${finallog} BAD random error" || echo "${finallog} OK"
248 echo "${finallog} OK"
250 elif [[ ${validationStatus} -eq 1 ]]; then
251 echo "${finallog} BAD ${errorSummary}"
252 elif [[ ${validationStatus} -eq 2 ]]; then
253 echo "${finallog} OK MWAH ${errorSummary}"
261 gdb --batch --quiet -ex "bt" -ex "quit" aliroot ${x} > stacktrace_${x//\//_}.log
262 done < <(/bin/ls ${PWD}/*/core 2>/dev/null; /bin/ls ${PWD}/core 2>/dev/null)
273 'error while loading shared libraries'
276 'Thread [0-9]* (Thread'
279 '\.C.*error:.*\.h: No such file'
288 local errorSummary=""
289 local warningSummary=""
291 for ((i=0; i<${#errorConditions[@]};i++)); do
292 local tmp=$(grep -m1 -e "${errorConditions[${i}]}" ${log})
293 [[ -n ${tmp} ]] && tmp+=" : "
297 for ((i=0; i<${#warningConditions[@]};i++)); do
298 local tmp=$(grep -m1 -e "${warningConditions[${i}]}" ${log})
299 [[ -n ${tmp} ]] && tmp+=" : "
300 warningSummary+=${tmp}
303 if [[ -n ${errorSummary} ]]; then
304 echo "${errorSummary}"
308 if [[ -n ${warningSummary} ]]; then
309 echo "${warningSummary}"
320 #where to search for qa files
323 workingDirectory="${PWD}"
324 #where to place the final qa plots
325 #outputDirectory="/afs/cern.ch/work/a/aliqa%det/www/"
326 outputDirectory="${workingDirectory}/%DET"
327 #filter out detector option
328 excludeDetectors="EXAMPLE"
330 logDirectory=${workingDirectory}/logs
332 #alirootEnv="/home/mkrzewic/alisoft/balice_master.sh"
334 #ocdbStorage="raw://"
336 #MAILTO="fbellini@cern.ch"
338 #first, check if the config file is configured
339 #is yes - source it so that other options can override it
342 if [[ ${opt} =~ configFile=.* ]]; then
344 configFile=$(readlink -f ${configFile})
345 source "${configFile}"
350 #then, parse the options as they override the options from file
351 while [[ -n ${1} ]]; do
353 if [[ ${var} =~ .*=.* ]]; then
356 echo "badly formatted option ${var}, should be: option=value, stopping..."
365 #guess the period from the path, pick the rightmost one
370 legoTrainRunNumber=""
373 local shortRunNumber=""
375 declare -a path=( $1 )
376 local dirDepth=$(( ${#path[*]}-1 ))
378 for ((x=${dirDepth};x>=0;x--)); do
380 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
381 local field=${path[${x}]}
382 local fieldNext=${path[$((x+1))]}
384 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
385 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
386 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
387 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
388 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
389 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
390 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
393 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
394 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
396 #if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
397 if [[ -z ${runNumber}} ]];
407 substituteDetectorName()
411 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
412 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}