1 | #!/bin/sh |
---|
2 | #Perform the ON-OFF analysis |
---|
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 | #which source to analyse |
---|
29 | |
---|
30 | #Process cmd line args: the -src option is mandatory (source name as Abell85) |
---|
31 | sourceRadio= |
---|
32 | dateSelected= |
---|
33 | #use -sim option to simulate processing (debug the script as if...) |
---|
34 | simulationMode=Off |
---|
35 | while [ $# -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 |
---|
48 | done |
---|
49 | |
---|
50 | if [ ${simulationMode} = "On" ]; then |
---|
51 | $ECHO "INFO ${scriptName} running in SIMUL mode" |
---|
52 | fi |
---|
53 | |
---|
54 | if [ "<${sourceRadio}>" = "<>" ]; then |
---|
55 | $ECHO "FATAL: You have forgotten to select the source option (-src)" |
---|
56 | exit 1 |
---|
57 | fi |
---|
58 | |
---|
59 | case ${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;; |
---|
65 | esac |
---|
66 | |
---|
67 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
68 | |
---|
69 | #Path to public backupable path |
---|
70 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
71 | |
---|
72 | |
---|
73 | #temporary files to synchronize scripts |
---|
74 | tmppublicpath=${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 |
---|
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 | #get the daq current irod status |
---|
103 | tag=`${DATE} +%F` |
---|
104 | OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
105 | |
---|
106 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
107 | $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..." |
---|
108 | $RM -f ${tmppublicpath}/statusdaq.finished |
---|
109 | ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
110 | while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do |
---|
111 | sleep 30 |
---|
112 | done |
---|
113 | $RM ${tmppublicpath}/statusdaq.finished |
---|
114 | #protect against remove/rewriting |
---|
115 | $CHMOD -v 444 ${OUT1} |
---|
116 | fi |
---|
117 | |
---|
118 | |
---|
119 | #Nb: if we want to implement a loop on sources we have to take care of srclower... |
---|
120 | |
---|
121 | $ECHO "You have selected sourceRadio = ${sourceRadio} [date = ${dateSelected}]" |
---|
122 | tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
123 | IFS=' |
---|
124 | ' |
---|
125 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
126 | IFS=$DefaultIFS |
---|
127 | |
---|
128 | |
---|
129 | for i in ${tableau[@]} |
---|
130 | do |
---|
131 | # |
---|
132 | # start a "fresh" session |
---|
133 | cd ${topDir} |
---|
134 | $LS | $XARGS -i $RM -rf {} |
---|
135 | |
---|
136 | $ECHO "DEBUG: (${scriptName}) irods root dir $i" |
---|
137 | dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"` |
---|
138 | |
---|
139 | $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}" |
---|
140 | $LS -lrt |
---|
141 | |
---|
142 | |
---|
143 | #Look if the date has changed since beginning of the job! |
---|
144 | curtag=`${DATE} +%F` |
---|
145 | if [ "<${curtag}>" != "<${tag}>" ]; then |
---|
146 | tag=${curtag} |
---|
147 | #it is necessary to update the daq status as the day has changed during the processing... (batch can take a long time...) |
---|
148 | OUT1=${publicpath}/baodaqstatus-${curtag}.txt |
---|
149 | $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..." |
---|
150 | $RM -f ${tmppublicpath}/statusdaq.finished |
---|
151 | ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
152 | while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do |
---|
153 | sleep 30 |
---|
154 | done |
---|
155 | $RM ${tmppublicpath}/statusdaq.finished |
---|
156 | #protect against remove/rewriting |
---|
157 | $CHMOD -v 444 ${OUT1} |
---|
158 | fi |
---|
159 | # |
---|
160 | # look if the gain & calibration files exist |
---|
161 | # |
---|
162 | gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l` |
---|
163 | if [ ! ${gainDone} -gt 0 ]; then |
---|
164 | $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` " |
---|
165 | continue |
---|
166 | fi |
---|
167 | |
---|
168 | # |
---|
169 | somethingTodo=1 |
---|
170 | input4dataOff=`ils ${i}/Off 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` |
---|
171 | input4dataOn=`ils ${i}/On 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` |
---|
172 | # |
---|
173 | if [ "<${input4dataOff}>" != "<>" -a "<${input4dataOn}>" != "<>" ]; then |
---|
174 | #look at the content of the datacycle directory as may be the previous batch job has crashed |
---|
175 | tableauOff=( `$ECHO ${input4dataOff}` ) |
---|
176 | IFS=' |
---|
177 | ' |
---|
178 | tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
179 | IFS=$DefaultIFS |
---|
180 | # |
---|
181 | nTotFilesOff=0 |
---|
182 | for j in ${tableauOff[@]} |
---|
183 | do |
---|
184 | nFiles=`ils ${i}/Off/${j} | $GREP -i "medfiltmtx" | $WC -l` |
---|
185 | nTotFilesOff=`expr ${nTotFilesOff} + ${nFiles}` |
---|
186 | done |
---|
187 | # |
---|
188 | tableauOn=( `$ECHO ${input4dataOn}` ) |
---|
189 | IFS=' |
---|
190 | ' |
---|
191 | tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
192 | IFS=$DefaultIFS |
---|
193 | # |
---|
194 | nTotFilesOn=0 |
---|
195 | for j in ${tableauOn[@]} |
---|
196 | do |
---|
197 | nFiles=`ils ${i}/On/${j} | $GREP -i "medfiltmtx" | $WC -l` |
---|
198 | nTotFilesOn=`expr ${nTotFilesOn} + ${nFiles}` |
---|
199 | done |
---|
200 | diffOnOff=`expr ${nTotFilesOff} - ${nTotFilesOn}` |
---|
201 | if [ ${diffOnOff} -lt 0 ]; then |
---|
202 | zero=0 |
---|
203 | diffOnOff=`expr ${zero} - ${diffOnOff}` |
---|
204 | fi |
---|
205 | #allow files differences but non zero |
---|
206 | if [ ${nTotFilesOff} -gt 0 -a ${nTotFilesOn} -gt 0 ]; then |
---|
207 | somethingTodo=0 |
---|
208 | $ECHO "DEBUG (${scriptName}): $sourceRadio $dateDAQ has <${nTotFilesOff}> Off-files and <${nTotFilesOn}> On-files but OK" |
---|
209 | else |
---|
210 | $ECHO "INFO (${scriptName}): $sourceRadio $dateDAQ has <${nTotFilesOff}> Off-files and <${nTotFilesOn}> On-files => one should rebuild has something is wrong" |
---|
211 | fi |
---|
212 | # |
---|
213 | #look at consecutive cycles |
---|
214 | |
---|
215 | rmDirectory=0 |
---|
216 | |
---|
217 | cycleIdOff=`$ECHO $input4dataOff | sed 's/datacycle//g'` |
---|
218 | tableauOff=( `$ECHO ${cycleIdOff}` ) |
---|
219 | IFS=' |
---|
220 | ' |
---|
221 | tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
222 | IFS=$DefaultIFS |
---|
223 | |
---|
224 | lastIdOff=`expr ${#tableauOff[*]} - 1` |
---|
225 | ncycleOff=`expr ${tableauOff[${lastIdOff}]} - ${tableauOff[0]} + 1` |
---|
226 | ncycleOffVerif=${#tableauOff[*]} |
---|
227 | if [ "<${ncycleOff}>" != "<${ncycleOffVerif}>" ]; then |
---|
228 | $ECHO "$sourceRadio $dateDAQ: There is a lack of OFF cycles in the sequence: ${tableauOff[@]}" |
---|
229 | rmDirectory=1 |
---|
230 | somethingTodo=1 |
---|
231 | else |
---|
232 | $ECHO "$sourceRadio $dateDAQ: Ok at least consecutive OFF cycles: ${tableauOff[@]}" |
---|
233 | fi |
---|
234 | |
---|
235 | cycleIdOn=`$ECHO $input4dataOn | sed 's/datacycle//g'` |
---|
236 | tableauOn=( `$ECHO ${cycleIdOn}` ) |
---|
237 | IFS=' |
---|
238 | ' |
---|
239 | tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
240 | IFS=$DefaultIFS |
---|
241 | |
---|
242 | lastIdOn=`expr ${#tableauOn[*]} - 1` |
---|
243 | ncycleOn=`expr ${tableauOn[${lastIdOn}]} - ${tableauOn[0]} + 1` |
---|
244 | ncycleOnVerif=${#tableauOn[*]} |
---|
245 | if [ "<${ncycleOn}>" != "<${ncycleOnVerif}>" ]; then |
---|
246 | $ECHO "$sourceRadio $dateDAQ: There is a lack of ON cycles in the sequence: ${tableauOn[@]}" |
---|
247 | rmDirectory=1 |
---|
248 | somethingTodo=1 |
---|
249 | else |
---|
250 | $ECHO "$sourceRadio $dateDAQ: Ok at least consecutive ON cycles: ${tableauOn[@]}" |
---|
251 | fi |
---|
252 | |
---|
253 | if [ "<${cycleIdOff}>" != "<${cycleIdOn}>" ]; then |
---|
254 | $ECHO "$sourceRadio $dateDAQ: cycles seq. missmatch ON and OFF" |
---|
255 | rmDirectory=1 |
---|
256 | somethingTodo=1 |
---|
257 | fi |
---|
258 | # |
---|
259 | fi |
---|
260 | ######## |
---|
261 | if [ ${somethingTodo} -eq 1 ]; then |
---|
262 | # |
---|
263 | $ECHO ">>>>>>>>>>>>>>>> Do $sourceRadio $dateDAQ ANALOFF" |
---|
264 | |
---|
265 | if [ ${rmDirectory} -eq 1 ]; then |
---|
266 | #delete datacycle Off |
---|
267 | dirToRmOff=`ils ${i}/Off 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}'` |
---|
268 | tableauOff=( `$ECHO ${dirToRmOff}` ) |
---|
269 | IFS=' |
---|
270 | ' |
---|
271 | tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
272 | IFS=$DefaultIFS |
---|
273 | for j in ${tableauOff[@]} |
---|
274 | do |
---|
275 | irm -f -r -v ${j} |
---|
276 | done |
---|
277 | #delete datacycle On |
---|
278 | dirToRmOn=`ils ${i}/On 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}'` |
---|
279 | tableauOn=( `$ECHO ${dirToRmOn}` ) |
---|
280 | IFS=' |
---|
281 | ' |
---|
282 | tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
283 | IFS=$DefaultIFS |
---|
284 | for j in ${tableauOn[@]} |
---|
285 | do |
---|
286 | irm -f -r -v ${j} |
---|
287 | done |
---|
288 | fi |
---|
289 | |
---|
290 | $RM -f ${tmppublicpath}/proc_script.finished |
---|
291 | if [ ${simulationMode} = "On" ]; then |
---|
292 | $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ OFF" |
---|
293 | else |
---|
294 | ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ OFF |
---|
295 | while [ ! -e "${tmppublicpath}/proc_script.finished" ]; do |
---|
296 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished" |
---|
297 | date +%T |
---|
298 | sleep 60 |
---|
299 | done |
---|
300 | fi |
---|
301 | $ECHO "INFO (${scriptName}): proc_script has finished" |
---|
302 | $ECHO ">>>>>>>>>>>> Done $sourceRadio $dateDAQ OFF" |
---|
303 | $ECHO ">>>>>>>>>>>>>>>> Do $sourceRadio $dateDAQ ON" |
---|
304 | $RM ${tmppublicpath}/proc_script.finished |
---|
305 | |
---|
306 | if [ ${simulationMode} = "On" ]; then |
---|
307 | $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ ON" |
---|
308 | else |
---|
309 | ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ ON |
---|
310 | while [ ! -e "${tmppublicpath}/proc_script.finished" ]; do |
---|
311 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished" |
---|
312 | date +%T |
---|
313 | sleep 60 |
---|
314 | done |
---|
315 | fi |
---|
316 | $ECHO "INFO (${scriptName}): proc_script has finished" |
---|
317 | $RM ${tmppublicpath}/proc_script.finished |
---|
318 | #Todo see if there is errors in the log file before copy |
---|
319 | $ECHO ">>>>>>>>>>>> Done $sourceRadio $dateDAQ ON" |
---|
320 | fi |
---|
321 | done |
---|
322 | |
---|
323 | exit 0 |
---|