]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/qa/RunGridQA.sh
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / qa / RunGridQA.sh
1 #!/bin/bash
2
3 # --- Usage ----------------------------------------------------------
4 usage()
5 {
6     cat <<EOF
7 Usage: $0 [OPTIONS]
8
9 Options:
10         -p,--production PERIOD      LHC Period identifier [$prod]
11         -P,--pass       PASS        Production pass identifier [$prodpass]
12         -n,--part       PART        Part identifier [$part]
13         -r,--runs       RUNS        List of runs or file [$runs]
14         -c,--clean                  Clean previous job output [$clean]
15         -v,--verbose                Increase verbosity [$verb]
16 EOF
17
18 }
19
20 # --- Check AliEn token ----------------------------------------------
21 check_token()
22 {
23     uid=`id -u`
24     genv_file=/tmp/gclient_env_${uid}
25     
26     if test ! -f ${genv_file} ; then 
27         echo "No such file: ${genv_file}, please do alien-token-init" \
28             >/dev/stderr
29         exit 1
30     fi
31     . ${genv_file}
32     alien-token-info | grep -q "Token is still valid"
33     if test $? -ne 0 ; then 
34         echo "Token not valid, please re-new" > /dev/stderr 
35         exit 1
36     fi
37 }
38
39 # --- Diagnostics output ---------------------------------------------
40 verb=0
41 mess()
42 {
43     if test $1 -gt $verb ; then return ; fi 
44     shift
45     echo $*
46 }
47
48 # --- Parse production information -----------------------------------
49 parse_prod()
50 {
51     prodyear=`echo $prodfull | sed 's/LHC\(..\).*/\1/'` 
52     prodletter=`echo $prodfull | sed "s/LHC${prodyear}\(.\).*/\1/"` 
53     prodpost=`echo $prodfull | sed "s/LHC${prodyear}${prodletter}//"` 
54 }
55
56 parse_pass()
57 {
58     passno=`echo $passfull | sed 's/.*pass\([0-9]*\).*/\1/'`  
59     passpost=`echo $passfull | sed -n "s/.*pass${passno}_//p"` 
60     passpre=`echo $passfull | sed -n "s/pass.*//p"` 
61 }
62
63 # --- Append path element --------------------------------------------
64 append_to_path()
65 {
66     local tmp=$1 ; shift 
67     local add=$1
68     if test "x$tmp" != "x" ; then tmp="${tmp}/" ; fi 
69     echo ${tmp}${add}
70 }
71
72 # --- Get the path and search pattern --------------------------------
73 path=
74 search=
75 setup_input()
76 {
77     local datd=data
78     local esdd=ESDs/
79     case x$prodpost in 
80         x_*) ;; 
81         x) ;; 
82         *)  mess 3 "Assuming simulation output"
83             datd=sim 
84             esdd= 
85             ;; 
86     esac
87     
88     local paid=
89     if echo "$passno" | grep -q -E '^[0-9]*[.]?[0-9]*$' ; then 
90         if test "x$passfull" != "x" && test $passno -gt 0 ; then 
91             paid=pass${passno}
92         fi
93     else
94         paid=${passfull}
95         passpre=
96         post=
97     fi
98     local post=${passpost}
99     case x$post in 
100         x_*) ;; 
101         x) ;; 
102         *) post="_${post}" ;; 
103     esac
104
105     # Assume official productions 
106     path=/alice/${datd}/${year}/${prodfull}/
107     search="${esdd}${passpre}${paid}${post}"
108     search=`append_to_path "$search" "*/AliESDs.root"` 
109 }
110
111 # --- Setup the runs -------------------------------------------------
112 unique=
113 setup_runs()
114 {
115     if test -f $runs ; then 
116         unique=`basename $runs .txt` 
117         unique=`basename $unique .list` 
118         unique=`basename $unique .runs` 
119         return
120     fi
121     local l=`echo "$runs" | tr ',+:.' ' '` 
122     local first=
123     local last=
124     for i in $l ; do 
125         if test "x$first" = "x" ; then first=$i ; fi 
126         last=$l 
127     done
128     unique=${first}_${last} 
129     runs=`echo "$l" | tr ' ' ','` 
130 }
131
132 # --- Clean previous attempt -----------------------------------------
133 clean_previous()
134 {
135     local alienu=`alien_whoami | tr -d ' '` 
136     local alienl=`echo ${alienu} | cut -c1` 
137     local aliend="/alice/cern.ch/user/${alienl}/${alienu}/${name}"
138     mess 1 "Removing local directory ${name}"
139     if test $noact -lt 1 ; then rm -rf ${name} ; fi
140     mess 1 "Removing alien directory ${aliend}"
141     if test $noact -lt 1 ; then alien_rmdir ${aliend} ; fi
142 }
143
144 # --- Parse command line options -------------------------------------
145 redir=/dev/null
146 part=
147 clean=0
148 noact=0
149 while test $# -gt 0 ; do 
150     case $1 in 
151         -h|--help)        usage ; exit 0 ;; 
152         -v|--verbose)     let verb=$verb+1   ;; 
153         -l|--log-file)    redir=             ;; 
154         -p|--production)  prodfull=$2; shift; parse_prod ; year=20${prodyear} ;;
155         -P|--pass)        passfull=$2; shift; parse_pass ;;
156         -n|--part)        part=$2 ; shift ;; 
157         -r|--runs)        runs=$2               ; shift ;;
158         -c|--clean)       clean=1 ; shift ;; 
159         -s|--noact)       noact=1 ; shift ;;
160         *) echo "$0: Unknown argument: $1" > /dev/stderr ; exit 1 ;; 
161     esac
162     shift
163 done
164
165 # --- Initial checks -------------------------------------------------
166 if test "x$prodfull" = "x" ; then 
167     echo "No production specified" > /dev/stderr 
168     exit 1
169 fi
170 if test "x$passfull" = "x" ; then 
171     echo "No pass specified" > /dev/stderr 
172     exit 1
173 fi
174 if test "x$runs" = "x" ; then 
175     echo "No runs specified" > /dev/stderr 
176     exit 1
177 fi
178
179 check_token 
180 setup_input
181 setup_runs
182 name="QA_${prodfull}_${passfull}"
183 if test "x$part" != "x" ; then 
184     if echo "$part" | grep -q -E '^[0-9]*[.]?[0-9]*$' ; then 
185         part="part${part}"
186     fi
187     name="${name}_${part}"
188 fi
189
190 if test $clean -gt 0 ; then clean_previous ; fi 
191     
192
193 # --- Some friendly information --------------------------------------
194 cat <<EOF
195         Year:                   ${year}
196         Production:             ${prodfull} 
197           Year:                 ${prodyear}
198           Letter:               ${prodletter}
199           Suffix:               ${prodpost}
200         Pass:                   ${passfull}
201           Number:               ${passno}
202           Prefix:               ${passpre}
203           Postfix:              ${passpost}
204         Lock file:              ${lock}
205         Log:                    ${redir}
206         Runs:                   ${runs}
207         Path:                   ${path}
208         Search:                 ${search}
209         Part:                   ${part}
210         Name:                   ${name}
211 EOF
212
213 # --- Do the actual running ------------------------------------------
214 url="alien:///alice/data/${year}/${prodfull}\?run=${runs}\&pattern=${search}&ttl=18000&split=100&merge=50#esdTree"
215 train=MakeQATrain
216 opts=(--class=${train} \
217     --name=${name} \
218     --cent \
219     --url="${url}")
220 mess 1 "Will do runTrain \"${opts[@]}\" $@" 
221 if test $noact -gt  0 ; then 
222     sleep 1 
223 else 
224     runTrain "${opts[@]}" $@
225 fi
226
227 mess 1 "Will monitor in directory $name" 
228 if test $noact -gt 0 ; then 
229     sleep 1 
230 else 
231     (cd ${name} && aliroot -b -x -q -l Watch.C)
232 fi
233
234 #
235 # EOF
236 #
237
238