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

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

add NGC4383 src (jec)

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