2 #############################################################################
3 # alirun - a shell script to run AliRoot
4 #############################################################################
10 # Revision 1.5 2001/02/23 17:33:40 buncic
11 # Added alifs wrapper for CASTOR and alirun modified accordingly.
13 # Revision 1.4 2001/02/08 18:55:43 buncic
14 # Support for writing to remote file systems (shift/castor).
16 # Revision 1.3 2001/02/01 18:00:23 buncic
17 # Use bash in place of sh for compatibility
19 # Revision 1.2 2001/02/01 17:46:26 buncic
20 # Fixed mktemp on HP and Sun
22 # Revision 1.1 2001/01/26 21:22:02 hristov
23 # Major upgrade of AliRoot code
27 # alirun [[-d <TPC+ITS+..>|-all]]
29 # [-o <output directory>]
33 # [-seed <seed for random number generator>]
38 # This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode.
40 # CONFIGURATION OPTIONS
41 # The following options are used to configure AliRoot session.
43 # -c <command1 command2 ...>
44 # 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:
46 # - Hits ................ simulation
47 # - Digits .............. digitisation
48 # - SDigits ............. creation of sumable digits
49 # - SDigits2Digits ...... conversion SDigits->Digits
50 # - Reco ................ reconstruction
52 # -d <TPC+ITS+..> | -d all | -all
53 # 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.
56 # 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.
59 # 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:
61 # o) if file name begins with rfio:, shift:, castor:, hpss:, /shift, /castor, /hpss => rfio (remote file i/o) protocol (requires rfiod on server side)
62 # o) if file name begins with root:, roots: => root and secure root protocol (requires rootd on server side)
63 # o) if file name begins with http: => HTTP protocol (requires modified apache server on server side)
66 # If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
68 # The layout of output directory is the following:
71 # |-- Digits.<detector>.root
72 # |-- SDigits.<detector>.root
79 # An alternative to Config.C macro which contains AliRoot configuration.
82 # 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.
85 # Seed for random number generator (used to initialise TRandom3(n)).
88 # Number of events to generate (not yet implemented).
91 # These options define run time appearance of the AliRoot session.
97 # Switch verbose screen output on.
100 # Switch verbose output off. Output is redirected to a file which is shown on standard output only if <command> returns non zero status.
103 # 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.
106 # Show trace of execution of shell commands.
109 # Execute AliRoot under gdb.
111 # -debugger <command_name>
112 # Execute AliRoot under debugger other than gdb.
114 # -debuglevel <level>
115 # Set AliRoot debug flag to <level>.
117 # -break <breakpoint>
118 # Execute AliRoot under gdb and set <breakpoint>.
121 # Create man page for alirun.
124 # Run sumulation for 1 event, 100 particles and store output in file galice.root in /tmp/event.1 directory:
126 # alirun -o /tmp/event.1 -p 100 -c Hits
128 # 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:
130 # alirun -o /tmp/event.2 -f test.root -split -p 100 -c Hits
132 # Use output from first step and create TOF and RICH digits. Output is in the same direcory and in file test.root
134 # alirun -d TOF+RICH -o /tmp/event.1 -c Digits
136 # Use output from second step and create digits for all detectors. Output is in the same direcory and branches are diverted to separate files:
138 # alirun -d all -o /tmp/event.2 -f test.root -split -c Digits
141 # Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
147 ###########################################################################
149 if [ "$ALIRUN_SHELL" = "" ]
152 for shell in bash zsh ksh
154 for dir in /bin /usr/bin /usr/local/bin
156 if [ -x $dir/$shell ]
158 ALIRUN_SHELL=$dir/$shell; export ALIRUN_SHELL
163 exec $ALIRUN_SHELL -norc -noprofile $0 $*
166 ###########################################################################
168 ###########################################################################
170 printf "Usage: alirun [[-d <TPC+ITS+..>|-all]]\n"
171 printf " [-f <hits file>]\n"
172 printf " [-o <output directory>]\n"
174 printf " [-C <Config.C>]\n"
175 printf " [-p <particle#>]\n"
176 printf " [-seed <seed for random number generator>]\n"
177 printf " [-n event #]\n"
178 printf " <-c <command ...>>\n"
182 ###########################################################################
184 ###########################################################################
186 # mktemp -qu /tmp/alirun.$$.XXXXXX
190 ###########################################################################
192 ###########################################################################
200 STAT="/usr/local/bin/rfstat"
201 if [ "$STAGE_HOST" = "" ]
205 if [ "$STAGE_POOL" = "" ]
211 MKDIR="/usr/local/bin/rfmkdir"
212 RMDIR="echo y | /usr/local/bin/rfrm -r"
213 STAT="/usr/local/bin/rfstat"
221 printf "%s I/O not yet supported by alirun.\n" $1
229 ###########################################################################
231 ###########################################################################
233 $STAT $ALIRUN_TMPDIR > /dev/null 2>&1
236 $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1
240 ###########################################################################
242 ###########################################################################
249 macro=`GenericMacro Hits2Digits`
252 macro=`GenericMacro Hits2SDigits`
255 macro=`GenericMacro SDigits2Digits`
258 macro=`GenericMacro RunReco`
264 printf "Unknown command: %s. Terminating...\n" $1
276 stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT}
278 hr="========================================"
280 if [ "$VERBOSE" = "FALSE" ]
282 printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr
285 if [ "$DEBUG" = "TRUE" ]
287 cat<<EOF>$ALIRUN_TMPDIR/gdb
295 $ECHO $ALIRUN_DEBUGGER -q -x $ALIRUN_TMPDIR/gdb aliroot
297 if [ "$VERBOSE" = "TRUE" ]
299 $ECHO aliroot -q -b $macro
305 $ECHO aliroot -q -b $macro > $stdout 2>&1
308 echo "- "aliroot -q -b " "$1" "$CONTEXT
312 echo "+ "aliroot -q -b " "$1" "$CONTEXT
320 ###########################################################################
322 ###########################################################################
324 macro=$ALIRUN_TMPDIR/Simulate.C
328 ////////////////////////////////////////////////////////////////////////////
331 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"recreate");
335 file->SetCompressionLevel(2);
337 gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE")));
339 gAlice->Init(gSystem->Getenv("CONFIG"));
343 gAlice->RunMC($NEVENTS);
345 ////////////////////////////////////////////////////////////////////////////
351 ###########################################################################
353 ###########################################################################
357 macro=$ALIRUN_TMPDIR/$mode.C
361 ////////////////////////////////////////////////////////////////////////////
364 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"update");
366 cout << "Could not open Hits file. Exiting..." << endl;
369 file->SetCompressionLevel(2);
373 if (gAlice) delete gAlice;
375 AliRun *gAlice = (AliRun*)file->Get("gAlice");
379 gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
381 ////////////////////////////////////////////////////////////////////////////
387 ###########################################################################
389 ###########################################################################
395 [ ! -d $mandir ] && mkdir -p $mandir
396 mv `basename $0`.? $mandir
401 ###########################################################################
403 ###########################################################################
408 ###########################################################################
410 ###########################################################################
415 ###########################################################################
417 ###########################################################################
419 if [ "$DETECTORS" = "" ]
423 for det in $DETECTORS
425 CONFIG_DETECTOR=$det; export CONFIG_DETECTOR
426 if [ "$FORK" = "TRUE" ]
428 if [ "$LSF_FORK" = "TRUE" ]
430 lsrun AliRoot $1 $CONFIG_DETECTOR
432 AliRoot $1 $CONFIG_DETECTOR &
435 AliRoot $1 $CONFIG_DETECTOR
442 ###########################################################################
444 ###########################################################################
446 AliRunSplitCmd Digits
449 ###########################################################################
451 ###########################################################################
456 ###########################################################################
458 ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD";
462 CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG
463 CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES
464 CONFIG_PATH=`pwd`; export CONFIG_PATH
465 CONFIG_BATCH="TRUE"; export CONFIG_BATCH
467 ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
480 USE_CACHE="file->UseCache()"
482 if [ -x /usr/local/lsf/bin/lsrun ]
487 for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C
491 CONFIG=$config; export CONFIG
509 DEBUG_LEVEL="gAlice->SetDebug($1)"
545 if [ "$list" = "all" ]
549 DETECTORS=`echo $list | sed 's/+/ /g'`
562 CONFIG_SPLIT_FILE="TRUE"; export CONFIG_SPLIT_FILE
574 CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES
578 CONFIG_SEED=$1; export CONFIG_SEED
592 if [ `dirname $CONFIG` = "." ]
604 if [ "$CMDLIST" = "" ]
609 if [ `dirname $OUTPUT` = "." ]
611 CONFIG_OUTDIR=`pwd`/$OUTPUT
613 CONFIG_OUTDIR=$OUTPUT
616 case $CONFIG_OUTDIR in
617 rfio:*|/shift/*|shift:*)
618 CONFIG_FILE_PREFIX="rfio:"
621 /castor/*|castor:*|hpss:*)
622 CONFIG_FILE_PREFIX="rfio:"
626 CONFIG_FILE_PREFIX="rfio:"
630 CONFIG_FILE_PREFIX="root:"
634 CONFIG_FILE_PREFIX="roots:"
638 CONFIG_FILE_PREFIX="http:"
642 CONFIG_FILE_PREFIX=""
646 CONFIG_FILE_PREFIX=""
650 CONFIG_FILE_PREFIX=`pwd`/
656 export CONFIG_FILE_PREFIX
658 $STAT $CONFIG_OUTDIR > /dev/null 2>&1
661 $MKDIR -p $CONFIG_OUTDIR
664 mkdir -p $ALIRUN_TMPDIR
666 CONFIG_FILE=$CONFIG_FILE_PREFIX$CONFIG_OUTDIR/$FILE; export CONFIG_FILE
674 case `type -t AliRun$cmd` in