]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/gridAnalysis.sh
37be56a9a550d941e97550cb56f8cb7c8e091cdd
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / gridAnalysis.sh
1 #!/bin/bash
2
3 # BEGIN_MANUAL
4 #       Script to help do PWGLF-Forward analsysis using AliEn
5 #       =====================================================
6 # First, one need to figure out what to analyse.  Visit the MonAlisa
7 # pages and find
8
9 #   * The list of runs and put that in a file - say runs.list
10 #   * The directory where the ESD files are stored 
11 #     - and the pattern that will match these for all runs 
12 #   * The directory where the MC ESD files are stored 
13 #     - and the pattern that will match these for all runs 
14
15 # Then, one needs to run this script in set-up mode e.g., 
16
17 #   $0 --what=setup  \
18 #       --name=LHC10h \
19 #       --real-dir=/alice/data/2010/LHC10h \
20 #       --real-pattern=ESDs/pass2/*/AliESDs.root \
21 #       --mc-dir=/alice/sim/LHC10h11 \
22 #       --mc-pattern=*/AliESDs.root \
23 #       --runs=LHC10.list \
24 #       --par
25
26 # Note, all the settings are written to the file .config in the
27 # current directory, so you do not need to give the parameters at
28 # subsequent steps.  As an alternative to giving the parameters, one
29 # can create the file by hand.
30
31 # Next, we need to generate the corrections.  Do 
32
33 #   $0 --what=corrs 
34
35 # and wait for the jobs to finish and terminate.  If 'watching' is
36 # turned off, one can also monitor output on MonAlisa, and then when
37 # enough has finished, execute
38
39 #   $0 --what=corrs --step=terminate 
40
41 # enough times to get the final merged result.  Next, we need to
42 # extract and upload the corrections to our local corrections folder
43
44 #   $0 --what=corrs --step=upload 
45
46 # Now we can submit our AOD generation jobs.  Do 
47
48 #   $0 --what=aod
49
50 # and wait for the jobs to finish and terminate.  If 'watching' is
51 # turned off, one can also monitor output on MonAlisa, and then when
52 # enough has finished, execute
53
54 #   $0 --what=aod --step=terminate 
55
56 # enough times to get the final merged result.  Next, we need to
57 # download the results and we draw the summary results
58
59 #   $0 --what aod --step=draw 
60
61 # Now, we should do the dN/deta analysis.  Do 
62
63 #   $0 --what=dndeta
64
65 # and wait for the jobs to finish and terminate.  If 'watching' is
66 # turned off, one can also monitor output on MonAlisa, and then when
67 # enough has finished, execute
68
69 #   $0 --what=dndeta --step=terminate 
70
71 # enough times to get the final merged result.  Next, we need to download 
72 # the results and we can draw the summary and final plot
73
74 #   $0 --what=dndeta --step=draw 
75
76 # When running the trains, one can pass additional options to the
77 # train after the special option -- e.g., 
78 #   
79 #   $0 --what=aod -- --verbose=2 --branches --satellite
80
81 # Enjoy
82
83 # Comments, questions, bugs, flames, suggestions, etc. should be sent
84 # to Christian Holm Christensen <cholm@nbi.dk>
85
86 # END_MANUAL
87
88 runs=
89 mcruns=
90 name=
91 sys=0
92 snn=0
93 field=0
94 corrs=
95 dotconf=.config
96 here=${PWD}
97 par=0
98 noact=0
99 # aliroot="&aliroot=v5-03-75pATF-AN"
100 # root="root=v5-34-02-1"
101 fwd_dir=$ALICE_ROOT/PWGLF/FORWARD/analysis2
102
103 real_dir=
104 real_pat=
105 mc_dir=
106 mc_pat=
107 my_real_dir=
108 my_mc_dir=
109 uuopts=
110 watch=0
111
112 # === Various functions ==============================================
113 # --- Usage ----------------------------------------------------------
114 usage()
115 {
116     cat <<EOF
117 Usage: $0 --what OPERATION [OPTIONS]
118
119 Options:
120   -r,--runs=FILENAME        Specify list of runs file ($runs)
121   -R,--mc-runs=FILENAME     Specify list of MC runs file ($mcruns)
122   -n,--name=STRING          Base name of jobs ($name)
123   -S,--sys=SYSTEM           Collision system ($sys)
124   -E,--snn=ENERGY           Center of mass energy per nuclean pair ($snn)
125   -F,--field=FIELD          L3 magnetic field ($field)
126   -d,--real-dir=ALIEN_DIR   Directory holding real data ($real_dir)
127   -p,--real-pattern=PATTERN Glob pattern to match when searching ($real_pat)
128   -D,--mc-dir=ALIEN_DIR     Directory holding MC data ($mc_dir)
129   -P,--mc-pattern=PATTERN   Glob pattern to match when searching ($mc_pat)
130   -s,--step=STEP            Run stage ($step)
131   -w,--what=TRAINS          What to do 
132   -c,--corrections=DIR      Directory where corrections are stored ($corrs)
133   -W,--watch                Watch for job status and terminate automatically
134   -a,--par                  Use par files ($par)
135   -u,--url-opts=OPTIONS     Additional user options ($uuopts)
136   -M,--man                  Show the manual  
137   -N,--noact                Show what will be done 
138
139 TRAINS is one of
140
141   clean       Clean directory
142   setup       Do intial setup 
143   corrs       Generate corrections 
144   aods        Generate AODs 
145   dndeta      Generate dNdeta 
146
147 and must be executed in that order.  STEP is one of 
148
149   full        Run the analysis 
150   terminate   Terminate the job (may need iterations)
151   upload      Upload corrections (only for TRAINS=corrs)
152   draw        Draw (partial) results (not for TRAINS=corrs)
153 EOF
154 }
155
156 # --- Manual ---------------------------------------------------------
157 manual()
158 {
159     prog=`basename $0`
160     grep ^# $0 | \
161         sed -n -e '/BEGIN_MANUAL/,/END_MANUAL/ p' | \
162         sed -e '/\(BEGIN\|END\)_MANUAL/ d' -e 's/^# //' \
163             -e "s,\$0,$prog,"
164 }
165
166 # === Utilities to execute scripts ===================================
167 # --- Run script -----------------------------------------------------
168 script()
169 {
170     local scr=$1 ; shift 
171     local args=$1 ; shift
172     echo "Will run aliroot -l -b -q $scr($args)"
173     if test $noact -gt 0 ; then return ; fi
174     aliroot -l -b <<EOF
175 .x $scr($args)
176 .q
177 EOF
178 }
179 # --- Run acceptance generation --------------------------------------
180 accGen()
181 {
182     local run=$1 
183     script ${fwd_dir}/corrs/ExtractAcceptance.C "${run}"
184 }
185
186 # --- Extract corrections --------------------------------------------
187 terminate()
188 {
189     script Terminate.C 
190 }
191 # --- Extract corrections --------------------------------------------
192 download()
193 {
194     if test -f .download ; then 
195         echo "Already downloaded in `basename $PWD`"
196         return 0 
197     fi
198     script Download.C 
199     touch .download
200 }
201 # --- Extract corrections --------------------------------------------
202 extract()
203 {
204     test -f .extract && return 0 
205     script Extract.C 
206     touch .extract
207 }
208 # --- Extract corrections --------------------------------------------
209 extract_up()
210 {
211     if test -f .extract ; then 
212         echo "Aldready extracted in `basename $PWD`" 
213         return 0;
214     fi 
215     echo "= Extracting"
216     script ../Extract.C > /dev/null 2>&1
217     touch .extract
218 }
219 # --- Upload a file --------------------------------------------------
220 upload()
221 {
222     if test -f .upload ; then 
223         echo "Already uploaded in `basename $PWD`"
224         return 0 
225     fi
226     echo "= Uploading"
227     script Upload.C \"file://${here}/${name}_corrs_${now}/\" >/dev/null 2>&1
228     touch .upload 
229 }
230 # --- Extract and upload ---------------------------------------------
231 extract_upload()
232 {
233     echo "=== Download, extract, and uploade in `basename $PWD` ==="
234     download
235     for i in *.zip ; do 
236         if test ! -f $i ; then continue ; fi 
237         if test $noact -gt 0 ; then continue ; fi
238         local d=`basename $i .zip` 
239         if test ! -d $d ; then 
240             mkdir $d 
241         fi
242         cd $d 
243         if test ! -f .zip ; then 
244             echo "= Unpacking ../$i"
245             unzip ../$i > /dev/null 2>&1
246             touch .zip 
247         fi
248         extract_up 
249         upload
250         cd ..
251     done
252 }
253
254 # --- Draw -----------------------------------------------------------
255 draw()
256 {
257     local scr=$1 
258     download 
259     for i in *.zip ; do 
260         if test "X$i" = "X*.zip" ; then continue ; fi
261         echo "Will extract $i"
262         d=`basename $i .zip` 
263         if test ! -d $d ; then 
264             mkdir -p $d 
265             unzip $i -d $d
266         fi
267         (cd $d && script $scr)
268     done
269 }
270 dndeta_draw()
271 {
272     local d=$1 
273     (cd $d && \
274         draw ${fwd_dir}/DrawdNdetaSummary.C && \
275         draw ../Draw.C)
276 }
277
278 # --- Get the grid home dir ------------------------------------------
279 outputs()
280 {
281     l=`aliroot -l -b <<EOF
282 gSystem->RedirectOutput("/dev/null");
283 TGrid::Connect("alien://");
284 gSystem->RedirectOutput(0);
285 std::cout << gGrid->GetHomeDirectory() << std::endl;
286 EOF`
287     my_real_dir="$l/${name}_aod_${now}/output"
288     my_mc_dir="$l/${name}_mcaod_${now}/output"
289 }
290
291 # === Trains =========================================================
292 # --- Run set-ups ----------------------------------------------------
293 setup()
294 {
295     run_for_acc=`grep -v ^# $runs | awk '{FS=" \n\t"}{printf "%d\n", $1}' | head -n 1` 
296     if test x$run_for_acc = "x" || test $run_for_acc -lt 1; then 
297         echo "No run for acceptance correction specified" > /dev/stderr 
298         exit 1
299     fi
300
301    now=`date '+%Y%m%d_%H%M'` 
302    outputs
303
304    # Write settings to a file, which we later can source 
305    dumpvar=
306    if test $par -gt 0 ; then dumpvar="--par " ; fi 
307    if test $watch -gt 0 ; then dumpvar="${dumpvar} --watch " ; fi 
308    cat > ${dotconf} <<EOF
309 # Settings:
310 name="$name"
311 runs=${runs}
312 mcruns=${mcruns}
313 sys=$sys
314 snn=$snn
315 field=$field
316 real_dir=${real_dir}
317 real_pat=${real_pat}
318 mc_dir=${mc_dir}
319 mc_pat=${mc_pat}
320 my_real_dir=${my_real_dir}
321 my_mc_dir=${my_mc_dir}
322 par=${par}
323 now=${now}
324 watch=${watch}
325 uuopts="${uuopts}"
326 # Options
327 if false ; then 
328   $0 --what=setup --name="$name" --runs="$runs" --mcruns="$mcruns" \
329   --sys="$sys" --snn="$snn" --field="$field" \
330   --real-dir="${real_dir}" --real-pattern="${real_pat}" \
331   --mc-dir="${mc_dir}" --mc-pattern="${mc_pat}" \
332   --now=${now} --url-opts="${uuopts}" ${dumpvar}
333 fi
334 EOF
335    corrdir=${name}_corrs_${now}
336    if test "x$corrs" != "x" && test -d ${corrs} ; then 
337        echo "Linking ${corrs} to ${corrdir}"
338        ln -sf $corrs ${corrdir}
339        ln -sf $corrs last_${name}_corrs        
340        corrdir=$corrs
341    elif test $noact -lt 1 ; then 
342         mkdir -p ${name}_acc_${now}
343         mkdir -p ${corrdir}
344         rm -f last_${name}_acc last_${name}_corrs
345         ln -sf ${name}_acc_${now} last_${name}_acc
346         ln -sf ${name}_corrs_${now} last_${name}_corrs
347         cat <<-EOF > ${corrdir}/Browse.C
348         TObject* Browse()
349         {
350           const char* fwd = "$ALICE_ROOT/PWGLF/FORWARD/analysis2";
351           if (!gROOT->GetClass("AliOADBForward"))
352             gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
353           gROOT->LoadMacro(Form("%s/corrs/ForwardOADBGui.C++g", fwd));
354           
355           AliOADBForward* db = new AliOADBForward;
356           db->Open("fmd_corrections.root", "*");
357           
358           ForwardOADBGui(db);
359
360           return db;
361         }
362         EOF
363         echo "Make acceptance corrections" 
364         (cd ${name}_acc_${now} && \
365             accGen $run_for_acc && \
366             upload )
367    fi
368    for i in fmd_corrections.root spd_corrections.root deadstrips.C ; do 
369        if test ! -f ${corrdir}/$i ; then continue ; fi 
370        echo "Linking ${corrdir}/$i here"
371        ln -fs ${corrdir}/$i . 
372    done
373 }    
374
375 # --- Run set-ups ----------------------------------------------------
376 cleanup()
377 {
378     rm -rf \
379         ${name}_acc_${now} \
380         ${name}_mccorr_${now} \
381         ${name}_mceloss_${now} \
382         ${name}_eloss_${now} \
383         ${name}_mcaod_${now} \
384         ${name}_aod_${now} \
385         ${name}_mcdndeta_*${now} \
386         ${name}_dndeta_*${now} \
387         ${name}_corrs_${now} \
388         last_${name}_acc \
389         last_${name}_corrs \
390         last_${name}_mceloss \
391         last_${name}_eloss \
392         last_${name}_mcaod \
393         last_${name}_aod \
394         last_${name}_mcdndeta* \
395         last_${name}_dndeta* \
396         build.log 
397     if test -L fmd_corrections.root ; then 
398         rm fmd_corrections.root
399     fi
400     if test -L spd_corrections.root ; then 
401         rm spd_corrections.root
402     fi
403 }
404
405 # --- Check AliEn token ----------------------------------------------
406 check_token()
407 {
408     uid=`id -u`
409     genv_file=/tmp/gclient_env_${uid}
410     
411     if test ! -f ${genv_file} ; then 
412         echo "No such file: ${genv_file}, please do alien-token-init" \
413             >/dev/stderr
414         exit 1
415     fi
416     . ${genv_file}
417     alien-token-info | grep -q "Token is still valid"
418     if test $? -ne 0 ; then 
419         echo "Token not valid, please re-new" > /dev/stderr 
420         exit 1
421     fi
422 }
423
424 # --- Check settings -------------------------------------------------
425 check()
426 {
427     local w=$1
428     if test "x$runs" = "x" || test ! -f $runs ; then 
429         echo "List of run file $runs not found" > /dev/stderr 
430         exit 1
431     fi
432     if test "x$mcruns" = "x" ; then mcruns=$runs ; fi 
433     if test ! -f $mcruns ; then 
434         echo "List of MC runs file $mcruns not found" > /dev/stderr 
435         exit 1
436     fi
437     if test "X$name" = X ; then 
438         echo "No name specified" > /dev/stderr 
439         exit 1
440     fi
441     # if test "x$sys" = "x" ; then 
442     #     echo "No collision system specified" > /dev/stderr 
443     #     exit 1
444     # fi
445     # if test "x$snn" = "x" ; then 
446     #     echo "No center of mass energy specified" > /dev/stderr 
447     #     exit 1
448     # fi
449     # if test "x$field" = "x" ; then 
450     #     echo "No L3 field setting specified" > /dev/stderr 
451     #     exit 1
452     # fi
453     if test "x$real_dir" = "x" ; then 
454         echo "No real data directory specified" > /dev/stderr 
455         exit 1
456     fi
457     if test "x$mc_dir" = "x" ; then 
458         echo "No MC data directory specified" > /dev/stderr 
459         exit 1
460     fi
461     if test "x$real_pat" = "x" ; then 
462         echo "No real data pattern specified" > /dev/stderr 
463         exit 1
464     fi
465     if test "x$mc_pat" = "x" ; then 
466         echo "No MC data pattern specified" > /dev/stderr 
467         exit 1
468     fi
469     if test "X$w" != "Xsetup" && test "x$now" = "x" ; then 
470         echo "No date/time specified" > /dev/stderr 
471         exit 1
472     fi
473     # sys==0 is OK - autoselect
474     case x$sys in 
475         xpp|xp-p)              sys=1 ;; 
476         xpbpb|xpb-pb|xaa|xa-a) sys=2 ;; 
477         xppb|xp-pb|xpa|xp-a)   sys=3 ;;
478         x0|x1|x2|x3)                 ;; 
479         x)                     sys=0 ;;
480         *) echo "$0: Unknown system: $sys" ; exit 1 ;;
481     esac
482
483     check_token
484 }
485
486 # --- Show the setup -------------------------------------------------
487 print_setup()
488 {
489     cat <<EOF
490 Name:                   $name
491 Run file:               ${runs}
492 MC Run file:            ${mcruns}
493 Collision system:       $sys
494 sqrt(s_NN):             ${snn}GeV
495 L3 Field:               ${field}kG
496 Real input directory:   ${real_dir}
497 Real file pattern:      ${real_pat}
498 MC input directory:     ${mc_dir}
499 MC file pattern:        ${mc_pat}
500 Real output:            ${my_real_dir}
501 MC output directory:    ${my_mc_dir}
502 Use PAR files:          ${par}
503 Date & time:            ${now}
504 Additional URL options: ${uuopts}
505 EOF
506 }
507
508 # --- Run the train --------------------------------------------------
509 # Usage:
510
511 allAboard()
512 {
513     type=$1 ; shift 
514     trig=$1 ; shift
515     cl=
516     nme=${name}_${type}
517     tree=esdTree
518     opts="--batch"
519     uopt="&merge=50&split=50&aliroot=last,regular"
520     mc=0
521     dir=$real_dir
522     pat=$real_pat
523     rl=$runs
524
525     case $type in 
526         mc*) 
527             mc=1  
528             # Default dirs are production dirs 
529             dir=$mc_dir
530             pat=$mc_pat
531             rl=$mcruns
532             ;;
533         *) ;;
534     esac
535     case $type in 
536         *corr)  cl=MakeMCCorrTrain ; mc=1 ;;
537         *eloss) cl=MakeFMDELossTrain ;;  
538         *aod)   cl=MakeAODTrain 
539             opts="${opts} --corr=."
540             # opts="--corr=${name}_corrs_${now} --cent"
541             # if test $sys -gt 0 && test $snn -gt 0 ; then 
542             #   opts="$opts --sys=${sys} --snn=${snn} --field=${field}"
543             # fi
544             ;;
545         *dndeta) cl=MakedNdetaTrain 
546             tree=aodTree 
547             uopt="${uopt}&concat"
548             opts="${opts} --cut-edges"
549             case x$trig in 
550                 xinel)    
551                     opts="$opts --scheme=trigger,event,background}" 
552                     opts="$opts --trig=INEL" 
553                     ;;
554                 xnsd)     
555                     opts="$opts --scheme=trigger,event"
556                     opts="$opts --trig=V0AND"
557                     ;;
558                 xinelgt0) 
559                     opts="$opts --scheme=trigger,event"
560                     opts="$opts --trig=INELGT0"
561                     ;;
562                 x*) trig= ;;
563             esac
564             if test "x$trig" != "x" ; then 
565                 nme="${nme}_${trig}"
566             fi
567             # Modify for input dir for our files
568             dir=$my_real_dir
569             pat="*/AliAOD.root"
570             if test $mc -gt 0 ; then 
571                 dir=$my_mc_dir
572                 opts="$opts --mc"
573             fi
574             ;;
575         *) echo "$0: Unknown type of train: $type" > /dev/stderr ; exit 1 ;;
576     esac
577     # add centrality flag if we do not know what collision system we're 
578     # looking at, or it's PbPb or pPb. 
579     case $sys in 
580         0|2|3) opts="$opts --cent" ;; 
581         1)                         ;;
582     esac
583     if test $mc -gt 0; then 
584         uopt="${uopt}&mc"
585     fi
586     if test $par -gt 0 ; then 
587         uopt="${uopt}&par"
588     fi
589     if test x$uuopts != x ; then 
590         uopt="${uopt}&${uuopts}"
591     fi
592     url="alien://${dir}?run=${rl}&pattern=${pat}${uopt}${aliroot}${root}#${tree}"
593     opts="${opts} --include=$ALICE_ROOT/PWGLF/FORWARD/analysis2/trains"
594     opts="${opts} --date=${now} --class=$cl --name=$nme --verbose=0"
595     
596     echo "Running train: runTrain2 ${opts} --url=${url} $@" 
597     if test $noact -gt 0 ; then return ; fi
598
599     runTrain ${opts} --overwrite --url=${url} $@ 
600
601     if test $watch -lt 1 ; then 
602         cat <<-EOF
603         Check https://alimonitor.cern.ch/users/jobs.jsp for progress 
604         
605         Remember to do 
606         
607           (cd ${nme}_${now} && aliroot -l -b -q Terminate.C)
608         
609         until the final merge stage, and then do 
610                 
611           (cd ${nme}_${now} && aliroot -l -b -q Download.C) 
612         
613         to get the results. 
614         EOF
615         
616         case $type in 
617             *corr|*esd) 
618                 cat <<-EOF
619         Then, do 
620         
621           (cd ${nme}_${now} && aliroot -l -b -q Extract.C)
622           (cd ${nme}_${now} && aliroot -l -b -q 'Upload.C("local://${here}/${nam        e}_corrs_${now}")')
623         
624         to upload the results to our local corrections store. 
625         EOF
626                 ;; 
627             *aod)
628                 cat <<-EOF
629         Then, do 
630          
631           (cd ${nme}_${now} && aliroot -l ${fwd_dir}/DrawAODSummary.C)
632         
633         to get a PDF of the diagnostics histograms
634         EOF
635                 ;;
636             *dndeta)
637                 cat <<-EOF
638         Then, do 
639          
640           (cd ${nme}_${now} && aliroot -l ${fwd_dir}/DrawdNdetaSummary.C)
641         
642         to get a PDF of the diagnostics histograms, and 
643         
644           (cd ${nme}_${now} && aliroot -l Draw.C)
645         
646         to get the final plot. 
647         EOF
648                 ;;
649         esac
650     else 
651         echo "Now waiting for jobs to finish"
652         (cd ${nme}_${now} && \
653             nice aliroot -l -b -x -q Watch.C\(1\) 2>&1 | \
654             tee watch.log > /dev/null &)
655     fi
656 }
657
658
659 # === Wrappers =======================================================
660 # --- Run all correction jobs ----------------------------------------
661 corrs()
662 {
663     allAboard mccorr "" $@
664     allAboard mceloss "" $@
665     allAboard eloss "" $@
666 }
667 corrs_terminate() 
668 {
669     (cd ${name}_mccorr_${now}  && terminate)
670     (cd ${name}_mceloss_${now} && terminate)
671     (cd ${name}_eloss_${now}   && terminate)
672 }
673 corrs_upload() 
674 {
675     (cd ${name}_mccorr_${now}  && extract_upload)
676     (cd ${name}_mceloss_${now} && extract_upload)
677     (cd ${name}_eloss_${now}   && extract_upload)
678     rm -f fmd_corrections.root spd_corrections.root 
679     ln -s ${name}_corrs_${now}/fmd_corrections.root .
680     ln -s ${name}_corrs_${now}/spd_corrections.root .
681 }
682 corrs_draw()
683 {
684     echo "Draw does not make sense for Correction jobs"
685 }
686 # --- Run all AOD jobs -----------------------------------------------
687 aods()
688 {
689     allAboard mcaod "" $@
690     allAboard aod "" $@
691 }
692 aods_terminate() 
693 {
694     (cd ${name}_mcaod_${now} && terminate)
695     (cd ${name}_aod_${now}   && terminate)
696 }
697 aods_upload()
698 {
699     echo "Upload does not make sense for AOD jobs"
700 }
701 aods_draw() 
702 {
703     (cd ${name}_mcaod_${now} && draw ${fwd_dir}/DrawAODSummary.C)
704     (cd ${name}_aod_${now}   && draw ${fwd_dir}/DrawAODSummary.C)
705 }
706
707 # --- Run all dN/deta jobs -------------------------------------------
708 dndetas()
709 {
710     allAboard mcdndeta $@
711     if test $sys -eq 1 ; then 
712         allAboard dndeta inel $@
713         allAboard dndeta nsd $@
714         allAboard dndeta inelgt0 $@
715     else
716         allAboard dndeta "" $@
717     fi
718 }
719 dndetas_terminate() 
720 {
721     (cd ${name}_mcdndeta_${now} && terminate)
722     if test $sys -eq 1 ; then 
723         (cd ${name}_dndeta_inel_${now}      && terminate)
724         (cd ${name}_dndeta_nsd_${now}       && terminate)
725         (cd ${name}_dndeta_inelgt0_${now}   && terminate)
726     else
727         (cd ${name}_dndeta_${now}   && terminate)
728     fi
729 }
730 dndetas_upload()
731 {
732     echo "Upload does not make sense for dN/deta jobs"
733 }
734 dndetas_draw() 
735 {
736     dndeta_draw ${name}_mcdndeta_${now}
737     if test $sys -eq 1 ; then 
738         dndeta_draw ${name}_dndeta_inel_${now} 
739         dndeta_draw ${name}_dndeta_nsd_${now} 
740         dndeta_draw ${name}_dndeta_inelgt0_${now} 
741     else
742         dndeta_draw ${name}_dndeta_${now} 
743     fi
744 }
745
746 # === Procedual code =================================================
747 # --- Source settings if found ---------------------------------------
748 if test -f $dotconf ; then 
749     source $dotconf 
750 fi
751
752
753 # --- Process command line -------------------------------------------
754 what=
755 step=
756 while test $# -gt 0 ; do
757     arg=$1 
758     opt=
759     case $1 in 
760         --) shift ; break ;;
761         --*=*) 
762             arg=`echo $1 | sed 's/=.*//'` ;
763             opt=`echo $1 | sed 's/--[^=][^=]*=//'` 
764             ;;
765         --*)
766             ;;
767         -h|-N|-H|-a) ;;
768         -*) opt=$2 ; shift ;; 
769     esac
770     shift 
771
772     case $arg in 
773         -r|--runs)         runs=$opt     ;; 
774         -R|--mc-runs)      mcruns=$opt   ;;
775         -n|--name)         name=$opt     ;; 
776         -S|--sys)          sys=`echo $opt | tr '[A-Z]' '[a-z]'` ;;
777         -E|--snn)          snn=$opt      ;; 
778         -F|--field)        field=$opt    ;;
779         -d|--real-dir)     real_dir=$opt ;;
780         -p|--real-pattern) real_pat=$opt ;; 
781         -D|--mc-dir)       mc_dir=$opt   ;; 
782         -P|--mc-pattern)   mc_pat=$opt   ;; 
783         -w|--what)         what=`echo $opt | tr '[A-Z]' '[a-z]'`  ;; 
784         -s|--step)         step=`echo $opt | tr '[A-Z]' '[a-z]'`  ;; 
785         -W|--watch)        let watch=\!$watch ;;
786         -N|--noact)        noact=1            ;;
787         -c|--corrections)  corrs=$opt    ;;
788         -a|--par)          par=1         ;;
789         -u|--url-opts)     uuopts="$opt" ;;
790         -h|--help)         usage         ; exit 0 ;; 
791         -H|--manual)       manual        ; exit 0 ;;
792         *) echo "$0: Unknown option $arg"  ; exit 1 ;; 
793     esac
794 done 
795
796 # --- Check settings -------------------------------------------------
797 check $what
798
799 # --- Select what to do ----------------------------------------------
800 func=
801 case $what in 
802     setup)   setup ; exit 0 ;; 
803     clean)   cleanup ; exit 0 ;;
804     corr*)   func=corrs;; 
805     aod*)    func=aods ;; 
806     dndeta*) func=dndetas ;; 
807     *) echo "$0: Unknown operation: $what" > /dev/stderr ; exit 1 ;;
808 esac
809 print_setup
810
811 case x$step in 
812     x|xfull) ;; 
813     xterm*) func=${func}_terminate ;; 
814     xup*)   func=${func}_upload ;; 
815     xdr*)   func=${func}_draw ;;
816     *) echo "$0: Unknown step $step" > /dev/stderr ; exit 1 ;;
817 esac
818
819 echo "Will execute $func" 
820 $func $@ 
821
822 #
823 # EOF
824 #
825