]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - share/alirun
Use same form in new and delete (item 5 of effective C++)
[u/mrichter/AliRoot.git] / share / alirun
... / ...
CommitLineData
1#!/bin/sh
2#############################################################################
3# alirun - a shell script to run AliRoot
4#############################################################################
5#
6# modification history
7#
8# $Log$
9# Revision 1.6 2001/05/16 14:57:30 alibrary
10# New files for folders and Stack
11#
12#
13# Revision 1.5 2001/02/23 17:33:40 buncic
14# Added alifs wrapper for CASTOR and alirun modified accordingly.
15#
16# Revision 1.4 2001/02/08 18:55:43 buncic
17# Support for writing to remote file systems (shift/castor).
18#
19# Revision 1.3 2001/02/01 18:00:23 buncic
20# Use bash in place of sh for compatibility
21#
22# Revision 1.2 2001/02/01 17:46:26 buncic
23# Fixed mktemp on HP and Sun
24#
25# Revision 1.1 2001/01/26 21:22:02 hristov
26# Major upgrade of AliRoot code
27#
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
53# - Reco ................ reconstruction
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>
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)
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#
114# -debugger <command_name>
115# Execute AliRoot under debugger other than gdb.
116#
117# -debuglevel <level>
118# Set AliRoot debug flag to <level>.
119#
120# -break <breakpoint>
121# Execute AliRoot under gdb and set <breakpoint>.
122#
123# -makeman
124# Create man page for alirun.
125#
126# EXAMPLES
127# Run sumulation for 1 event, 100 particles and store output in file galice.root in /tmp/event.1 directory:
128#
129# alirun -o /tmp/event.1 -p 100 -c Hits
130#
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:
132#
133# alirun -o /tmp/event.2 -f test.root -split -p 100 -c Hits
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#
137# alirun -d TOF+RICH -o /tmp/event.1 -c Digits
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#
141# alirun -d all -o /tmp/event.2 -f test.root -split -c Digits
142#
143# AUTHOR:
144# Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
145#
146# CREATION DATE:
147# 06-Nov-2000
148#
149#C<
150###########################################################################
151
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
168
169
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
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
218###########################################################################
219Mktemp()
220###########################################################################
221{
222# mktemp -qu /tmp/alirun.$$.XXXXXX
223 echo /tmp/alirun.$$.
224}
225
226###########################################################################
227ConfigureIO()
228###########################################################################
229{
230 if [ "$1" != "" ]
231 then
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
261 fi
262}
263
264
265###########################################################################
266Cleanup()
267###########################################################################
268{
269 $STAT $ALIRUN_TMPDIR > /dev/null 2>&1
270 if [ $? -eq 0 ]
271 then
272 $RMDIR $ALIRUN_TMPDIR >/dev/null 2>&1
273 fi
274}
275
276###########################################################################
277AliRoot()
278###########################################################################
279{
280 case $1 in
281 Hits)
282 macro=`HitsMacro`
283 ;;
284 Digits)
285 macro=`GenericMacro Hits2Digits`
286 ;;
287 SDigits)
288 macro=`GenericMacro Hits2SDigits`
289 ;;
290 SDigits2Digits)
291 macro=`GenericMacro SDigits2Digits`
292 ;;
293 Reco)
294 macro=`GenericMacro RunReco`
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
331 $ECHO $ALIRUN_DEBUGGER -q -x $ALIRUN_TMPDIR/gdb aliroot
332 else
333 if [ "$VERBOSE" = "TRUE" ]
334 then
335 $ECHO aliroot -q -b $macro
336 if [ $? -ne 0 ]
337 then
338 exit $?
339 fi
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{
367 TFile *file = TFile::Open(gSystem->Getenv("CONFIG_FILE"),"recreate");
368
369 $USE_CACHE;
370
371 file->SetCompressionLevel(2);
372
373 gAlice->SetBaseFile(gSystem->DirName(gSystem->Getenv("CONFIG_FILE")));
374
375 gAlice->Init(gSystem->Getenv("CONFIG"));
376
377 $DEBUG_LEVEL;
378
379 gAlice->RunMC($NEVENTS);
380}
381////////////////////////////////////////////////////////////////////////////
382
383EOF
384 echo $macro
385}
386
387###########################################################################
388GenericMacro()
389###########################################################################
390{
391 mode=$1
392
393 macro=$ALIRUN_TMPDIR/$mode.C
394
395 cat <<EOF> $macro
396
397////////////////////////////////////////////////////////////////////////////
398void $mode()
399{
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
407 $USE_CACHE;
408
409 if (gAlice) delete gAlice;
410
411 AliRun *gAlice = (AliRun*)file->Get("gAlice");
412
413 $DEBUG_LEVEL;
414
415 gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
416}
417////////////////////////////////////////////////////////////////////////////
418
419EOF
420 echo $macro
421}
422
423###########################################################################
424AliRunMakeman()
425###########################################################################
426{
427 mandir=../man/man4
428 ./mangen -n tool $0
429 if [ $? -eq 0 ]
430 then
431 [ ! -d $mandir ] && mkdir -p $mandir
432 mv `basename $0`.? $mandir
433 exit
434 fi
435}
436
437###########################################################################
438AliRunMacro()
439###########################################################################
440{
441 AliRoot $*
442}
443
444###########################################################################
445AliRunHits()
446###########################################################################
447{
448 AliRoot Hits
449}
450
451###########################################################################
452AliRunSplitCmd()
453###########################################################################
454{
455 if [ "$DETECTORS" = "" ]
456 then
457 AliRoot $1
458 else
459 for det in $DETECTORS
460 do
461 CONFIG_DETECTOR=$det; export CONFIG_DETECTOR
462 if [ "$FORK" = "TRUE" ]
463 then
464 if [ "$LSF_FORK" = "TRUE" ]
465 then
466 lsrun AliRoot $1 $CONFIG_DETECTOR
467 else
468 AliRoot $1 $CONFIG_DETECTOR &
469 fi
470 else
471 AliRoot $1 $CONFIG_DETECTOR
472 fi
473 done
474 wait
475 fi
476}
477
478###########################################################################
479AliRunDigits()
480###########################################################################
481{
482 AliRunSplitCmd Digits
483}
484
485###########################################################################
486AliRunReco()
487###########################################################################
488{
489 AliRunSplitCmd Reco
490}
491
492###########################################################################
493
494ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD";
495DETECTORS="";
496FILE="galice.root";
497
498CONFIG=$ALICE_ROOT/macros/Config.C; export CONFIG
499CONFIG_NPARTICLES=50; export CONFIG_NPARTICLES
500CONFIG_PATH=`pwd`; export CONFIG_PATH
501CONFIG_BATCH="TRUE"; export CONFIG_BATCH
502
503ALIRUN_TMPDIR=`Mktemp`; export ALIRUN_TMPDIR
504ALIRUN_DEBUGGER=gdb
505
506DEBUG="FALSE"
507DEBUG_LEVEL=""
508BREAK=""
509VERBOSE="TRUE"
510OUTPUT=.
511CMDLIST=""
512FORK="FALSE"
513FORK_LSF="FALSE"
514BATCH="FALSE"
515ECHO=""
516NEVENTS=1
517USE_CACHE="file->UseCache()"
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
528 CONFIG=$config; export CONFIG
529 break
530 fi
531done
532
533for param in $*
534do
535 case $param in
536 -debug)
537 shift 1
538 DEBUG="TRUE"
539 ;;
540 -debugger)
541 shift 1
542 ALIRUN_DEBUGGER=$1
543 ;;
544 -debuglevel)
545 shift 1
546 DEBUG_LEVEL="gAlice->SetDebug($1)"
547 ;;
548 -break)
549 shift 1
550 DEBUG="TRUE"
551 BREAK=$1
552 ;;
553 -trace)
554 shift 1
555 set -vx
556 ;;
557 -setroot)
558 shift 1
559 AliSetRoot $1 $2
560 shift 1
561 ;;
562 -batch)
563 shift 1
564 BATCH="TRUE"
565 ;;
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
608 CONFIG_SPLIT_FILE="TRUE"; export CONFIG_SPLIT_FILE
609 ;;
610 -f)
611 shift 1
612 FILE=$1
613 ;;
614 -n)
615 shift 1
616 NEVENTS=$1
617 ;;
618 -p)
619 shift 1
620 CONFIG_NPARTICLES=$1; export CONFIG_NPARTICLES
621 ;;
622 -seed)
623 shift 1
624 CONFIG_SEED=$1; export CONFIG_SEED
625 ;;
626 -nocache)
627 shift 1
628 USE_CACHE=""
629 ;;
630 -c)
631 shift 1
632 CMDLIST=$*
633 break
634 ;;
635 -C)
636 shift 1
637 CONFIG=$1;
638 if [ `dirname $CONFIG` = "." ]
639 then
640 CONFIG=`pwd`/$CONFIG
641 fi
642 export CONFIG
643 ;;
644 *)
645 shift 1
646 ;;
647 esac
648done
649
650if [ "$CMDLIST" = "" ]
651then
652 AliRun
653fi
654
655if [ `dirname $OUTPUT` = "." ]
656then
657 CONFIG_OUTDIR=`pwd`/$OUTPUT
658else
659 CONFIG_OUTDIR=$OUTPUT
660fi
661
662case $CONFIG_OUTDIR in
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
674 ;;
675 root:*)
676 CONFIG_FILE_PREFIX="root:"
677 ConfigureIO ROOT
678 ;;
679 roots:*)
680 CONFIG_FILE_PREFIX="roots:"
681 ConfigureIO ROOT
682 ;;
683 http:*)
684 CONFIG_FILE_PREFIX="http:"
685 ConfigureIO HTTP
686 ;;
687 file:*)
688 CONFIG_FILE_PREFIX=""
689 ConfigureIO LOCAL
690 ;;
691 /*)
692 CONFIG_FILE_PREFIX=""
693 ConfigureIO LOCAL
694 ;;
695 *)
696 CONFIG_FILE_PREFIX=`pwd`/
697 ConfigureIO LOCAL
698 ;;
699esac
700
701export CONFIG_OUTDIR
702export CONFIG_FILE_PREFIX
703
704$STAT $CONFIG_OUTDIR > /dev/null 2>&1
705if [ $? -ne 0 ]
706then
707 $MKDIR -p $CONFIG_OUTDIR
708fi
709
710CONFIG_FILE=$CONFIG_FILE_PREFIX$CONFIG_OUTDIR/$FILE; export CONFIG_FILE
711
712mkdir -p $ALIRUN_TMPDIR
713
714trap Cleanup 2
715
716(
717 cd $ALIRUN_TMPDIR
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
731Cleanup