3 # Script to merge objects coming out of the calibration train and export of the OCDB:
4 # Arguments for local use:
5 # 1 - directory on which to look for the files to be merged
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
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
20 # $1 = directory where to perform the find
24 if [[ $# -eq 0 ]]; then
26 echo " 1 - directory on which to look for the files to be merged or local file list"
28 echo " 3 - OCDB output path"
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"
38 echo " ./mergeMakeOCDB.byComponent.sh /alice/data/2012/LHC12g/000188362/cpass1/ 188362 local://./OCDB raw:// alien_cp 10"
46 run=$(echo "$2" | sed 's/^0*//')
49 [[ -n $4 ]] && defaultOCDB=$4
51 [[ "$fileAccessMethod" != "alien_cp" && "$fileAccessMethod" != "tfilecp" && "$fileAccessMethod" != "nocopy" ]] && fileAccessMethod="tfilecp"
52 numberOfFilesInAbunch=50
53 [[ $6 =~ ^[0-9]+$ ]] && numberOfFilesInAbunch=$6
56 [[ -f $path ]] && isLocal=1
58 [[ $isLocal -eq 1 ]] && cleanup=0
59 [[ $isLocal -eq 1 ]] && fileAccessMethod="nocopy"
61 # setup components to be merged
62 components="TOF MeanVertex T0 SDD TRD TPCCalib TPCAlign TPCCluster"
64 #################################################################
68 echo "***********************" | tee -a merge.log
69 echo mergeMakeOCDB.byComponent.sh started | tee -a merge.log
70 echo path = $path | tee -a merge.log
71 echo run = $run | tee -a merge.log
72 echo ocdb = $ocdb | tee -a merge.log
73 echo defaultOCDB=$defaultOCDB | tee -a merge.log
74 echo isLocal = $isLocal | tee -a merge.log
75 echo cleanup = $cleanup | tee -a merge.log
76 echo fileAccessMethod=$fileAccessMethod | tee -a merge.log
77 echo numberOfFilesInAbunch = $numberOfFilesInAbunch | tee -a merge.log
78 echo "***********************" | tee -a merge.log
80 alienFileList="alien.list"
81 localFileList="local.list"
82 partialLocalFileListPrefix=${localFileList}_
83 partialAlienFileListPrefix=${alienFileList}_
84 runningMergeByComponentLockFile="runningMergeByComponent.lock"
88 # process by component
89 # first argument is the file list to process
92 touch $runningMergeByComponentLockFile
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"
102 [[ ! -f $fileList ]] && echo "$fileList does not exist" && return
103 mkdir -p $runningDirectory
104 [[ ! -d $runningDirectory ]] && echo "cannot create the running directory $runningDirectory" && return 1
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
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
115 if [[ $entry =~ ^.*\.root$ ]]; then
117 fileContent=${entry##*#}
118 [[ "${fileContent}" == "${file}" ]] && fileContent=""
119 [[ -n ${fileContent} ]] && fileContent="#${fileContent}"
120 if [[ -f ${file} ]]; then
122 if [[ -f "./${file}" ]]; then
123 echo "../${file}${fileContent}" >> "${runningDirectory}/$fileList"
125 echo "${file}${fileContent}" >> "${runningDirectory}/$fileList"
130 [[ $nFiles -lt 1 ]] && echo "no new files in $fileList" && rm -rf $runningDirectory && return
132 #copy the macro to the running directory
133 [[ -f mergeByComponent.C ]] && cp mergeByComponent.C $runningDirectory
137 echo "processing following files from $fileList:"
140 for det in $components; do
142 echo "***********************"
143 echo merging $det data
144 echo "***********************"
145 echo aliroot -b -q "mergeByComponent.C(\"$det\", \"$fileList\")"
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
151 echo "### merging not validated"
152 rm -f CalibObjects.root
154 mv syswatch.log syswatch_merge_$det.log
158 echo "***********************"
159 echo merging ALL data
160 echo "***********************"
161 partialCalibObjectsList="objects.list.${1}"
162 ls -1 CalibObjects_*.root > $partialCalibObjectsList
163 echo aliroot -b -q "mergeByComponent.C(\"ALL\", \"$partialCalibObjectsList\")"
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 ..
170 echo "### merging not validated"
171 rm -f CalibObjects.root
174 mv syswatch.log syswatch_ALL.log
175 rm $partialCalibObjectsList
177 #move stuff back to the parent dir and clean up
178 #merge the syswatch logs
179 for x in syswatch*log; do
180 [[ ! -f $x ]] && continue
183 echo "sed '1d' $x >> ../$x"
192 #merge the other logs
194 [[ ! -f $x ]] && continue
197 echo "cat $x >> ../$x"
206 #go to parent dir first to use the original fileList
207 #without ../CalibObjects.root
209 if [[ $cleanup -eq 1 ]]; then
210 echo "cleaning up merged files..."
216 rm -rf $runningDirectory
219 rm -f $runningMergeByComponentLockFile
220 [[ ! -f CalibObjects.root ]] && echo "WARNING: CalibObjects.root not available!"
221 echo "***mergeByComponent() DONE"
229 [[ ! -f $1 ]] && break
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"
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"
257 #first, make sure we have the scripts
258 copyScripts | tee -a copy.log
260 #with alien files copy them first to local
261 echo "***********************" 2>&1 | tee -a copy.log
262 echo copying files for run $run 2>&1 | tee -a copy.log
263 echo from $path 2>&1 | tee -a copy.log
264 echo "***********************" 2>&1 | tee -a copy.log
265 if [[ $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"
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
274 echo "MAKEALIENLIST done"
278 cp $path $alienFileList
280 echo split --numeric-suffixes --suffix-length=6 --lines=$numberOfFilesInAbunch ${alienFileList} ${partialAlienFileListPrefix} | tee -a copy.log
281 split --numeric-suffixes --suffix-length=6 --lines=$numberOfFilesInAbunch ${alienFileList} ${partialAlienFileListPrefix}
282 rm -f $runningMergeByComponentLockFile
283 for partialAlienFileList in ${partialAlienFileListPrefix}*
285 partialAlienFileListPostfix=${partialAlienFileList#$partialAlienFileListPrefix}
286 partialLocalFileList=${partialLocalFileListPrefix}${partialAlienFileListPostfix}
288 #copy the files if appropriate and make a list of files to use
289 rm -f $partialLocalFileList
290 if [[ "$fileAccessMethod" == "alien_cp" ]]; then
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
303 [[ $isLocal -eq 0 ]] && echo "alien://$x" >> $partialLocalFileList
304 [[ $isLocal -eq 1 ]] && echo "$x" >> $partialLocalFileList
305 done<$partialAlienFileList
310 if [[ -f syswatch_copy.log ]]
312 sed '1d' syswatch.log >> syswatch_copy.log
315 [[ -f syswatch.log ]] && mv syswatch.log syswatch_copy.log
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
326 mergeByComponent $partialLocalFileList $cleanup 2>&1 | tee -a merge.log &
331 rm -f ${partialAlienFileListPrefix}*
332 rm -f ${partialLocalFileListPrefix}*
336 echo "***********************" 2>&1 | tee -a ocdb.log
337 echo making $det OCDB 2>&1 | tee -a ocdb.log
338 echo "***********************" 2>&1 | tee -a ocdb.log
339 echo aliroot -b -q "makeOCDB.C($run, \"$ocdb\", \"$defaultOCDB\")" 2>&1 | tee -a ocdb.log
340 aliroot -b -q "makeOCDB.C($run, \"$ocdb\", \"$defaultOCDB\")" 2>&1 | tee -a ocdb.log
341 mv syswatch.log syswatch_makeOCDB.log
344 echo "***********************" 2>&1 | tee -a ocdb.log
345 echo SUMMARY 2>&1 | tee -a ocdb.log
346 echo "***********************" 2>&1 | tee -a ocdb.log
347 ls -altr *CalibObjects.root *done 2>&1 | tee -a ocdb.log