]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGPP/CalibMacros/CPass0/mergeMakeOCDB.byComponent.sh
Changing cuts for TRD calibration (kSPD, kAny for ITS requirement, and MaxNbOfTracks...
[u/mrichter/AliRoot.git] / PWGPP / CalibMacros / CPass0 / mergeMakeOCDB.byComponent.sh
CommitLineData
e9129651 1#!/bin/bash
27eb9bff 2
d157f353 3# Script to merge objects coming out of the calibration train and export of the OCDB:
9e160db9 4# Arguments for local use:
d157f353 5# 1 - directory on which to look for the files to be merged
9e160db9 6# 2 - runNumber
d157f353 7# 3 - OCDB output path
e9129651 8# optional:
9# 4 - input default OCDB, default="raw://"
10# 5 - option: "alien_cp" will use alien_cp to copy files from alien
11# "tfilecp" will copy the files first using TFile::Cp()
12# "nocopy" will access files over the network directly TFile::Open()
13# default is tfilecp, use 0
14# 6 - number of files to download per iteration, default 20
15#
16# example local use (files will be downloaded from alien)
17#./mergeMakeOCDB.byComponent.sh /alice/data/2012/LHC12g/000188362/cpass0/ 188362 local://./OCDB local:///cvmfs/alice.gsi.de/alice/data/2011/OCDB/ 0 30
18#
19# on ALIEN just do:
d157f353 20# $1 = directory where to perform the find
9e160db9 21# $2 = runNumber
d157f353 22# $3 = OCDB path
23
e9129651 24if [[ $# -eq 0 ]]; then
25 echo arguments:
26 echo " 1 - directory on which to look for the files to be merged or local file list"
27 echo " 2 - runNumber"
28 echo " 3 - OCDB output path"
29 echo " optional:"
30 echo " 4 - input default OCDB, default=\"raw://\""
31 echo " 5 - option: \"alien_cp\" will use alien_cp to copy files from alien"
32 echo " \"tfilecp\" will copy the files first using TFile::Cp()"
33 echo " \"nocopy\" will access files over the network directly TFile::Open()"
34 echo " default is tfilecp (use 0)"
35 echo " 6 - number of files to download/merge per iteration, default 20"
36 echo
37 echo "example:"
38 echo " ./mergeMakeOCDB.byComponent.sh /alice/data/2012/LHC12g/000188362/cpass1/ 188362 local://./OCDB raw:// alien_cp 10"
39 echo
40
41 exit 0
42fi
d157f353 43
27eb9bff 44# init
45path=$1
d1c49c14 46run=$(echo "$2" | sed 's/^0*//')
27eb9bff 47ocdb=$3
e9129651 48defaultOCDB="raw://"
49[[ -n $4 ]] && defaultOCDB=$4
50fileAccessMethod=$5
51[[ "$fileAccessMethod" != "alien_cp" && "$fileAccessMethod" != "tfilecp" && "$fileAccessMethod" != "nocopy" ]] && fileAccessMethod="tfilecp"
52numberOfFilesInAbunch=50
53[[ $6 =~ ^[0-9]+$ ]] && numberOfFilesInAbunch=$6
54
d157f353 55isLocal=0
22019e94 56[[ -f $path ]] && isLocal=1
e9129651 57cleanup=1
58[[ $isLocal -eq 1 ]] && cleanup=0
59[[ $isLocal -eq 1 ]] && fileAccessMethod="nocopy"
d157f353 60
e9129651 61# setup components to be merged
62components="TOF MeanVertex T0 SDD TRD TPCCalib TPCAlign TPCCluster"
27eb9bff 63
e9129651 64#################################################################
65echo
66echo $0" $*"
67echo
68echo "***********************" | tee -a merge.log
69echo mergeMakeOCDB.byComponent.sh started | tee -a merge.log
70echo path = $path | tee -a merge.log
71echo run = $run | tee -a merge.log
72echo ocdb = $ocdb | tee -a merge.log
73echo defaultOCDB=$defaultOCDB | tee -a merge.log
74echo isLocal = $isLocal | tee -a merge.log
75echo cleanup = $cleanup | tee -a merge.log
76echo fileAccessMethod=$fileAccessMethod | tee -a merge.log
77echo numberOfFilesInAbunch = $numberOfFilesInAbunch | tee -a merge.log
78echo "***********************" | tee -a merge.log
27eb9bff 79
9e160db9 80alienFileList="alien.list"
81localFileList="local.list"
82partialLocalFileListPrefix=${localFileList}_
83partialAlienFileListPrefix=${alienFileList}_
84runningMergeByComponentLockFile="runningMergeByComponent.lock"
85
86mergeByComponent()
87{
88 # process by component
89 # first argument is the file list to process
9e160db9 90
91 #lock
92 touch $runningMergeByComponentLockFile
27eb9bff 93
40f73007 94 # run inside a dedicated running directory
95 # whic means copy the file list to process and prefic each line with ../
96 # since the file names have no absolute paths!
97 runningDirectory="${runningMergeByComponentLockFile}.${1}.dir"
e9129651 98 fileList="$1"
99 cleanup=$2
100
101 #sanity checks
102 [[ ! -f $fileList ]] && echo "$fileList does not exist" && return
40f73007 103 mkdir -p $runningDirectory
e9129651 104 [[ ! -d $runningDirectory ]] && echo "cannot create the running directory $runningDirectory" && return 1
105
106 #add the results of previous iteration to the BEGINNING of the list of files to be merged
107 if [[ -f CalibObjects.root ]]; then
108 echo "../CalibObjects.root" > $runningDirectory/$fileList
109 fi
40f73007 110
e9129651 111 #move the to be merged files to the running directory and make a list of available files
112 #handle the case of archives (x.zip#y.root) as well
113 nFiles=0
114 while read entry; do
115 if [[ $entry =~ ^.*\.root$ ]]; then
116 file=${entry%#*}
117 fileContent=${entry##*#}
118 [[ "${fileContent}" == "${file}" ]] && fileContent=""
119 [[ -n ${fileContent} ]] && fileContent="#${fileContent}"
120 if [[ -f ${file} ]]; then
121 ((nFiles++))
122 if [[ -f "./${file}" ]]; then
123 echo "../${file}${fileContent}" >> "${runningDirectory}/$fileList"
124 else
125 echo "${file}${fileContent}" >> "${runningDirectory}/$fileList"
126 fi
127 fi
128 fi
129 done < $fileList
130 [[ $nFiles -lt 1 ]] && echo "no new files in $fileList" && rm -rf $runningDirectory && return
40f73007 131
e9129651 132 #copy the macro to the running directory
133 [[ -f mergeByComponent.C ]] && cp mergeByComponent.C $runningDirectory
134
135 cd $runningDirectory
136
137 echo "processing following files from $fileList:"
138 cat $fileList
27eb9bff 139
9e160db9 140 for det in $components; do
27eb9bff 141 # merge
40f73007 142 echo "***********************"
143 echo merging $det data
144 echo "***********************"
145 echo aliroot -b -q "mergeByComponent.C(\"$det\", \"$fileList\")"
e9129651 146 aliroot -b -q "mergeByComponent.C(\"$det\", \"$fileList\")" 2>&1 | tee -a merge_${det}.log
147 if validateMerging ${det}; then
148 echo "### merge OK: mv CalibObjects.root CalibObjects_$det.root"
149 mv CalibObjects.root CalibObjects_$det.root
150 else
151 echo "### merging not validated"
152 rm -f CalibObjects.root
153 fi
9e160db9 154 mv syswatch.log syswatch_merge_$det.log
9e160db9 155 done
156
9e160db9 157 # global merge
40f73007 158 echo "***********************"
159 echo merging ALL data
160 echo "***********************"
9e160db9 161 partialCalibObjectsList="objects.list.${1}"
162 ls -1 CalibObjects_*.root > $partialCalibObjectsList
40f73007 163 echo aliroot -b -q "mergeByComponent.C(\"ALL\", \"$partialCalibObjectsList\")"
e9129651 164 aliroot -b -q "mergeByComponent.C(\"ALL\", \"$partialCalibObjectsList\")" 2>&1 | tee -a merge_ALL.log
165 if validateMerging "ALL"; then
166 #move the new CalibObjects to parent directory
167 echo mv -f CalibObjects.root ..
168 mv -f CalibObjects.root ..
169 else
170 echo "### merging not validated"
171 rm -f CalibObjects.root
172 fi
173
9e160db9 174 mv syswatch.log syswatch_ALL.log
40f73007 175 rm $partialCalibObjectsList
9e160db9 176
40f73007 177 #move stuff back to the parent dir and clean up
178 #merge the syswatch logs
179 for x in syswatch*log; do
e9129651 180 [[ ! -f $x ]] && continue
181 if [[ -f ../$x ]]
40f73007 182 then
e9129651 183 echo "sed '1d' $x >> ../$x"
184 sed '1d' $x >> ../$x
40f73007 185 rm -f $x
186 else
e9129651 187 echo mv -f $x ..
188 mv -f $x ..
40f73007 189 fi
190 done
e9129651 191
40f73007 192 #merge the other logs
193 for x in *.log; do
e9129651 194 [[ ! -f $x ]] && continue
195 if [[ -f ../$x ]]
40f73007 196 then
e9129651 197 echo "cat $x >> ../$x"
198 cat $x >> ../$x
40f73007 199 else
e9129651 200 echo "mv -f $x .."
201 mv -f $x ..
40f73007 202 fi
203 done
e9129651 204
205 #final cleanup.
206 #go to parent dir first to use the original fileList
207 #without ../CalibObjects.root
208 cd ..
209 if [[ $cleanup -eq 1 ]]; then
210 echo "cleaning up merged files..."
211 while read file; do
212 echo rm -rf $file
213 rm -rf $file
214 done<$fileList
215 fi
40f73007 216 rm -rf $runningDirectory
217
9e160db9 218 #unlock
219 rm -f $runningMergeByComponentLockFile
e9129651 220 [[ ! -f CalibObjects.root ]] && echo "WARNING: CalibObjects.root not available!"
40f73007 221 echo "***mergeByComponent() DONE"
e9129651 222 echo
223 return 0
9e160db9 224}
d157f353 225
9e160db9 226waitIfLocked()
227{
228 while [ 1 ]; do
229 [[ ! -f $1 ]] && break
230 sleep 1
231 done
e9129651 232 return 0
233}
234
235validateMerging()
236{
237 det=$1
238 retCode=0
239 [[ ! -f CalibObjects.root ]] && ((retCode++)) && echo "### no CalibObjects.root..."
240 [[ ! -f ${det}_merge_done ]] && ((retCode++)) && echo "### no ${det}_merge_done, job finished abnormally..."
241 error=$(grep -e "was a crash" *.log)
242 [[ -n $error ]] && ((retCode++)) && echo "### error: $error"
243
244 return $retCode
9e160db9 245}
d157f353 246
40f73007 247copyScripts()
248{
e9129651 249 [[ ! -f mergeByComponent.C ]] && \
250 cp -f $ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeByComponent.C $PWD && \
251 echo "taking the default scripts from $ALICE_ROOT"
252 [[ ! -f makeOCDB.C ]] && \
253 cp -f $ALICE_ROOT/PWGPP/CalibMacros/CPass0/makeOCDB.C $PWD && \
254 echo "taking the default scripts from $ALICE_ROOT"
40f73007 255}
256
e9129651 257#first, make sure we have the scripts
258copyScripts | tee -a copy.log
259ls
260#with alien files copy them first to local
261echo "***********************" 2>&1 | tee -a copy.log
262echo copying files for run $run 2>&1 | tee -a copy.log
263echo from $path 2>&1 | tee -a copy.log
264echo "***********************" 2>&1 | tee -a copy.log
265if [[ $isLocal -eq 0 ]]; then
266 if [[ "$fileAccessMethod" == "alien_cp" ]]; then
267 echo "alien_find $path AliESDfriends_v1.root | egrep ^/ > $alienFileList" 2>&1 | tee -a copy.log
268 alien_find $path "AliESDfriends_v1.root" | egrep "^/" > $alienFileList
269 echo "alien_find done"
270 echo
271 else
40f73007 272 echo aliroot -b -q "mergeByComponent.C(\"MAKEALIENLIST\",\"$alienFileList\", \"$path\", \"AliESDfriends_v1.root\")" 2>&1 | tee -a copy.log
273 aliroot -b -q "mergeByComponent.C(\"MAKEALIENLIST\",\"$alienFileList\", \"$path\", \"AliESDfriends_v1.root\")" 2>&1 | tee -a copy.log
e9129651 274 echo "MAKEALIENLIST done"
275 echo
276 fi
9e160db9 277else
e9129651 278 cp $path $alienFileList
279fi
280echo split --numeric-suffixes --suffix-length=6 --lines=$numberOfFilesInAbunch ${alienFileList} ${partialAlienFileListPrefix} | tee -a copy.log
281split --numeric-suffixes --suffix-length=6 --lines=$numberOfFilesInAbunch ${alienFileList} ${partialAlienFileListPrefix}
282rm -f $runningMergeByComponentLockFile
283for partialAlienFileList in ${partialAlienFileListPrefix}*
284do
285 partialAlienFileListPostfix=${partialAlienFileList#$partialAlienFileListPrefix}
286 partialLocalFileList=${partialLocalFileListPrefix}${partialAlienFileListPostfix}
287
288 #copy the files if appropriate and make a list of files to use
289 rm -f $partialLocalFileList
290 if [[ "$fileAccessMethod" == "alien_cp" ]]; then
291 while read x; do
292 [[ $x != /* ]] && continue
293 localName=${x//"/"/_}
294 echo "alien_cp "alien://$x" $localName" 2>&1 | tee -a copy.log
295 alien_cp "alien://$x" $localName
296 echo $localName>>$partialLocalFileList
297 done<$partialAlienFileList
298 elif [[ "$fileAccessMethod" == "tfilecp" ]]; then
299 echo aliroot -b -q "mergeByComponent.C(\"COPY\",\"$partialAlienFileList\",\"noPath\",\"noPattern\",10,\"$partialLocalFileList\")" 2>&1 | tee -a copy.log
300 aliroot -b -q "mergeByComponent.C(\"COPY\",\"$partialAlienFileList\",\"noPath\",\"noPattern\",10,\"$partialLocalFileList\")" 2>&1 | tee -a copy.log
301 elif [[ "$fileAccessMethod" == "nocopy" ]]; then
302 while read x; do
303 [[ $isLocal -eq 0 ]] && echo "alien://$x" >> $partialLocalFileList
304 [[ $isLocal -eq 1 ]] && echo "$x" >> $partialLocalFileList
305 done<$partialAlienFileList
306 cleanup=0
307 fi
308
309 #handle syswatch
310 if [[ -f syswatch_copy.log ]]
311 then
312 sed '1d' syswatch.log >> syswatch_copy.log
313 rm -f syswatch.log
314 else
315 [[ -f syswatch.log ]] && mv syswatch.log syswatch_copy.log
316 fi
317
318 #merge in parallel, use a simple lockfile
319 #echo "waitIfLocked $runningMergeByComponentLockFile" | tee -a merge.log
320 waitIfLocked $runningMergeByComponentLockFile
321 if [[ $isLocal -eq 1 ]]; then
322 #locally we don't need to run in parallel since we dont download,
323 #besides it causes problems on some filesystems (like lustre) with file sync
324 mergeByComponent $partialLocalFileList $cleanup 2>&1 | tee -a merge.log
325 else
326 mergeByComponent $partialLocalFileList $cleanup 2>&1 | tee -a merge.log &
327 fi
328done
9e160db9 329
330#cleanup
9e160db9 331rm -f ${partialAlienFileListPrefix}*
332rm -f ${partialLocalFileListPrefix}*
e9129651 333rm -f $alienFileList
d157f353 334
335# make OCDB
336echo "***********************" 2>&1 | tee -a ocdb.log
337echo making $det OCDB 2>&1 | tee -a ocdb.log
338echo "***********************" 2>&1 | tee -a ocdb.log
40f73007 339echo aliroot -b -q "makeOCDB.C($run, \"$ocdb\", \"$defaultOCDB\")" 2>&1 | tee -a ocdb.log
340aliroot -b -q "makeOCDB.C($run, \"$ocdb\", \"$defaultOCDB\")" 2>&1 | tee -a ocdb.log
9e160db9 341mv syswatch.log syswatch_makeOCDB.log
27eb9bff 342
343# summary
344echo "***********************" 2>&1 | tee -a ocdb.log
345echo SUMMARY 2>&1 | tee -a ocdb.log
346echo "***********************" 2>&1 | tee -a ocdb.log
9e160db9 347ls -altr *CalibObjects.root *done 2>&1 | tee -a ocdb.log