]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/qa/getQAResults.sh
Updates to deal with an beam type of p-A.
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / qa / getQAResults.sh
1 #!/bin/bash
2
3 # --------------------------------------------------------------------
4 verb=0
5
6 mess()
7 {
8     if test $verb -lt 1 ; then return ; fi 
9     echo $@
10 }
11
12 # --------------------------------------------------------------------
13 usage()
14 {
15     cat <<EOF
16 Usage: $0 -p PRODUCTION [OPTIONS]
17
18 Options: 
19         -h,--help                     This help 
20         -v,--verbose                  Be verbose
21         -p,--production  IDENTIFIER   Production identifier [$prod]
22         -P,--pass        NUMBER       Reconstruction pass number [$pass]
23         -Q,--pre-pass    STRING       Prefix to pass identifier [${prep}]
24         -R,--post-pass   STRING       Postfix to pass identifier [$post]
25         -y,--year        YEAR         Year of production [$year]
26         -d,--destination DIRECTORY    Directory to store result in [$dest] 
27         -r,--run         NUMBER       Run number [$runn]
28         -q,--qa          NUMBER       QA number 
29         -f,--file        NAME         File to get [$file]
30         -T,--trending                 Get trending.root file 
31         -a,--archives                 Get ZIP archives 
32         -n,--no-action                Run dry (do not copy files)
33
34 If run number is set, get the parts of next-to-last merge of that run only.
35
36 EOF
37 }
38
39 # --------------------------------------------------------------------
40 check_file()
41 {
42     inp=$1 
43     scr=`mktemp -u Check_XXXXXXXX` 
44     cat <<EOF > ${scr}.C  
45 void ${scr}() 
46 {
47   int ret = 0;
48   gSystem->Load("libANALYSIS");
49   gSystem->Load("libANALYSISalice");
50   gSystem->Load("libTENDER");
51   // gSystem->Load("libTENDERSupplies");
52   gSystem->Load("libPWG1");
53   gSystem->Load("libPWG3base");
54   TFile* file = TFile::Open("${inp}", "READ");
55   if (!file) { 
56     Error("${scr}", "No such file ${inp}");
57     exit(1);
58   }
59   TObject* forward1 = file->Get("Forward");
60   if (!forward1) {
61     Error("${scr}", "No Forward object found in ${inp}");
62     ret |= 2;
63   } 
64   TObject* forward2 = file->Get("ForwardResults");
65   if (!forward2) {
66     Error("${scr}", "No ForwardResults object found in ${inp}");
67     ret |= 4;
68   } 
69   exit(ret);
70 }
71 EOF
72     # cat ${scr}.C 
73     mess -n "aliroot -l -b -q ${scr}.C "
74     aliroot -l -b -q ${scr}.C > /dev/null 2>&1 
75     ret=$? 
76     mess "-> $ret (0: good, 1: no file, 2: no Forward, 4: no ForwardResults"
77     rm -f ${scr}.C 
78     return $ret
79 }
80
81 # --------------------------------------------------------------------
82 year=""
83 prod=""
84 pass=-1
85 prep=""
86 post=""
87 dest=.
88 runn=0
89 qano=0
90 noac=0
91 arch=0
92 file=QAresults.root 
93
94 while test $# -gt 0 ; do 
95     case $1 in 
96         -h|--help)        usage   ; exit 0 ;; 
97         -v|--verbose)     let verb=$verb+1  ;; 
98         -p|--production)  prod=$2 ; shift ;; 
99         -P|--pass)        pass=$2 ; shift ;; 
100         -Q|--prepass)     prep=$2 ; shift ;; 
101         -R|--postpass)    post=$2 ; shift ;; 
102         -y|--year)        year=$2 ; shift ;; 
103         -d|--destination) dest=$2 ; shift ;; 
104         -r|--run)         runn=$2 ; shift ;; 
105         -q|--qa)          qano=$2 ; shift ;; 
106         -f|--file)        file=$2 ; shift ;; 
107         -T|--trending)    file=trending.root ; shift ;; 
108         -a|--archives)    arch=1  ;; 
109         -n|--no-action)   noac=1  ;; 
110         *) echo "$0: Unknown option $1" > /dev/stderr ; exit 2 ;; 
111     esac
112     shift
113 done
114
115 # --------------------------------------------------------------------
116 uid=`id -u`
117 genv_file=/tmp/gclient_env_${uid}
118
119 if test ! -f ${genv_file} ; then 
120     echo "No such file: ${genv_file}, please do alien-token-init" >/dev/stderr
121     exit 1
122 fi
123 . ${genv_file}
124 alien-token-info | grep -q "Token is still valid"
125 if test $? -ne 0 ; then 
126     echo "Token not valid, please re-new" > /dev/stderr 
127     exit 1
128 fi
129
130
131 # --------------------------------------------------------------------
132 if test "x$prod" = "x" ; then 
133     echo "No production identifier given" > /dev/stderr 
134     exit 2
135 fi
136
137 if test "x$year" = "x" ; then 
138     year=`echo $prod | sed -e 's/LHC\(..\).*/\1/'` 
139     if test "x$year" = "x" ; then 
140         echo "Couldn't get year from production identifier $prod" > /dev/stderr
141         exit 2
142     fi
143 fi
144 lett=`echo $prod | sed -e "s/LHC${year}\(.\).*/\1/"`
145 suff=`echo $prod | sed -e "s/LHC${year}${lett}//"`
146
147 redir="/dev/null"
148 if test $verb -gt 1 ; then redir=/dev/stderr ; fi
149
150 # --------------------------------------------------------------------
151 if test "x$post" != "x" ; then 
152     case $post in 
153         _*) ;; 
154         *) post="_${post}" ;; 
155     esac
156 fi
157 if test ${pass} -ge 0 ; then 
158     paid=pass${pass} 
159 fi
160 datd=data
161 esdd=ESDs/
162 if test "x${suff}" != "x" ; then 
163     datd=sim
164     esdd=
165 fi
166 path=/alice/${datd}/20${year}/${prod}/
167 store=${dest}/${prod}/${prep}${paid}${post}
168 search="${esdd}${prep}${paid}${post}"
169 if test $runn -gt 0 ; then 
170     path=`printf "${path}%09d/ESDs/${prep}${paid}${pass}${post}/" $runn` 
171     store=`printf "${store}/%09d" $runn` 
172     search=
173 fi
174 if test $qano -gt 0 ; then 
175     if test $runn -gt 0 ; then 
176         path=`printf "%sQA%02d/" $path $qano` 
177     else
178         if test "x$search" != "x" ; then search=${search}/ ; fi
179         search=${search}QA`printf %02d ${qano}` 
180     fi
181 fi
182 if test $arch -gt 0 ; then 
183     file=QA_archive.zip
184 fi
185 base=`basename $file .root`
186 if test "x$search" != "x" ; then search=${search}/ ; fi
187 search="${search}${file}"
188
189 # --------------------------------------------------------------------
190 cat <<EOF
191 Settings:
192
193         Production:             $prod
194         Year:                   $year
195         Letter:                 $lett
196         Suffix:                 $suff
197         Pass:                   $pass
198         Pass prefix:            $prep
199         Pass postfix:           $post
200         File:                   $file
201         Path:                   $path
202         Destination:            $dest
203         Store:                  $store
204         Run number:             $runn
205         Search string:          $search
206         Verbosity:              $verb
207         Redirection:            $redir
208 EOF
209     
210 # --------------------------------------------------------------------
211 mkdir -p ${store}
212 mess "alien_find ${path} ${search}"
213 files=`alien_find ${path} ${search} | grep -v "files found" 2> ${redir}` 
214 j=0
215 runs=
216 for i in $files ; do 
217     b=`echo $i | sed -e "s,${path},,"` 
218     d=
219     if test $runn -gt 0 ; then 
220         r=`echo $b | sed -e "s,[0-9]*${runn}\([0-9.]*\)/.*,\1," | tr '.' '_'`
221         if test $arch -lt 1 ; then 
222             o=${store}/${base}_${r}.root
223         else
224             d=${store}/${r}
225             mkdir -p $d
226             o=${d}/${file}
227         fi
228     else 
229         r=`echo $b | sed -e "s,/.*,,"` 
230         o=${store}/${base}_${r}.root
231     fi
232     runs="$runs $r" 
233     mess "$i -> $o"
234     if test $noac -lt 1 && test ! -f $o ; then 
235         mess "alien_cp alien:${i} file:${o}"
236         alien_cp alien:${i} file:${o} > ${redir} 2>&1 
237     fi
238     if test $noac -lt 1 && test $arch -lt 1  ; then check_file $o ; fi
239     if test $noac -lt 1 && test $arch -gt 0 ; then 
240         (cd ${d} && unzip QAarchive.zip) > $redir 2>&1 
241     fi
242     let j=$j+1
243 done 
244 mess "Got a total of $j files for runs $runs"
245
246 # --------------------------------------------------------------------
247 #
248 # EOF
249 #
250
251