]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGPP/CalibMacros/AliOCDBtoolkit.sh
AliOCDBtoolkit.sh - make a diff between 2 OCDB
[u/mrichter/AliRoot.git] / PWGPP / CalibMacros / AliOCDBtoolkit.sh
1 #!/bin/bash
2 #
3 # Shell script to compare content of the OCDB entries.
4 #
5 # ocdbMakeTable() 
6 #       Usage: bash $inputFile $flag $outputFile
7 # dumpObject()
8 #       Usage: bash $inputFile $object_name $dump_type [XML/MI] $outfile
9 # diffObject
10 #       Usage: bash $inputFile1 $inputFile2 $object_name $dump_type [XML/MI] $outfile
11 # Example usage:  see example functions below
12
13 ocdbMakeTable(){
14 #
15 # create a text file with the OCDB setupt descriptors#
16 #
17 # Input: 
18 #   $1 inputFile name
19 #   $2 flag type of the input file
20 #   flags: 
21 #   log file = "log"
22 #   AliESDs.root = "ESD"
23 #   galice.root = "MC"
24 # Output:
25 #   $3 output file name
26     if [ $# -lt 3 ] ; then
27         echo "Usage: $0 \$inputFile \$flag \$outputFile"
28         return 1
29     fi
30     local inFile=${1}
31     local inFlag=${2}
32     local outFile=${3}
33     shift 3
34     if [ ! -f ${inFile} ] ; then 
35         echo ${inFile} not found!
36         return 1
37     fi
38     if [ -f ${outFile} ] ; then 
39         >${outFile}
40     fi
41
42     tmpscript=$(mktemp)
43     cat > ${tmpscript} <<HEREDOC
44         {
45             AliOCDBtoolkit::DumpOCDBAsTxt("${inFile}","${inFlag}","${outFile}");
46         }
47 HEREDOC
48
49     aliroot -l -q -b ${tmpscript} 
50     sleep 60 && rm ${tmpscript} &
51     return 1
52 }
53
54
55 dumpObject(){
56 #
57 #
58 #  Input:
59 #    $1 path
60 #    $2 obj name 
61 #    $3 type of the dump (XML or MI recursive dump )
62 #  Output:
63 #    $4 output file name   
64     if [ $# -lt 4 ] ; then
65         echo "Usage: $0 \$inputFile \$object_name \$dump_type [XML/MI] \$outfile"
66         return 1
67     fi
68     local inFile=${1}
69     local fobject=${2}
70     local ftype=${3}
71     local outFile=${4}
72     shift 4
73     if [ ! -f ${inFile} ] ; then 
74         echo ${inFile} not found!
75         return 1
76     fi
77     if [ -f ${outFile} ] ; then 
78         >${outFile}
79     fi
80     if [ ${ftype} = "XML" ] ; then
81         isXML=kTRUE
82     elif [ ${ftype} = "MI" ] ; then
83         isXML=kFALSE
84     else
85         echo "option ${ftype} not recognized! Use \"XML\" or \"MI\"!"
86         return 1
87     fi
88     tmpscript=$(mktemp)
89     cat > ${tmpscript} <<HEREDOC
90         {
91             AliOCDBtoolkit::DumpOCDBFile("${inFile}","${outFile}",1,${isXML});
92         }
93 HEREDOC
94
95     aliroot -l -q -b ${tmpscript} 
96     sleep 60 && rm ${tmpscript} &
97     return 1
98 }
99
100 diffObject(){
101 #
102 #
103 #  Input:
104 #    $1 path0
105 #    $2 path1
106 #    $3 obj name 
107 #    $4 type of the dump (xml or MI recursive dump )
108 #  Output:
109 #    $5 output diff file name   
110     if [ $# -lt 5 ] ; then
111         echo "Usage: $0 \$inputFile1 \$inputFile2 \$object_name \$dump_type [XML/MI] \$outfile"
112         return 1
113     fi
114     local inFile1=${1}
115     local inFile2=${2}
116     local fobject=${3}
117     local ftype=${4}
118     local outFile=${5}
119     shift 5
120     local tmp1=$(mktemp)
121     local tmp2=$(mktemp)
122     if [ ${ftype} = "XML" ] ; then
123         isXML=kTRUE
124         tmp1="${tmp1}.xml"
125         tmp2="${tmp2}.xml"
126     elif [ ${ftype} = "MI" ] ; then
127         isXML=kFALSE
128     else
129         echo "option ${ftype} not recognized! Use \"XML\" or \"MI\"!"
130         return 1
131     fi
132     dumpObject ${inFile1} ${fobject} ${ftype} ${tmp1%.xml}
133     dumpObject ${inFile2} ${fobject} ${ftype} ${tmp2%.xml}
134     diff ${tmp1} ${tmp2} >${outFile}
135     rm ${tmp1} ${tmp2} 2>/dev/null
136     rm "${tmp1}.xml" "${tmp2}.xml" 2>/dev/null
137     return 1
138 }
139
140 dumpOCDBDiffTable(){
141 #
142 # Dump  differences between the OCDB tables -comparison based on the hash values of OCDB entries
143 # Input:
144 #   $1  - list 1
145 #   $2  - list 2
146 # Output:
147 #   difference is stdout
148
149     list1=$1
150     list2=$2
151     shift 2
152     cdbName=$(cut -f1 $list1)
153     for i in $cdbName ; do
154         line1="$(grep $i $list1)"
155         line2="$(grep $i $list2)"
156         if [ -z "${line2}" ] ; then
157             echo $i not found in $list2!
158             continue
159         fi
160         match1=$(echo $line1 | cut -d' ' -f 5)
161         match2=$(echo $line2 | cut -d' ' -f 5)
162         if [ "$match1" -ne "$match2" ] ; then
163             echo $i doesnt match:
164             echo $(echo $line1| awk '{print $2 "/" $3}') \#hash: $match1
165             echo $(echo $line2| awk '{print $2 "/" $3}') \#hash: $match2
166             echo 
167         fi
168     done
169 }
170
171
172
173
174
175 #
176 # Example usage+ developer test routines. 
177 #
178
179 example1(){
180     ocdbMakeTable "/hera/alice/jwagner/simulations/benchmark/aliroot_tests/ppbench/rec.log" "log" "testout"
181 }
182 example2(){
183     dumpObject "/hera/alice/jwagner/OCDB/temp/TPC/Calib/RecoParam/Run0_999999999_v0_s0.root" "object" "XML" "testout2XML"
184     dumpObject "/hera/alice/jwagner/OCDB/temp/TPC/Calib/RecoParam/Run0_999999999_v0_s0.root" "object" "MI" "testout2MI" 
185 }
186 example3(){
187     file1="/hera/alice/jwagner/OCDB/temp/TPC/Calib/RecoParam/Run0_999999999_v0_s0.root"
188     file2="$ALICE_ROOT/OCDB/TPC/Calib/RecoParam/Run0_999999999_v0_s0.root"
189     diffObject ${file1} ${file2} "object" "MI" "testdiffMI"
190     diffObject ${file1} ${file2} "object" "XML" "testdiffXML"
191 }
192
193 developerTest(){
194     source /hera/alice/jwagner/software/aliroot/loadMyAliroot.sh TPCdev
195     example1
196     example2
197     example3
198 }