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