5 echo "Usage: $0 configFile [optionalStuff]"
6 echo " - optionalStuff overrides config file, e.g.:"
7 echo " $0 configFile inputList=somefile.list outputDirectory='${PWD}'/output"
10 [[ ! -f $1 ]] && echo "argument not a file" && exit 1
16 [[ -z $ALICE_ROOT ]] && source $alirootEnv
17 [[ -z $ALICE_ROOT ]] && echo "ALICE_ROOT not defined" && exit 1
20 [[ ${ocdbStorage} =~ ${ocdbregex} ]] && alien-token-init
22 updateQA ${configFile} $@
27 #this guy takes config file as only positional argument
28 #optional stugg allowerd to override config
32 parseConfig $configFile $@
34 dateString=$(date +%Y-%m-%d-%H-%M)
35 echo "Start time QA process: $dateString"
38 mkdir -p $logDirectory
39 [[ ! -d $logDirectory ]] && echo "no log dir $logDirectory" && exit 1
40 logFile="$logDirectory/${0##*/}.${dateString}.log"
42 [[ ! -f ${logFile} ]] && echo "cannot write logfile $logfile" && exit 1
43 echo "logFile = $logFile"
47 lockFile=${logDirectory}/runQA.lock
48 [[ -f ${lockFile} ]] && echo "lock ${lockFile} exists!" && exit 1
50 [[ ! -f ${lockFile} ]] && echo "cannot lock $lockFile" && exit 1
52 #be paranoid and make some full paths
53 inputList=$(readlink -f ${inputList})
54 workingDirectory=$(readlink -f ${workingDirectory})
55 mkdir -p ${workingDirectory}
56 if [[ ! -d ${workingDirectory} ]]; then
57 echo "working dir $workingDirectory does not exist and cannot be created"
60 cd ${workingDirectory}
62 ################################################################
64 for detectorScript in $ALICE_ROOT/PWGPP/QA/detectorQAscripts/*; do
66 [[ ! ${detectorScript} =~ .*\.sh ]] && continue
67 detector=${detectorScript%.sh}
68 detector=${detector##*/}
69 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
70 tmpRunDir=${workingDirectory}/tmpQArunDir${detector}
71 if ! mkdir -p ${tmpRunDir}; then
72 echo "cannot create the temp dir $tmpRunDir"
77 tmpPrefix=${tmpRunDir}/${outputDir}
78 echo "running QA for ${detector}"
79 echo " outputDir=$outputDir"
80 echo " tmpPrefix=$tmpPrefix"
83 unset -f periodLevelQA
84 source ${detectorScript}
86 #################################################################
87 #produce the QA and trending tree for each file (run)
90 guessRunData ${qaFile}
92 runDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}/000${runNumber}
96 #handle the case of a zip archive
97 [[ "$qaFile" =~ .*.zip$ ]] && qaFile="${qaFile}#QAresults.root"
99 echo running ${detector} runLevelQA for run ${runNumber} from ${qaFile}
100 runLevelQA ${qaFile} &> runLevelQA.log
106 #################################################################
107 #cache which productions were (re)done
108 arrOfTouchedProductions=( $(/bin/ls -d ${tmpPrefix}/*/*/*/*) )
109 echo "list of processed productions:"
110 echo " ${arrOfTouchedProductions[@]}"
112 #################################################################
113 #(re)do the merging/trending in the final destination
114 for tmpProductionDir in ${arrOfTouchedProductions[@]}; do
116 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
118 echo mkdir -p ${productionDir}
119 mkdir -p ${productionDir}
120 if [[ ! -d ${productionDir} ]]; then
121 echo "cannot make productionDir $productionDir" && continue
124 #move to final destination
125 for dir in ${tmpProductionDir}/*; do
126 oldRunDir=${outputDir}/${dir#${tmpPrefix}}
127 if [[ -d ${oldRunDir} ]]; then
128 echo "removing old run: rm -rf ${oldRunDir}"
131 echo "moving output to final destination"
132 echo mv -f ${dir} ${productionDir}
133 mv -f ${dir} ${productionDir}
136 guessRunData "${productionDir}/dummyName"
141 hadd trending.root 000*/trending.root
143 echo running ${detector} periodLevelQA for production ${period}/${pass}
144 periodLevelQA trending.root &> periodLevelQA.log
150 cd ${workingDirectory}
151 echo cleaning up: rm -rf ${tmpRunDir}
164 #first, source the config file
165 if [ -f ${configFile} ]; then
168 echo "config file ${configFile} not found!, skipping..."
171 #then, parse the options as they override the options from file
172 while [[ -n ${1} ]]; do
181 #guess the period from the path, pick the rightmost one
186 legoTrainRunNumber=""
189 local shortRunNumber=""
191 declare -a path=( $1 )
192 local dirDepth=$(( ${#path[*]}-1 ))
194 for ((x=${dirDepth};x>=0;x--)); do
196 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
197 local field=${path[${x}]}
198 local fieldNext=${path[$((x+1))]}
200 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
201 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
202 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
203 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
204 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
205 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
206 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
209 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
210 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
212 if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
222 substituteDetectorName()
226 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
227 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}