source: BAORadio/AmasNancay/v3/anarawonoffmaker.sh@ 631

Last change on this file since 631 was 547, checked in by campagne, 14 years ago

move to trunk the previous HEAD (jec)

  • Property svn:executable set to *
File size: 11.2 KB
Line 
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;;
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 *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen"
64 exit 1;;
65esac
66
67srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
68
69#Path to public backupable path
70publicpath="/afs/in2p3.fr/home/c/campagne/public"
71
72
73#temporary files to synchronize scripts
74tmppublicpath=${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
81if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then
82 iojobpath="/sps/baoradio/AmasNancay/JEC"
83 $MKDIR -p $iojobpath
84 $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!"
85 exit 0;
86elif [ ${ENVIRONMENT} = "BATCH" ] ; then
87 iojobpath=${TMPBATCH}
88else
89 $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
90 exit 1
91fi
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
102scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
103
104#JEC 1/10/11 Use generic baodaqstatus name
105#get the daq current irod status
106#tag=`${DATE} +%F`
107#OUT1=${publicpath}/baodaqstatus-${tag}.txt
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# $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
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$ECHO "You have selected sourceRadio = ${sourceRadio} [date = ${dateSelected}]"
127tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
128IFS='
129'
130tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
131IFS=$DefaultIFS
132
133
134for i in ${tableau[@]}
135 do
136#
137# start a "fresh" session
138 cd ${topDir}
139 $LS | $XARGS -i $RM -rf {}
140
141 $ECHO "DEBUG: (${scriptName}) irods root dir $i"
142 dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
143
144 $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}"
145 $LS -lrt
146
147
148#JEC 1/10/11 Use generic baodaqstatus name
149#Look if the date has changed since beginning of the job!
150# curtag=`${DATE} +%F`
151# if [ "<${curtag}>" != "<${tag}>" ]; then
152# tag=${curtag}
153#it is necessary to update the daq status as the day has changed during the processing... (batch can take a long time...)
154# OUT1=${publicpath}/baodaqstatus-${curtag}.txt
155# $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
156# $RM -f ${tmppublicpath}/statusdaq.finished
157# ${scriptpath}/statusdaq.sh > ${OUT1}
158# while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
159# sleep 30
160# done
161# $RM ${tmppublicpath}/statusdaq.finished
162#protect against remove/rewriting
163# $CHMOD -v 444 ${OUT1}
164# fi
165#
166# look if the gain & calibration files exist
167#
168 gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l`
169 if [ ! ${gainDone} -gt 0 ]; then
170 $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` "
171 continue
172 fi
173
174######
175 $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}"
176#go to the .../source/date-sourcelowercase directory
177#download Off/datacycle<> and On/datacycle<> directories
178 $MKDIR -p ${topDir}/${dateDAQ}${srclower}
179 cd ${topDir}/${dateDAQ}${srclower}
180 aboveOnOffDir=`pwd`
181 $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>"
182#
183 mode="Off"
184 $ECHO "DEBUG (${scriptName}): START download the ${mode} data fits files"
185 inFileDirectory="./${mode}"
186 $MKDIR -p ${inFileDirectory}
187 listOfDataCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "datacycle"|$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` )
188 IFS='
189'
190 listOfDataCycle=( $( $PRINTF "%s\n" "${listOfDataCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
191 IFS=$DefaultIFS
192
193 firstCycleOff=`$ECHO ${listOfDataCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
194 nCyclesOff=`expr ${#listOfDataCycle[*]} - 1`
195
196 if [ ${nCyclesOff} -eq -1 ]; then
197 continue
198 fi
199
200 lastCycleOff=`$ECHO ${listOfDataCycle[${nCyclesOff}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
201
202 listOfDataCycle=( "${listOfDataCycle[@]/#/${i}/${mode}/}" )
203
204
205 for j in ${listOfDataCycle[@]}
206 do
207 irodsDownDir="${j}"
208 OUT=./getInFits.$$
209 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
210 igetStatus=`$GREP "^ERROR" ${OUT}`
211 if [ "<$igetStatus>" != "<>" ]; then
212 $ECHO "FATAL (${scriptName}): error while iget fits files:"
213 $ECHO $igetStatus
214 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
215 continue
216 fi
217 $RM -f ${OUT}
218 done
219 $ECHO "DEBUG (${scriptName}): END download the ${mode} data fits files"
220#
221 mode="On"
222 $ECHO "DEBUG (${scriptName}): START download the ${mode} data fits files"
223 inFileDirectory="./${mode}"
224 $MKDIR -p ${inFileDirectory}
225
226 listOfDataCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "datacycle" |$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` )
227 IFS='
228'
229 listOfDataCycle=( $( $PRINTF "%s\n" "${listOfDataCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
230 IFS=$DefaultIFS
231
232 firstCycleOn=`$ECHO ${listOfDataCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
233 nCyclesOn=`expr ${#listOfDataCycle[*]} - 1`
234
235 if [ ${nCyclesOn} -eq -1 ]; then
236 continue
237 fi
238
239 lastCycleOn=`$ECHO ${listOfDataCycle[${nCyclesOn}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
240
241 listOfDataCycle=( "${listOfDataCycle[@]/#/${i}/${mode}/}" )
242
243#
244#Check if there is the same number of cycles in Off and On mode
245#
246#first cycle = max(firstCycleOn, firstCycleOff)
247#last cycle = min(lastCycleOn,lastCycleOff)
248
249 if [ ${firstCycleOn} -eq ${firstCycleOff} -a ${lastCycleOn} -eq ${lastCycleOff} ]; then
250 firstCycle=${firstCycleOff}
251 lastCycle=${lastCycleOff}
252 else
253 $ECHO "INFO (${scriptName}): missmatch between Off and On mode"
254 $ECHO "${firstCycleOn} != ${firstCycleOff} OR ${lastCycleOn} != ${lastCycleOff}"
255 firstCycle=${firstCycleOff}
256 if [ ${firstCycleOn} -gt ${firstCycle} ]; then
257 firstCycle=${firstCycleOn}
258 fi
259 lastCycle=${lastCycleOff}
260 if [ ${lastCycleOn} -lt ${lastCycle} ]; then
261 lastCycle=${lastCycleOn}
262 fi
263 fi
264 $ECHO "INFO (${scriptName}): use cycles [${firstCycle}, ${lastCycle}]"
265
266
267 for j in ${listOfDataCycle[@]}
268 do
269 irodsDownDir="${j}"
270 OUT=./getInFits.$$
271 iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
272 igetStatus=`$GREP "^ERROR" ${OUT}`
273 if [ "<$igetStatus>" != "<>" ]; then
274 $ECHO "FATAL (${scriptName}): error while iget fits files:"
275 $ECHO $igetStatus
276 $ECHO " ==> skip this run $sourceRadio $dateDAQ"
277 continue
278 fi
279 $RM -f ${OUT}
280 done
281 $ECHO "DEBUG (${scriptName}): END download the ${mode} data fits files"
282#Get sca file
283 $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}"
284 OUT1=./getScaStatus.$$
285 $RM -f ${tmppublicpath}/getscafiles.finished
286 ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
287 while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
288 $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
289 date +%T
290 sleep 30
291 done
292 $RM ${tmppublicpath}/getscafiles.finished
293 $ECHO "DEBUG (${scriptName}): END"
294#
295 getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
296#
297 if [ "<${getScaStatus}>" != "<>" ]; then
298 $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ"
299 $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
300 $CAT ${OUT1}
301 $ECHO "DEBUG (${scriptName}): END"
302 continue
303 fi
304 $RM -f ${OUT1}
305
306 scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}`
307
308
309#prepare job submission
310 cd ${aboveOnOffDir}
311#the default spectra name is medfiltmtx, otherwise use -specname <a_string>
312
313 logFile="analyse_RAWDATA_${sourceRadio}_${dateDAQ}.log"
314 $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`"
315 if [ ${simulationMode} = "On" ]; then
316 $ECHO "SIMUL: ${scriptpath}/Objs/analyse -act rawOnOff -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir datacycle -numcycle ${firstCycle},${lastCycle} -debug 1 >& ${logFile}"
317 cat > ${logFile} <<EOF
318 Ok rawOnOff finished
319EOF
320 else
321 ${scriptpath}/Objs/analyse -act rawOnOff -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir datacycle -numcycle ${firstCycle},${lastCycle} -debug 1 >& ${logFile}
322 fi
323 $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods"
324 rcstatus=`$GREP -i "Ok rawOnOff finished" ${logFile} | $WC -l`
325 if [ ${rcstatus} -eq 0 ]; then
326 $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}"
327 $ECHO " START logfile"
328 $CAT ${logFile}
329 $ECHO " END logFile"
330#clean and leave
331 cd ${aboveOnOffDir}
332 $LS | $XARGS -i $RM -rf {}
333 continue
334 fi
335#Save into Irods
336 $ECHO "DEBUG (${scriptName}): START save output files"
337 $LS ${aboveOnOffDir}
338#use -f option for iput ONLY to force override
339 if [ ${simulationMode} = "On" ]; then
340 $ECHO "SIMUL: here we look for output files and put them in Irods"
341 else
342 $LS -lrth
343 $FIND . -name "dataRaw_*" -print | $XARGS -i iput -f -v -K {} ${i}
344 $FIND . -name "diffOnOffRaw_*" -print | $XARGS -i iput -f -v -K {} ${i}
345 fi
346#save analysis logfile
347 $LS -l ${tmppublicpath} > /dev/null
348 $CP ${logFile} ${tmppublicpath}
349 $ECHO "DEBUG (${scriptName}): END save output files"
350#clean up to avoid scratch SIZE EXCEED LIMIT
351 cd ${aboveOnOffDir}
352 $LS | $XARGS -i $RM -rf {}
353
354done
355
356exit 0
Note: See TracBrowser for help on using the repository browser.