]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PWGPP/CalibMacros/CPass1/mergeMakeOCDB.byComponent.sh
Improving printouts, minor changes, update according to current settings for T0 and...
[u/mrichter/AliRoot.git] / PWGPP / CalibMacros / CPass1 / mergeMakeOCDB.byComponent.sh
... / ...
CommitLineData
1#! /bin/bash
2
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
6# 2 - runNumber
7# 3 - OCDB output path
8# [4 - input default OCDB]
9
10#ALIEN setting
11# $1 = directory where to perform the find
12# $2 = runNumber
13# $3 = OCDB path
14
15# if fourth argument given, its the default OCDB, otherwise use the default raw://
16defaultOCDB=$4
17[[ -z $4 ]] && defaultOCDB="raw://"
18
19# init
20path=$1
21run=$2
22ocdb=$3
23isLocal=0
24[[ -f $path ]] && isLocal=1
25
26echo "***********************" 2>&1 | tee -a merge.log
27echo mergeMakeOCDB.byComponent.sh started 2>&1 | tee -a merge.log
28echo path = $path 2>&1 | tee -a merge.log
29echo run = $run 2>&1 | tee -a merge.log
30echo ocdb = $ocdb 2>&1 | tee -a merge.log
31echo defaultOCDB=$defaultOCDB | tee -a merge.log
32echo isLocal = $isLocal 2>&1 | tee -a merge.log
33echo "***********************" 2>&1 | tee -a merge.log
34
35# setup components
36components="TOF MeanVertex T0 SDD TRD TPCCalib TPCAlign TPCCluster"
37
38alienFileList="alien.list"
39localFileList="local.list"
40partialLocalFileListPrefix=${localFileList}_
41partialAlienFileListPrefix=${alienFileList}_
42runningMergeByComponentLockFile="runningMergeByComponent.lock"
43
44makeAbsolutePathsInList()
45{
46 #make sure the files in the list have absolute paths
47 rm -f $2
48 while read file; do
49 readlink -f $file >> $2
50 done < $1
51}
52
53mergeByComponent()
54{
55 # process by component
56 # first argument is the file list to process
57 # second argument can be "doCleanup" to delete merged files
58
59 #lock
60 touch $runningMergeByComponentLockFile
61
62 # run inside a dedicated running directory
63 # whic means copy the file list to process and prefic each line with ../
64 # since the file names have no absolute paths!
65 runningDirectory="${runningMergeByComponentLockFile}.${1}.dir"
66 parentDirectory=$PWD
67 fileList="$1.local"
68 mkdir -p $runningDirectory
69 makeAbsolutePathsInList $1 $runningDirectory/$fileList
70 cd $runningDirectory
71
72 previousResults=PREVIOUS_ITERATION_CalibObjects.root
73 if [[ -f $parentDirectory/CalibObjects.root ]]; then
74 mv $parentDirectory/CalibObjects.root $previousResults
75 echo "$previousResults" >> $fileList
76 fi
77
78 echo "####DEBUG" | tee -a merge.log
79 echo "####processed list $fileList" | tee -a merge.log
80 cat $fileList | tee -a merge.log
81
82 for det in $components; do
83 # merge
84 echo "***********************" 2>&1 | tee -a merge.log
85 echo merging $det data 2>&1 | tee -a merge.log
86 echo "***********************" 2>&1 | tee -a merge.log
87 echo aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/mergeByComponent.C(\"$det\", \"$fileList\")" 2>&1 | tee -a merge.log
88 aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/mergeByComponent.C(\"$det\", \"$fileList\")" 2>&1 | tee -a merge.log
89 mv syswatch.log syswatch_merge_$det.log
90 mv CalibObjects.root CalibObjects_$det.root
91 done
92
93 rm -f $previousResults
94
95 # global merge
96 echo "***********************" 2>&1 | tee -a merge.log
97 echo merging ALL data 2>&1 | tee -a merge.log
98 echo "***********************" 2>&1 | tee -a merge.log
99 partialCalibObjectsList="objects.list.${1}"
100 ls -1 CalibObjects_*.root > $partialCalibObjectsList
101 aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/mergeByComponent.C(\"ALL\", \"$partialCalibObjectsList\")" 2>&1 | tee -a merge.log
102 mv syswatch.log syswatch_ALL.log
103
104 #cleanup
105 if [[ "$2" == "doCleanup" ]]; then
106 while read filename; do
107 echo rm -f $filename | tee -a merge.log
108 rm -f $filename
109 done < $fileList
110 fi
111 rm -f CalibObjects_*.root
112 rm -f $fileList
113
114 #move stuff back to the parent dir and clean up
115 #merge the syswatch logs
116 for x in syswatch*log; do
117 if [[ -f $parentDirectory/$x ]]
118 then
119 sed '1d' >> $parentDirectory/$x
120 rm -f $x
121 else
122 mv $x $parentDirectory/$x
123 fi
124 done
125 mv * $parentDirectory
126 cd $parentDirectory
127 rm -rf $runningDirectory
128
129 #unlock
130 rm -f $runningMergeByComponentLockFile
131}
132
133waitIfLocked()
134{
135 while [ 1 ]; do
136 [[ ! -f $1 ]] && break
137 sleep 1
138 done
139}
140
141if [ $isLocal -eq 0 ]; then
142 #with alien files copy them first to local
143 echo "***********************" 2>&1 | tee -a merge.log
144 echo copying files for run $run 2>&1 | tee -a merge.log
145 echo from $path 2>&1 | tee -a merge.log
146 echo "***********************" 2>&1 | tee -a merge.log
147 aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/mergeByComponent.C(\"MAKEALIENLIST\",\"$alienFileList\", \"$path\", \"AliESDfriends_v1.root\")" 2>&1 | tee -a merge.log
148 split --numeric-suffixes --suffix-length=4 --lines=20 ${alienFileList} ${partialAlienFileListPrefix}
149 rm -f $runningMergeByComponentLockFile
150 for partialAlienFileList in ${partialAlienFileListPrefix}*
151 do
152 #copy the alien files to local
153 partialAlienFileListPostfix=${partialAlienFileList#$partialAlienFileListPrefix}
154 partialLocalFileList=${partialLocalFileListPrefix}${partialAlienFileListPostfix}
155 aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/mergeByComponent.C(\"COPY\",\"$partialAlienFileList\",\"noPath\",\"noPattern\",10,\"$partialLocalFileList\")" 2>&1 | tee -a merge.log
156
157 #handle syswatch
158 if [[ -f syswatch_copy.log ]]
159 then
160 sed '1d' syswatch.log >> syswatch_copy.log
161 rm -f syswatch.log
162 else
163 mv syswatch.log syswatch_copy.log
164 fi
165
166 #merge in parallel, use a simple lockfile
167 waitIfLocked $runningMergeByComponentLockFile
168 mergeByComponent $partialLocalFileList "doCleanup" &
169 done
170else
171 #locally just use the list directly
172 mergeByComponent $path
173fi;
174
175#cleanup
176cat ${partialAlienFileListPrefix}* >> ${localFileList}
177rm -f ${partialAlienFileListPrefix}*
178rm -f ${partialLocalFileListPrefix}*
179
180# make OCDB
181echo "***********************" 2>&1 | tee -a ocdb.log
182echo making $det OCDB 2>&1 | tee -a ocdb.log
183echo "***********************" 2>&1 | tee -a ocdb.log
184aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass1/makeOCDB.C($run, \"$ocdb\", \"$defaultOCDB\")" 2>&1 | tee -a ocdb.log
185mv syswatch.log syswatch_makeOCDB.log
186
187# summary
188echo "***********************" 2>&1 | tee -a ocdb.log
189echo SUMMARY 2>&1 | tee -a ocdb.log
190echo "***********************" 2>&1 | tee -a ocdb.log
191ls -altr *CalibObjects.root *done 2>&1 | tee -a ocdb.log