]> git.uio.no Git - u/mrichter/AliRoot.git/blob - share/alirun
0bf080f5ec45d47f96d4bc2d0ee92c25a2cd9e2e
[u/mrichter/AliRoot.git] / share / alirun
1 #!/bin/sh
2 #############################################################################
3 # alirun - a shell script to run AliRoot
4 #############################################################################
5 #
6 # modification history
7 # $Log$
8 # Revision 1.1  2001/01/26 21:22:02  hristov
9 # Major upgrade of AliRoot code
10 #
11 #
12 # SYNOPSIS
13 # alirun [[-d <TPC+ITS+..>|-all]]
14 #         [-f <hits file>]
15 #         [-o <output directory>]
16 #         [-split]
17 #         [-C <Config.C>]
18 #         [-p <particle#>]
19 #         [-seed <seed for random number generator>]
20 #         [-n <event #>]
21 #         <-c <command ...>>
22 #
23 # DESCRIPTION
24 # This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode.
25 #
26 # CONFIGURATION OPTIONS
27 # The following options are used to configure AliRoot session.
28
29 # -c <command1 command2 ...>
30 #    This option must be the last one on alirun command line and specifies the sequence of alirun commands to be executed. At present, the following commands are supported:
31 #
32 #     - Hits ................ simulation 
33 #     - Digits .............. digitisation
34 #     - SDigits ............. creation of sumable digits
35 #     - SDigits2Digits ...... conversion SDigits->Digits 
36 #
37 # -d <TPC+ITS+..> | -d all | -all 
38 #    Selects detector for which <command> will be run. If none of these options was specified, an internal loop in AliRoot over all active detectors is assumed.  Otherwise, for each detector, input file(s) are re-opened in update mode, command (or macro) is executed and the file is closed. Option -all is equivalent to MUON+RICH+TOF+ITS+TPC+PHOS+PMD+CASTOR+TRD. Detectors are processed in order as they appear on the command line.   
39 #
40 # -f <file>
41 #    Name of the top level Root file where Root trees will be stored (branches may reside in the same file or be diverted to separate files (see -split option). By default, file is named galice.root.
42 #
43 # -o <directory> 
44 #    A directory where output file(s) will be stored. If does not exist, it will be created. If not specified, current directory is used.
45 #
46 # -split
47 #    If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
48 #
49 #    The layout of output directory is the following:
50 #    
51 #    <directory>
52 #     |-- Digits.<detector>.root
53 #     |-- SDigits.<detector>.root
54 #     |-- Hits.root
55 #     |-- Kine.root
56 #     |-- Reco.root
57 #     `-- galice.root
58 #
59 # -C <macro.C>
60 #    An alternative to Config.C macro which contains AliRoot configuration. 
61 #
62 # -p <n> 
63 #    Number of primary particles to be generated by selected event generator. Required for Hits command, Ignored by Digits command (digitisation is performed for all particles found in input file). Default value is 50. 
64 #   
65 # -seed <n> 
66 #    Seed for random number generator (used to initialise TRandom3(n)).  
67 #   
68 # -n <n>
69 #    Number of events to generate (not yet implemented).  
70
71 # RUN OPTIONS
72 # These options define run time appearance of the AliRoot session.
73 #
74 # -help
75 #    Display usage.
76 #
77 # -verbose
78 #    Switch verbose screen output on. 
79 #
80 # -quiet
81 #    Switch verbose output off. Output is redirected to a file which is shown on standard output only if <command> returns non zero status.
82
83 # -fork
84 #    Forks all digitisation processes in background, using LSF if available, in order to speed up execution. It cannot be used in present design where only tree branches are diverted to separate files as top level Root file must be kept open in update mode.
85
86 # -trace
87 #    Show trace of execution of shell commands.
88 #   
89 # -debug
90 #    Execute AliRoot under gdb. 
91 #
92 # -break <breakpoint>
93 #    Execute AliRoot under gdb and set <breakpoint>.
94 #
95 # -makeman
96 #    Create man page for alirun. 
97 #   
98 # EXAMPLES
99 #    Run sumulation for 1 event, 100 particles and store output in file test.root in /tmp/event.1 directory:
100
101 #    alirun -o /tmp/event.1 -f test.root -p 100 -verbose -c Hits
102 #
103 #    Run sumulation for 1 event, 100 particles and store output in default file galice.root in /tmp/event.1 directory. In adition, divert branches of TreeD,TreeR and TreeK into separate files:
104 #    
105 #    alirun -o /tmp/event.2 -split -p 100 -verbose -c Hits
106 #
107 #   Use output from first step and create TOF and RICH digits. Output is in the same direcory and in file test.root
108 #
109 #    alirun -d TOF+RICH -o /tmp/event.1 -f test.root  -verbose -c Digits
110 #
111 #   Use output from second step and create digits for all detectors. Output is in the same direcory and branches are diverted to separate files:
112 #
113 #    alirun -d all -o /tmp/event.2 -split  -verbose -c Digits
114 #
115 # AUTHOR:
116 #    Predrag Buncic, e-mail: Predrag.Buncic@cern.ch 
117 #
118 # CREATION DATE:
119 #    06-Nov-2000
120 #
121 #C<
122 ###########################################################################
123
124 ###########################################################################
125 AliRun()
126 ###########################################################################
127 {
128    printf "Usage: alirun [[-d <TPC+ITS+..>|-all]]\n"
129    printf "              [-f <hits file>]\n"
130    printf "              [-o <output directory>]\n"
131    printf "              [-split]\n"
132    printf "              [-C <Config.C>]\n"
133    printf "              [-p <particle#>]\n"
134    printf "              [-seed <seed for random number generator>]\n"
135    printf "              [-n event #]\n"
136    printf "              <-c <command ...>>\n"
137    exit
138 }
139
140 ###########################################################################
141 Mktemp()
142 ###########################################################################
143 {
144 #  mktemp -qu /tmp/alirun.$$.XXXXXX
145    echo /tmp/alirun.$$. 
146 }
147
148 ###########################################################################
149 Cleanup()
150 ###########################################################################
151 {
152   if [ -d $ALIRUN_TMPDIR ]
153   then
154     rm -rf $ALIRUN_TMPDIR
155   fi
156 }
157
158 ###########################################################################
159 AliRoot()
160 ###########################################################################
161 {
162   case $1 in
163     Hits)
164        macro=`HitsMacro`
165        ;;
166     Digits)
167        macro=`DigitsMacro Hits2Digits`
168        ;;
169     SDigits)
170        macro=`DigitsMacro Hits2SDigits`
171        ;;
172     SDigits2Digits)
173        macro=`DigitsMacro SDigits2Digits`
174        ;;
175     *.C|*.C\(*\)) 
176        macro=$1
177        ;;
178     *)
179        printf "Unknown command: %s. Terminating...\n" $1
180        exit 255
181        ;;
182   esac
183
184   if [ "$2" != "" ]
185   then  
186     CONTEXT="<"$2">"
187   else
188     CONTEXT="<"None">"
189   fi
190   
191   stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT}
192
193   hr="========================================"
194
195   if [ "$VERBOSE" = "FALSE" ]
196   then
197     printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr
198   fi > $stdout
199
200   if [ "$DEBUG" = "TRUE" ]
201   then
202   cat<<EOF>$ALIRUN_TMPDIR/gdb
203 b main
204 r -q -b $macro
205 disable breakpoints
206 b $BREAK
207 c
208 where
209 EOF
210     $ECHO gdb -q -x $ALIRUN_TMPDIR/gdb aliroot 
211   else
212     if [ "$VERBOSE" = "TRUE" ] 
213     then
214       $ECHO aliroot -q -b $macro 
215     else
216       $ECHO aliroot -q -b $macro > $stdout 2>&1
217       if [ $? -ne 0 ] 
218       then
219         echo "- "aliroot -q -b " "$1" "$CONTEXT
220         cat $stdout
221         exit
222       else
223         echo "+ "aliroot -q -b " "$1" "$CONTEXT
224       fi
225     fi
226   fi
227
228 }
229
230
231 ###########################################################################
232 HitsMacro()
233 ###########################################################################
234 {
235   macro=$ALIRUN_TMPDIR/Simulate.C 
236
237   cat <<EOF> $macro
238
239 ////////////////////////////////////////////////////////////////////////////
240 void Simulate()
241 {
242    gAlice->Init(gSystem->Getenv("CONFIG"));
243
244    gAlice->Run(1);
245 }
246 ////////////////////////////////////////////////////////////////////////////
247
248 EOF
249  echo $macro
250 }
251
252 ###########################################################################
253 DigitsMacro()
254 ###########################################################################
255 {
256   mode=$1
257
258   macro=$ALIRUN_TMPDIR/Digitize.C 
259
260   cat <<EOF> $macro
261
262 ////////////////////////////////////////////////////////////////////////////
263 void Digitize()
264 {
265    gAlice->OpenBaseFile("update");
266
267    if (gAlice) delete gAlice;
268    
269    AliRun *gAlice = (AliRun*)gDirectory->Get("gAlice");
270   
271    gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
272 }
273 ////////////////////////////////////////////////////////////////////////////
274
275 EOF
276  echo $macro
277 }
278
279 ###########################################################################
280 AliRunMakeman()
281 ###########################################################################
282 {
283    mangen -n tool $0
284    if [ $? -eq 0 ]
285    then
286      if [ -d ../man/man4 ] 
287      then
288        mv $0.? ../man/man4
289      fi
290    fi
291    exit
292 }
293
294 ###########################################################################
295 AliRunMacro()
296 ###########################################################################
297
298   AliRoot $*
299 }
300
301 ###########################################################################
302 AliRunHits()
303 ###########################################################################
304
305   AliRoot Hits
306 }
307
308 ###########################################################################
309 AliRunDigits()
310 ###########################################################################
311 {
312   if [ "$DETECTORS" = "" ]
313   then
314     AliRoot Digits 
315   else
316     for det in $DETECTORS
317     do
318       CONFIG_DETECTOR=$det; export CONFIG_DETECTOR 
319       if [ "$FORK" = "TRUE" ]
320       then
321         if [ "$LSF_FORK" = "TRUE" ]
322         then
323           lsrun AliRoot Digits $CONFIG_DETECTOR
324         else
325           AliRoot Digits $CONFIG_DETECTOR &
326         fi
327       else
328         AliRoot Digits $CONFIG_DETECTOR
329       fi
330     done
331     wait
332   fi
333 }
334
335
336
337 ###########################################################################
338
339 ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD"; export ALL
340 DETECTORS="";                                        export DETECTORS
341 CONFIG_FILE="galice.root";                           export CONFIG_FILE
342 CONFIG=$ALICE_ROOT/macros/Config.C;                  export CONFIG
343 CONFIG_NPARTICLES=50;                                export CONFIG_NPARTICLES
344 CONFIG_PATH=`pwd`;                                   export CONFIG_PATH
345
346 ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
347
348 DEBUG="FALSE"
349 BREAK=""
350 VERBOSE="TRUE"
351 OUTPUT=.
352 CMDLIST="Usage"
353 FORK="FALSE"
354 FORK_LSF="FALSE"
355 ECHO=""
356
357 if [ -x /usr/local/lsf/bin/lsrun ] 
358 then
359   FORK_LSF="TRUE"  
360 fi
361
362 for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C
363 do
364   if [ -f $config ]
365   then 
366     CONFIG=$config; export CONFIG
367     break
368   fi
369 done
370
371 for param in $*
372 do
373     case $param in
374         -debug)
375             shift 1
376             DEBUG="TRUE"
377             ;;
378         -break)
379             shift 1
380             DEBUG="TRUE"
381             BREAK=$1
382             ;;
383         -trace)
384             shift 1
385             set -vx
386             ;;
387         -echo)
388             shift 1
389             ECHO="echo "
390             ;;
391         -verbose)
392             shift 1
393             VERBOSE="TRUE"
394             ;;
395         -quiet)
396             shift 1
397             VERBOSE="FALSE"
398             ;;
399         -help)
400             AliRun
401              ;;
402         -makeman)
403             AliRunMakeman
404              ;;
405         -fork)
406             shift 1
407             FORK="TRUE"
408             ;;
409         -d)
410             shift 1
411             list=$1
412             if [ "$list" = "all" ]
413             then
414                DETECTORS=$ALL
415             else
416                DETECTORS=`echo $list | sed 's/+/ /g'`
417             fi
418             ;;
419         -all)
420             shift 1
421             DETECTORS=$ALL
422             ;;
423         -o)
424             shift 1
425             OUTPUT=$1
426             ;;
427         -split)
428             shift 1
429             CONFIG_SPLIT_FILE="TRUE"; export  CONFIG_SPLIT_FILE
430             ;;
431         -f)
432             shift 1
433             CONFIG_FILE=$1; export CONFIG_FILE 
434             ;;
435         -n)
436             shift 1
437             NEVENTS=$1
438             ;;
439         -p)
440             shift 1
441             CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES
442             ;;
443         -seed)
444             shift 1
445             CONFIG_SEED=$1; export CONFIG_SEED
446             ;;
447         -c) 
448             shift 1
449             CMDLIST=$*
450             break
451             ;;
452         -C) 
453             shift 1
454             CONFIG=$1; export CONFIG
455             ;;
456         *)
457             shift 1
458             ;;
459     esac
460 done
461
462
463 if [ `dirname $OUTPUT` = "." ]
464 then
465   OUTPUT=`pwd`/$OUTPUT
466 fi
467
468 [ ! -d $OUTPUT        ] && mkdir -p $OUTPUT
469 [ ! -d $ALIRUN_TMPDIR ] && mkdir -p $ALIRUN_TMPDIR
470
471 trap Cleanup 2
472
473 (
474  cd $OUTPUT
475  for cmd in $CMDLIST
476  do
477     case `type -t AliRun$cmd` in
478       function)
479             shift 1
480             AliRun$cmd $*
481             ;;
482          *)
483             ;;
484     esac
485  done
486 )
487
488 Cleanup