-#!/usr/local/bin/bash
+#!/bin/sh
#############################################################################
# alirun - a shell script to run AliRoot
#############################################################################
#
# modification history
+#
# $Log$
+# Revision 1.6 2001/05/16 14:57:30 alibrary
+# New files for folders and Stack
+#
+#
+# Revision 1.5 2001/02/23 17:33:40 buncic
+# Added alifs wrapper for CASTOR and alirun modified accordingly.
+#
+# Revision 1.4 2001/02/08 18:55:43 buncic
+# Support for writing to remote file systems (shift/castor).
+#
+# Revision 1.3 2001/02/01 18:00:23 buncic
+# Use bash in place of sh for compatibility
+#
# Revision 1.2 2001/02/01 17:46:26 buncic
# Fixed mktemp on HP and Sun
#
# - Digits .............. digitisation
# - SDigits ............. creation of sumable digits
# - SDigits2Digits ...... conversion SDigits->Digits
+# - Reco ................ reconstruction
#
# -d <TPC+ITS+..> | -d all | -all
# 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.
# 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.
#
# -o <directory>
-# A directory where output file(s) will be stored. If does not exist, it will be created. If not specified, current directory is used.
+# 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:
+#
+# o) if file name begins with rfio:, shift:, castor:, hpss:, /shift, /castor, /hpss => rfio (remote file i/o) protocol (requires rfiod on server side)
+# o) if file name begins with root:, roots: => root and secure root protocol (requires rootd on server side)
+# o) if file name begins with http: => HTTP protocol (requires modified apache server on server side)
#
# -split
# If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
# -debug
# Execute AliRoot under gdb.
#
+# -debugger <command_name>
+# Execute AliRoot under debugger other than gdb.
+#
+# -debuglevel <level>
+# Set AliRoot debug flag to <level>.
+#
# -break <breakpoint>
# Execute AliRoot under gdb and set <breakpoint>.
#
# Create man page for alirun.
#
# EXAMPLES
-# Run sumulation for 1 event, 100 particles and store output in file test.root in /tmp/event.1 directory:
+# Run sumulation for 1 event, 100 particles and store output in file galice.root in /tmp/event.1 directory:
#
-# alirun -o /tmp/event.1 -f test.root -p 100 -verbose -c Hits
+# alirun -o /tmp/event.1 -p 100 -c Hits
#
-# 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:
+# 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:
#
-# alirun -o /tmp/event.2 -split -p 100 -verbose -c Hits
+# alirun -o /tmp/event.2 -f test.root -split -p 100 -c Hits
#
# Use output from first step and create TOF and RICH digits. Output is in the same direcory and in file test.root
#
-# alirun -d TOF+RICH -o /tmp/event.1 -f test.root -verbose -c Digits
+# alirun -d TOF+RICH -o /tmp/event.1 -c Digits
#
# Use output from second step and create digits for all detectors. Output is in the same direcory and branches are diverted to separate files:
#
-# alirun -d all -o /tmp/event.2 -split -verbose -c Digits
+# alirun -d all -o /tmp/event.2 -f test.root -split -c Digits
#
# AUTHOR:
# Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
#C<
###########################################################################
+if [ "$ALIRUN_SHELL" = "" ]
+then
+ ALIRUN_SHELL=bin/sh
+ for shell in bash zsh ksh
+ do
+ for dir in /bin /usr/bin /usr/local/bin
+ do
+ if [ -x $dir/$shell ]
+ then
+ ALIRUN_SHELL=$dir/$shell; export ALIRUN_SHELL
+ break 2
+ fi
+ done
+ done
+ exec $ALIRUN_SHELL -norc -noprofile $0 $*
+fi
+
+
###########################################################################
AliRun()
###########################################################################
exit
}
+###########################################################################
+AliSetRoot()
+###########################################################################
+{
+ ALICE_ROOT=$1; export ALICE_ROOT
+ ALICE=`dirname $ALICE_ROOT`; export ALICE
+ ALICE_LEVEL=`basename $ALICE_ROOT`; export ALICE_LEVEL
+ ALICE_TARGET=`uname`; export ALICE_TARGET
+ ROOTSYS=$2; export ROOTSYS
+
+ LD_LIBRARY_PATH=$ROOTSYS/lib
+
+ if [ -f $ALICE/bin/changeRoot.sh ]
+ then
+ . $ALICE/bin/changeRoot.sh \
+ $ALICE $ALICE_LEVEL $ALICE_TARGET $ROOTSYS
+ fi
+
+ if [ ! -x $ALICE_BIN/aliroot -o ! -x $ROOTSYS/bin/root ]
+ then
+ printf "Invalid Alice library directory: %s\n" $1
+ exit 1
+ fi
+
+ LD_LIBRARY_PATH=${ROOTSYS}/lib:${ALICE_LIB}; export LD_LIBRARY_PATH
+ PATH=${ALICE_BIN}:${ROOTSYS}/bin:${PATH}; export PATH
+
+ printf "ALICE environment reset to %s\n" $ALICE_ROOT
+ which root
+ which aliroot
+}
+
###########################################################################
Mktemp()
###########################################################################
echo /tmp/alirun.$$.
}
+###########################################################################
+ConfigureIO()
+###########################################################################
+{
+ if [ "$1" != "" ]
+ then
+ case $1 in
+ CASTOR)
+ MKDIR="alifs mkdir"
+ RMDIR="alifs rm -r"
+ STAT="/usr/local/bin/rfstat"
+ if [ "$STAGE_HOST" = "" ]
+ then
+ unset STAGE_HOST
+ fi
+ if [ "$STAGE_POOL" = "" ]
+ then
+ unset STAGE_POOL
+ fi
+ ;;
+ RFIO)
+ MKDIR="/usr/local/bin/rfmkdir"
+ RMDIR="echo y | /usr/local/bin/rfrm -r"
+ STAT="/usr/local/bin/rfstat"
+ ;;
+ LOCAL)
+ MKDIR="mkdir"
+ RMDIR="rm -rf"
+ STAT="test -d"
+ ;;
+ *)
+ printf "%s I/O not yet supported by alirun.\n" $1
+ exit 255
+ ;;
+ esac
+ fi
+}
+
+
###########################################################################
Cleanup()
###########################################################################
{
- if [ -d $ALIRUN_TMPDIR ]
+ $STAT $ALIRUN_TMPDIR > /dev/null 2>&1
+ if [ $? -eq 0 ]
then
- rm -rf $ALIRUN_TMPDIR
+ $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1
fi
}
macro=`HitsMacro`
;;
Digits)
- macro=`DigitsMacro Hits2Digits`
+ macro=`GenericMacro Hits2Digits`
;;
SDigits)
- macro=`DigitsMacro Hits2SDigits`
+ macro=`GenericMacro Hits2SDigits`
;;
SDigits2Digits)
- macro=`DigitsMacro SDigits2Digits`
+ macro=`GenericMacro SDigits2Digits`
+ ;;
+ Reco)
+ macro=`GenericMacro RunReco`
;;
*.C|*.C\(*\))
macro=$1
c
where
EOF
- $ECHO gdb -q -x $ALIRUN_TMPDIR/gdb aliroot
+ $ECHO $ALIRUN_DEBUGGER -q -x $ALIRUN_TMPDIR/gdb aliroot
else
if [ "$VERBOSE" = "TRUE" ]
then
$ECHO aliroot -q -b $macro
+ if [ $? -ne 0 ]
+ then
+ exit $?
+ fi
else
$ECHO aliroot -q -b $macro > $stdout 2>&1
if [ $? -ne 0 ]
////////////////////////////////////////////////////////////////////////////
void Simulate()
{
+ TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"recreate");
+
+ $USE_CACHE;
+
+ file->SetCompressionLevel(2);
+
+ gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE")));
+
gAlice->Init(gSystem->Getenv("CONFIG"));
- gAlice->Run(1);
+ $DEBUG_LEVEL;
+
+ gAlice->RunMC($NEVENTS);
}
////////////////////////////////////////////////////////////////////////////
}
###########################################################################
-DigitsMacro()
+GenericMacro()
###########################################################################
{
mode=$1
- macro=$ALIRUN_TMPDIR/Digitize.C
+ macro=$ALIRUN_TMPDIR/$mode.C
cat <<EOF> $macro
////////////////////////////////////////////////////////////////////////////
-void Digitize()
+void $mode()
{
- gAlice->OpenBaseFile("update");
+ TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"update");
+ if (! file ) {
+ cout << "Could not open Hits file. Exiting..." << endl;
+ exit(1);
+ }
+ file->SetCompressionLevel(2);
+
+ $USE_CACHE;
if (gAlice) delete gAlice;
- AliRun *gAlice = (AliRun*)gDirectory->Get("gAlice");
+ AliRun *gAlice = (AliRun*)file->Get("gAlice");
+ $DEBUG_LEVEL;
+
gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
}
////////////////////////////////////////////////////////////////////////////
AliRunMakeman()
###########################################################################
{
- mangen -n tool $0
+ mandir=../man/man4
+ ./mangen -n tool $0
if [ $? -eq 0 ]
then
- if [ -d ../man/man4 ]
- then
- mv $0.? ../man/man4
- fi
+ [ ! -d $mandir ] && mkdir -p $mandir
+ mv `basename $0`.? $mandir
+ exit
fi
- exit
}
###########################################################################
}
###########################################################################
-AliRunDigits()
+AliRunSplitCmd()
###########################################################################
{
if [ "$DETECTORS" = "" ]
then
- AliRoot Digits
+ AliRoot $1
else
for det in $DETECTORS
do
then
if [ "$LSF_FORK" = "TRUE" ]
then
- lsrun AliRoot Digits $CONFIG_DETECTOR
+ lsrun AliRoot $1 $CONFIG_DETECTOR
else
- AliRoot Digits $CONFIG_DETECTOR &
+ AliRoot $1 $CONFIG_DETECTOR &
fi
else
- AliRoot Digits $CONFIG_DETECTOR
+ AliRoot $1 $CONFIG_DETECTOR
fi
done
wait
fi
}
+###########################################################################
+AliRunDigits()
+###########################################################################
+{
+ AliRunSplitCmd Digits
+}
+###########################################################################
+AliRunReco()
+###########################################################################
+{
+ AliRunSplitCmd Reco
+}
###########################################################################
-ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD"; export ALL
-DETECTORS=""; export DETECTORS
-CONFIG_FILE="galice.root"; export CONFIG_FILE
+ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD";
+DETECTORS="";
+FILE="galice.root";
+
CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG
CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES
CONFIG_PATH=`pwd`; export CONFIG_PATH
+CONFIG_BATCH="TRUE"; export CONFIG_BATCH
ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
+ALIRUN_DEBUGGER=gdb
DEBUG="FALSE"
+DEBUG_LEVEL=""
BREAK=""
VERBOSE="TRUE"
OUTPUT=.
-CMDLIST="Usage"
+CMDLIST=""
FORK="FALSE"
FORK_LSF="FALSE"
+BATCH="FALSE"
ECHO=""
+NEVENTS=1
+USE_CACHE="file->UseCache()"
if [ -x /usr/local/lsf/bin/lsrun ]
then
shift 1
DEBUG="TRUE"
;;
+ -debugger)
+ shift 1
+ ALIRUN_DEBUGGER=$1
+ ;;
+ -debuglevel)
+ shift 1
+ DEBUG_LEVEL="gAlice->SetDebug($1)"
+ ;;
-break)
shift 1
DEBUG="TRUE"
shift 1
set -vx
;;
+ -setroot)
+ shift 1
+ AliSetRoot $1 $2
+ shift 1
+ ;;
+ -batch)
+ shift 1
+ BATCH="TRUE"
+ ;;
-echo)
shift 1
ECHO="echo "
;;
-f)
shift 1
- CONFIG_FILE=$1; export CONFIG_FILE
+ FILE=$1
;;
-n)
shift 1
shift 1
CONFIG_SEED=$1; export CONFIG_SEED
;;
+ -nocache)
+ shift 1
+ USE_CACHE=""
+ ;;
-c)
shift 1
CMDLIST=$*
;;
-C)
shift 1
- CONFIG=$1; export CONFIG
+ CONFIG=$1;
+ if [ `dirname $CONFIG` = "." ]
+ then
+ CONFIG=`pwd`/$CONFIG
+ fi
+ export CONFIG
;;
*)
shift 1
esac
done
+if [ "$CMDLIST" = "" ]
+then
+ AliRun
+fi
if [ `dirname $OUTPUT` = "." ]
then
- OUTPUT=`pwd`/$OUTPUT
+ CONFIG_OUTDIR=`pwd`/$OUTPUT
+else
+ CONFIG_OUTDIR=$OUTPUT
fi
-[ ! -d $OUTPUT ] && mkdir -p $OUTPUT
-[ ! -d $ALIRUN_TMPDIR ] && mkdir -p $ALIRUN_TMPDIR
+case $CONFIG_OUTDIR in
+ rfio:*|/shift/*|shift:*)
+ CONFIG_FILE_PREFIX="rfio:"
+ ConfigureIO RFIO
+ ;;
+ /castor/*|castor:*|hpss:*)
+ CONFIG_FILE_PREFIX="rfio:"
+ ConfigureIO CASTOR
+ ;;
+ hpss:*)
+ CONFIG_FILE_PREFIX="rfio:"
+ ConfigureIO RFIO
+ ;;
+ root:*)
+ CONFIG_FILE_PREFIX="root:"
+ ConfigureIO ROOT
+ ;;
+ roots:*)
+ CONFIG_FILE_PREFIX="roots:"
+ ConfigureIO ROOT
+ ;;
+ http:*)
+ CONFIG_FILE_PREFIX="http:"
+ ConfigureIO HTTP
+ ;;
+ file:*)
+ CONFIG_FILE_PREFIX=""
+ ConfigureIO LOCAL
+ ;;
+ /*)
+ CONFIG_FILE_PREFIX=""
+ ConfigureIO LOCAL
+ ;;
+ *)
+ CONFIG_FILE_PREFIX=`pwd`/
+ ConfigureIO LOCAL
+ ;;
+esac
+
+export CONFIG_OUTDIR
+export CONFIG_FILE_PREFIX
+
+$STAT $CONFIG_OUTDIR > /dev/null 2>&1
+if [ $? -ne 0 ]
+then
+ $MKDIR -p $CONFIG_OUTDIR
+fi
+
+CONFIG_FILE=$CONFIG_FILE_PREFIX$CONFIG_OUTDIR/$FILE; export CONFIG_FILE
+
+mkdir -p $ALIRUN_TMPDIR
trap Cleanup 2
(
- cd $OUTPUT
+ cd $ALIRUN_TMPDIR
for cmd in $CMDLIST
do
case `type -t AliRun$cmd` in
done
)
-Cleanup
\ No newline at end of file
+Cleanup