]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/gridAnalysis.sh
1c586eda0cacb73d34e4076492efe92f27f11d85
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / gridAnalysis.sh
1 #!/bin/bash
2
3 # BEGIN_MANUAL
4 #       Script to help do PWGLF-Forward analsysis using AliEn
5 #       =====================================================
6 # First, one need to figure out what to analyse.  Visit the MonAlisa
7 # pages and find
8
9 #   * The list of runs and put that in a file - say runs.list
10 #   * The directory where the ESD files are stored 
11 #     - and the pattern that will match these for all runs 
12 #   * The directory where the MC ESD files are stored 
13 #     - and the pattern that will match these for all runs 
14
15 # Then, one needs to run this script in set-up mode e.g., 
16
17 #   $0 --what=setup  \
18 #       --name=LHC10h \
19 #       --real-dir=/alice/data/2010/LHC10h \
20 #       --real-pattern=ESDs/pass2/*/AliESDs.root \
21 #       --mc-dir=/alice/sim/LHC10h11 \
22 #       --mc-pattern=*/AliESDs.root \
23 #       --runs=LHC10.list \
24 #       --par
25
26 # Note, all the settings are written to the file .config in the
27 # current directory, so you do not need to give the parameters at
28 # subsequent steps.  As an alternative to giving the parameters, one
29 # can create the file by hand.
30
31 # Next, we need to generate the corrections.  Do 
32
33 #   $0 --what=corrs 
34
35 # and wait for the jobs to finish and terminate.  If 'watching' is
36 # turned off, one can also monitor output on MonAlisa, and then when
37 # enough has finished, execute
38
39 #   $0 --what=corrs --step=terminate 
40
41 # enough times to get the final merged result.  Next, we need to
42 # extract and upload the corrections to our local corrections folder
43
44 #   $0 --what=corrs --step=upload 
45 #   $0 --what=corrs --step=draw
46
47 # Now we can submit our AOD generation jobs.  Do 
48
49 #   $0 --what=aod
50
51 # and wait for the jobs to finish and terminate.  If 'watching' is
52 # turned off, one can also monitor output on MonAlisa, and then when
53 # enough has finished, execute
54
55 #   $0 --what=aod --step=terminate 
56
57 # enough times to get the final merged result.  Next, we need to
58 # download the results and we draw the summary results
59
60 #   $0 --what aod --step=draw 
61
62 # Now, we should do the dN/deta analysis.  Do 
63
64 #   $0 --what=dndeta
65
66 # and wait for the jobs to finish and terminate.  If 'watching' is
67 # turned off, one can also monitor output on MonAlisa, and then when
68 # enough has finished, execute
69
70 #   $0 --what=dndeta --step=terminate 
71
72 # enough times to get the final merged result.  If you passed the
73 # option --sys=1 in the setup phase, then this will run 3 jobs for
74 # real and MC each - one for INEL, INEL>0, and NSD (V0-AND). Next, we
75 # need to download the results and we can draw the summary and final
76 # plot
77
78 #   $0 --what=dndeta --step=draw 
79
80 # When running the trains, one can pass additional options to the
81 # train after the special option -- e.g., 
82 #   
83 #   $0 --what=aod -- --verbose=2 --branches --satellite
84
85 # Enjoy
86
87 # Comments, questions, bugs, flames, suggestions, etc. should be sent
88 # to Christian Holm Christensen <cholm@nbi.dk>
89
90 # END_MANUAL
91 if test ! -f $ALICE_ROOT/PWGLF/FORWARD/analysis2/baseAnalysis.sh  ; then 
92     echo "baseAnalysis not found!" > /dev/stderr 
93     exit 1
94 fi
95 . $ALICE_ROOT/PWGLF/FORWARD/analysis2/baseAnalysis.sh 
96
97 runs=
98 mcruns=
99 par=0
100 real_dir=
101 real_pat=
102 mc_dir=
103 mc_pat=
104 my_real_dir=
105 my_mc_dir=
106 watch=0
107
108 # === Various functions ==============================================
109
110
111 # === Implement base functions =======================================
112 # --- Usage ----------------------------------------------------------
113 setup_usage()
114 {
115     cat <<EOF
116   -r,--runs=FILENAME        Specify list of runs file ($runs)
117   -R,--mc-runs=FILENAME     Specify list of MC runs file ($mcruns)
118   -d,--real-dir=ALIEN_DIR   Directory holding real data ($real_dir)
119   -p,--real-pattern=PATTERN Glob pattern to match when searching ($real_pat)
120   -D,--mc-dir=ALIEN_DIR     Directory holding MC data ($mc_dir)
121   -P,--mc-pattern=PATTERN   Glob pattern to match when searching ($mc_pat)
122   -W,--watch                Watch for job status and terminate automatically
123   -a,--par                  Use par files ($par)
124 EOF
125 }
126 handle_setup_option()
127 {
128     local arg="$1"
129     local opt="$2"
130     # echo "Grid: Processing '$arg' ('$opt')"
131     case $arg in 
132         -r|--runs)         runs=$opt     ;; 
133         -R|--mc-runs)      mcruns=$opt   ;;
134         -d|--real-dir)     real_dir=$opt ;;
135         -p|--real-pattern) real_pat=$opt ;; 
136         -D|--mc-dir)       mc_dir=$opt   ;; 
137         -P|--mc-pattern)   mc_pat=$opt   ;; 
138         -W|--watch)        let watch=\!$watch ;;
139         -a|--par)          par=1         ;;
140         *) echo "$0: [SETUP] Unknown option $arg"  ; exit 1 ;; 
141     esac
142 }    
143 # --- Extract corrections --------------------------------------------
144 terminate()
145 {
146     script Terminate.C 
147 }
148
149 # --- Extract and upload ---------------------------------------------
150 extract_upload()
151 {
152     echo "=== Download, extract, and uploade in `basename $PWD` ==="
153     download
154     for i in *.zip ; do 
155         if test ! -f $i ; then continue ; fi 
156         if test $noact -gt 0 ; then continue ; fi
157         local d=`basename $i .zip` 
158         if test ! -d $d ; then 
159             mkdir $d 
160         fi
161         cd $d 
162         if test ! -f .zip ; then 
163             echo "= Unpacking ../$i"
164             unzip ../$i > /dev/null 2>&1
165             touch .zip 
166         fi
167         extract ../Extract.C 
168         upload
169         cd ..
170     done
171 }
172
173 # --- Draw -----------------------------------------------------------
174 draw()
175 {
176     local scr=$1  ; shift
177     # local args=$1 ; shift
178     download 
179     for i in *.zip ; do 
180         if test "X$i" = "X*.zip" ; then continue ; fi
181         echo "Will extract $i"
182         d=`basename $i .zip` 
183         if test ! -d $d ; then 
184             mkdir -p $d 
185             unzip $i -d $d
186         fi
187         (cd $d && _draw $scr $@)
188     done
189 }
190 dndeta_draw()
191 {
192     download 
193     for i in *.zip ; do 
194         if test "X$i" = "X*.zip" ; then continue ; fi
195         echo "Will extract $i"
196         d=`basename $i .zip` 
197         if test ! -d $d ; then 
198             mkdir -p $d 
199             unzip $i -d $d
200         fi
201         _dndeta_draw $d ../Draw.C $@
202     done
203 }
204
205 # === Script specific functions ======================================
206 # --- Extract corrections --------------------------------------------
207 download()
208 {
209     if test -f .download ; then 
210         echo "Already downloaded in `basename $PWD`"
211         return 0 
212     fi
213     script Download.C 
214     touch .download
215 }
216     
217 # --- Get the grid home dir ------------------------------------------
218 outputs()
219 {
220     l=`aliroot -l -b <<EOF
221 gSystem->RedirectOutput("/dev/null");
222 TGrid::Connect("alien://");
223 gSystem->RedirectOutput(0);
224 std::cout << gGrid->GetHomeDirectory() << std::endl;
225 EOF`
226     my_real_dir="$l/${name}_aod_${now}/output"
227     my_mc_dir="$l/${name}_mcaod_${now}/output"
228 }
229
230
231 run_for_acc()
232 {
233     local r=`grep -v ^# $runs | awk '{FS=" \n\t"}{printf "%d\n", $1}' | head -n 1` 
234     if test x$r = "x" || test $r -lt 1; then 
235         echo "No run for acceptance correction specified" > /dev/stderr 
236         exit 1
237     fi
238     echo $r 
239 }
240
241 # --- Dump the setup -------------------------------------------------
242 dump_setup()
243 {
244     local out=$1 
245     cat >> ${out} <<-EOF 
246         # Real data 
247         runs=${runs}
248         real_dir=${real_dir}
249         real_pat=${real_pat}
250         # Simulated data
251         mcruns=${mcruns}
252         mc_dir=${mc_dir}
253         mc_pat=${mc_pat}
254         # Output directories 
255         my_real_dir=${my_real_dir}
256         my_mc_dir=${my_mc_dir}
257         # Other options 
258         par=${par}
259         watch=${watch}
260         EOF
261 }
262
263 # --- Run set-ups ----------------------------------------------------
264 setup()
265 {
266     _setup $@
267 }    
268
269
270 # --- Check settings -------------------------------------------------
271 check_setup()
272 {
273     check_token
274
275     if test "x$runs" = "x" || test ! -f $runs ; then 
276         echo "List of run file $runs not found" > /dev/stderr 
277         exit 1
278     fi
279     if test "x$mcruns" = "x" ; then mcruns=$runs ; fi 
280     if test ! -f $mcruns ; then 
281         echo "List of MC runs file $mcruns not found" > /dev/stderr 
282         exit 1
283     fi
284     if test "x$real_dir" = "x" ; then 
285         echo "No real data directory specified" > /dev/stderr 
286         exit 1
287     fi
288     if test "x$mc_dir" = "x" ; then 
289         echo "No MC data directory specified" > /dev/stderr 
290         exit 1
291     fi
292     if test "x$real_pat" = "x" ; then 
293         echo "No real data pattern specified" > /dev/stderr 
294         exit 1
295     fi
296     if test "x$mc_pat" = "x" ; then 
297         echo "No MC data pattern specified" > /dev/stderr 
298         exit 1
299     fi
300
301 }
302
303 # --- Show the setup -------------------------------------------------
304 print_setup()
305 {
306     cat <<-EOF
307         Real data:
308           Run file:             ${runs}
309           Directory:            ${real_dir}
310           Pattern:              ${real_pat}
311           Output:               ${my_real_dir}
312         MC data:
313           Run file:             ${mcruns}
314           Directory:            ${mc_dir}
315           Pattern:              ${mc_pat}
316           Output:               ${my_mc_dir}
317         Use PAR files:          ${par}
318         EOF
319 }
320
321
322
323 # --- Make URI -------------------------------------------------------
324 # Must modify URL 
325 url_opts()
326 {
327     local mc=$1         ; shift
328     local type=$1       ; shift 
329     local trig=$1       ; shift
330
331     local uopt="&merge=50&split=50&aliroot=last,regular"
332
333     local dir=$real_dir
334     local pat=$real_pat
335     local rl=$runs
336     local tree=esdTree
337
338     if test $mc -gt 0 ; then 
339         dir=$mc_dir
340         pat=$mc_pat
341         rl=$mcruns
342     fi
343     case $type in 
344         *dndeta|*multdists) 
345             uopt="${uopt}&concat"
346             tree=aodTree 
347             # Modify for input dir for our files
348             dir=$my_real_dir
349             pat="*/AliAOD.root"
350             if test $mc -gt 0 ; then 
351                 dir=$my_mc_dir
352             fi
353             ;;
354     esac
355     if test $mc -gt 0; then 
356         uopt="${uopt}&mc"
357     fi
358     if test $par -gt 0 ; then 
359         uopt="${uopt}&par"
360     fi
361     if test x$uuopts != x ; then 
362         uopt="${uopt}&${uuopts}"
363     fi
364     url="alien://${dir}?run=${rl}&pattern=${pat}${uopt}#${tree}"    
365 }
366
367     
368 # --- Run the train --------------------------------------------------
369 # Usage:
370
371 allAboard()
372 {
373     local type=$1 ; shift
374     local trig=$1 ; shift
375     opts="--batch"
376     _allAboard "$type" "$trig" $@ 
377
378     if test $watch -lt 1 ; then 
379         cat <<-EOF
380         Check https://alimonitor.cern.ch/users/jobs.jsp for progress 
381         
382         Remember to do 
383         
384           $0 --what=... --step=terminate
385         
386         until the final merge stage to get the results. 
387         EOF
388         
389         case $type in 
390             *corr|*esd) 
391                 cat <<-EOF
392         Then, do 
393         
394           $0 --what=... --step=upload 
395         
396         to upload the results to our local corrections store. 
397         EOF
398                 ;; 
399             *aod|*dndeta)
400                 cat <<-EOF
401         Then, do 
402          
403           $0 --what=... --step=draw
404         
405         to get a PDF of the diagnostics histograms and the final plots. 
406         EOF
407                 ;;
408         esac
409     else 
410         echo "Now waiting for jobs to finish"
411         (cd ${nme}_${now} && \
412             nice aliroot -l -b -x -q Watch.C\(1\) 2>&1 | \
413             tee watch.log > /dev/null &)
414     fi
415 }
416
417 # --- Collect a directory --------------------------------------------
418 collect_files()
419 {
420     local dir=$1 ; shift
421     local d=$1 ; shift 
422     local M=$1 ; shift 
423     local out=$1 ; shift
424     local r=$1 ; shift
425     local files="$1"
426
427     for ad in $dir/root_archive_* ; do 
428         if test ! -d $ad ; then continue ; fi 
429         local r=`basename $ad | sed 's/root_archive_0*//'` 
430         _collect_files "$ad" "$d" "$M" "$out" "$r" "$files"
431     done # for ad in ...
432 }
433
434     
435 # === Procedual code =================================================
436 runIt $@
437
438 #
439 # EOF
440 #
441