1 | #!/bin/sh -xvf
|
---|
2 | #download SCA file, proceed to introspection, and upload results
|
---|
3 | DATE=/bin/date
|
---|
4 | GREP=/bin/grep
|
---|
5 | AWK=/bin/awk
|
---|
6 | ECHO=/bin/echo
|
---|
7 | WC=/usr/bin/wc
|
---|
8 | CAT=/bin/cat
|
---|
9 | PRINTF=/usr/bin/printf
|
---|
10 | FIND=/usr/bin/find
|
---|
11 | MKDIR=/bin/mkdir
|
---|
12 | XARGS=/usr/bin/xargs
|
---|
13 | SORT=/bin/sort
|
---|
14 | RM=/bin/rm
|
---|
15 | TR=/usr/bin/tr
|
---|
16 | CP=/bin/cp
|
---|
17 | LS=/bin/ls
|
---|
18 | CHMOD=/bin/chmod
|
---|
19 |
|
---|
20 | DefaultIFS=$' \t\n'
|
---|
21 | IFS=$DefaultIFS
|
---|
22 |
|
---|
23 | #set Irods environment
|
---|
24 | . /usr/local/shared/bin/irods_env.sh -noverbose
|
---|
25 |
|
---|
26 | scriptName="`basename $0`"
|
---|
27 | #$ECHO "Processing script ${scriptName} at `date`"
|
---|
28 |
|
---|
29 | #$ECHO "SHOULD BE RETUNED FOR THE inPath cmd line of analyse.cc (Sorry...): 21/7/11 by JEC"
|
---|
30 | #exit 1
|
---|
31 |
|
---|
32 | #Process cmd line args: the -src option is mandatory (source name as Abell85)
|
---|
33 | sourceRadio=
|
---|
34 | #use -sim option to simulate processing (debug the script as if...)
|
---|
35 | simulationMode=Off
|
---|
36 | while [ $# -gt 0 ]
|
---|
37 | do
|
---|
38 | case "$1" in
|
---|
39 | -src) sourceRadio=$2; shift;;
|
---|
40 | -sim) simulationMode=On; shift;;
|
---|
41 | -h)
|
---|
42 | echo >&2 \
|
---|
43 | "usage: $0 -src souce [-sim]"
|
---|
44 | exit 1;;
|
---|
45 | *) break;; # terminate while loop
|
---|
46 | esac
|
---|
47 | shift
|
---|
48 | done
|
---|
49 |
|
---|
50 | if [ ${simulationMode} = "On" ]; then
|
---|
51 | $ECHO "INFO ${scriptName} running in SIMUL mode"
|
---|
52 | fi
|
---|
53 |
|
---|
54 |
|
---|
55 | if [ "<${sourceRadio}>" = "<>" ]; then
|
---|
56 | $ECHO "FATAL: You have forgotten to select the source option (-src)"
|
---|
57 | exit 1
|
---|
58 | fi
|
---|
59 |
|
---|
60 | case ${sourceRadio} in
|
---|
61 | Abell85) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
|
---|
62 | Abell2440) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
|
---|
63 | Abell1205) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
|
---|
64 | *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen"
|
---|
65 | exit 1;;
|
---|
66 | esac
|
---|
67 |
|
---|
68 |
|
---|
69 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
|
---|
70 |
|
---|
71 | #Path to public backupable path
|
---|
72 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
|
---|
73 |
|
---|
74 |
|
---|
75 | #temporary files to synchronize scripts
|
---|
76 | tmppublicpath=${TMPPUBLICPATH}
|
---|
77 | $LS -l ${tmppublicpath} > /dev/null
|
---|
78 |
|
---|
79 |
|
---|
80 | #Path where the job will do temporary IO
|
---|
81 | if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then
|
---|
82 | iojobpath="/sps/baoradio/AmasNancay/JEC"
|
---|
83 | $MKDIR -p $iojobpath
|
---|
84 | elif [ ${ENVIRONMENT} = "BATCH" ] ; then
|
---|
85 | iojobpath=${TMPBATCH}
|
---|
86 | else
|
---|
87 | $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
|
---|
88 | exit 1
|
---|
89 | fi
|
---|
90 | cd ${iojobpath}
|
---|
91 |
|
---|
92 | localpath="${sourceRadio}"
|
---|
93 | $MKDIR -p ./${localpath}
|
---|
94 | cd ./${localpath}
|
---|
95 |
|
---|
96 | #save the top directory
|
---|
97 | topDir=`pwd`
|
---|
98 |
|
---|
99 | #Path of the utility scripts
|
---|
100 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
|
---|
101 |
|
---|
102 |
|
---|
103 | #get the daq current irod status
|
---|
104 | tag=`${DATE} +%F`
|
---|
105 | OUT1=${publicpath}/baodaqstatus-${tag}.txt
|
---|
106 |
|
---|
107 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
|
---|
108 | $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
|
---|
109 | $RM -f ${tmppublicpath}/statusdaq.finished
|
---|
110 | ${scriptpath}/statusdaq.sh > ${OUT1}
|
---|
111 | while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
|
---|
112 | sleep 30
|
---|
113 | done
|
---|
114 | $RM ${tmppublicpath}/statusdaq.finished
|
---|
115 | #protect against remove/rewriting
|
---|
116 | $CHMOD -v 444 ${OUT1}
|
---|
117 | fi
|
---|
118 |
|
---|
119 | #
|
---|
120 | #We forbib to perform the gain for all the sources in one shot!
|
---|
121 | #
|
---|
122 | #if [ ! "<${sourceRadio}>" = "All" ]; then
|
---|
123 | $ECHO "You have selected sourceRadio = $sourceRadio"
|
---|
124 | tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
|
---|
125 | #else
|
---|
126 | # tableau=( `$CAT ${OUT1} | $AWK '( NF==4 ) { print $2 }'` )
|
---|
127 | #fi
|
---|
128 | IFS='
|
---|
129 | '
|
---|
130 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
|
---|
131 | IFS=$DefaultIFS
|
---|
132 |
|
---|
133 |
|
---|
134 | for i in ${tableau[@]}
|
---|
135 | do
|
---|
136 | $ECHO "DEBUG (${scriptName}): irods root dir $i"
|
---|
137 | dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
|
---|
138 | #Look if the date has changed since beginning of the job!
|
---|
139 | curtag=`${DATE} +%F`
|
---|
140 | if [ "<${curtag}>" != "<${tag}>" ]; then
|
---|
141 | tag=${curtag}
|
---|
142 | #it is necessary to update the daq status as the day has changed during the processing... (batch can take a long time...)
|
---|
143 | OUT1=${publicpath}/baodaqstatus-${curtag}.txt
|
---|
144 | $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
|
---|
145 | $RM -f ${tmppublicpath}/statusdaq.finished
|
---|
146 | ${scriptpath}/statusdaq.sh > ${OUT1}
|
---|
147 | while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
|
---|
148 | sleep 30
|
---|
149 | done
|
---|
150 | $RM ${tmppublicpath}/statusdaq.finished
|
---|
151 | #protect against remove/rewriting
|
---|
152 | $CHMOD -v 444 ${OUT1}
|
---|
153 | fi
|
---|
154 | #
|
---|
155 | # look if the fits file of the gains already exists
|
---|
156 | alreadyDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l`
|
---|
157 | if [ ${alreadyDone} -gt 0 ]; then
|
---|
158 | $ECHO "INFO (${scriptName}): Fits file for gains already exists"
|
---|
159 | continue
|
---|
160 | fi
|
---|
161 | # Something should be done...
|
---|
162 | #look if the files for the input to gain computations have been done
|
---|
163 | somethingTodo=1
|
---|
164 | input4gainOk1=`ils ${i}/Off 2>&1 | $GREP -i "^ERROR" | $WC -l`
|
---|
165 | input4gainOk2=`ils ${i}/Off 2>&1 | $GREP -i "gaincycle"`
|
---|
166 | if [ $input4gainOk1 -eq 0 -a "<${input4gainOk2}>" != "<>" ]; then
|
---|
167 | gaincycle=`$ECHO ${input4gainOk2} | $AWK '($1 == "C-"){print $2}'| $XARGS -i basename {}`
|
---|
168 | input4gainOk3=`ils ${i}/Off/${gaincycle} 2>&1 | $GREP -i "medfiltmtx" | $WC -l`
|
---|
169 | if [ $input4gainOk3 -gt 0 ]; then
|
---|
170 | somethingTodo=0
|
---|
171 | fi
|
---|
172 | fi
|
---|
173 | if [ $somethingTodo -eq 1 ]; then
|
---|
174 | #
|
---|
175 | $ECHO ">>>>>>>>>>>>>>>> Do proc_script $sourceRadio $dateDAQ GAIN"
|
---|
176 | $RM -f ${tmppublicpath}/proc_script.finished
|
---|
177 | if [ ${simulationMode} = "On" ]; then
|
---|
178 | $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ GAIN"
|
---|
179 | else
|
---|
180 | ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ GAIN
|
---|
181 | while [ ! -e "${tmppublicpath}/proc_script.finished" ]; do
|
---|
182 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished"
|
---|
183 | date +%T
|
---|
184 | sleep 60
|
---|
185 | done
|
---|
186 | fi
|
---|
187 | $ECHO "INFO (${scriptName}): proc_script has finished"
|
---|
188 | $RM ${tmppublicpath}/proc_script.finished
|
---|
189 | #Todo see if there is errors in the log file before copy
|
---|
190 | $ECHO ">>>>>>>>>>>>>>>> Done proc_script $sourceRadio $dateDAQ GAIN"
|
---|
191 | ######
|
---|
192 | fi
|
---|
193 | ######
|
---|
194 | $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}"
|
---|
195 | #go to the .../source/date-sourcelowercase directory
|
---|
196 | $MKDIR -p ${topDir}/${dateDAQ}${srclower}
|
---|
197 | cd ${topDir}/${dateDAQ}${srclower}
|
---|
198 | aboveOnOffDir=`pwd`
|
---|
199 | $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>"
|
---|
200 | # So the input files are there, so the fits file can be determined
|
---|
201 | mode="Off"
|
---|
202 | spectraGenDirName=`$ECHO ${gaincycle} | $AWK '{match($0,"[a-zA-Z]+",arr); print arr[0]}'`
|
---|
203 | cycleNumber=`$ECHO ${gaincycle} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
|
---|
204 | #care: the gaincycle variable contains the cycle number
|
---|
205 | $ECHO "DEBUG (${scriptName}): START download the fits files"
|
---|
206 | inFileDirectory="./${mode}"
|
---|
207 | $MKDIR -p ${inFileDirectory}
|
---|
208 | irodsDownDir="${i}/${mode}/${gaincycle}"
|
---|
209 | OUT=./getInFits.$$
|
---|
210 | iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
|
---|
211 | $LS ${inFileDirectory}/${gaincycle}
|
---|
212 | igetStatus=`$GREP "^ERROR" ${OUT}`
|
---|
213 | if [ "<$igetStatus>" != "<>" ]; then
|
---|
214 | $ECHO "FATAL (${scriptName}): error while iget fits files:"
|
---|
215 | $ECHO $igetStatus
|
---|
216 | continue
|
---|
217 | fi
|
---|
218 | $RM -f ${OUT}
|
---|
219 | $ECHO "DEBUG (${scriptName}): END download the fits files"
|
---|
220 | #Get sca files
|
---|
221 | $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}"
|
---|
222 | OUT1=./getScaStatus.$$
|
---|
223 | $RM -f ${tmppublicpath}/getscafiles.finished
|
---|
224 | ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
|
---|
225 | while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
|
---|
226 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
|
---|
227 | date +%T
|
---|
228 | sleep 30
|
---|
229 | done
|
---|
230 | $RM ${tmppublicpath}/getscafiles.finished
|
---|
231 | $ECHO "DEBUG (${scriptName}): END"
|
---|
232 | #
|
---|
233 | getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
|
---|
234 | #
|
---|
235 | if [ "<${getScaStatus}>" != "<>" ]; then
|
---|
236 | $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ"
|
---|
237 | $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
|
---|
238 | $CAT ${OUT1}
|
---|
239 | $ECHO "DEBUG (${scriptName}): END"
|
---|
240 | continue
|
---|
241 | fi
|
---|
242 | $RM -f ${OUT1}
|
---|
243 | $ECHO "DEBUG (${scriptName}): where am i `pwd`"
|
---|
244 | $LS -lrt
|
---|
245 |
|
---|
246 | scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}`
|
---|
247 | #
|
---|
248 | #the default spectra name is medfiltmtx, otherwise use -specname <a_string>
|
---|
249 | logFile="analyse_GAIN_${sourceRadio}_${dateDAQ}.log"
|
---|
250 | $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`"
|
---|
251 | if [ ${simulationMode} = "On" ]; then
|
---|
252 | $ECHO "SIMUL: ${scriptpath}/Objs/analyse -act gain -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir ${spectraGenDirName} -mode ${mode} -numcycle ${cycleNumber},${cycleNumber} -debug 1 >& ${logFile}"
|
---|
253 | cat > ${logFile} <<EOF
|
---|
254 | Ok gain finished
|
---|
255 | EOF
|
---|
256 |
|
---|
257 | else
|
---|
258 | ${scriptpath}/Objs/analyse -act gain -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir ${spectraGenDirName} -mode ${mode} -numcycle ${cycleNumber},${cycleNumber} -debuglev 1 >& ${logFile}
|
---|
259 | fi
|
---|
260 | #
|
---|
261 | $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods"
|
---|
262 | rcstatus=`$GREP -i "OK gain finished" ${logFile} | $WC -l`
|
---|
263 | if [ ${rcstatus} -eq 0 ]; then
|
---|
264 | $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}"
|
---|
265 | $ECHO " START logfile"
|
---|
266 | $CAT ${logFile}
|
---|
267 | $ECHO " END logFile"
|
---|
268 | #clean and leave
|
---|
269 | cd ${aboveOnOffDir}
|
---|
270 | $RM -rf ./*
|
---|
271 | continue
|
---|
272 | fi
|
---|
273 | #Save into Irods
|
---|
274 | $ECHO "DEBUG (${scriptName}): START save output files"
|
---|
275 | $LS ${aboveOnOffDir}
|
---|
276 | #use -f option of iput ONLY to force override
|
---|
277 | if [ ${simulationMode} = "On" ]; then
|
---|
278 | $ECHO "SIMUL: here we look for gain file and put them in Irods"
|
---|
279 | else
|
---|
280 | $FIND . -name "gain_*" -print | $XARGS -i iput -v -K {} ${i}
|
---|
281 | fi
|
---|
282 | #save analysis logfile
|
---|
283 | $LS -l ${tmppublicpath} > /dev/null
|
---|
284 | $CP ${logFile} ${tmppublicpath}
|
---|
285 | $ECHO "DEBUG (${scriptName}): END save output files"
|
---|
286 | #clean
|
---|
287 | cd ${aboveOnOffDir}
|
---|
288 | $RM -rf ./*
|
---|
289 | done
|
---|
290 |
|
---|
291 | exit 0 |
---|