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