1 | #!/bin/sh |
---|
2 | #Perform the ON-OFF analysis |
---|
3 | DATE=/bin/date |
---|
4 | GREP=/bin/grep |
---|
5 | AWK=/bin/awk |
---|
6 | ECHO=/bin/echo |
---|
7 | WC=/usr/bin/wc |
---|
8 | CAT=/bin/cat |
---|
9 | PRINTF=/usr/bin/printf |
---|
10 | FIND=/usr/bin/find |
---|
11 | MKDIR=/bin/mkdir |
---|
12 | XARGS=/usr/bin/xargs |
---|
13 | SORT=/bin/sort |
---|
14 | RM=/bin/rm |
---|
15 | TR=/usr/bin/tr |
---|
16 | CP=/bin/cp |
---|
17 | LS=/bin/ls |
---|
18 | CHMOD=/bin/chmod |
---|
19 | |
---|
20 | DefaultIFS=$' \t\n' |
---|
21 | IFS=$DefaultIFS |
---|
22 | |
---|
23 | #set Irods environment |
---|
24 | . /usr/local/shared/bin/irods_env.sh -noverbose |
---|
25 | |
---|
26 | scriptName="`basename $0`" |
---|
27 | $ECHO "Processing script ${scriptName} at `date`" |
---|
28 | #which source to analyse |
---|
29 | |
---|
30 | #Process cmd line args: the -src option is mandatory (source name as Abell85) |
---|
31 | sourceRadio= |
---|
32 | dateSelected= |
---|
33 | #use -sim option to simulate processing (debug the script as if...) |
---|
34 | simulationMode=Off |
---|
35 | while [ $# -gt 0 ] |
---|
36 | do |
---|
37 | case "$1" in |
---|
38 | -src) sourceRadio=$2; shift;; |
---|
39 | -date) dateSelected=$2; shift;; |
---|
40 | -sim) simulationMode=On;; |
---|
41 | -h) |
---|
42 | echo >&2 \ |
---|
43 | "usage: $0 -src souce -date YYYYMMDD [-freq freq in MHz (default ${freqBAOCalib})] [-sim to trig simulation mode]" |
---|
44 | exit 1;; |
---|
45 | *) break;; # terminate while loop |
---|
46 | esac |
---|
47 | shift |
---|
48 | done |
---|
49 | |
---|
50 | if [ ${simulationMode} = "On" ]; then |
---|
51 | $ECHO "INFO ${scriptName} running in SIMUL mode" |
---|
52 | fi |
---|
53 | |
---|
54 | if [ "<${sourceRadio}>" = "<>" ]; then |
---|
55 | $ECHO "FATAL: You have forgotten to select the source option (-src)" |
---|
56 | exit 1 |
---|
57 | fi |
---|
58 | |
---|
59 | case ${sourceRadio} in |
---|
60 | Abell85) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
61 | Abell2440) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
62 | Abell1205) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
63 | *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen" |
---|
64 | exit 1;; |
---|
65 | esac |
---|
66 | |
---|
67 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
68 | |
---|
69 | #Path to public backupable path |
---|
70 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
71 | |
---|
72 | |
---|
73 | #temporary files to synchronize scripts |
---|
74 | tmppublicpath=${TMPPUBLICPATH} |
---|
75 | #wakeup the NFS disk |
---|
76 | $LS -l ${tmppublicpath} > /dev/null |
---|
77 | #clean previous spurious files |
---|
78 | $RM -f ${tmppublicpath}/*.finished |
---|
79 | |
---|
80 | #Path where the job will do temporary IO |
---|
81 | . ${SCRIPTPATH}/isInteractive.sh |
---|
82 | isInteractive=$(isInteractive) |
---|
83 | if [ ${isInteractive} == "1" ]; then |
---|
84 | $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!" |
---|
85 | exit 0; |
---|
86 | fi |
---|
87 | |
---|
88 | . ${SCRIPTPATH}/set_iojobpath.sh |
---|
89 | iojobpath=$(set_iojobpath) |
---|
90 | cd ${iojobpath} |
---|
91 | |
---|
92 | localpath="${sourceRadio}" |
---|
93 | $MKDIR -p ./${localpath} |
---|
94 | cd ./${localpath} |
---|
95 | |
---|
96 | #save the top directory |
---|
97 | topDir=`pwd` |
---|
98 | |
---|
99 | #Path of the utility scripts |
---|
100 | scriptpath=${SCRIPTPATH} |
---|
101 | |
---|
102 | #get the daq current irod status |
---|
103 | #tag=`${DATE} +%F` |
---|
104 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
105 | ####JEC 1/10/11 tag=`${DATE} +%F` |
---|
106 | #Use generic baodaqstatus name |
---|
107 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
108 | |
---|
109 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
110 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
111 | exit 1 |
---|
112 | #JEC 29/9/11 avoid finished stuff |
---|
113 | # $RM -f ${tmppublicpath}/statusdaq.finished |
---|
114 | # ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
115 | # while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do |
---|
116 | # sleep 30 |
---|
117 | # done |
---|
118 | # $RM ${tmppublicpath}/statusdaq.finished |
---|
119 | #protect against remove/rewriting |
---|
120 | # $CHMOD -v 444 ${OUT1} |
---|
121 | fi |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | #Nb: if we want to implement a loop on sources we have to take care of srclower... |
---|
127 | |
---|
128 | $ECHO "You have selected sourceRadio = ${sourceRadio} [date = ${dateSelected}]" |
---|
129 | tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
130 | IFS=' |
---|
131 | ' |
---|
132 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
133 | IFS=$DefaultIFS |
---|
134 | |
---|
135 | |
---|
136 | for i in ${tableau[@]} |
---|
137 | do |
---|
138 | # |
---|
139 | # start a "fresh" session |
---|
140 | cd ${topDir} |
---|
141 | $LS | $XARGS -i $RM -rf {} |
---|
142 | |
---|
143 | $ECHO "DEBUG: (${scriptName}) irods root dir $i" |
---|
144 | dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"` |
---|
145 | |
---|
146 | $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}" |
---|
147 | $LS -lrt |
---|
148 | |
---|
149 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
150 | #Look if the date has changed since beginning of the job! |
---|
151 | # curtag=`${DATE} +%F` |
---|
152 | # if [ "<${curtag}>" != "<${tag}>" ]; then |
---|
153 | # tag=${curtag} |
---|
154 | #it is necessary to update the daq status as the day has changed during the processing... (batch can take a long time...) |
---|
155 | # OUT1=${publicpath}/baodaqstatus-${curtag}.txt |
---|
156 | # $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..." |
---|
157 | # $RM -f ${tmppublicpath}/statusdaq.finished |
---|
158 | # ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
159 | # while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do |
---|
160 | # sleep 30 |
---|
161 | # done |
---|
162 | # $RM ${tmppublicpath}/statusdaq.finished |
---|
163 | #protect against remove/rewriting |
---|
164 | # $CHMOD -v 444 ${OUT1} |
---|
165 | # fi |
---|
166 | # |
---|
167 | # look if the gain & calibration files exist |
---|
168 | # |
---|
169 | gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l` |
---|
170 | if [ ! ${gainDone} -gt 0 ]; then |
---|
171 | $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` " |
---|
172 | continue |
---|
173 | fi |
---|
174 | |
---|
175 | # |
---|
176 | somethingTodo=1 |
---|
177 | input4dataOff=`ils ${i}/Off 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` |
---|
178 | input4dataOn=`ils ${i}/On 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` |
---|
179 | # |
---|
180 | if [ "<${input4dataOff}>" != "<>" -a "<${input4dataOn}>" != "<>" ]; then |
---|
181 | #look at the content of the datacycle directory as may be the previous batch job has crashed |
---|
182 | tableauOff=( `$ECHO ${input4dataOff}` ) |
---|
183 | IFS=' |
---|
184 | ' |
---|
185 | tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
186 | IFS=$DefaultIFS |
---|
187 | # |
---|
188 | nTotFilesOff=0 |
---|
189 | for j in ${tableauOff[@]} |
---|
190 | do |
---|
191 | nFiles=`ils ${i}/Off/${j} | $GREP -i "medfiltmtx" | $WC -l` |
---|
192 | nTotFilesOff=`expr ${nTotFilesOff} + ${nFiles}` |
---|
193 | done |
---|
194 | # |
---|
195 | tableauOn=( `$ECHO ${input4dataOn}` ) |
---|
196 | IFS=' |
---|
197 | ' |
---|
198 | tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
199 | IFS=$DefaultIFS |
---|
200 | # |
---|
201 | nTotFilesOn=0 |
---|
202 | for j in ${tableauOn[@]} |
---|
203 | do |
---|
204 | nFiles=`ils ${i}/On/${j} | $GREP -i "medfiltmtx" | $WC -l` |
---|
205 | nTotFilesOn=`expr ${nTotFilesOn} + ${nFiles}` |
---|
206 | done |
---|
207 | diffOnOff=`expr ${nTotFilesOff} - ${nTotFilesOn}` |
---|
208 | if [ ${diffOnOff} -lt 0 ]; then |
---|
209 | zero=0 |
---|
210 | diffOnOff=`expr ${zero} - ${diffOnOff}` |
---|
211 | fi |
---|
212 | #allow files differences but non zero |
---|
213 | if [ ${nTotFilesOff} -gt 0 -a ${nTotFilesOn} -gt 0 ]; then |
---|
214 | somethingTodo=0 |
---|
215 | $ECHO "DEBUG (${scriptName}): $sourceRadio $dateDAQ has <${nTotFilesOff}> Off-files and <${nTotFilesOn}> On-files but OK" |
---|
216 | else |
---|
217 | $ECHO "INFO (${scriptName}): $sourceRadio $dateDAQ has <${nTotFilesOff}> Off-files and <${nTotFilesOn}> On-files => one should rebuild has something is wrong" |
---|
218 | fi |
---|
219 | # |
---|
220 | #look at consecutive cycles |
---|
221 | |
---|
222 | rmDirectory=0 |
---|
223 | |
---|
224 | cycleIdOff=`$ECHO $input4dataOff | sed 's/datacycle//g'` |
---|
225 | tableauOff=( `$ECHO ${cycleIdOff}` ) |
---|
226 | IFS=' |
---|
227 | ' |
---|
228 | tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
229 | IFS=$DefaultIFS |
---|
230 | |
---|
231 | lastIdOff=`expr ${#tableauOff[*]} - 1` |
---|
232 | ncycleOff=`expr ${tableauOff[${lastIdOff}]} - ${tableauOff[0]} + 1` |
---|
233 | ncycleOffVerif=${#tableauOff[*]} |
---|
234 | if [ "<${ncycleOff}>" != "<${ncycleOffVerif}>" ]; then |
---|
235 | $ECHO "$sourceRadio $dateDAQ: There is a lack of OFF cycles in the sequence: ${tableauOff[@]}" |
---|
236 | rmDirectory=1 |
---|
237 | somethingTodo=1 |
---|
238 | else |
---|
239 | $ECHO "$sourceRadio $dateDAQ: Ok at least consecutive OFF cycles: ${tableauOff[@]}" |
---|
240 | fi |
---|
241 | |
---|
242 | cycleIdOn=`$ECHO $input4dataOn | sed 's/datacycle//g'` |
---|
243 | tableauOn=( `$ECHO ${cycleIdOn}` ) |
---|
244 | IFS=' |
---|
245 | ' |
---|
246 | tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
247 | IFS=$DefaultIFS |
---|
248 | |
---|
249 | lastIdOn=`expr ${#tableauOn[*]} - 1` |
---|
250 | ncycleOn=`expr ${tableauOn[${lastIdOn}]} - ${tableauOn[0]} + 1` |
---|
251 | ncycleOnVerif=${#tableauOn[*]} |
---|
252 | if [ "<${ncycleOn}>" != "<${ncycleOnVerif}>" ]; then |
---|
253 | $ECHO "$sourceRadio $dateDAQ: There is a lack of ON cycles in the sequence: ${tableauOn[@]}" |
---|
254 | rmDirectory=1 |
---|
255 | somethingTodo=1 |
---|
256 | else |
---|
257 | $ECHO "$sourceRadio $dateDAQ: Ok at least consecutive ON cycles: ${tableauOn[@]}" |
---|
258 | fi |
---|
259 | |
---|
260 | if [ "<${cycleIdOff}>" != "<${cycleIdOn}>" ]; then |
---|
261 | $ECHO "$sourceRadio $dateDAQ: cycles seq. missmatch ON and OFF" |
---|
262 | rmDirectory=1 |
---|
263 | somethingTodo=1 |
---|
264 | fi |
---|
265 | # |
---|
266 | fi |
---|
267 | ######## |
---|
268 | if [ ${somethingTodo} -eq 1 ]; then |
---|
269 | # |
---|
270 | $ECHO ">>>>>>>>>>>>>>>> Do $sourceRadio $dateDAQ ANALOFF" |
---|
271 | |
---|
272 | if [ ${rmDirectory} -eq 1 ]; then |
---|
273 | #delete datacycle Off |
---|
274 | dirToRmOff=`ils ${i}/Off 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}'` |
---|
275 | tableauOff=( `$ECHO ${dirToRmOff}` ) |
---|
276 | IFS=' |
---|
277 | ' |
---|
278 | tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
279 | IFS=$DefaultIFS |
---|
280 | for j in ${tableauOff[@]} |
---|
281 | do |
---|
282 | irm -f -r -v ${j} |
---|
283 | done |
---|
284 | #delete datacycle On |
---|
285 | dirToRmOn=`ils ${i}/On 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}'` |
---|
286 | tableauOn=( `$ECHO ${dirToRmOn}` ) |
---|
287 | IFS=' |
---|
288 | ' |
---|
289 | tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
290 | IFS=$DefaultIFS |
---|
291 | for j in ${tableauOn[@]} |
---|
292 | do |
---|
293 | irm -f -r -v ${j} |
---|
294 | done |
---|
295 | fi |
---|
296 | |
---|
297 | $RM -f ${tmppublicpath}/proc_script.finished |
---|
298 | if [ ${simulationMode} = "On" ]; then |
---|
299 | $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ OFF" |
---|
300 | else |
---|
301 | ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ OFF |
---|
302 | while [ ! -e "${tmppublicpath}/proc_script.finished" ]; do |
---|
303 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished" |
---|
304 | date +%T |
---|
305 | sleep 60 |
---|
306 | done |
---|
307 | fi |
---|
308 | $ECHO "INFO (${scriptName}): proc_script has finished" |
---|
309 | $ECHO ">>>>>>>>>>>> Done $sourceRadio $dateDAQ OFF" |
---|
310 | $ECHO ">>>>>>>>>>>>>>>> Do $sourceRadio $dateDAQ ON" |
---|
311 | $RM ${tmppublicpath}/proc_script.finished |
---|
312 | |
---|
313 | if [ ${simulationMode} = "On" ]; then |
---|
314 | $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ ON" |
---|
315 | else |
---|
316 | ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ ON |
---|
317 | while [ ! -e "${tmppublicpath}/proc_script.finished" ]; do |
---|
318 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished" |
---|
319 | date +%T |
---|
320 | sleep 60 |
---|
321 | done |
---|
322 | fi |
---|
323 | $ECHO "INFO (${scriptName}): proc_script has finished" |
---|
324 | $RM ${tmppublicpath}/proc_script.finished |
---|
325 | #Todo see if there is errors in the log file before copy |
---|
326 | $ECHO ">>>>>>>>>>>> Done $sourceRadio $dateDAQ ON" |
---|
327 | fi |
---|
328 | done |
---|
329 | |
---|
330 | exit 0 |
---|