Last minute changes (C.Blume)
[u/mrichter/AliRoot.git] / share / alirun
CommitLineData
a571aae4 1#!/bin/sh
e0381e22 2#############################################################################
3# alirun - a shell script to run AliRoot
4#############################################################################
5#
6# modification history
9e1a0ddb 7#
e0381e22 8# $Log$
9e1a0ddb 9#
10# Revision 1.5 2001/02/23 17:33:40 buncic
11# Added alifs wrapper for CASTOR and alirun modified accordingly.
12#
124fe280 13# Revision 1.4 2001/02/08 18:55:43 buncic
14# Support for writing to remote file systems (shift/castor).
15#
a571aae4 16# Revision 1.3 2001/02/01 18:00:23 buncic
17# Use bash in place of sh for compatibility
18#
572784b9 19# Revision 1.2 2001/02/01 17:46:26 buncic
20# Fixed mktemp on HP and Sun
21#
da41e58d 22# Revision 1.1 2001/01/26 21:22:02 hristov
23# Major upgrade of AliRoot code
24#
e0381e22 25#
26# SYNOPSIS
27# alirun [[-d <TPC+ITS+..>|-all]]
28# [-f <hits file>]
29# [-o <output directory>]
30# [-split]
31# [-C <Config.C>]
32# [-p <particle#>]
33# [-seed <seed for random number generator>]
34# [-n <event #>]
35# <-c <command ...>>
36#
37# DESCRIPTION
38# This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode.
39#
40# CONFIGURATION OPTIONS
41# The following options are used to configure AliRoot session.
42#
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:
45#
46# - Hits ................ simulation
47# - Digits .............. digitisation
48# - SDigits ............. creation of sumable digits
49# - SDigits2Digits ...... conversion SDigits->Digits
124fe280 50# - Reco ................ reconstruction
e0381e22 51#
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.
54#
55# -f <file>
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.
57#
58# -o <directory>
124fe280 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:
60#
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)
e0381e22 64#
65# -split
66# If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
67#
68# The layout of output directory is the following:
69#
70# <directory>
71# |-- Digits.<detector>.root
72# |-- SDigits.<detector>.root
73# |-- Hits.root
74# |-- Kine.root
75# |-- Reco.root
76# `-- galice.root
77#
78# -C <macro.C>
79# An alternative to Config.C macro which contains AliRoot configuration.
80#
81# -p <n>
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.
83#
84# -seed <n>
85# Seed for random number generator (used to initialise TRandom3(n)).
86#
87# -n <n>
88# Number of events to generate (not yet implemented).
89#
90# RUN OPTIONS
91# These options define run time appearance of the AliRoot session.
92#
93# -help
94# Display usage.
95#
96# -verbose
97# Switch verbose screen output on.
98#
99# -quiet
100# Switch verbose output off. Output is redirected to a file which is shown on standard output only if <command> returns non zero status.
101#
102# -fork
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.
104#
105# -trace
106# Show trace of execution of shell commands.
107#
108# -debug
109# Execute AliRoot under gdb.
110#
124fe280 111# -debugger <command_name>
112# Execute AliRoot under debugger other than gdb.
113#
9e1a0ddb 114# -debuglevel <level>
115# Set AliRoot debug flag to <level>.
116#
e0381e22 117# -break <breakpoint>
118# Execute AliRoot under gdb and set <breakpoint>.
119#
120# -makeman
121# Create man page for alirun.
122#
123# EXAMPLES
124fe280 124# Run sumulation for 1 event, 100 particles and store output in file galice.root in /tmp/event.1 directory:
e0381e22 125#
124fe280 126# alirun -o /tmp/event.1 -p 100 -c Hits
e0381e22 127#
124fe280 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:
e0381e22 129#
124fe280 130# alirun -o /tmp/event.2 -f test.root -split -p 100 -c Hits
e0381e22 131#
132# Use output from first step and create TOF and RICH digits. Output is in the same direcory and in file test.root
133#
124fe280 134# alirun -d TOF+RICH -o /tmp/event.1 -c Digits
e0381e22 135#
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:
137#
124fe280 138# alirun -d all -o /tmp/event.2 -f test.root -split -c Digits
e0381e22 139#
140# AUTHOR:
141# Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
142#
143# CREATION DATE:
144# 06-Nov-2000
145#
146#C<
147###########################################################################
124fe280 148
a571aae4 149if [ "$ALIRUN_SHELL" = "" ]
150then
151 ALIRUN_SHELL=bin/sh
152 for shell in bash zsh ksh
153 do
154 for dir in /bin /usr/bin /usr/local/bin
155 do
156 if [ -x $dir/$shell ]
157 then
158 ALIRUN_SHELL=$dir/$shell; export ALIRUN_SHELL
159 break 2
160 fi
161 done
162 done
163 exec $ALIRUN_SHELL -norc -noprofile $0 $*
164fi
124fe280 165
e0381e22 166###########################################################################
167AliRun()
168###########################################################################
169{
170 printf "Usage: alirun [[-d <TPC+ITS+..>|-all]]\n"
171 printf " [-f <hits file>]\n"
172 printf " [-o <output directory>]\n"
173 printf " [-split]\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"
179 exit
180}
181
182###########################################################################
183Mktemp()
184###########################################################################
185{
da41e58d 186# mktemp -qu /tmp/alirun.$$.XXXXXX
187 echo /tmp/alirun.$$.
e0381e22 188}
189
a571aae4 190###########################################################################
124fe280 191ConfigureIO()
a571aae4 192###########################################################################
193{
124fe280 194 if [ "$1" != "" ]
a571aae4 195 then
124fe280 196 case $1 in
197 CASTOR)
198 MKDIR="alifs mkdir"
199 RMDIR="alifs rm -r"
200 STAT="/usr/local/bin/rfstat"
201 if [ "$STAGE_HOST" = "" ]
202 then
203 unset STAGE_HOST
204 fi
205 if [ "$STAGE_POOL" = "" ]
206 then
207 unset STAGE_POOL
208 fi
209 ;;
210 RFIO)
211 MKDIR="/usr/local/bin/rfmkdir"
212 RMDIR="echo y | /usr/local/bin/rfrm -r"
213 STAT="/usr/local/bin/rfstat"
214 ;;
215 LOCAL)
216 MKDIR="mkdir"
217 RMDIR="rm -rf"
218 STAT="test -d"
219 ;;
220 *)
221 printf "%s I/O not yet supported by alirun.\n" $1
222 exit 255
223 ;;
224 esac
a571aae4 225 fi
226}
227
124fe280 228
e0381e22 229###########################################################################
230Cleanup()
231###########################################################################
232{
a571aae4 233 $STAT $ALIRUN_TMPDIR > /dev/null 2>&1
234 if [ $? -eq 0 ]
e0381e22 235 then
a571aae4 236 $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1
e0381e22 237 fi
238}
239
240###########################################################################
241AliRoot()
242###########################################################################
243{
244 case $1 in
245 Hits)
246 macro=`HitsMacro`
247 ;;
248 Digits)
124fe280 249 macro=`GenericMacro Hits2Digits`
e0381e22 250 ;;
251 SDigits)
124fe280 252 macro=`GenericMacro Hits2SDigits`
e0381e22 253 ;;
254 SDigits2Digits)
124fe280 255 macro=`GenericMacro SDigits2Digits`
256 ;;
257 Reco)
258 macro=`GenericMacro RunReco`
e0381e22 259 ;;
260 *.C|*.C\(*\))
261 macro=$1
262 ;;
263 *)
264 printf "Unknown command: %s. Terminating...\n" $1
265 exit 255
266 ;;
267 esac
268
269 if [ "$2" != "" ]
270 then
271 CONTEXT="<"$2">"
272 else
273 CONTEXT="<"None">"
274 fi
275
276 stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT}
277
278 hr="========================================"
279
280 if [ "$VERBOSE" = "FALSE" ]
281 then
282 printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr
283 fi > $stdout
284
285 if [ "$DEBUG" = "TRUE" ]
286 then
287 cat<<EOF>$ALIRUN_TMPDIR/gdb
288b main
289r -q -b $macro
290disable breakpoints
291b $BREAK
292c
293where
294EOF
124fe280 295 $ECHO $ALIRUN_DEBUGGER -q -x $ALIRUN_TMPDIR/gdb aliroot
e0381e22 296 else
297 if [ "$VERBOSE" = "TRUE" ]
298 then
299 $ECHO aliroot -q -b $macro
124fe280 300 if [ $? -ne 0 ]
301 then
302 exit $?
303 fi
e0381e22 304 else
305 $ECHO aliroot -q -b $macro > $stdout 2>&1
306 if [ $? -ne 0 ]
307 then
308 echo "- "aliroot -q -b " "$1" "$CONTEXT
309 cat $stdout
310 exit
311 else
312 echo "+ "aliroot -q -b " "$1" "$CONTEXT
313 fi
314 fi
315 fi
316
317}
318
319
320###########################################################################
321HitsMacro()
322###########################################################################
323{
324 macro=$ALIRUN_TMPDIR/Simulate.C
325
326 cat <<EOF> $macro
327
328////////////////////////////////////////////////////////////////////////////
329void Simulate()
330{
a571aae4 331 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"recreate");
332
124fe280 333 $USE_CACHE;
a571aae4 334
335 file->SetCompressionLevel(2);
336
337 gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE")));
338
e0381e22 339 gAlice->Init(gSystem->Getenv("CONFIG"));
340
9e1a0ddb 341 $DEBUG_LEVEL;
342
343 gAlice->RunMC($NEVENTS);
e0381e22 344}
345////////////////////////////////////////////////////////////////////////////
346
347EOF
348 echo $macro
349}
350
351###########################################################################
124fe280 352GenericMacro()
e0381e22 353###########################################################################
354{
355 mode=$1
356
124fe280 357 macro=$ALIRUN_TMPDIR/$mode.C
e0381e22 358
359 cat <<EOF> $macro
360
361////////////////////////////////////////////////////////////////////////////
124fe280 362void $mode()
e0381e22 363{
a571aae4 364 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"update");
365 if (! file ) {
366 cout << "Could not open Hits file. Exiting..." << endl;
367 exit(1);
368 }
369 file->SetCompressionLevel(2);
370
124fe280 371 $USE_CACHE;
e0381e22 372
373 if (gAlice) delete gAlice;
374
a571aae4 375 AliRun *gAlice = (AliRun*)file->Get("gAlice");
e0381e22 376
9e1a0ddb 377 $DEBUG_LEVEL;
378
e0381e22 379 gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
380}
381////////////////////////////////////////////////////////////////////////////
382
383EOF
384 echo $macro
385}
386
387###########################################################################
388AliRunMakeman()
389###########################################################################
390{
a571aae4 391 mandir=../man/man4
392 ./mangen -n tool $0
e0381e22 393 if [ $? -eq 0 ]
394 then
a571aae4 395 [ ! -d $mandir ] && mkdir -p $mandir
396 mv `basename $0`.? $mandir
397 exit
e0381e22 398 fi
e0381e22 399}
400
401###########################################################################
402AliRunMacro()
403###########################################################################
404{
405 AliRoot $*
406}
407
408###########################################################################
409AliRunHits()
410###########################################################################
411{
412 AliRoot Hits
413}
414
415###########################################################################
9e1a0ddb 416AliRunSplitCmd()
e0381e22 417###########################################################################
418{
419 if [ "$DETECTORS" = "" ]
420 then
9e1a0ddb 421 AliRoot $1
e0381e22 422 else
423 for det in $DETECTORS
424 do
da41e58d 425 CONFIG_DETECTOR=$det; export CONFIG_DETECTOR
e0381e22 426 if [ "$FORK" = "TRUE" ]
427 then
428 if [ "$LSF_FORK" = "TRUE" ]
429 then
9e1a0ddb 430 lsrun AliRoot $1 $CONFIG_DETECTOR
e0381e22 431 else
9e1a0ddb 432 AliRoot $1 $CONFIG_DETECTOR &
e0381e22 433 fi
434 else
9e1a0ddb 435 AliRoot $1 $CONFIG_DETECTOR
e0381e22 436 fi
437 done
438 wait
439 fi
440}
441
9e1a0ddb 442###########################################################################
443AliRunDigits()
444###########################################################################
445{
446 AliRunSplitCmd Digits
447}
448
449###########################################################################
450AliRunReco()
451###########################################################################
452{
453 AliRunSplitCmd Reco
454}
455
a571aae4 456###########################################################################
457
124fe280 458ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD";
459DETECTORS="";
a571aae4 460FILE="galice.root";
e0381e22 461
da41e58d 462CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG
463CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES
464CONFIG_PATH=`pwd`; export CONFIG_PATH
124fe280 465CONFIG_BATCH="TRUE"; export CONFIG_BATCH
e0381e22 466
da41e58d 467ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
124fe280 468ALIRUN_DEBUGGER=gdb
e0381e22 469
470DEBUG="FALSE"
9e1a0ddb 471DEBUG_LEVEL=""
e0381e22 472BREAK=""
473VERBOSE="TRUE"
474OUTPUT=.
9e1a0ddb 475CMDLIST=""
e0381e22 476FORK="FALSE"
477FORK_LSF="FALSE"
478ECHO=""
9e1a0ddb 479NEVENTS=1
124fe280 480USE_CACHE="file->UseCache()"
e0381e22 481
482if [ -x /usr/local/lsf/bin/lsrun ]
483then
484 FORK_LSF="TRUE"
485fi
486
487for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C
488do
489 if [ -f $config ]
490 then
da41e58d 491 CONFIG=$config; export CONFIG
e0381e22 492 break
493 fi
494done
495
496for param in $*
497do
498 case $param in
499 -debug)
500 shift 1
501 DEBUG="TRUE"
502 ;;
124fe280 503 -debugger)
504 shift 1
505 ALIRUN_DEBUGGER=$1
506 ;;
9e1a0ddb 507 -debuglevel)
508 shift 1
509 DEBUG_LEVEL="gAlice->SetDebug($1)"
510 ;;
e0381e22 511 -break)
512 shift 1
513 DEBUG="TRUE"
514 BREAK=$1
515 ;;
516 -trace)
517 shift 1
518 set -vx
519 ;;
520 -echo)
521 shift 1
522 ECHO="echo "
523 ;;
524 -verbose)
525 shift 1
526 VERBOSE="TRUE"
527 ;;
528 -quiet)
529 shift 1
530 VERBOSE="FALSE"
531 ;;
532 -help)
533 AliRun
534 ;;
535 -makeman)
536 AliRunMakeman
537 ;;
538 -fork)
539 shift 1
540 FORK="TRUE"
541 ;;
542 -d)
543 shift 1
544 list=$1
545 if [ "$list" = "all" ]
546 then
547 DETECTORS=$ALL
548 else
549 DETECTORS=`echo $list | sed 's/+/ /g'`
550 fi
551 ;;
552 -all)
553 shift 1
554 DETECTORS=$ALL
555 ;;
556 -o)
557 shift 1
558 OUTPUT=$1
559 ;;
560 -split)
561 shift 1
da41e58d 562 CONFIG_SPLIT_FILE="TRUE"; export CONFIG_SPLIT_FILE
e0381e22 563 ;;
564 -f)
565 shift 1
a571aae4 566 FILE=$1
e0381e22 567 ;;
568 -n)
569 shift 1
570 NEVENTS=$1
571 ;;
572 -p)
573 shift 1
da41e58d 574 CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES
e0381e22 575 ;;
576 -seed)
577 shift 1
da41e58d 578 CONFIG_SEED=$1; export CONFIG_SEED
e0381e22 579 ;;
124fe280 580 -nocache)
581 shift 1
582 USE_CACHE=""
583 ;;
e0381e22 584 -c)
585 shift 1
586 CMDLIST=$*
587 break
588 ;;
589 -C)
590 shift 1
124fe280 591 CONFIG=$1;
592 if [ `dirname $CONFIG` = "." ]
593 then
594 CONFIG=`pwd`/$CONFIG
595 fi
596 export CONFIG
e0381e22 597 ;;
598 *)
599 shift 1
600 ;;
601 esac
602done
603
9e1a0ddb 604if [ "$CMDLIST" = "" ]
605then
606 AliRun
607fi
608
e0381e22 609if [ `dirname $OUTPUT` = "." ]
610then
a571aae4 611 CONFIG_OUTDIR=`pwd`/$OUTPUT
612else
613 CONFIG_OUTDIR=$OUTPUT
e0381e22 614fi
615
a571aae4 616case $CONFIG_OUTDIR in
124fe280 617 rfio:*|/shift/*|shift:*)
618 CONFIG_FILE_PREFIX="rfio:"
619 ConfigureIO RFIO
620 ;;
621 /castor/*|castor:*|hpss:*)
622 CONFIG_FILE_PREFIX="rfio:"
623 ConfigureIO CASTOR
624 ;;
625 hpss:*)
626 CONFIG_FILE_PREFIX="rfio:"
627 ConfigureIO RFIO
a571aae4 628 ;;
629 root:*)
124fe280 630 CONFIG_FILE_PREFIX="root:"
631 ConfigureIO ROOT
632 ;;
633 roots:*)
634 CONFIG_FILE_PREFIX="roots:"
635 ConfigureIO ROOT
a571aae4 636 ;;
637 http:*)
124fe280 638 CONFIG_FILE_PREFIX="http:"
639 ConfigureIO HTTP
a571aae4 640 ;;
641 file:*)
124fe280 642 CONFIG_FILE_PREFIX=""
643 ConfigureIO LOCAL
a571aae4 644 ;;
124fe280 645 /*)
646 CONFIG_FILE_PREFIX=""
647 ConfigureIO LOCAL
648 ;;
a571aae4 649 *)
124fe280 650 CONFIG_FILE_PREFIX=`pwd`/
651 ConfigureIO LOCAL
a571aae4 652 ;;
653esac
654
655export CONFIG_OUTDIR
124fe280 656export CONFIG_FILE_PREFIX
a571aae4 657
124fe280 658$STAT $CONFIG_OUTDIR > /dev/null 2>&1
659if [ $? -ne 0 ]
660then
661 $MKDIR -p $CONFIG_OUTDIR
662fi
663
664mkdir -p $ALIRUN_TMPDIR
a571aae4 665
124fe280 666CONFIG_FILE=$CONFIG_FILE_PREFIX$CONFIG_OUTDIR/$FILE; export CONFIG_FILE
e0381e22 667
668trap Cleanup 2
669
670(
a571aae4 671 cd $ALIRUN_TMPDIR
e0381e22 672 for cmd in $CMDLIST
673 do
674 case `type -t AliRun$cmd` in
675 function)
676 shift 1
677 AliRun$cmd $*
678 ;;
679 *)
680 ;;
681 esac
682 done
683)
684
a571aae4 685Cleanup