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