2 #############################################################################
3 # alirun - a shell script to run AliRoot
4 #############################################################################
9 # Revision 1.6 2001/05/16 14:57:30 alibrary
10 # New files for folders and Stack
13 # Revision 1.5 2001/02/23 17:33:40 buncic
14 # Added alifs wrapper for CASTOR and alirun modified accordingly.
16 # Revision 1.4 2001/02/08 18:55:43 buncic
17 # Support for writing to remote file systems (shift/castor).
19 # Revision 1.3 2001/02/01 18:00:23 buncic
20 # Use bash in place of sh for compatibility
22 # Revision 1.2 2001/02/01 17:46:26 buncic
23 # Fixed mktemp on HP and Sun
25 # Revision 1.1 2001/01/26 21:22:02 hristov
26 # Major upgrade of AliRoot code
30 # alirun [[-d <TPC+ITS+..>|-all]]
32 # [-o <output directory>]
36 # [-seed <seed for random number generator>]
41 # This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode.
43 # CONFIGURATION OPTIONS
44 # The following options are used to configure AliRoot session.
46 # -c <command1 command2 ...>
47 # 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:
49 # - Hits ................ simulation
50 # - Digits .............. digitisation
51 # - SDigits ............. creation of sumable digits
52 # - SDigits2Digits ...... conversion SDigits->Digits
53 # - Reco ................ reconstruction
55 # -d <TPC+ITS+..> | -d all | -all
56 # 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.
59 # 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.
62 # 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:
64 # o) if file name begins with rfio:, shift:, castor:, hpss:, /shift, /castor, /hpss => rfio (remote file i/o) protocol (requires rfiod on server side)
65 # o) if file name begins with root:, roots: => root and secure root protocol (requires rootd on server side)
66 # o) if file name begins with http: => HTTP protocol (requires modified apache server on server side)
69 # If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
71 # The layout of output directory is the following:
74 # |-- Digits.<detector>.root
75 # |-- SDigits.<detector>.root
82 # An alternative to Config.C macro which contains AliRoot configuration.
85 # 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.
88 # Seed for random number generator (used to initialise TRandom3(n)).
91 # Number of events to generate (not yet implemented).
94 # These options define run time appearance of the AliRoot session.
100 # Switch verbose screen output on.
103 # Switch verbose output off. Output is redirected to a file which is shown on standard output only if <command> returns non zero status.
106 # 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.
109 # Show trace of execution of shell commands.
112 # Execute AliRoot under gdb.
114 # -debugger <command_name>
115 # Execute AliRoot under debugger other than gdb.
117 # -debuglevel <level>
118 # Set AliRoot debug flag to <level>.
120 # -break <breakpoint>
121 # Execute AliRoot under gdb and set <breakpoint>.
124 # Create man page for alirun.
127 # Run sumulation for 1 event, 100 particles and store output in file galice.root in /tmp/event.1 directory:
129 # alirun -o /tmp/event.1 -p 100 -c Hits
131 # 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:
133 # alirun -o /tmp/event.2 -f test.root -split -p 100 -c Hits
135 # Use output from first step and create TOF and RICH digits. Output is in the same direcory and in file test.root
137 # alirun -d TOF+RICH -o /tmp/event.1 -c Digits
139 # Use output from second step and create digits for all detectors. Output is in the same direcory and branches are diverted to separate files:
141 # alirun -d all -o /tmp/event.2 -f test.root -split -c Digits
144 # Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
150 ###########################################################################
152 if [ "$ALIRUN_SHELL" = "" ]
155 for shell in bash zsh ksh
157 for dir in /bin /usr/bin /usr/local/bin
159 if [ -x $dir/$shell ]
161 ALIRUN_SHELL=$dir/$shell; export ALIRUN_SHELL
166 exec $ALIRUN_SHELL -norc -noprofile $0 $*
170 ###########################################################################
172 ###########################################################################
174 printf "Usage: alirun [[-d <TPC+ITS+..>|-all]]\n"
175 printf " [-f <hits file>]\n"
176 printf " [-o <output directory>]\n"
178 printf " [-C <Config.C>]\n"
179 printf " [-p <particle#>]\n"
180 printf " [-seed <seed for random number generator>]\n"
181 printf " [-n event #]\n"
182 printf " <-c <command ...>>\n"
186 ###########################################################################
188 ###########################################################################
190 ALICE_ROOT=$1; export ALICE_ROOT
191 ALICE=`dirname $ALICE_ROOT`; export ALICE
192 ALICE_LEVEL=`basename $ALICE_ROOT`; export ALICE_LEVEL
193 ALICE_TARGET=`uname`; export ALICE_TARGET
194 ROOTSYS=$2; export ROOTSYS
196 LD_LIBRARY_PATH=$ROOTSYS/lib
198 if [ -f $ALICE/bin/changeRoot.sh ]
200 . $ALICE/bin/changeRoot.sh \
201 $ALICE $ALICE_LEVEL $ALICE_TARGET $ROOTSYS
204 if [ ! -x $ALICE_BIN/aliroot -o ! -x $ROOTSYS/bin/root ]
206 printf "Invalid Alice library directory: %s\n" $1
210 LD_LIBRARY_PATH=${ROOTSYS}/lib:${ALICE_LIB}; export LD_LIBRARY_PATH
211 PATH=${ALICE_BIN}:${ROOTSYS}/bin:${PATH}; export PATH
213 printf "ALICE environment reset to %s\n" $ALICE_ROOT
218 ###########################################################################
220 ###########################################################################
222 # mktemp -qu /tmp/alirun.$$.XXXXXX
226 ###########################################################################
228 ###########################################################################
236 STAT="/usr/local/bin/rfstat"
237 if [ "$STAGE_HOST" = "" ]
241 if [ "$STAGE_POOL" = "" ]
247 MKDIR="/usr/local/bin/rfmkdir"
248 RMDIR="echo y | /usr/local/bin/rfrm -r"
249 STAT="/usr/local/bin/rfstat"
257 printf "%s I/O not yet supported by alirun.\n" $1
265 ###########################################################################
267 ###########################################################################
269 $STAT $ALIRUN_TMPDIR > /dev/null 2>&1
272 $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1
276 ###########################################################################
278 ###########################################################################
285 macro=`GenericMacro Hits2Digits`
288 macro=`GenericMacro Hits2SDigits`
291 macro=`GenericMacro SDigits2Digits`
294 macro=`GenericMacro RunReco`
300 printf "Unknown command: %s. Terminating...\n" $1
312 stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT}
314 hr="========================================"
316 if [ "$VERBOSE" = "FALSE" ]
318 printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr
321 if [ "$DEBUG" = "TRUE" ]
323 cat<<EOF>$ALIRUN_TMPDIR/gdb
331 $ECHO $ALIRUN_DEBUGGER -q -x $ALIRUN_TMPDIR/gdb aliroot
333 if [ "$VERBOSE" = "TRUE" ]
335 $ECHO aliroot -q -b $macro
341 $ECHO aliroot -q -b $macro > $stdout 2>&1
344 echo "- "aliroot -q -b " "$1" "$CONTEXT
348 echo "+ "aliroot -q -b " "$1" "$CONTEXT
356 ###########################################################################
358 ###########################################################################
360 macro=$ALIRUN_TMPDIR/Simulate.C
364 ////////////////////////////////////////////////////////////////////////////
367 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"recreate");
371 file->SetCompressionLevel(2);
373 gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE")));
375 gAlice->Init(gSystem->Getenv("CONFIG"));
379 gAlice->RunMC($NEVENTS);
381 ////////////////////////////////////////////////////////////////////////////
387 ###########################################################################
389 ###########################################################################
393 macro=$ALIRUN_TMPDIR/$mode.C
397 ////////////////////////////////////////////////////////////////////////////
400 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"update");
402 cout << "Could not open Hits file. Exiting..." << endl;
405 file->SetCompressionLevel(2);
409 if (gAlice) delete gAlice;
411 AliRun *gAlice = (AliRun*)file->Get("gAlice");
415 gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
417 ////////////////////////////////////////////////////////////////////////////
423 ###########################################################################
425 ###########################################################################
431 [ ! -d $mandir ] && mkdir -p $mandir
432 mv `basename $0`.? $mandir
437 ###########################################################################
439 ###########################################################################
444 ###########################################################################
446 ###########################################################################
451 ###########################################################################
453 ###########################################################################
455 if [ "$DETECTORS" = "" ]
459 for det in $DETECTORS
461 CONFIG_DETECTOR=$det; export CONFIG_DETECTOR
462 if [ "$FORK" = "TRUE" ]
464 if [ "$LSF_FORK" = "TRUE" ]
466 lsrun AliRoot $1 $CONFIG_DETECTOR
468 AliRoot $1 $CONFIG_DETECTOR &
471 AliRoot $1 $CONFIG_DETECTOR
478 ###########################################################################
480 ###########################################################################
482 AliRunSplitCmd Digits
485 ###########################################################################
487 ###########################################################################
492 ###########################################################################
494 ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD";
498 CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG
499 CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES
500 CONFIG_PATH=`pwd`; export CONFIG_PATH
501 CONFIG_BATCH="TRUE"; export CONFIG_BATCH
503 ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
517 USE_CACHE="file->UseCache()"
519 if [ -x /usr/local/lsf/bin/lsrun ]
524 for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C
528 CONFIG=$config; export CONFIG
546 DEBUG_LEVEL="gAlice->SetDebug($1)"
591 if [ "$list" = "all" ]
595 DETECTORS=`echo $list | sed 's/+/ /g'`
608 CONFIG_SPLIT_FILE="TRUE"; export CONFIG_SPLIT_FILE
620 CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES
624 CONFIG_SEED=$1; export CONFIG_SEED
638 if [ `dirname $CONFIG` = "." ]
650 if [ "$CMDLIST" = "" ]
655 if [ `dirname $OUTPUT` = "." ]
657 CONFIG_OUTDIR=`pwd`/$OUTPUT
659 CONFIG_OUTDIR=$OUTPUT
662 case $CONFIG_OUTDIR in
663 rfio:*|/shift/*|shift:*)
664 CONFIG_FILE_PREFIX="rfio:"
667 /castor/*|castor:*|hpss:*)
668 CONFIG_FILE_PREFIX="rfio:"
672 CONFIG_FILE_PREFIX="rfio:"
676 CONFIG_FILE_PREFIX="root:"
680 CONFIG_FILE_PREFIX="roots:"
684 CONFIG_FILE_PREFIX="http:"
688 CONFIG_FILE_PREFIX=""
692 CONFIG_FILE_PREFIX=""
696 CONFIG_FILE_PREFIX=`pwd`/
702 export CONFIG_FILE_PREFIX
704 $STAT $CONFIG_OUTDIR > /dev/null 2>&1
707 $MKDIR -p $CONFIG_OUTDIR
710 CONFIG_FILE=$CONFIG_FILE_PREFIX$CONFIG_OUTDIR/$FILE; export CONFIG_FILE
712 mkdir -p $ALIRUN_TMPDIR
720 case `type -t AliRun$cmd` in