]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/qa/getQAResults.sh
Fixes for pA indenfication of events
[u/mrichter/AliRoot.git] / PWGLF / 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#
bd6f5206 10# @ingroup pwglf_forward_qa_scripts
2dbde04b 11#
9b2f2e39 12
9b2f2e39 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]
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]
bae153e5 40 -m,--max NUMBER Maximum number of files to get [$maxf]
0151a6c6 41 -T,--trending Get trending.root file
9b2f2e39 42 -a,--archives Get ZIP archives
43 -n,--no-action Run dry (do not copy files)
e92d0953 44 -i,--no-check Do not check files [$docheck]
9b2f2e39 45
46If run number is set, get the parts of next-to-last merge of that run only.
47
48EOF
49}
50
51# --------------------------------------------------------------------
e92d0953 52docheck=1
9b2f2e39 53check_file()
54{
e92d0953 55 if test $docheck -lt 1 ; then return 0; fi
9b2f2e39 56 inp=$1
57 scr=`mktemp -u Check_XXXXXXXX`
58 cat <<EOF > ${scr}.C
59void ${scr}()
60{
871a9ac1 61 int ret = 0;
9b2f2e39 62 gSystem->Load("libANALYSIS");
63 gSystem->Load("libANALYSISalice");
64 gSystem->Load("libTENDER");
65 // gSystem->Load("libTENDERSupplies");
2bfe5463 66 gSystem->Load("libPWGPP");
9b2f2e39 67 gSystem->Load("libPWG3base");
68 TFile* file = TFile::Open("${inp}", "READ");
69 if (!file) {
70 Error("${scr}", "No such file ${inp}");
71 exit(1);
9b2f2e39 72 }
73 TObject* forward1 = file->Get("Forward");
74 if (!forward1) {
75 Error("${scr}", "No Forward object found in ${inp}");
871a9ac1 76 ret |= 2;
9b2f2e39 77 }
78 TObject* forward2 = file->Get("ForwardResults");
79 if (!forward2) {
80 Error("${scr}", "No ForwardResults object found in ${inp}");
871a9ac1 81 ret |= 4;
9b2f2e39 82 }
871a9ac1 83 exit(ret);
9b2f2e39 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# --------------------------------------------------------------------
871a9ac1 96year=""
97prod=""
98pass=-1
99prep=""
100post=""
9b2f2e39 101dest=.
102runn=0
103qano=0
104noac=0
105arch=0
bae153e5 106maxf=-1
871a9ac1 107file=QAresults.root
9b2f2e39 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 ;;
871a9ac1 115 -Q|--prepass) prep=$2 ; shift ;;
116 -R|--postpass) post=$2 ; shift ;;
9b2f2e39 117 -y|--year) year=$2 ; shift ;;
118 -d|--destination) dest=$2 ; shift ;;
119 -r|--run) runn=$2 ; shift ;;
120 -q|--qa) qano=$2 ; shift ;;
871a9ac1 121 -f|--file) file=$2 ; shift ;;
bae153e5 122 -m|--max) maxf=$2 ; shift ;;
0151a6c6 123 -T|--trending) file=trending.root ; shift ;;
9b2f2e39 124 -a|--archives) arch=1 ;;
0151a6c6 125 -n|--no-action) noac=1 ;;
e92d0953 126 -i|--no-check) docheck=0 ;;
9b2f2e39 127 *) echo "$0: Unknown option $1" > /dev/stderr ; exit 2 ;;
128 esac
129 shift
130done
131
871a9ac1 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
9b2f2e39 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
871a9ac1 161lett=`echo $prod | sed -e "s/LHC${year}\(.\).*/\1/"`
162suff=`echo $prod | sed -e "s/LHC${year}${lett}//"`
9b2f2e39 163
164redir="/dev/null"
871a9ac1 165if test $verb -gt 1 ; then redir=/dev/stderr ; fi
9b2f2e39 166
167# --------------------------------------------------------------------
871a9ac1 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/
bae153e5 179dprod=LHC${year}${lett}
180case x${suff} in
181 x_*) ;;
182 x);;
183 *) datd=sim ; esdd= ; dprod=${dprod}${suff};;
184esac
871a9ac1 185path=/alice/${datd}/20${year}/${prod}/
bae153e5 186store=${dest}/${dprod}/${prep}${paid}${post}
871a9ac1 187search="${esdd}${prep}${paid}${post}"
9b2f2e39 188if test $runn -gt 0 ; then
871a9ac1 189 path=`printf "${path}%09d/ESDs/${prep}${paid}${pass}${post}/" $runn`
9b2f2e39 190 store=`printf "${store}/%09d" $runn`
191 search=
192fi
193if test $qano -gt 0 ; then
871a9ac1 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
0151a6c6 198 search=${search}QA`printf %02d ${qano}`
871a9ac1 199 fi
9b2f2e39 200fi
201if test $arch -gt 0 ; then
871a9ac1 202 file=QA_archive.zip
9b2f2e39 203fi
871a9ac1 204base=`basename $file .root`
205if test "x$search" != "x" ; then search=${search}/ ; fi
206search="${search}${file}"
9b2f2e39 207
871a9ac1 208# --------------------------------------------------------------------
9b2f2e39 209cat <<EOF
210Settings:
211
212 Production: $prod
213 Year: $year
871a9ac1 214 Letter: $lett
215 Suffix: $suff
9b2f2e39 216 Pass: $pass
871a9ac1 217 Pass prefix: $prep
218 Pass postfix: $post
219 File: $file
9b2f2e39 220 Path: $path
221 Destination: $dest
222 Store: $store
223 Run number: $runn
224 Search string: $search
871a9ac1 225 Verbosity: $verb
226 Redirection: $redir
bae153e5 227EOF
9b2f2e39 228
229# --------------------------------------------------------------------
bae153e5 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
9b2f2e39 243j=0
244runs=
245for i in $files ; do
bae153e5 246 if test $maxf -gt 0 && test $j -ge $maxf ; then
247 break
248 fi
9b2f2e39 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
871a9ac1 254 o=${store}/${base}_${r}.root
9b2f2e39 255 else
256 d=${store}/${r}
257 mkdir -p $d
871a9ac1 258 o=${d}/${file}
9b2f2e39 259 fi
260 else
261 r=`echo $b | sed -e "s,/.*,,"`
871a9ac1 262 o=${store}/${base}_${r}.root
9b2f2e39 263 fi
bae153e5 264 runs="$runs $r"
265 printf "%3d/%3d: " $j $tot
266 mess -n "$i -> $o "
9b2f2e39 267 if test $noac -lt 1 && test ! -f $o ; then
bae153e5 268 # mess "alien_cp alien:${i} file:${o}"
269 mess " copying"
9b2f2e39 270 alien_cp alien:${i} file:${o} > ${redir} 2>&1
2dbde04b 271 if test -f $o ; then chmod g+rw ${o} ; fi
bae153e5 272 else
273 mess " exists"
9b2f2e39 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
bae153e5 277 (cd ${d} && unzip QAarchive.zip) > $redir 2>&1
278 fi
9b2f2e39 279 let j=$j+1
280done
281mess "Got a total of $j files for runs $runs"
282
283# --------------------------------------------------------------------
284#
285# EOF
286#
287
0151a6c6 288