source: BAORadio/AmasNancay/trunk/anarawonoffmaker.sh@ 639

Last change on this file since 639 was 635, checked in by campagne, 14 years ago

first introduction of DRIFT data (jec)

  • Property svn:executable set to *
File size: 10.3 KB
RevLine 
[535]1#!/bin/sh -xvf
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 ]
36 do
37 case "$1" in
38 -src) sourceRadio=$2; shift;;
[540]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
[535]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}";;
[601]63 NGC4383) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
[635]64 3C273) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
[535]65 *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen"
66 exit 1;;
67esac
68
69srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
70
71#Path to public backupable path
72publicpath="/afs/in2p3.fr/home/c/campagne/public"
73
74
75#temporary files to synchronize scripts
76tmppublicpath=${TMPPUBLICPATH}
77#wakeup the NFS disk
78$LS -l ${tmppublicpath} > /dev/null
79#clean previous spurious files
80$RM -f ${tmppublicpath}/*.finished
81
82#Path where the job will do temporary IO
[579]83. ${SCRIPTPATH}/isInteractive.sh
84isInteractive=$(isInteractive)
85if [ ${isInteractive} == "1" ]; then
86 $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!"
87 exit 0;
[535]88fi
[579]89
90. ${SCRIPTPATH}/set_iojobpath.sh
91iojobpath=$(set_iojobpath)
[535]92cd ${iojobpath}
93
94localpath="${sourceRadio}"
95$MKDIR -p ./${localpath}
96cd ./${localpath}
97
98#save the top directory
99topDir=`pwd`
100
101#Path of the utility scripts
[575]102scriptpath=${SCRIPTPATH}
[535]103
[540]104#JEC 1/10/11 Use generic baodaqstatus name
[535]105#get the daq current irod status
[540]106#tag=`${DATE} +%F`
107#OUT1=${publicpath}/baodaqstatus-${tag}.txt
108OUT1=${publicpath}/baodaqstatus-current.txt
[535]109
110if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
[540]111 $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
112 exit 1
[535]113fi
114
115
116
117$ECHO "You have selected sourceRadio = ${sourceRadio} [date = ${dateSelected}]"
[626]118#JEC 14/12/11 One should take care of DR extension for Drift Scan
119#tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
120tableau=( `$GREP -i "${sourceRadio}/${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
[535]121IFS='
122'
123tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
124IFS=$DefaultIFS
125
126
127for i in ${tableau[@]}
128 do
129#
130# start a "fresh" session
131 cd ${topDir}
132 $LS | $XARGS -i $RM -rf {}
133
134 $ECHO "DEBUG: (${scriptName}) irods root dir $i"
135 dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
136
137 $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}"
138 $LS -lrt
139
140 gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l`
141 if [ ! ${gainDone} -gt 0 ]; then
142 $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` "
143 continue
144 fi
145
146######
147 $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}"
148#go to the .../source/date-sourcelowercase directory
149#download Off/datacycle<> and On/datacycle<> directories
150 $MKDIR -p ${topDir}/${dateDAQ}${srclower}
151 cd ${topDir}/${dateDAQ}${srclower}
152 aboveOnOffDir=`pwd`
153 $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>"
154#
155 mode="Off"
156 $ECHO "DEBUG (${scriptName}): START download the ${mode} data fits files"
157 inFileDirectory="./${mode}"
158 $MKDIR -p ${inFileDirectory}
159 listOfDataCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "datacycle"|$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` )
160 IFS='
161'
162 listOfDataCycle=( $( $PRINTF "%s\n" "${listOfDataCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
163 IFS=$DefaultIFS
164
165 firstCycleOff=`$ECHO ${listOfDataCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
166 nCyclesOff=`expr ${#listOfDataCycle[*]} - 1`
167
168 if [ ${nCyclesOff} -eq -1 ]; then
169 continue
170 fi
171
172 lastCycleOff=`$ECHO ${listOfDataCycle[${nCyclesOff}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
173
174 listOfDataCycle=( "${listOfDataCycle[@]/#/${i}/${mode}/}" )
175
176
177 for j in ${listOfDataCycle[@]}
178 do
179 irodsDownDir="${j}"
180 OUT=./getInFits.$$
181 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
182 igetStatus=`$GREP "^ERROR" ${OUT}`
183 if [ "<$igetStatus>" != "<>" ]; then
184 $ECHO "FATAL (${scriptName}): error while iget fits files:"
185 $ECHO $igetStatus
186 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
187 continue
188 fi
189 $RM -f ${OUT}
190 done
191 $ECHO "DEBUG (${scriptName}): END download the ${mode} data fits files"
192#
193 mode="On"
194 $ECHO "DEBUG (${scriptName}): START download the ${mode} data fits files"
195 inFileDirectory="./${mode}"
196 $MKDIR -p ${inFileDirectory}
197
198 listOfDataCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "datacycle" |$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` )
199 IFS='
200'
201 listOfDataCycle=( $( $PRINTF "%s\n" "${listOfDataCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
202 IFS=$DefaultIFS
203
204 firstCycleOn=`$ECHO ${listOfDataCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
205 nCyclesOn=`expr ${#listOfDataCycle[*]} - 1`
206
207 if [ ${nCyclesOn} -eq -1 ]; then
208 continue
209 fi
210
211 lastCycleOn=`$ECHO ${listOfDataCycle[${nCyclesOn}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
212
213 listOfDataCycle=( "${listOfDataCycle[@]/#/${i}/${mode}/}" )
214
215#
216#Check if there is the same number of cycles in Off and On mode
217#
218#first cycle = max(firstCycleOn, firstCycleOff)
219#last cycle = min(lastCycleOn,lastCycleOff)
220
221 if [ ${firstCycleOn} -eq ${firstCycleOff} -a ${lastCycleOn} -eq ${lastCycleOff} ]; then
222 firstCycle=${firstCycleOff}
223 lastCycle=${lastCycleOff}
224 else
225 $ECHO "INFO (${scriptName}): missmatch between Off and On mode"
226 $ECHO "${firstCycleOn} != ${firstCycleOff} OR ${lastCycleOn} != ${lastCycleOff}"
227 firstCycle=${firstCycleOff}
228 if [ ${firstCycleOn} -gt ${firstCycle} ]; then
229 firstCycle=${firstCycleOn}
230 fi
231 lastCycle=${lastCycleOff}
232 if [ ${lastCycleOn} -lt ${lastCycle} ]; then
233 lastCycle=${lastCycleOn}
234 fi
235 fi
236 $ECHO "INFO (${scriptName}): use cycles [${firstCycle}, ${lastCycle}]"
237
238
239 for j in ${listOfDataCycle[@]}
240 do
241 irodsDownDir="${j}"
242 OUT=./getInFits.$$
243 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
244 igetStatus=`$GREP "^ERROR" ${OUT}`
245 if [ "<$igetStatus>" != "<>" ]; then
246 $ECHO "FATAL (${scriptName}): error while iget fits files:"
247 $ECHO $igetStatus
248 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
249 continue
250 fi
251 $RM -f ${OUT}
252 done
253 $ECHO "DEBUG (${scriptName}): END download the ${mode} data fits files"
254#Get sca file
255 $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}"
256 OUT1=./getScaStatus.$$
[599]257# $RM -f ${tmppublicpath}/getscafiles.finished
[535]258 ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
[595]259# while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
260# $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
261# date +%T
262# sleep 30
263# done
[599]264# $RM ${tmppublicpath}/getscafiles.finished
[535]265 $ECHO "DEBUG (${scriptName}): END"
266#
267 getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
268#
269 if [ "<${getScaStatus}>" != "<>" ]; then
270 $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ"
271 $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
272 $CAT ${OUT1}
273 $ECHO "DEBUG (${scriptName}): END"
274 continue
275 fi
276 $RM -f ${OUT1}
277
278 scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}`
279
280
281#prepare job submission
282 cd ${aboveOnOffDir}
283#the default spectra name is medfiltmtx, otherwise use -specname <a_string>
284
285 logFile="analyse_RAWDATA_${sourceRadio}_${dateDAQ}.log"
286 $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`"
287 if [ ${simulationMode} = "On" ]; then
288 $ECHO "SIMUL: ${scriptpath}/Objs/analyse -act rawOnOff -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir datacycle -numcycle ${firstCycle},${lastCycle} -debug 1 >& ${logFile}"
289 cat > ${logFile} <<EOF
290 Ok rawOnOff finished
291EOF
292 else
293 ${scriptpath}/Objs/analyse -act rawOnOff -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir datacycle -numcycle ${firstCycle},${lastCycle} -debug 1 >& ${logFile}
294 fi
295 $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods"
296 rcstatus=`$GREP -i "Ok rawOnOff finished" ${logFile} | $WC -l`
297 if [ ${rcstatus} -eq 0 ]; then
298 $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}"
299 $ECHO " START logfile"
300 $CAT ${logFile}
301 $ECHO " END logFile"
302#clean and leave
303 cd ${aboveOnOffDir}
304 $LS | $XARGS -i $RM -rf {}
305 continue
306 fi
307#Save into Irods
308 $ECHO "DEBUG (${scriptName}): START save output files"
309 $LS ${aboveOnOffDir}
310#use -f option for iput ONLY to force override
311 if [ ${simulationMode} = "On" ]; then
312 $ECHO "SIMUL: here we look for output files and put them in Irods"
313 else
314 $LS -lrth
315 $FIND . -name "dataRaw_*" -print | $XARGS -i iput -f -v -K {} ${i}
316 $FIND . -name "diffOnOffRaw_*" -print | $XARGS -i iput -f -v -K {} ${i}
317 fi
318#save analysis logfile
319 $LS -l ${tmppublicpath} > /dev/null
320 $CP ${logFile} ${tmppublicpath}
321 $ECHO "DEBUG (${scriptName}): END save output files"
322#clean up to avoid scratch SIZE EXCEED LIMIT
323 cd ${aboveOnOffDir}
324 $LS | $XARGS -i $RM -rf {}
325
326done
327
328exit 0
Note: See TracBrowser for help on using the repository browser.