2 #############################################################################
3 # alirun - a shell script to run AliRoot
4 #############################################################################
8 # Revision 1.4 2001/02/08 18:55:43 buncic
9 # Support for writing to remote file systems (shift/castor).
11 # Revision 1.3 2001/02/01 18:00:23 buncic
12 # Use bash in place of sh for compatibility
14 # Revision 1.2 2001/02/01 17:46:26 buncic
15 # Fixed mktemp on HP and Sun
17 # Revision 1.1 2001/01/26 21:22:02 hristov
18 # Major upgrade of AliRoot code
22 # alirun [[-d <TPC+ITS+..>|-all]]
24 # [-o <output directory>]
28 # [-seed <seed for random number generator>]
33 # This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode.
35 # CONFIGURATION OPTIONS
36 # The following options are used to configure AliRoot session.
38 # -c <command1 command2 ...>
39 # 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:
41 # - Hits ................ simulation
42 # - Digits .............. digitisation
43 # - SDigits ............. creation of sumable digits
44 # - SDigits2Digits ...... conversion SDigits->Digits
45 # - Reco ................ reconstruction
47 # -d <TPC+ITS+..> | -d all | -all
48 # 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.
51 # 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.
54 # A directory where output file(s) will be stored. If does not exist, it will be created. If not specified, current directory is used. One can prefix the directory name with a string indicting file transport protocols (as supported by ROOT). In addition, some file transport protocols are selected by name signatures. At present the following methods are available:
56 # o) if file name begins with rfio:, shift:, castor:, hpss:, /shift, /castor, /hpss => rfio (remote file i/o) protocol (requires rfiod on server side)
57 # o) if file name begins with root:, roots: => root and secure root protocol (requires rootd on server side)
58 # o) if file name begins with http: => HTTP protocol (requires modified apache server on server side)
61 # If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
63 # The layout of output directory is the following:
66 # |-- Digits.<detector>.root
67 # |-- SDigits.<detector>.root
74 # An alternative to Config.C macro which contains AliRoot configuration.
77 # 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.
80 # Seed for random number generator (used to initialise TRandom3(n)).
83 # Number of events to generate (not yet implemented).
86 # These options define run time appearance of the AliRoot session.
92 # Switch verbose screen output on.
95 # Switch verbose output off. Output is redirected to a file which is shown on standard output only if <command> returns non zero status.
98 # 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.
101 # Show trace of execution of shell commands.
104 # Execute AliRoot under gdb.
106 # -debugger <command_name>
107 # Execute AliRoot under debugger other than gdb.
109 # -break <breakpoint>
110 # Execute AliRoot under gdb and set <breakpoint>.
113 # Create man page for alirun.
116 # Run sumulation for 1 event, 100 particles and store output in file galice.root in /tmp/event.1 directory:
118 # alirun -o /tmp/event.1 -p 100 -c Hits
120 # Run sumulation for 1 event, 100 particles and store output in file test.root in /tmp/event.2 directory. In adition, divert branches of TreeD,TreeR and TreeK into separate files:
122 # alirun -o /tmp/event.2 -f test.root -split -p 100 -c Hits
124 # Use output from first step and create TOF and RICH digits. Output is in the same direcory and in file test.root
126 # alirun -d TOF+RICH -o /tmp/event.1 -c Digits
128 # Use output from second step and create digits for all detectors. Output is in the same direcory and branches are diverted to separate files:
130 # alirun -d all -o /tmp/event.2 -f test.root -split -c Digits
133 # Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
139 ###########################################################################
141 if [ "$ALIRUN_SHELL" = "" ]
144 for shell in bash zsh ksh
146 for dir in /bin /usr/bin /usr/local/bin
148 if [ -x $dir/$shell ]
150 ALIRUN_SHELL=$dir/$shell; export ALIRUN_SHELL
155 exec $ALIRUN_SHELL -norc -noprofile $0 $*
158 ###########################################################################
160 ###########################################################################
162 printf "Usage: alirun [[-d <TPC+ITS+..>|-all]]\n"
163 printf " [-f <hits file>]\n"
164 printf " [-o <output directory>]\n"
166 printf " [-C <Config.C>]\n"
167 printf " [-p <particle#>]\n"
168 printf " [-seed <seed for random number generator>]\n"
169 printf " [-n event #]\n"
170 printf " <-c <command ...>>\n"
174 ###########################################################################
176 ###########################################################################
178 # mktemp -qu /tmp/alirun.$$.XXXXXX
182 ###########################################################################
184 ###########################################################################
192 STAT="/usr/local/bin/rfstat"
193 if [ "$STAGE_HOST" = "" ]
197 if [ "$STAGE_POOL" = "" ]
203 MKDIR="/usr/local/bin/rfmkdir"
204 RMDIR="echo y | /usr/local/bin/rfrm -r"
205 STAT="/usr/local/bin/rfstat"
213 printf "%s I/O not yet supported by alirun.\n" $1
221 ###########################################################################
223 ###########################################################################
225 $STAT $ALIRUN_TMPDIR > /dev/null 2>&1
228 $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1
232 ###########################################################################
234 ###########################################################################
241 macro=`GenericMacro Hits2Digits`
244 macro=`GenericMacro Hits2SDigits`
247 macro=`GenericMacro SDigits2Digits`
250 macro=`GenericMacro RunReco`
256 printf "Unknown command: %s. Terminating...\n" $1
268 stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT}
270 hr="========================================"
272 if [ "$VERBOSE" = "FALSE" ]
274 printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr
277 if [ "$DEBUG" = "TRUE" ]
279 cat<<EOF>$ALIRUN_TMPDIR/gdb
287 $ECHO $ALIRUN_DEBUGGER -q -x $ALIRUN_TMPDIR/gdb aliroot
289 if [ "$VERBOSE" = "TRUE" ]
291 $ECHO aliroot -q -b $macro
297 $ECHO aliroot -q -b $macro > $stdout 2>&1
300 echo "- "aliroot -q -b " "$1" "$CONTEXT
304 echo "+ "aliroot -q -b " "$1" "$CONTEXT
312 ###########################################################################
314 ###########################################################################
316 macro=$ALIRUN_TMPDIR/Simulate.C
320 ////////////////////////////////////////////////////////////////////////////
323 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"recreate");
327 file->SetCompressionLevel(2);
329 gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE")));
331 gAlice->Init(gSystem->Getenv("CONFIG"));
335 ////////////////////////////////////////////////////////////////////////////
341 ###########################################################################
343 ###########################################################################
347 macro=$ALIRUN_TMPDIR/$mode.C
351 ////////////////////////////////////////////////////////////////////////////
354 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"update");
356 cout << "Could not open Hits file. Exiting..." << endl;
359 file->SetCompressionLevel(2);
363 if (gAlice) delete gAlice;
365 AliRun *gAlice = (AliRun*)file->Get("gAlice");
367 gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
369 ////////////////////////////////////////////////////////////////////////////
375 ###########################################################################
377 ###########################################################################
383 [ ! -d $mandir ] && mkdir -p $mandir
384 mv `basename $0`.? $mandir
389 ###########################################################################
391 ###########################################################################
396 ###########################################################################
398 ###########################################################################
403 ###########################################################################
405 ###########################################################################
407 if [ "$DETECTORS" = "" ]
411 for det in $DETECTORS
413 CONFIG_DETECTOR=$det; export CONFIG_DETECTOR
414 if [ "$FORK" = "TRUE" ]
416 if [ "$LSF_FORK" = "TRUE" ]
418 lsrun AliRoot Digits $CONFIG_DETECTOR
420 AliRoot Digits $CONFIG_DETECTOR &
423 AliRoot Digits $CONFIG_DETECTOR
430 ###########################################################################
432 ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD";
436 CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG
437 CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES
438 CONFIG_PATH=`pwd`; export CONFIG_PATH
439 CONFIG_BATCH="TRUE"; export CONFIG_BATCH
441 ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
452 USE_CACHE="file->UseCache()"
454 if [ -x /usr/local/lsf/bin/lsrun ]
459 for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C
463 CONFIG=$config; export CONFIG
513 if [ "$list" = "all" ]
517 DETECTORS=`echo $list | sed 's/+/ /g'`
530 CONFIG_SPLIT_FILE="TRUE"; export CONFIG_SPLIT_FILE
542 CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES
546 CONFIG_SEED=$1; export CONFIG_SEED
560 if [ `dirname $CONFIG` = "." ]
572 if [ `dirname $OUTPUT` = "." ]
574 CONFIG_OUTDIR=`pwd`/$OUTPUT
576 CONFIG_OUTDIR=$OUTPUT
579 case $CONFIG_OUTDIR in
580 rfio:*|/shift/*|shift:*)
581 CONFIG_FILE_PREFIX="rfio:"
584 /castor/*|castor:*|hpss:*)
585 CONFIG_FILE_PREFIX="rfio:"
589 CONFIG_FILE_PREFIX="rfio:"
593 CONFIG_FILE_PREFIX="root:"
597 CONFIG_FILE_PREFIX="roots:"
601 CONFIG_FILE_PREFIX="http:"
605 CONFIG_FILE_PREFIX=""
609 CONFIG_FILE_PREFIX=""
613 CONFIG_FILE_PREFIX=`pwd`/
619 export CONFIG_FILE_PREFIX
621 $STAT $CONFIG_OUTDIR > /dev/null 2>&1
624 $MKDIR -p $CONFIG_OUTDIR
627 mkdir -p $ALIRUN_TMPDIR
629 CONFIG_FILE=$CONFIG_FILE_PREFIX$CONFIG_OUTDIR/$FILE; export CONFIG_FILE
637 case `type -t AliRun$cmd` in