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