source: BAORadio/AmasNancay/v4/anarawonoffmaker.sh@ 590

Last change on this file since 590 was 575, checked in by campagne, 14 years ago

introduce SCRIPTPATH environment variable (jec)

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