5 echo "Usage: $0 configFile [optionalStuff]"
6 echo " - optionalStuff overrides config file, e.g.:"
7 echo " $0 configFile inputList=somefile.list outputDirectory='${PWD}'/output"
9 [[ ! -f $1 ]] && echo "argument not a file" && exit 1
16 updateQA ${configFile} $@
21 #this guy takes config file as only positional argument
22 #optional stugg allowerd to override config
26 parseConfig $configFile $@
29 mkdir -p $logDirectory
30 [[ ! -d $logDirectory ]] && echo "no log dir $logDirectory" && exit 1
31 logFile="$logDirectory/${0##*/}.$dateString.log"
33 [[ ! -f ${logFile} ]] && echo "cannot write logfile $logfile" && exit 1
37 lockFile=${logDirectory}/runQA.lock
38 [[ -f ${lockFile} ]] && echo "lock ${lockFile} exists!" && exit 1
40 [[ ! -f ${lockFile} ]] && echo "cannot lock $lockFile" && exit 1
42 #be paranoid and make some full paths
43 inputList=$(readlink -f ${inputList})
44 workingDirectory=$(readlink -f ${workingDirectory})
45 mkdir -p ${workingDirectory}
46 if [[ ! -d ${workingDirectory} ]]; then
47 echo "working dir $workingDirectory does not exist and cannot be created"
50 cd ${workingDirectory}
52 [[ -z $ALICE_ROOT ]] && source $alirootEnv
53 [[ -z $ALICE_ROOT ]] && echo "ALICE_ROOT not defined" && exit 1
55 dateString=$(date +%Y-%m-%d-%H-%M)
56 echo "Start time QA process: $dateString"
58 ################################################################
60 for detectorScript in $ALICE_ROOT/PWGPP/QA/detectorQAscripts/*; do
62 [[ ! ${detectorScript} =~ .*\.sh ]] && continue
63 detector=${detectorScript%.sh}
64 detector=${detector##*/}
65 outputDir=$(substituteDetectorName ${detector} ${outputDirectory})
66 tmpRunDir=${workingDirectory}/tmpQArunDir${detector}
67 if ! mkdir -p ${tmpRunDir}; then
68 echo "cannot create the temp dir $tmpRunDir"
73 tmpPrefix=${tmpRunDir}/${outputDir}
74 echo outputDir=$outputDir
75 echo tmpPrefix=$tmpPrefix
76 echo detector=$detector
79 unset -f periodLevelQA
80 source ${detectorScript}
82 #################################################################
83 #produce the QA and trending tree for each file (run)
86 guessRunData ${qaFile}
88 runDir=${tmpPrefix}/${dataType}/${year}/${period}/${pass}/000${runNumber}
93 #handle the case of a zip archive
94 [[ "$qaFile" =~ .*.zip$ ]] && qaFile="${qaFile}#QAresults.root"
102 #################################################################
103 #cache which productions were (re)done
104 arrOfTouchedProductions=( $(/bin/ls -d ${tmpPrefix}/*/*/*/*) )
105 echo arrOfTouchedProductions=${arrOfTouchedProductions[@]}
107 #################################################################
108 #(re)do the merging/trending in the final destination
109 for tmpProductionDir in ${arrOfTouchedProductions[@]}; do
111 echo productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
112 productionDir=${outputDir}/${tmpProductionDir#${tmpPrefix}}
114 echo mkdir -p ${productionDir}
115 mkdir -p ${productionDir}
116 if [[ ! -d ${productionDir} ]]; then
117 echo "cannot make productionDir $productionDir" && return 1
120 echo mv -f ${tmpProductionDir}/* ${productionDir}
121 mv -f ${tmpProductionDir}/* ${productionDir}
123 guessRunData "${productionDir}/dummyName"
127 hadd trending.root 000*/trending.root
129 periodLevelQA trending.root
135 cd ${workingDirectory}
148 #first, source the config file
149 if [ -f ${configFile} ]; then
152 echo "config file ${configFile} not found!, skipping..."
155 #then, parse the options as they override the options from file
156 while [[ -n ${1} ]]; do
165 #guess the period from the path, pick the rightmost one
170 legoTrainRunNumber=""
173 local shortRunNumber=""
175 declare -a path=( $1 )
176 local dirDepth=$(( ${#path[*]}-1 ))
178 for ((x=${dirDepth};x>=0;x--)); do
180 [[ $((x-1)) -ge 0 ]] && local fieldPrev=${path[$((x-1))]}
181 local field=${path[${x}]}
182 local fieldNext=${path[$((x+1))]}
184 [[ ${field} =~ ^[0-9]*$ && ${fieldNext} =~ (.*\.zip$|.*\.root$) ]] && legoTrainRunNumber=${field}
185 [[ -n ${legoTrainRunNumber} && -z ${pass} ]] && pass=${fieldPrev}
186 [[ ${field} =~ ^LHC[0-9][0-9][a-z].*$ ]] && period=${field%_*}
187 [[ ${field} =~ ^000[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && runNumber=${field#000}
188 [[ ${field} =~ ^[0-9][0-9][0-9][0-9][0-9][0-9]$ ]] && shortRunNumber=${field}
189 [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
190 [[ ${field} =~ ^(^sim$|^data$) ]] && dataType=${field}
193 [[ -z ${legoTrainRunNumber} ]] && pass=${path[$((dirDepth-1))]}
194 [[ "${dataType}" =~ ^sim$ ]] && pass="passMC" && runNumber=${shortRunNumber}
196 if [[ -z ${dataType} || -z ${year} || -z ${period} || -z ${runNumber}} || -z ${pass} ]];
206 substituteDetectorName()
210 [[ ${dir} =~ \%det ]] && det=${det,,} && echo ${dir/\%det/${det}}
211 [[ ${dir} =~ \%DET ]] && det=${det} && echo ${dir/\%DET/${det}}