]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - share/alirun
Some B mesons added
[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# $Log$
8#
9# SYNOPSIS
10# alirun [[-d <TPC+ITS+..>|-all]]
11# [-f <hits file>]
12# [-o <output directory>]
13# [-split]
14# [-C <Config.C>]
15# [-p <particle#>]
16# [-seed <seed for random number generator>]
17# [-n <event #>]
18# <-c <command ...>>
19#
20# DESCRIPTION
21# This script is a wrapper for AliRoot and provides a command line interface suitable for running in batch mode.
22#
23# CONFIGURATION OPTIONS
24# The following options are used to configure AliRoot session.
25#
26# -c <command1 command2 ...>
27# 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:
28#
29# - Hits ................ simulation
30# - Digits .............. digitisation
31# - SDigits ............. creation of sumable digits
32# - SDigits2Digits ...... conversion SDigits->Digits
33#
34# -d <TPC+ITS+..> | -d all | -all
35# 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.
36#
37# -f <file>
38# 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.
39#
40# -o <directory>
41# A directory where output file(s) will be stored. If does not exist, it will be created. If not specified, current directory is used.
42#
43# -split
44# If specified, this option will tell AliRoot to divert branches of Root trees into separate files.
45#
46# The layout of output directory is the following:
47#
48# <directory>
49# |-- Digits.<detector>.root
50# |-- SDigits.<detector>.root
51# |-- Hits.root
52# |-- Kine.root
53# |-- Reco.root
54# `-- galice.root
55#
56# -C <macro.C>
57# An alternative to Config.C macro which contains AliRoot configuration.
58#
59# -p <n>
60# 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.
61#
62# -seed <n>
63# Seed for random number generator (used to initialise TRandom3(n)).
64#
65# -n <n>
66# Number of events to generate (not yet implemented).
67#
68# RUN OPTIONS
69# These options define run time appearance of the AliRoot session.
70#
71# -help
72# Display usage.
73#
74# -verbose
75# Switch verbose screen output on.
76#
77# -quiet
78# Switch verbose output off. Output is redirected to a file which is shown on standard output only if <command> returns non zero status.
79#
80# -fork
81# 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.
82#
83# -trace
84# Show trace of execution of shell commands.
85#
86# -debug
87# Execute AliRoot under gdb.
88#
89# -break <breakpoint>
90# Execute AliRoot under gdb and set <breakpoint>.
91#
92# -makeman
93# Create man page for alirun.
94#
95# EXAMPLES
96# Run sumulation for 1 event, 100 particles and store output in file test.root in /tmp/event.1 directory:
97#
98# alirun -o /tmp/event.1 -f test.root -p 100 -verbose -c Hits
99#
100# Run sumulation for 1 event, 100 particles and store output in default file galice.root in /tmp/event.1 directory. In adition, divert branches of TreeD,TreeR and TreeK into separate files:
101#
102# alirun -o /tmp/event.2 -split -p 100 -verbose -c Hits
103#
104# Use output from first step and create TOF and RICH digits. Output is in the same direcory and in file test.root
105#
106# alirun -d TOF+RICH -o /tmp/event.1 -f test.root -verbose -c Digits
107#
108# Use output from second step and create digits for all detectors. Output is in the same direcory and branches are diverted to separate files:
109#
110# alirun -d all -o /tmp/event.2 -split -verbose -c Digits
111#
112# AUTHOR:
113# Predrag Buncic, e-mail: Predrag.Buncic@cern.ch
114#
115# CREATION DATE:
116# 06-Nov-2000
117#
118#C<
119###########################################################################
120
121###########################################################################
122AliRun()
123###########################################################################
124{
125 printf "Usage: alirun [[-d <TPC+ITS+..>|-all]]\n"
126 printf " [-f <hits file>]\n"
127 printf " [-o <output directory>]\n"
128 printf " [-split]\n"
129 printf " [-C <Config.C>]\n"
130 printf " [-p <particle#>]\n"
131 printf " [-seed <seed for random number generator>]\n"
132 printf " [-n event #]\n"
133 printf " <-c <command ...>>\n"
134 exit
135}
136
137###########################################################################
138Mktemp()
139###########################################################################
140{
141 mktemp -qu /tmp/alirun.$$.XXXXXX
142}
143
144###########################################################################
145Cleanup()
146###########################################################################
147{
148 if [ -d $ALIRUN_TMPDIR ]
149 then
150 rm -rf $ALIRUN_TMPDIR
151 fi
152}
153
154###########################################################################
155AliRoot()
156###########################################################################
157{
158 case $1 in
159 Hits)
160 macro=`HitsMacro`
161 ;;
162 Digits)
163 macro=`DigitsMacro Hits2Digits`
164 ;;
165 SDigits)
166 macro=`DigitsMacro Hits2SDigits`
167 ;;
168 SDigits2Digits)
169 macro=`DigitsMacro SDigits2Digits`
170 ;;
171 *.C|*.C\(*\))
172 macro=$1
173 ;;
174 *)
175 printf "Unknown command: %s. Terminating...\n" $1
176 exit 255
177 ;;
178 esac
179
180 if [ "$2" != "" ]
181 then
182 CONTEXT="<"$2">"
183 else
184 CONTEXT="<"None">"
185 fi
186
187 stdout=$ALIRUN_TMPDIR/STDOUT.$${$CONTEXT}
188
189 hr="========================================"
190
191 if [ "$VERBOSE" = "FALSE" ]
192 then
193 printf "%s\n+ aliroot -q -b %s %s\n%s\n" $hr$hr $1 $CONTEXT $hr$hr
194 fi > $stdout
195
196 if [ "$DEBUG" = "TRUE" ]
197 then
198 cat<<EOF>$ALIRUN_TMPDIR/gdb
199b main
200r -q -b $macro
201disable breakpoints
202b $BREAK
203c
204where
205EOF
206 $ECHO gdb -q -x $ALIRUN_TMPDIR/gdb aliroot
207 else
208 if [ "$VERBOSE" = "TRUE" ]
209 then
210 $ECHO aliroot -q -b $macro
211 else
212 $ECHO aliroot -q -b $macro > $stdout 2>&1
213 if [ $? -ne 0 ]
214 then
215 echo "- "aliroot -q -b " "$1" "$CONTEXT
216 cat $stdout
217 exit
218 else
219 echo "+ "aliroot -q -b " "$1" "$CONTEXT
220 fi
221 fi
222 fi
223
224}
225
226
227###########################################################################
228HitsMacro()
229###########################################################################
230{
231 macro=$ALIRUN_TMPDIR/Simulate.C
232
233 cat <<EOF> $macro
234
235////////////////////////////////////////////////////////////////////////////
236void Simulate()
237{
238 gAlice->Init(gSystem->Getenv("CONFIG"));
239
240 gAlice->Run(1);
241}
242////////////////////////////////////////////////////////////////////////////
243
244EOF
245 echo $macro
246}
247
248###########################################################################
249DigitsMacro()
250###########################################################################
251{
252 mode=$1
253
254 macro=$ALIRUN_TMPDIR/Digitize.C
255
256 cat <<EOF> $macro
257
258////////////////////////////////////////////////////////////////////////////
259void Digitize()
260{
261 gAlice->OpenBaseFile("update");
262
263 if (gAlice) delete gAlice;
264
265 AliRun *gAlice = (AliRun*)gDirectory->Get("gAlice");
266
267 gAlice->$mode(gSystem->Getenv("CONFIG_DETECTOR"));
268}
269////////////////////////////////////////////////////////////////////////////
270
271EOF
272 echo $macro
273}
274
275###########################################################################
276AliRunMakeman()
277###########################################################################
278{
279 mangen -n tool $0
280 if [ $? -eq 0 ]
281 then
282 if [ -d ../man/man4 ]
283 then
284 mv $0.? ../man/man4
285 fi
286 fi
287 exit
288}
289
290###########################################################################
291AliRunMacro()
292###########################################################################
293{
294 AliRoot $*
295}
296
297###########################################################################
298AliRunHits()
299###########################################################################
300{
301 AliRoot Hits
302}
303
304###########################################################################
305AliRunDigits()
306###########################################################################
307{
308 if [ "$DETECTORS" = "" ]
309 then
310 AliRoot Digits
311 else
312 for det in $DETECTORS
313 do
314 export CONFIG_DETECTOR=$det;
315 if [ "$FORK" = "TRUE" ]
316 then
317 if [ "$LSF_FORK" = "TRUE" ]
318 then
319 lsrun AliRoot Digits $CONFIG_DETECTOR
320 else
321 AliRoot Digits $CONFIG_DETECTOR &
322 fi
323 else
324 AliRoot Digits $CONFIG_DETECTOR
325 fi
326 done
327 wait
328 fi
329}
330
331
332
333###########################################################################
334
335export ALL="MUON RICH TOF ITS TPC PHOS PMD CASTOR ZDC TRD"
336export DETECTORS=""
337export CONFIG_FILE="galice.root"
338export CONFIG=$ALICE_ROOT/macros/Config.C
339export CONFIG_NPARTICLES=50
340export CONFIG_PATH=`pwd`
341
342export ALIRUN_TMPDIR=`Mktemp`
343
344DEBUG="FALSE"
345BREAK=""
346VERBOSE="TRUE"
347OUTPUT=.
348CMDLIST="Usage"
349FORK="FALSE"
350FORK_LSF="FALSE"
351ECHO=""
352
353if [ -x /usr/local/lsf/bin/lsrun ]
354then
355 FORK_LSF="TRUE"
356fi
357
358for config in $CONFIG_PATH/Config.C $ALICE_ROOT/macros/Config.C
359do
360 if [ -f $config ]
361 then
362 export CONFIG=$config
363 break
364 fi
365done
366
367for param in $*
368do
369 case $param in
370 -debug)
371 shift 1
372 DEBUG="TRUE"
373 ;;
374 -break)
375 shift 1
376 DEBUG="TRUE"
377 BREAK=$1
378 ;;
379 -trace)
380 shift 1
381 set -vx
382 ;;
383 -echo)
384 shift 1
385 ECHO="echo "
386 ;;
387 -verbose)
388 shift 1
389 VERBOSE="TRUE"
390 ;;
391 -quiet)
392 shift 1
393 VERBOSE="FALSE"
394 ;;
395 -help)
396 AliRun
397 ;;
398 -makeman)
399 AliRunMakeman
400 ;;
401 -fork)
402 shift 1
403 FORK="TRUE"
404 ;;
405 -d)
406 shift 1
407 list=$1
408 if [ "$list" = "all" ]
409 then
410 DETECTORS=$ALL
411 else
412 DETECTORS=`echo $list | sed 's/+/ /g'`
413 fi
414 ;;
415 -all)
416 shift 1
417 DETECTORS=$ALL
418 ;;
419 -o)
420 shift 1
421 OUTPUT=$1
422 ;;
423 -split)
424 shift 1
425 export CONFIG_SPLIT_FILE="TRUE"
426 ;;
427 -f)
428 shift 1
429 export CONFIG_FILE=$1
430 ;;
431 -n)
432 shift 1
433 NEVENTS=$1
434 ;;
435 -p)
436 shift 1
437 export CONFIG_NPARTICLES=$1
438 ;;
439 -seed)
440 shift 1
441 export CONFIG_SEED=$1
442 ;;
443 -c)
444 shift 1
445 CMDLIST=$*
446 break
447 ;;
448 -C)
449 shift 1
450 export CONFIG=$1
451 ;;
452 *)
453 shift 1
454 ;;
455 esac
456done
457
458
459if [ `dirname $OUTPUT` = "." ]
460then
461 OUTPUT=`pwd`/$OUTPUT
462fi
463
464[ ! -d $OUTPUT ] && mkdir -p $OUTPUT
465[ ! -d $ALIRUN_TMPDIR ] && mkdir -p $ALIRUN_TMPDIR
466
467trap Cleanup 2
468
469(
470 cd $OUTPUT
471 for cmd in $CMDLIST
472 do
473 case `type -t AliRun$cmd` in
474 function)
475 shift 1
476 AliRun$cmd $*
477 ;;
478 *)
479 ;;
480 esac
481 done
482)
483
484Cleanup