2 #############################################################################
3 # alirun - a shell script to run AliRoot
4 #############################################################################
8 # Revision 1.3 2001/02/01 18:00:23 buncic
9 # Use bash in place of sh for compatibility
11 # Revision 1.2 2001/02/01 17:46:26 buncic
12 # Fixed mktemp on HP and Sun
14 # Revision 1.1 2001/01/26 21:22:02 hristov
15 # Major upgrade of AliRoot code
17 #############################################################################
20 # alirun [[-d <TPC+ITS+..>|-all]]
22 # [-o <output directory>]
26 # [-seed <seed for random number generator>]
31 # This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode.
33 # CONFIGURATION OPTIONS
34 # The following options are used to configure AliRoot session.
36 # -c <command1 command2 ...>
37 # 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:
39 # - Hits ................ simulation
40 # - Digits .............. digitisation
41 # - SDigits ............. creation of sumable digits
42 # - SDigits2Digits ...... conversion SDigits->Digits
44 # -d <TPC+ITS+..> | -d all | -all
45 # 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.
48 # 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.
51 # A directory where output file(s) will be stored. If does not exist, it will be created. If not specified, current directory is used.
54 # If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
56 # The layout of output directory is the following:
59 # |-- Digits.<detector>.root
60 # |-- SDigits.<detector>.root
67 # An alternative to Config.C macro which contains AliRoot configuration.
70 # 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.
73 # Seed for random number generator (used to initialise TRandom3(n)).
76 # Number of events to generate (not yet implemented).
79 # These options define run time appearance of the AliRoot session.
85 # Switch verbose screen output on.
88 # Switch verbose output off. Output is redirected to a file which is shown on standard output only if <command> returns non zero status.
91 # 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.
94 # Show trace of execution of shell commands.
97 # Execute AliRoot under gdb.
100 # Execute AliRoot under gdb and set <breakpoint>.
103 # Create man page for alirun.
106 # Run sumulation for 1 event, 100 particles and store output in file test.root in /tmp/event.1 directory:
108 # alirun -o /tmp/event.1 -f test.root -p 100 -verbose -c Hits
110 # 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:
112 # alirun -o /tmp/event.2 -split -p 100 -verbose -c Hits
114 # Use output from first step and create TOF and RICH digits. Output is in the same direcory and in file test.root
116 # alirun -d TOF+RICH -o /tmp/event.1 -f test.root -verbose -c Digits
118 # Use output from second step and create digits for all detectors. Output is in the same direcory and branches are diverted to separate files:
120 # alirun -d all -o /tmp/event.2 -split -verbose -c Digits
123 # Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
129 ###########################################################################
130 if [ "$ALIRUN_SHELL" = "" ]
133 for shell in bash zsh ksh
135 for dir in /bin /usr/bin /usr/local/bin
137 if [ -x $dir/$shell ]
139 ALIRUN_SHELL=$dir/$shell; export ALIRUN_SHELL
144 exec $ALIRUN_SHELL -norc -noprofile $0 $*
146 ###########################################################################
148 ###########################################################################
150 printf "Usage: alirun [[-d <TPC+ITS+..>|-all]]\n"
151 printf " [-f <hits file>]\n"
152 printf " [-o <output directory>]\n"
154 printf " [-C <Config.C>]\n"
155 printf " [-p <particle#>]\n"
156 printf " [-seed <seed for random number generator>]\n"
157 printf " [-n event #]\n"
158 printf " <-c <command ...>>\n"
162 ###########################################################################
164 ###########################################################################
166 # mktemp -qu /tmp/alirun.$$.XXXXXX
170 ###########################################################################
172 ###########################################################################
174 if [ -x /usr/local/bin/rfmkdir ]
176 MKDIR="/usr/local/bin/rfmkdir"
180 if [ -x /usr/local/bin/rfrm ]
182 RMDIR="echo y | /usr/local/bin/rfrm -r"
186 if [ -x /usr/local/bin/rfstat ]
188 STAT="/usr/local/bin/rfstat"
194 ###########################################################################
196 ###########################################################################
198 $STAT $ALIRUN_TMPDIR > /dev/null 2>&1
201 $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1
205 ###########################################################################
207 ###########################################################################
214 macro=`DigitsMacro Hits2Digits`
217 macro=`DigitsMacro Hits2SDigits`
220 macro=`DigitsMacro SDigits2Digits`
226 printf "Unknown command: %s. Terminating...\n" $1
238 stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT}
240 hr="========================================"
242 if [ "$VERBOSE" = "FALSE" ]
244 printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr
247 if [ "$DEBUG" = "TRUE" ]
249 cat<<EOF>$ALIRUN_TMPDIR/gdb
257 $ECHO gdb -q -x $ALIRUN_TMPDIR/gdb aliroot
259 if [ "$VERBOSE" = "TRUE" ]
261 $ECHO aliroot -q -b $macro
263 $ECHO aliroot -q -b $macro > $stdout 2>&1
266 echo "- "aliroot -q -b " "$1" "$CONTEXT
270 echo "+ "aliroot -q -b " "$1" "$CONTEXT
278 ###########################################################################
280 ###########################################################################
282 macro=$ALIRUN_TMPDIR/Simulate.C
286 ////////////////////////////////////////////////////////////////////////////
289 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"recreate");
293 file->SetCompressionLevel(2);
295 gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE")));
297 gAlice->Init(gSystem->Getenv("CONFIG"));
301 ////////////////////////////////////////////////////////////////////////////
307 ###########################################################################
309 ###########################################################################
313 macro=$ALIRUN_TMPDIR/Digitize.C
317 ////////////////////////////////////////////////////////////////////////////
320 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"update");
322 cout << "Could not open Hits file. Exiting..." << endl;
325 file->SetCompressionLevel(2);
329 if (gAlice) delete gAlice;
331 AliRun *gAlice = (AliRun*)file->Get("gAlice");
333 gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
335 ////////////////////////////////////////////////////////////////////////////
341 ###########################################################################
343 ###########################################################################
349 [ ! -d $mandir ] && mkdir -p $mandir
350 mv `basename $0`.? $mandir
355 ###########################################################################
357 ###########################################################################
362 ###########################################################################
364 ###########################################################################
369 ###########################################################################
371 ###########################################################################
373 if [ "$DETECTORS" = "" ]
377 for det in $DETECTORS
379 CONFIG_DETECTOR=$det; export CONFIG_DETECTOR
380 if [ "$FORK" = "TRUE" ]
382 if [ "$LSF_FORK" = "TRUE" ]
384 lsrun AliRoot Digits $CONFIG_DETECTOR
386 AliRoot Digits $CONFIG_DETECTOR &
389 AliRoot Digits $CONFIG_DETECTOR
397 ###########################################################################
399 ###########################################################################
401 ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD"; # export ALL
402 DETECTORS=""; # export DETECTORS
405 CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG
406 CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES
407 CONFIG_PATH=`pwd`; export CONFIG_PATH
409 ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
420 if [ -x /usr/local/lsf/bin/lsrun ]
425 for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C
429 CONFIG=$config; export CONFIG
475 if [ "$list" = "all" ]
479 DETECTORS=`echo $list | sed 's/+/ /g'`
492 CONFIG_SPLIT_FILE="TRUE"; export CONFIG_SPLIT_FILE
504 CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES
508 CONFIG_SEED=$1; export CONFIG_SEED
517 CONFIG=$1; export CONFIG
525 if [ `dirname $OUTPUT` = "." ]
527 CONFIG_OUTDIR=`pwd`/$OUTPUT
529 CONFIG_OUTDIR=$OUTPUT
532 case $CONFIG_OUTDIR in
533 rfio:*|/shift/*|shift:*|/castor/*|castor:*)
534 ROOT_FILE_TYPE="rfio:"
537 ROOT_FILE_TYPE="root:"
540 ROOT_FILE_TYPE="http:"
551 export CONFIG_ROOT_FILE_TYPE
553 for dir in $CONFIG_OUTDIR $ALIRUN_TMPDIR
555 $STAT $dir > /dev/null 2>&1
562 CONFIG_FILE=$ROOT_FILE_TYPE$CONFIG_OUTDIR/$FILE; export CONFIG_FILE
570 case `type -t AliRun$cmd` in