source: BAORadio/AmasNancay/trunk/rawonoffmaker.sh@ 604

Last change on this file since 604 was 601, checked in by campagne, 14 years ago

add NGC4383 src (jec)

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