#!/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 # # Revision 1.1 2001/01/26 21:22:02 hristov # Major upgrade of AliRoot code # # # SYNOPSIS # alirun [[-d |-all]] # [-f ] # [-o ] # [-split] # [-C ] # [-p ] # [-seed ] # [-n ] # <-c > # # DESCRIPTION # This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode. # # CONFIGURATION OPTIONS # The following options are used to configure AliRoot session. # # -c # 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: # # - Hits ................ simulation # - Digits .............. digitisation # - SDigits ............. creation of sumable digits # - SDigits2Digits ...... conversion SDigits->Digits # - Reco ................ reconstruction # # -d | -d all | -all # Selects detector for which 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. # # -f # 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 # 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. # # The layout of output directory is the following: # # # |-- Digits..root # |-- SDigits..root # |-- Hits.root # |-- Kine.root # |-- Reco.root # `-- galice.root # # -C # An alternative to Config.C macro which contains AliRoot configuration. # # -p # 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. # # -seed # Seed for random number generator (used to initialise TRandom3(n)). # # -n # Number of events to generate (not yet implemented). # # RUN OPTIONS # These options define run time appearance of the AliRoot session. # # -help # Display usage. # # -verbose # Switch verbose screen output on. # # -quiet # Switch verbose output off. Output is redirected to a file which is shown on standard output only if returns non zero status. # # -fork # 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. # # -trace # Show trace of execution of shell commands. # # -debug # Execute AliRoot under gdb. # # -debugger # Execute AliRoot under debugger other than gdb. # # -debuglevel # Set AliRoot debug flag to . # # -break # Execute AliRoot under gdb and set . # # -makeman # Create man page for alirun. # # EXAMPLES # Run sumulation for 1 event, 100 particles and store output in file galice.root in /tmp/event.1 directory: # # alirun -o /tmp/event.1 -p 100 -c Hits # # 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 -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 -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 -f test.root -split -c Digits # # AUTHOR: # Predrag Buncic, e-mail: Predrag.Buncic@cern.ch # # CREATION DATE: # 06-Nov-2000 # #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() ########################################################################### { printf "Usage: alirun [[-d |-all]]\n" printf " [-f ]\n" printf " [-o ]\n" printf " [-split]\n" printf " [-C ]\n" printf " [-p ]\n" printf " [-seed ]\n" printf " [-n event #]\n" printf " <-c >\n" 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() ########################################################################### { # mktemp -qu /tmp/alirun.$$.XXXXXX 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() ########################################################################### { $STAT $ALIRUN_TMPDIR > /dev/null 2>&1 if [ $? -eq 0 ] then $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1 fi } ########################################################################### AliRoot() ########################################################################### { case $1 in Hits) macro=`HitsMacro` ;; Digits) macro=`GenericMacro Hits2Digits` ;; SDigits) macro=`GenericMacro Hits2SDigits` ;; SDigits2Digits) macro=`GenericMacro SDigits2Digits` ;; Reco) macro=`GenericMacro RunReco` ;; *.C|*.C\(*\)) macro=$1 ;; *) printf "Unknown command: %s. Terminating...\n" $1 exit 255 ;; esac if [ "$2" != "" ] then CONTEXT="<"$2">" else CONTEXT="<"None">" fi stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT} hr="========================================" if [ "$VERBOSE" = "FALSE" ] then printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr fi > $stdout if [ "$DEBUG" = "TRUE" ] then cat<$ALIRUN_TMPDIR/gdb b main r -q -b $macro disable breakpoints b $BREAK c where EOF $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 ] then echo "- "aliroot -q -b " "$1" "$CONTEXT cat $stdout exit else echo "+ "aliroot -q -b " "$1" "$CONTEXT fi fi fi } ########################################################################### HitsMacro() ########################################################################### { macro=$ALIRUN_TMPDIR/Simulate.C cat < $macro //////////////////////////////////////////////////////////////////////////// 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")); $DEBUG_LEVEL; gAlice->RunMC($NEVENTS); } //////////////////////////////////////////////////////////////////////////// EOF echo $macro } ########################################################################### GenericMacro() ########################################################################### { mode=$1 macro=$ALIRUN_TMPDIR/$mode.C cat < $macro //////////////////////////////////////////////////////////////////////////// void $mode() { 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*)file->Get("gAlice"); $DEBUG_LEVEL; gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR")); } //////////////////////////////////////////////////////////////////////////// EOF echo $macro } ########################################################################### AliRunMakeman() ########################################################################### { mandir=../man/man4 ./mangen -n tool $0 if [ $? -eq 0 ] then [ ! -d $mandir ] && mkdir -p $mandir mv `basename $0`.? $mandir exit fi } ########################################################################### AliRunMacro() ########################################################################### { AliRoot $* } ########################################################################### AliRunHits() ########################################################################### { AliRoot Hits } ########################################################################### AliRunSplitCmd() ########################################################################### { if [ "$DETECTORS" = "" ] then AliRoot $1 else for det in $DETECTORS do CONFIG_DETECTOR=$det; export CONFIG_DETECTOR if [ "$FORK" = "TRUE" ] then if [ "$LSF_FORK" = "TRUE" ] then lsrun AliRoot $1 $CONFIG_DETECTOR else AliRoot $1 $CONFIG_DETECTOR & fi else 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"; 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="" FORK="FALSE" FORK_LSF="FALSE" BATCH="FALSE" ECHO="" NEVENTS=1 USE_CACHE="file->UseCache()" if [ -x /usr/local/lsf/bin/lsrun ] then FORK_LSF="TRUE" fi for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C do if [ -f $config ] then CONFIG=$config; export CONFIG break fi done for param in $* do case $param in -debug) shift 1 DEBUG="TRUE" ;; -debugger) shift 1 ALIRUN_DEBUGGER=$1 ;; -debuglevel) shift 1 DEBUG_LEVEL="gAlice->SetDebug($1)" ;; -break) shift 1 DEBUG="TRUE" BREAK=$1 ;; -trace) shift 1 set -vx ;; -setroot) shift 1 AliSetRoot $1 $2 shift 1 ;; -batch) shift 1 BATCH="TRUE" ;; -echo) shift 1 ECHO="echo " ;; -verbose) shift 1 VERBOSE="TRUE" ;; -quiet) shift 1 VERBOSE="FALSE" ;; -help) AliRun ;; -makeman) AliRunMakeman ;; -fork) shift 1 FORK="TRUE" ;; -d) shift 1 list=$1 if [ "$list" = "all" ] then DETECTORS=$ALL else DETECTORS=`echo $list | sed 's/+/ /g'` fi ;; -all) shift 1 DETECTORS=$ALL ;; -o) shift 1 OUTPUT=$1 ;; -split) shift 1 CONFIG_SPLIT_FILE="TRUE"; export CONFIG_SPLIT_FILE ;; -f) shift 1 FILE=$1 ;; -n) shift 1 NEVENTS=$1 ;; -p) shift 1 CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES ;; -seed) shift 1 CONFIG_SEED=$1; export CONFIG_SEED ;; -nocache) shift 1 USE_CACHE="" ;; -c) shift 1 CMDLIST=$* break ;; -C) shift 1 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 CONFIG_OUTDIR=`pwd`/$OUTPUT else CONFIG_OUTDIR=$OUTPUT fi 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 $ALIRUN_TMPDIR for cmd in $CMDLIST do case `type -t AliRun$cmd` in function) shift 1 AliRun$cmd $* ;; *) ;; esac done ) Cleanup