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