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