]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/qa/RunQA.sh
Fixes for pA indenfication of events
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / qa / RunQA.sh
1 #!/bin/bash
2 #
3 # This is deprecated.  Use RunQAMT.sh instead
4 #
5 jobid=0
6 top=.
7 verb=0
8 nodw=0
9 notr=0
10 norn=0
11 maxf=-1
12 last="unknown"
13 lock=
14
15
16 export PATH=$PATH:$ALICE_ROOT/PWGLF/FORWARD/analysis2/qa:../scripts
17
18 # --- Handle exit ----------------------------------------------------
19 handle_exit()
20 {
21     echo "Removing $lock"
22     rm -f $lock
23 }
24 trap handle_exit EXIT 
25
26 # --- Usage information ----------------------------------------------
27 usage()
28
29 cat <<EOF
30 Usage: $0 -j JOBID [OPTIONS]
31
32 Options:
33         -h.--help                  This help
34         -j,--jobid      JOBID      Job id from MonALisa                [$jobid]
35         -d,--nodownload            Do not download                     [$nodw]
36         -t,--notrend               Do not make new trend tree          [$notr]
37         -r,--no-run                Do not make per-run info            [$norn]
38         -o,--output     DIRECTORY  Where to store the result           [$top]
39         -v,--verbose               Be verbose                          [$verb]
40         -m,--max        NUMBER     Maximum number of runs to get       [$maxf]
41         -s,--skip-lines NUMBER     Number of lines to skip in job list [$skip]
42 EOF
43 }     
44
45 # --- Messages -------------------------------------------------------
46 mess()
47 {
48     if test $verb -lt 1 ; then return ; fi 
49     last="$@"
50     echo $@
51
52
53 # --- Get parts of the passed path -----------------------------------
54 get_parts()
55 {
56     y=$1 ; shift 
57     p=$1 ; shift 
58     r=$1 ; shift 
59     e=$1 ; shift 
60     x=$1 ; shift 
61     r=$1 
62     
63     P=`echo $x | sed 's/.*pass\([0-9]*\).*/\1/'`
64     R=`echo $x | sed -n "s/.*pass${P}_//p"` 
65     Q=`echo $x | sed -n 's/pass.*//p'`
66     Y=`echo $p | sed 's/LHC\(..\).*/\1/'` 
67     L=`echo $p | sed "s/LHC${Y}\(.\).*/\1/"` 
68     S=`echo $p | sed "s/LHC${Y}${L}//"` 
69
70     dprod=LHC${Y}${L}
71     case x$S in 
72         x) ;; 
73         x_*) ;; 
74         *) dprod=${dprod}${S} ;; 
75     esac
76     
77     case x$r in 
78         xQA*) q=`echo $r | sed 's/QA//'` ;; 
79         x) ;;
80         *) ;;
81     esac
82             
83     opts="-p $p -P $P"
84     if test "x$R" != "x" ; then opts="$opts -R $R" ; fi 
85     if test "x$q" != "x" ; then opts="$opts -q $q" ; fi 
86     if test "x$Q" != "x" ; then opts="$opts -Q $Q" ; fi 
87
88     dest="${dprod}/${Q}pass${P}"
89     if test "x$R" != "x" ; then dest="${dest}_${R}" ; fi 
90
91 }
92
93 # --- Get the options ------------------------------------------------
94 skip=1
95 jobUrl="http://alimonitor.cern.ch/prod/jobs.jsp?t="
96 get_opts() { 
97     wget -q ${jobUrl}${jobid} -O job.html
98     p=`grep "/catalogue/index.jsp?path" job.html | head -n $skip | tail -n 1 | sed -e 's,.*/alice/data/\([^<]*\)<.*,\1,' | tr '/' ' '` 
99     rm -f job.html 
100
101     get_parts $p
102
103
104 # --- Trapping errors ------------------------------------------------
105 handle_err()
106 {
107     echo "Got an error: $last"
108     exit 1
109
110 enable_trap ()
111 {
112     # echo "Enabling trapping errors"
113     trap handle_err ERR 
114     # trap -p ERR
115 }
116 disable_trap ()
117 {
118     # echo "Disabling trapping errors"
119     trap - ERR
120     # trap -p ERR
121 }
122
123
124 # --- Deprecated -----------------------------------------------------
125 cat <<EOF
126 This script is deprecated.  You should use the more advanced script RunQAMT.sh 
127 which process the runs in parallel and in general is more flexible
128 EOF
129 read -n 1 -i n -p "Do you want to continue [yN]? "
130 case $REPLY in 
131     y|Y) echo "" ;; 
132     *) exit 0 ;; 
133 esac
134
135
136 # --- comamnd line ---------------------------------------------------
137 while test $# -gt 0 ; do 
138     case $1 in 
139         -h|--help)        usage   ; exit 0 ;;
140         -j|--jobid)       jobid=$2; shift  ;;
141         -o|--output)      top=$2  ; shift  ;; 
142         -d|--no-download) nodw=1  ;;
143         -t|--no-trend)    notr=1  ;;
144         -r|--no-run)      norn=1  ;; 
145         -v|--verbose)     verb=1  ;;
146         -s|--skip-lines)  skip=$2 ; shift ;; 
147         -m|--max)         maxf=$2 ; shift ;; 
148         *) echo "Unknown option $1" > /dev/stderr ; exit 1 ;; 
149     esac
150     shift 
151 done
152
153 # --- Sanity ---------------------------------------------------------
154 if test $jobid -lt 1 ; then 
155     echo "No JOBID specified" > /dev/stderr 
156     exit 1
157 fi
158
159 # --- Extract options -----------------------------------------------
160 get_opts $jobid
161 if test "x$opts" = "x" ; then 
162     echo "No options found" 
163     rm -f $lock
164     exit 1
165 fi
166
167 # --- Display job setting --------------------------------------------
168 cat <<EOF
169 ----------------------------------------------------------------------
170 Job id:           $jobid
171 Top directory:    $top
172 Don't download:   $nodw
173 Don't make tree:  $notr
174 Download options: $opts
175 Destination:      $dest
176 Skip lines:       $skip
177 Max # of runs:    $maxf
178 ----------------------------------------------------------------------
179 EOF
180
181 # --- Lock -----------------------------------------------------------
182 lock=${top}/${dest}/.lock
183 if test -f $lock ; then 
184     echo "Another QA process is already running:" > /dev/stderr 
185     echo "Content of ${top}/${dest}/.lock:" > /dev/stderr 
186     cat $lock > /dev/stderr 
187     trap - EXIT
188     exit 1
189 fi
190
191 now=`date`
192 cat <<EOF > $lock
193 Process: $$ 
194 User:    $USER 
195 Start:   $now 
196 EOF
197
198
199 # --- Download the files ---------------------------------------------
200 if test $nodw -lt 1 ; then 
201     mess "Running getQAResults.sh $opts -d $top -n "
202     getQAResults.sh $opts -d $top -T -v -v -i -m $maxf
203 else 
204     mess "Not downloading"
205 fi
206
207 # --- Now run the QA code -------------------------------------------
208
209 mess "Now running code"
210 enable_trap
211 savdir=`pwd`
212 mess "Change directory to $top/$dest"
213 cd $top/${dest} 
214
215 disable_trap
216 trap - ERR
217 trap -p ERR 
218 mess "List of trend_<x>.html files"
219 idx=`ls trend_*_*.html 2>/dev/null`
220 mess "Removing indeces"  
221 rm -f index.html
222 for i in $idx ; do 
223     if test -f $i ; then rm -f $i ; fi
224 done 
225
226 what=3
227 if test $notr -gt 0 ; then let what=$what^0x2 ; fi
228 if test $norn -gt 0 ; then let what=$what^0x1 ; fi
229
230 scr=$ALICE_ROOT/PWGLF/FORWARD/analysis2/qa/RunQA.C
231 mess "Running root -l -b -q ${scr}\(\".\",1,-1,$what\)"
232
233 enable_trap
234 root -l -b -q ${scr}\(\".\",1,-1,$what\)
235 trap - ERR
236 disable_trap
237
238 idx=`ls trend_*_*.html 2>/dev/null` 
239 rm -f index.html
240 for i in $idx ; do 
241     echo "making index.html point to $i"
242     cat $i | \
243         sed -e "s,index.html,../index.html," \
244             -e "s,!--JOBID--,a target='_blank' href='${jobUrl}${jobid}'>Job</a," \
245         > index.html  
246     cp index.html $i 
247 done 
248 if test ! -f index.html ; then 
249     echo "No index file found" 
250     exit 1
251 fi
252 chmod g+rw  index.html
253 chmod g+rw .  > /dev/null 2>&1
254
255 style= 
256 if test -f $ALICE_ROOT/PWGLF/FORWARD/analysis2/qa/style.css ; then 
257     style=$ALICE_ROOT/PWGLF/FORWARD/analysis2/qa/style.css
258 elif test -f $savdir/style.css ; then 
259     style=$savdir/style.css 
260 fi 
261    
262 if test x$style != x ; then 
263     rm -f style.css 
264     cp $style .
265     chmod g+rw style.css
266 fi
267
268 cat <<EOF
269
270 Finished running QA for jobid $jobid.  
271 Output is stored in  $top/${dest} 
272
273 EOF
274
275 # --- Make index.html ------------------------------------------------
276 cd ..
277 date=`date`
278 period=`pwd`
279 period=`basename $period`
280 rm -f index.html
281 cat <<EOF > index.html
282 <html>
283 <head>
284 <title>$period</title>
285 <LINK REL="stylesheet" href="style.css">
286 </head>
287 <body>
288 <h1>$period</h1>
289 <ul>
290 EOF
291 for i in * ; do 
292     if test ! -d $i ; then continue ; fi 
293     echo "<li><a href='$i'>$i</a></li>" >> index.html 
294 done
295 cat <<EOF >> index.html
296 </ul>
297 <div class='jobid'>
298    
299 </div>
300 <div class='back'>
301   <a href="../">Back</a>
302 </div>
303 <div class='change'>
304   Last update: $date
305 </div>
306 </body>
307 </html>
308 EOF
309 chmod g+rw index.html 
310 chmod g+rw .  > /dev/null 2>&1
311 if test x$style != x ; then 
312     rm -f style.css
313     cp $style .
314     chmod g+rw style.css
315 fi
316
317 # --- Make index.html ------------------------------------------------
318 cd ..
319 rm -f index.html
320 cat <<EOF >index.html
321 <html>
322 <head>
323 <title>QA for the FMD</title>
324 <LINK REL="stylesheet" href="style.css">
325 </head>
326 <body>
327 <h1>QA for the FMD</h1>
328 <p>
329 For more information, see <a href='https://twiki.cern.ch/twiki/bin/viewauth/ALICE/FMDQA'>TWiki pages</a>
330 </p>
331 <ul>
332 EOF
333 for i in * ; do 
334     if test ! -d $i ; then continue ; fi 
335     echo "<li><a href='$i'>$i</a></li>" >> index.html 
336 done
337 cat <<EOF >> index.html
338 </ul>
339 <div class='change'>
340 Last update: $date
341 </div>
342 </body>
343 </html>
344 EOF
345 chmod g+rw index.html 
346 chmod g+rw .  > /dev/null 2>&1
347 if test x$style != x ; then 
348     rm -f style.css
349     cp $style . 
350     chmod g+rw style.css
351 fi
352
353 cd $savdir
354 rm -f $lock
355
356
357 # EOF
358 #
359
360
361
362