#!/bin/sh ############################################################################# # alirun - a shell script to run AliRoot ############################################################################# # # modification history # $Log$ # 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 # # -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. # # -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. # # -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 test.root in /tmp/event.1 directory: # # alirun -o /tmp/event.1 -f test.root -p 100 -verbose -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: # # alirun -o /tmp/event.2 -split -p 100 -verbose -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 # # 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 # # 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 } ########################################################################### Mktemp() ########################################################################### { # mktemp -qu /tmp/alirun.$$.XXXXXX echo /tmp/alirun.$$. } ########################################################################### Configure() ########################################################################### { if [ -x /usr/local/bin/rfmkdir ] then MKDIR="/usr/local/bin/rfmkdir" else MKDIR="mkdir" fi if [ -x /usr/local/bin/rfrm ] then RMDIR="echo y | /usr/local/bin/rfrm -r" else RMDIR="rm -rf" fi if [ -x /usr/local/bin/rfstat ] then STAT="/usr/local/bin/rfstat" else STAT="test -d" 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=`DigitsMacro Hits2Digits` ;; SDigits) macro=`DigitsMacro Hits2SDigits` ;; SDigits2Digits) macro=`DigitsMacro SDigits2Digits` ;; *.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 gdb -q -x $ALIRUN_TMPDIR/gdb aliroot else if [ "$VERBOSE" = "TRUE" ] then $ECHO aliroot -q -b $macro 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"); //file->UseCache(); file->SetCompressionLevel(2); gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE"))); gAlice->Init(gSystem->Getenv("CONFIG")); gAlice->Run(1); } //////////////////////////////////////////////////////////////////////////// EOF echo $macro } ########################################################################### DigitsMacro() ########################################################################### { mode=$1 macro=$ALIRUN_TMPDIR/Digitize.C cat < $macro //////////////////////////////////////////////////////////////////////////// void Digitize() { TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"update"); if (! file ) { cout << "Could not open Hits file. Exiting..." << endl; exit(1); } file->SetCompressionLevel(2); //file->UseCache(); if (gAlice) delete gAlice; AliRun *gAlice = (AliRun*)file->Get("gAlice"); 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 } ########################################################################### AliRunDigits() ########################################################################### { if [ "$DETECTORS" = "" ] then AliRoot Digits else for det in $DETECTORS do CONFIG_DETECTOR=$det; export CONFIG_DETECTOR if [ "$FORK" = "TRUE" ] then if [ "$LSF_FORK" = "TRUE" ] then lsrun AliRoot Digits $CONFIG_DETECTOR else AliRoot Digits $CONFIG_DETECTOR & fi else AliRoot Digits $CONFIG_DETECTOR fi done wait fi } ########################################################################### Configure; ########################################################################### ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD"; # export ALL DETECTORS=""; # export DETECTORS FILE="galice.root"; CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES CONFIG_PATH=`pwd`; export CONFIG_PATH ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR DEBUG="FALSE" BREAK="" VERBOSE="TRUE" OUTPUT=. CMDLIST="Usage" FORK="FALSE" FORK_LSF="FALSE" ECHO="" 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" ;; -break) shift 1 DEBUG="TRUE" BREAK=$1 ;; -trace) shift 1 set -vx ;; -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 ;; -c) shift 1 CMDLIST=$* break ;; -C) shift 1 CONFIG=$1; export CONFIG ;; *) shift 1 ;; esac done if [ `dirname $OUTPUT` = "." ] then CONFIG_OUTDIR=`pwd`/$OUTPUT else CONFIG_OUTDIR=$OUTPUT fi case $CONFIG_OUTDIR in rfio:*|/shift/*|shift:*|/castor/*|castor:*) ROOT_FILE_TYPE="rfio:" ;; root:*) ROOT_FILE_TYPE="root:" ;; http:*) ROOT_FILE_TYPE="http:" ;; file:*) ROOT_FILE_TYPE="" ;; *) ROOT_FILE_TYPE="" ;; esac export CONFIG_OUTDIR export CONFIG_ROOT_FILE_TYPE for dir in $CONFIG_OUTDIR $ALIRUN_TMPDIR do $STAT $dir > /dev/null 2>&1 if [ $? -ne 0 ] then $MKDIR -p $dir fi done CONFIG_FILE=$ROOT_FILE_TYPE$CONFIG_OUTDIR/$FILE; export CONFIG_FILE 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