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