]>
Commit | Line | Data |
---|---|---|
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 | # -------------------------------------------------------------------- | |
14 | verb=0 | |
15 | ||
16 | mess() | |
17 | { | |
18 | if test $verb -lt 1 ; then return ; fi | |
19 | echo $@ | |
20 | } | |
21 | ||
22 | # -------------------------------------------------------------------- | |
23 | usage() | |
24 | { | |
25 | cat <<EOF | |
26 | Usage: $0 -p PRODUCTION [OPTIONS] | |
27 | ||
28 | Options: | |
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 | ||
46 | If run number is set, get the parts of next-to-last merge of that run only. | |
47 | ||
48 | EOF | |
49 | } | |
50 | ||
51 | # -------------------------------------------------------------------- | |
52 | docheck=1 | |
53 | check_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 | |
59 | void ${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 | } | |
85 | EOF | |
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 | # -------------------------------------------------------------------- | |
96 | year="" | |
97 | prod="" | |
98 | pass=-1 | |
99 | prep="" | |
100 | post="" | |
101 | dest=. | |
102 | runn=0 | |
103 | qano=0 | |
104 | noac=0 | |
105 | arch=0 | |
106 | maxf=-1 | |
107 | file=QAresults.root | |
108 | ||
109 | while 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 | |
130 | done | |
131 | ||
132 | # -------------------------------------------------------------------- | |
133 | uid=`id -u` | |
134 | genv_file=/tmp/gclient_env_${uid} | |
135 | ||
136 | if test ! -f ${genv_file} ; then | |
137 | echo "No such file: ${genv_file}, please do alien-token-init" >/dev/stderr | |
138 | exit 1 | |
139 | fi | |
140 | . ${genv_file} | |
141 | alien-token-info | grep -q "Token is still valid" | |
142 | if test $? -ne 0 ; then | |
143 | echo "Token not valid, please re-new" > /dev/stderr | |
144 | exit 1 | |
145 | fi | |
146 | ||
147 | ||
148 | # -------------------------------------------------------------------- | |
149 | if test "x$prod" = "x" ; then | |
150 | echo "No production identifier given" > /dev/stderr | |
151 | exit 2 | |
152 | fi | |
153 | ||
154 | if 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 | |
160 | fi | |
161 | lett=`echo $prod | sed -e "s/LHC${year}\(.\).*/\1/"` | |
162 | suff=`echo $prod | sed -e "s/LHC${year}${lett}//"` | |
163 | ||
164 | redir="/dev/null" | |
165 | if test $verb -gt 1 ; then redir=/dev/stderr ; fi | |
166 | ||
167 | # -------------------------------------------------------------------- | |
168 | if test "x$post" != "x" ; then | |
169 | case $post in | |
170 | _*) ;; | |
171 | *) post="_${post}" ;; | |
172 | esac | |
173 | fi | |
174 | if test ${pass} -ge 0 ; then | |
175 | paid=pass${pass} | |
176 | fi | |
177 | datd=data | |
178 | esdd=ESDs/ | |
179 | dprod=LHC${year}${lett} | |
180 | case x${suff} in | |
181 | x_*) ;; | |
182 | x);; | |
183 | *) datd=sim ; esdd= ; dprod=${dprod}${suff};; | |
184 | esac | |
185 | path=/alice/${datd}/20${year}/${prod}/ | |
186 | store=${dest}/${dprod}/${prep}${paid}${post} | |
187 | search="${esdd}${prep}${paid}${post}" | |
188 | if test $runn -gt 0 ; then | |
189 | path=`printf "${path}%09d/ESDs/${prep}${paid}${pass}${post}/" $runn` | |
190 | store=`printf "${store}/%09d" $runn` | |
191 | search= | |
192 | fi | |
193 | if 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 | |
200 | fi | |
201 | if test $arch -gt 0 ; then | |
202 | file=QA_archive.zip | |
203 | fi | |
204 | base=`basename $file .root` | |
205 | if test "x$search" != "x" ; then search=${search}/ ; fi | |
206 | search="${search}${file}" | |
207 | ||
208 | # -------------------------------------------------------------------- | |
209 | cat <<EOF | |
210 | Settings: | |
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 | |
227 | EOF | |
228 | ||
229 | # -------------------------------------------------------------------- | |
230 | mkdir -p ${store} | |
231 | mess "Getting list of files from AliEn - can take minutes - be patient" | |
232 | mess "alien_find ${path} ${search}" | |
233 | files=`alien_find ${path} ${search} | grep -v "files found" 2> ${redir}` | |
234 | tot=0 | |
235 | for i in $files ; do | |
236 | let tot=$tot+1 | |
237 | done | |
238 | mess "Got a list of $tot files" | |
239 | if test $maxf -gt 0 && test $maxf -lt $tot ; then | |
240 | mess "Number of files to get limited to $maxf" | |
241 | tot=$maxf | |
242 | fi | |
243 | j=0 | |
244 | runs= | |
245 | for 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 | |
280 | done | |
281 | mess "Got a total of $j files for runs $runs" | |
282 | ||
283 | # -------------------------------------------------------------------- | |
284 | # | |
285 | # EOF | |
286 | # | |
287 | ||
288 |