2 #############################################################################
3 # alirun - a shell script to run AliRoot
4 #############################################################################
9 # Revision 1.7 2001/05/21 17:22:52 buncic
10 # Fixed problem with missing AliConfig while reading galice.root
12 # Revision 1.6 2001/05/16 14:57:30 alibrary
13 # New files for folders and Stack
16 # Revision 1.5 2001/02/23 17:33:40 buncic
17 # Added alifs wrapper for CASTOR and alirun modified accordingly.
19 # Revision 1.4 2001/02/08 18:55:43 buncic
20 # Support for writing to remote file systems (shift/castor).
22 # Revision 1.3 2001/02/01 18:00:23 buncic
23 # Use bash in place of sh for compatibility
25 # Revision 1.2 2001/02/01 17:46:26 buncic
26 # Fixed mktemp on HP and Sun
28 # Revision 1.1 2001/01/26 21:22:02 hristov
29 # Major upgrade of AliRoot code
33 # alirun [[-d <TPC+ITS+..>|-all]]
35 # [-o <output directory>]
39 # [-seed <seed for random number generator>]
44 # This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode.
46 # CONFIGURATION OPTIONS
47 # The following options are used to configure AliRoot session.
49 # -c <command1 command2 ...>
50 # 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:
52 # - Hits ................ simulation
53 # - Digits .............. digitisation
54 # - SDigits ............. creation of sumable digits
55 # - SDigits2Digits ...... conversion SDigits->Digits
56 # - Reco ................ reconstruction
58 # -d <TPC+ITS+..> | -d all | -all
59 # 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+HMPID+TOF+ITS+TPC+PHOS+PMD+CASTOR+TRD. Detectors are processed in order as they appear on the command line.
62 # 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.
65 # 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:
67 # o) if file name begins with rfio:, shift:, castor:, hpss:, /shift, /castor, /hpss => rfio (remote file i/o) protocol (requires rfiod on server side)
68 # o) if file name begins with root:, roots: => root and secure root protocol (requires rootd on server side)
69 # o) if file name begins with http: => HTTP protocol (requires modified apache server on server side)
72 # If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
74 # The layout of output directory is the following:
77 # |-- Digits.<detector>.root
78 # |-- SDigits.<detector>.root
85 # An alternative to Config.C macro which contains AliRoot configuration.
88 # 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.
91 # Seed for random number generator (used to initialise TRandom3(n)).
94 # Number of events to generate (not yet implemented).
97 # These options define run time appearance of the AliRoot session.
103 # Switch verbose screen output on.
106 # Switch verbose output off. Output is redirected to a file which is shown on standard output only if <command> returns non zero status.
109 # 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.
112 # Show trace of execution of shell commands.
115 # Execute AliRoot under gdb.
117 # -debugger <command_name>
118 # Execute AliRoot under debugger other than gdb.
120 # -debuglevel <level>
121 # Set AliRoot debug flag to <level>.
123 # -break <breakpoint>
124 # Execute AliRoot under gdb and set <breakpoint>.
127 # Create man page for alirun.
130 # Run sumulation for 1 event, 100 particles and store output in file galice.root in /tmp/event.1 directory:
132 # alirun -o /tmp/event.1 -p 100 -c Hits
134 # 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:
136 # alirun -o /tmp/event.2 -f test.root -split -p 100 -c Hits
138 # Use output from first step and create TOF and HMPID digits. Output is in the same direcory and in file test.root
140 # alirun -d TOF+HMPID -o /tmp/event.1 -c Digits
142 # Use output from second step and create digits for all detectors. Output is in the same direcory and branches are diverted to separate files:
144 # alirun -d all -o /tmp/event.2 -f test.root -split -c Digits
147 # Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
153 ###########################################################################
155 if [ "$ALIRUN_SHELL" = "" ]
158 for shell in bash zsh ksh
160 for dir in /bin /usr/bin /usr/local/bin
162 if [ -x $dir/$shell ]
164 ALIRUN_SHELL=$dir/$shell; export ALIRUN_SHELL
169 exec $ALIRUN_SHELL -norc -noprofile $0 $*
173 ###########################################################################
175 ###########################################################################
177 printf "Usage: alirun [[-d <TPC+ITS+..>|-all]]\n"
178 printf " [-f <hits file>]\n"
179 printf " [-o <output directory>]\n"
181 printf " [-C <Config.C>]\n"
182 printf " [-p <particle#>]\n"
183 printf " [-seed <seed for random number generator>]\n"
184 printf " [-n event #]\n"
185 printf " <-c <command ...>>\n"
189 ###########################################################################
191 ###########################################################################
193 ALICE_ROOT=$1; export ALICE_ROOT
194 ALICE=`dirname $ALICE_ROOT`; export ALICE
195 ALICE_LEVEL=`basename $ALICE_ROOT`; export ALICE_LEVEL
196 ALICE_TARGET=`uname`; export ALICE_TARGET
197 ROOTSYS=$2; export ROOTSYS
199 LD_LIBRARY_PATH=$ROOTSYS/lib
201 if [ -f $ALICE/bin/changeRoot.sh ]
203 . $ALICE/bin/changeRoot.sh \
204 $ALICE $ALICE_LEVEL $ALICE_TARGET $ROOTSYS
207 if [ ! -x $ALICE_BIN/aliroot -o ! -x $ROOTSYS/bin/root ]
209 printf "Invalid Alice library directory: %s\n" $1
213 LD_LIBRARY_PATH=${ROOTSYS}/lib:${ALICE_LIB}; export LD_LIBRARY_PATH
214 PATH=${ALICE_BIN}:${ROOTSYS}/bin:${PATH}; export PATH
216 printf "ALICE environment reset to %s\n" $ALICE_ROOT
221 ###########################################################################
223 ###########################################################################
225 # mktemp -qu /tmp/alirun.$$.XXXXXX
229 ###########################################################################
231 ###########################################################################
239 STAT="/usr/local/bin/rfstat"
240 if [ "$STAGE_HOST" = "" ]
244 if [ "$STAGE_POOL" = "" ]
250 MKDIR="/usr/local/bin/rfmkdir"
251 RMDIR="echo y | /usr/local/bin/rfrm -r"
252 STAT="/usr/local/bin/rfstat"
260 printf "%s I/O not yet supported by alirun.\n" $1
268 ###########################################################################
270 ###########################################################################
272 $STAT $ALIRUN_TMPDIR > /dev/null 2>&1
275 $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1
279 ###########################################################################
281 ###########################################################################
288 macro=`GenericMacro Hits2Digits`
291 macro=`GenericMacro Hits2SDigits`
294 macro=`GenericMacro SDigits2Digits`
297 macro=`GenericMacro RunReco`
303 printf "Unknown command: %s. Terminating...\n" $1
315 stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT}
317 hr="========================================"
319 if [ "$VERBOSE" = "FALSE" ]
321 printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr
324 if [ "$DEBUG" = "TRUE" ]
326 cat<<EOF>$ALIRUN_TMPDIR/gdb
334 $ECHO $ALIRUN_DEBUGGER -q -x $ALIRUN_TMPDIR/gdb aliroot
336 if [ "$VERBOSE" = "TRUE" ]
338 $ECHO aliroot -q -b $macro
344 $ECHO aliroot -q -b $macro > $stdout 2>&1
347 echo "- "aliroot -q -b " "$1" "$CONTEXT
351 echo "+ "aliroot -q -b " "$1" "$CONTEXT
359 ###########################################################################
361 ###########################################################################
363 macro=$ALIRUN_TMPDIR/Simulate.C
367 ////////////////////////////////////////////////////////////////////////////
370 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"recreate");
374 file->SetCompressionLevel(2);
376 gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE")));
378 gAlice->Init(gSystem->Getenv("CONFIG"));
382 gAlice->RunMC($NEVENTS);
384 ////////////////////////////////////////////////////////////////////////////
390 ###########################################################################
392 ###########################################################################
396 macro=$ALIRUN_TMPDIR/$mode.C
400 ////////////////////////////////////////////////////////////////////////////
403 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"update");
405 cout << "Could not open Hits file. Exiting..." << endl;
408 file->SetCompressionLevel(2);
412 if (gAlice) delete gAlice;
414 AliRun *gAlice = (AliRun*)file->Get("gAlice");
418 gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
420 ////////////////////////////////////////////////////////////////////////////
426 ###########################################################################
428 ###########################################################################
434 [ ! -d $mandir ] && mkdir -p $mandir
435 mv `basename $0`.? $mandir
440 ###########################################################################
442 ###########################################################################
447 ###########################################################################
449 ###########################################################################
454 ###########################################################################
456 ###########################################################################
458 if [ "$DETECTORS" = "" ]
462 for det in $DETECTORS
464 CONFIG_DETECTOR=$det; export CONFIG_DETECTOR
465 if [ "$FORK" = "TRUE" ]
467 if [ "$LSF_FORK" = "TRUE" ]
469 lsrun AliRoot $1 $CONFIG_DETECTOR
471 AliRoot $1 $CONFIG_DETECTOR &
474 AliRoot $1 $CONFIG_DETECTOR
481 ###########################################################################
483 ###########################################################################
485 AliRunSplitCmd Digits
488 ###########################################################################
490 ###########################################################################
495 ###########################################################################
497 ALL="MUON HMPID TOF ITS TPC PHOS PMD CASTOR ZDC TRD";
501 CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG
502 CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES
503 CONFIG_PATH=`pwd`; export CONFIG_PATH
504 CONFIG_BATCH="TRUE"; export CONFIG_BATCH
506 ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
520 USE_CACHE="file->UseCache()"
522 if [ -x /usr/local/lsf/bin/lsrun ]
527 for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C
531 CONFIG=$config; export CONFIG
549 DEBUG_LEVEL="gAlice->SetDebug($1)"
594 if [ "$list" = "all" ]
598 DETECTORS=`echo $list | sed 's/+/ /g'`
611 CONFIG_SPLIT_FILE="TRUE"; export CONFIG_SPLIT_FILE
623 CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES
627 CONFIG_SEED=$1; export CONFIG_SEED
641 if [ `dirname $CONFIG` = "." ]
653 if [ "$CMDLIST" = "" ]
658 if [ `dirname $OUTPUT` = "." ]
660 CONFIG_OUTDIR=`pwd`/$OUTPUT
662 CONFIG_OUTDIR=$OUTPUT
665 case $CONFIG_OUTDIR in
666 rfio:*|/shift/*|shift:*)
667 CONFIG_FILE_PREFIX="rfio:"
670 /castor/*|castor:*|hpss:*)
671 CONFIG_FILE_PREFIX="rfio:"
675 CONFIG_FILE_PREFIX="rfio:"
679 CONFIG_FILE_PREFIX="root:"
683 CONFIG_FILE_PREFIX="roots:"
687 CONFIG_FILE_PREFIX="http:"
691 CONFIG_FILE_PREFIX=""
695 CONFIG_FILE_PREFIX=""
699 CONFIG_FILE_PREFIX=`pwd`/
705 export CONFIG_FILE_PREFIX
707 $STAT $CONFIG_OUTDIR > /dev/null 2>&1
710 $MKDIR -p $CONFIG_OUTDIR
713 CONFIG_FILE=$CONFIG_FILE_PREFIX$CONFIG_OUTDIR/$FILE; export CONFIG_FILE
715 mkdir -p $ALIRUN_TMPDIR
723 case `type -t AliRun$cmd` in