]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/CalibMacros/CPass0/mergeMakeOCDB.byComponent.sh
Changes (Marian and Mikolaj):
[u/mrichter/AliRoot.git] / PWGPP / CalibMacros / CPass0 / mergeMakeOCDB.byComponent.sh
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://
16 defaultOCDB=$4
17 [[ -z $4 ]] && defaultOCDB="raw://"
18
19 # init
20 path=$1
21 run=$2
22 ocdb=$3
23 isLocal=0
24 [[ -f $path ]] && isLocal=1
25
26 echo "***********************" 2>&1 | tee -a merge.log
27 echo mergeMakeOCDB.byComponent.sh started 2>&1 | tee -a merge.log
28 echo path = $path 2>&1 | tee -a merge.log
29 echo run  = $run 2>&1 | tee -a merge.log
30 echo ocdb = $ocdb 2>&1 | tee -a merge.log
31 echo defaultOCDB=$defaultOCDB | tee -a merge.log
32 echo isLocal = $isLocal 2>&1 | tee -a merge.log
33 echo "***********************" 2>&1 | tee -a merge.log
34
35 # setup components
36 components="TOF MeanVertex T0 SDD TRD TPCCalib  TPCAlign TPCCluster"
37
38 alienFileList="alien.list"
39 localFileList="local.list"
40 partialLocalFileListPrefix=${localFileList}_
41 partialAlienFileListPrefix=${alienFileList}_
42 runningMergeByComponentLockFile="runningMergeByComponent.lock"
43
44 mergeByComponent()
45 {
46   # process by component
47   # first argument is the file list to process
48   # second argument can be "doCleanup" to delete merged files
49
50   #lock
51   touch $runningMergeByComponentLockFile
52
53   previousResults=PREVIOUS_ITERATION_CalibObjects.root
54   if [[ -f CalibObjects.root ]]; then
55     mv CalibObjects.root $previousResults
56     echo "$previousResults" >> $1
57   fi
58
59   echo "####DEBUG" | tee -a merge.log
60   echo "####processed list $1" | tee -a merge.log
61   cat $1
62
63   for det in $components; do
64     # merge
65     echo "***********************" 2>&1 | tee -a merge.log
66     echo merging $det data 2>&1 | tee -a merge.log
67     echo "***********************" 2>&1 | tee -a merge.log
68     echo aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeByComponent.C(\"$det\", \"$1\")" 2>&1 | tee -a merge.log
69     aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeByComponent.C(\"$det\", \"$1\")" 2>&1 | tee -a merge.log
70     mv syswatch.log syswatch_merge_$det.log
71     mv CalibObjects.root CalibObjects_$det.root
72   done
73   
74   rm -f $previousResults
75   
76   # global merge
77   echo "***********************" 2>&1 | tee -a merge.log
78   echo merging ALL data 2>&1 | tee -a merge.log
79   echo "***********************" 2>&1 | tee -a merge.log
80   partialCalibObjectsList="objects.list.${1}"
81   ls -1 CalibObjects_*.root > $partialCalibObjectsList
82   aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeByComponent.C(\"ALL\", \"$partialCalibObjectsList\")" 2>&1 | tee -a merge.log
83   mv syswatch.log syswatch_ALL.log
84   
85   #cleanup
86   if [[ "$2" == "doCleanup" ]]; then
87     while read filename; do
88       echo rm -f $filename | tee -a merge.log
89       rm -f $filename
90     done < $1
91   fi
92   rm -f CalibObjects_*.root
93
94   #unlock
95   rm -f $runningMergeByComponentLockFile
96 }
97
98 waitIfLocked()
99 {
100   while [ 1 ]; do
101     [[ ! -f $1 ]] && break
102     sleep 1
103   done
104 }
105
106 if [ $isLocal -eq 0 ]; then
107     #with alien files copy them first to local
108     echo "***********************" 2>&1 | tee -a merge.log
109     echo copying files for run $run 2>&1 | tee -a merge.log
110     echo from $path 2>&1 | tee -a merge.log
111     echo "***********************" 2>&1 | tee -a merge.log
112     aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeByComponent.C(\"MAKEALIENLIST\",\"$alienFileList\", \"$path\", \"AliESDfriends_v1.root\")" 2>&1 | tee -a merge.log
113     split --numeric-suffixes --suffix-length=4 --lines=100 ${alienFileList} ${partialAlienFileListPrefix}
114     counter=0
115     rm -f $runningMergeByComponentLockFile
116     for partialAlienFileList in ${partialAlienFileListPrefix}*
117     do
118       #copy the alien files to local
119       partialAlienFileListPostfix=${partialAlienFileList#$partialAlienFileListPrefix}
120       partialLocalFileList=${partialLocalFileListPrefix}${partialAlienFileListPostfix}
121       aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/mergeByComponent.C(\"COPY\",\"$partialAlienFileList\",\"noPath\",\"noPattern\",10,\"$partialLocalFileList\")" 2>&1 | tee -a merge.log
122       [[ $counter -ne 0 ]] && sed -i '1d' syswatch.log && $(( $counter++ ))
123       cat syswatch.log >> syswatch_copy.log
124       rm syswatch.log
125
126       #merge in parallel, use a simple lockfile
127       waitIfLocked $runningMergeByComponentLockFile
128       mergeByComponent $partialLocalFileList "doCleanup" &
129     done
130 else
131   #locally just use the list directly
132   mergeByComponent $path
133 fi;
134
135 #cleanup
136 cat ${partialAlienFileListPrefix}* >> ${localFileList}
137 rm -f ${partialAlienFileListPrefix}*
138 rm -f ${partialLocalFileListPrefix}*
139
140 # make OCDB
141 echo "***********************" 2>&1 | tee -a ocdb.log
142 echo making $det OCDB 2>&1 | tee -a ocdb.log
143 echo "***********************" 2>&1 | tee -a ocdb.log
144 aliroot -b -q "$ALICE_ROOT/PWGPP/CalibMacros/CPass0/makeOCDB.C($run, \"$ocdb\", \"$defaultOCDB\")" 2>&1 | tee -a ocdb.log
145 mv syswatch.log syswatch_makeOCDB.log
146
147 # summary
148 echo "***********************" 2>&1 | tee -a ocdb.log
149 echo SUMMARY 2>&1 | tee -a ocdb.log
150 echo "***********************" 2>&1 | tee -a ocdb.log
151 ls -altr *CalibObjects.root *done 2>&1 | tee -a ocdb.log