source: BAORadio/AmasNancay/v6/rawonoffmaker.sh@ 689

Last change on this file since 689 was 626, checked in by campagne, 14 years ago

drift scan runs (jec)

  • Property svn:executable set to *
File size: 9.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
104OUT1=${publicpath}/baodaqstatus-current.txt
105
106if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
107 $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
108 exit 1
109fi
110
111
112
113
114#Nb: if we want to implement a loop on sources we have to take care of srclower...
115
116$ECHO "You have selected sourceRadio = ${sourceRadio} [date = ${dateSelected}]"
117#JEC 14/12/11 One should take care of DR extension for Drift Scan
118#tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
119tableau=( `$GREP -i "${sourceRadio}/${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
120IFS='
121'
122tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
123IFS=$DefaultIFS
124
125
126for i in ${tableau[@]}
127 do
128#
129# start a "fresh" session
130 cd ${topDir}
131 $LS | $XARGS -i $RM -rf {}
132
133 $ECHO "DEBUG: (${scriptName}) irods root dir $i"
134 dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
135
136 $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}"
137 $LS -lrt
138
139#
140# look if the gain & calibration files exist
141#
142 gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l`
143 if [ ! ${gainDone} -gt 0 ]; then
144 $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` "
145 continue
146 fi
147
148#
149 somethingTodo=1
150 input4dataOff=`ils ${i}/Off 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n`
151 input4dataOn=`ils ${i}/On 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n`
152#
153 if [ "<${input4dataOff}>" != "<>" -a "<${input4dataOn}>" != "<>" ]; then
154#look at the content of the datacycle directory as may be the previous batch job has crashed
155 tableauOff=( `$ECHO ${input4dataOff}` )
156 IFS='
157'
158 tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) )
159 IFS=$DefaultIFS
160#
161 nTotFilesOff=0
162 for j in ${tableauOff[@]}
163 do
164 nFiles=`ils ${i}/Off/${j} | $GREP -i "medfiltmtx" | $WC -l`
165 nTotFilesOff=`expr ${nTotFilesOff} + ${nFiles}`
166 done
167#
168 tableauOn=( `$ECHO ${input4dataOn}` )
169 IFS='
170 '
171 tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) )
172 IFS=$DefaultIFS
173#
174 nTotFilesOn=0
175 for j in ${tableauOn[@]}
176 do
177 nFiles=`ils ${i}/On/${j} | $GREP -i "medfiltmtx" | $WC -l`
178 nTotFilesOn=`expr ${nTotFilesOn} + ${nFiles}`
179 done
180 diffOnOff=`expr ${nTotFilesOff} - ${nTotFilesOn}`
181 if [ ${diffOnOff} -lt 0 ]; then
182 zero=0
183 diffOnOff=`expr ${zero} - ${diffOnOff}`
184 fi
185#allow files differences but non zero
186 if [ ${nTotFilesOff} -gt 0 -a ${nTotFilesOn} -gt 0 ]; then
187 somethingTodo=0
188 $ECHO "DEBUG (${scriptName}): $sourceRadio $dateDAQ has <${nTotFilesOff}> Off-files and <${nTotFilesOn}> On-files but OK"
189 else
190 $ECHO "INFO (${scriptName}): $sourceRadio $dateDAQ has <${nTotFilesOff}> Off-files and <${nTotFilesOn}> On-files => one should rebuild has something is wrong"
191 fi
192#
193#look at consecutive cycles
194
195 rmDirectory=0
196
197 cycleIdOff=`$ECHO $input4dataOff | sed 's/datacycle//g'`
198 tableauOff=( `$ECHO ${cycleIdOff}` )
199 IFS='
200'
201 tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) )
202 IFS=$DefaultIFS
203
204 lastIdOff=`expr ${#tableauOff[*]} - 1`
205 ncycleOff=`expr ${tableauOff[${lastIdOff}]} - ${tableauOff[0]} + 1`
206 ncycleOffVerif=${#tableauOff[*]}
207 if [ "<${ncycleOff}>" != "<${ncycleOffVerif}>" ]; then
208 $ECHO "$sourceRadio $dateDAQ: There is a lack of OFF cycles in the sequence: ${tableauOff[@]}"
209 rmDirectory=1
210 somethingTodo=1
211 else
212 $ECHO "$sourceRadio $dateDAQ: Ok at least consecutive OFF cycles: ${tableauOff[@]}"
213 fi
214
215 cycleIdOn=`$ECHO $input4dataOn | sed 's/datacycle//g'`
216 tableauOn=( `$ECHO ${cycleIdOn}` )
217 IFS='
218'
219 tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) )
220 IFS=$DefaultIFS
221
222 lastIdOn=`expr ${#tableauOn[*]} - 1`
223 ncycleOn=`expr ${tableauOn[${lastIdOn}]} - ${tableauOn[0]} + 1`
224 ncycleOnVerif=${#tableauOn[*]}
225 if [ "<${ncycleOn}>" != "<${ncycleOnVerif}>" ]; then
226 $ECHO "$sourceRadio $dateDAQ: There is a lack of ON cycles in the sequence: ${tableauOn[@]}"
227 rmDirectory=1
228 somethingTodo=1
229 else
230 $ECHO "$sourceRadio $dateDAQ: Ok at least consecutive ON cycles: ${tableauOn[@]}"
231 fi
232
233 if [ "<${cycleIdOff}>" != "<${cycleIdOn}>" ]; then
234 $ECHO "$sourceRadio $dateDAQ: cycles seq. missmatch ON and OFF"
235 rmDirectory=1
236 somethingTodo=1
237 fi
238#
239 fi
240########
241 if [ ${somethingTodo} -eq 1 ]; then
242#
243 $ECHO ">>>>>>>>>>>>>>>> Do $sourceRadio $dateDAQ ANALOFF"
244
245 if [ ${rmDirectory} -eq 1 ]; then
246#delete datacycle Off
247 dirToRmOff=`ils ${i}/Off 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}'`
248 tableauOff=( `$ECHO ${dirToRmOff}` )
249 IFS='
250'
251 tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) )
252 IFS=$DefaultIFS
253 for j in ${tableauOff[@]}
254 do
255 irm -f -r -v ${j}
256 done
257#delete datacycle On
258 dirToRmOn=`ils ${i}/On 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}'`
259 tableauOn=( `$ECHO ${dirToRmOn}` )
260 IFS='
261'
262 tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) )
263 IFS=$DefaultIFS
264 for j in ${tableauOn[@]}
265 do
266 irm -f -r -v ${j}
267 done
268 fi
269
270 $RM -f ${tmppublicpath}/proc_script.finished
271 if [ ${simulationMode} = "On" ]; then
272 $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ OFF"
273 else
274 ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ OFF
275 while [ ! -e "${tmppublicpath}/proc_script.finished" ]; do
276 $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished"
277 date +%T
278 sleep 60
279 done
280 fi
281 $ECHO "INFO (${scriptName}): proc_script has finished"
282 $ECHO ">>>>>>>>>>>> Done $sourceRadio $dateDAQ OFF"
283 $ECHO ">>>>>>>>>>>>>>>> Do $sourceRadio $dateDAQ ON"
284 $RM ${tmppublicpath}/proc_script.finished
285
286 if [ ${simulationMode} = "On" ]; then
287 $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ ON"
288 else
289 ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ ON
290 while [ ! -e "${tmppublicpath}/proc_script.finished" ]; do
291 $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished"
292 date +%T
293 sleep 60
294 done
295 fi
296 $ECHO "INFO (${scriptName}): proc_script has finished"
297 $RM ${tmppublicpath}/proc_script.finished
298#Todo see if there is errors in the log file before copy
299 $ECHO ">>>>>>>>>>>> Done $sourceRadio $dateDAQ ON"
300 fi
301done
302
303exit 0
Note: See TracBrowser for help on using the repository browser.