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