source: BAORadio/AmasNancay/trunk/rawonoffmaker.sh @ 675

Last change on this file since 675 was 635, checked in by campagne, 12 years ago

first introduction of DRIFT data (jec)

  • Property svn:executable set to *
File size: 9.1 KB
Line 
1#!/bin/sh
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 ]
36do
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    NGC4383) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
64    3C273) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
65    *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen"
66    exit 1;;
67esac
68
69srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
70
71#Path to public backupable path
72publicpath="/afs/in2p3.fr/home/c/campagne/public"
73
74
75#temporary files to synchronize scripts
76tmppublicpath=${TMPPUBLICPATH}
77#wakeup the NFS disk
78$LS -l ${tmppublicpath} > /dev/null
79#clean previous spurious files
80$RM -f ${tmppublicpath}/*.finished
81
82#Path where the job will do temporary IO
83. ${SCRIPTPATH}/isInteractive.sh
84isInteractive=$(isInteractive)
85if [ ${isInteractive} == "1" ]; then
86  $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!"
87   exit 0;
88fi
89
90. ${SCRIPTPATH}/set_iojobpath.sh
91iojobpath=$(set_iojobpath)
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#get the daq current irod status
105OUT1=${publicpath}/baodaqstatus-current.txt
106
107if [ ! -e ${OUT1}  -o ! -r ${OUT1} ]; then
108    $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
109    exit 1
110fi
111
112
113
114
115#Nb: if we want to implement a loop on sources we have to take care of srclower...
116
117$ECHO "You have selected sourceRadio = ${sourceRadio} [date = ${dateSelected}]"
118#JEC 14/12/11 One should take care of DR extension for Drift Scan
119#tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
120tableau=( `$GREP -i "${sourceRadio}/${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
121IFS='
122' 
123tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
124IFS=$DefaultIFS
125
126
127for i in ${tableau[@]}
128  do
129#
130# start a "fresh" session 
131  cd ${topDir}
132  $LS | $XARGS -i $RM -rf {}
133 
134  $ECHO "DEBUG: (${scriptName}) irods root dir $i"
135  dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
136
137  $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}"
138  $LS -lrt
139
140#
141# look if the gain & calibration files exist
142#
143  gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l`
144  if [ ! ${gainDone} -gt 0 ]; then
145      $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` "
146      continue
147  fi
148
149#
150  somethingTodo=1
151  input4dataOff=`ils ${i}/Off 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` 
152  input4dataOn=`ils ${i}/On 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.10n` 
153#
154  if [ "<${input4dataOff}>" != "<>" -a "<${input4dataOn}>" != "<>"  ]; then
155#look at the content of the datacycle directory as may be the previous batch job has crashed
156      tableauOff=( `$ECHO ${input4dataOff}` )
157      IFS='
158'
159      tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) )
160      IFS=$DefaultIFS
161#
162      nTotFilesOff=0
163      for j in ${tableauOff[@]}
164        do
165        nFiles=`ils ${i}/Off/${j} | $GREP -i "medfiltmtx" | $WC -l`
166        nTotFilesOff=`expr ${nTotFilesOff} + ${nFiles}`
167      done
168#
169      tableauOn=( `$ECHO ${input4dataOn}` )
170      IFS='
171      '
172      tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) )
173      IFS=$DefaultIFS
174#
175      nTotFilesOn=0
176      for j in ${tableauOn[@]}
177        do
178        nFiles=`ils ${i}/On/${j} | $GREP -i "medfiltmtx" | $WC -l`
179        nTotFilesOn=`expr ${nTotFilesOn} + ${nFiles}`
180      done
181      diffOnOff=`expr ${nTotFilesOff} - ${nTotFilesOn}`
182      if [ ${diffOnOff} -lt 0 ]; then
183          zero=0
184          diffOnOff=`expr ${zero} - ${diffOnOff}` 
185      fi
186#allow files differences but non zero
187      if [  ${nTotFilesOff} -gt 0 -a ${nTotFilesOn} -gt 0  ]; then
188          somethingTodo=0
189          $ECHO "DEBUG (${scriptName}): $sourceRadio $dateDAQ has <${nTotFilesOff}> Off-files and <${nTotFilesOn}> On-files but OK"
190      else
191          $ECHO "INFO (${scriptName}): $sourceRadio $dateDAQ has <${nTotFilesOff}> Off-files and <${nTotFilesOn}> On-files => one should rebuild has something is wrong"
192      fi
193#
194#look at consecutive cycles
195
196      rmDirectory=0
197
198      cycleIdOff=`$ECHO $input4dataOff | sed 's/datacycle//g'`
199      tableauOff=( `$ECHO ${cycleIdOff}` )
200      IFS='
201'
202      tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) )
203      IFS=$DefaultIFS
204     
205      lastIdOff=`expr ${#tableauOff[*]} - 1`
206      ncycleOff=`expr ${tableauOff[${lastIdOff}]} - ${tableauOff[0]} + 1`
207      ncycleOffVerif=${#tableauOff[*]}
208      if [ "<${ncycleOff}>" != "<${ncycleOffVerif}>"  ]; then
209          $ECHO "$sourceRadio $dateDAQ: There is a lack of OFF cycles in the sequence: ${tableauOff[@]}"
210          rmDirectory=1
211          somethingTodo=1
212      else
213          $ECHO "$sourceRadio $dateDAQ: Ok at least consecutive OFF cycles: ${tableauOff[@]}"
214      fi
215
216      cycleIdOn=`$ECHO $input4dataOn | sed 's/datacycle//g'`
217      tableauOn=( `$ECHO ${cycleIdOn}` )
218      IFS='
219'
220      tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) )
221      IFS=$DefaultIFS
222     
223      lastIdOn=`expr ${#tableauOn[*]} - 1`
224      ncycleOn=`expr ${tableauOn[${lastIdOn}]} - ${tableauOn[0]} + 1`
225      ncycleOnVerif=${#tableauOn[*]}
226      if [ "<${ncycleOn}>" != "<${ncycleOnVerif}>"  ]; then
227          $ECHO "$sourceRadio $dateDAQ: There is a lack of ON cycles in the sequence: ${tableauOn[@]}"
228          rmDirectory=1
229          somethingTodo=1
230      else
231          $ECHO "$sourceRadio $dateDAQ: Ok at least consecutive ON cycles:  ${tableauOn[@]}"
232      fi
233
234      if [ "<${cycleIdOff}>" != "<${cycleIdOn}>" ]; then
235          $ECHO "$sourceRadio $dateDAQ: cycles seq. missmatch ON and OFF"
236          rmDirectory=1
237          somethingTodo=1         
238      fi
239#
240  fi 
241########
242  if [ ${somethingTodo} -eq 1 ]; then
243#
244      $ECHO ">>>>>>>>>>>>>>>> Do $sourceRadio $dateDAQ ANALOFF"
245
246      if [ ${rmDirectory} -eq 1 ]; then
247#delete datacycle Off
248          dirToRmOff=`ils ${i}/Off 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}'` 
249          tableauOff=( `$ECHO ${dirToRmOff}` )
250          IFS='
251'
252          tableauOff=( $( $PRINTF "%s\n" "${tableauOff[@]}" | $AWK 'x[$0]++ == 0' ) )
253          IFS=$DefaultIFS
254          for j in ${tableauOff[@]}
255            do
256            irm -f -r -v ${j}
257          done
258#delete datacycle On
259          dirToRmOn=`ils ${i}/On 2>&1 | $GREP -i "datacycle" | $AWK 'BEGIN{FS="C- "}{print $2}'` 
260          tableauOn=( `$ECHO ${dirToRmOn}` )
261          IFS='
262'
263          tableauOn=( $( $PRINTF "%s\n" "${tableauOn[@]}" | $AWK 'x[$0]++ == 0' ) )
264          IFS=$DefaultIFS
265          for j in ${tableauOn[@]}
266            do
267            irm -f -r -v ${j}
268          done
269      fi
270         
271      $RM -f ${tmppublicpath}/proc_script.finished
272      if [ ${simulationMode} = "On" ]; then
273          $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ OFF"
274      else
275          ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ OFF
276          while [ ! -e "${tmppublicpath}/proc_script.finished"  ]; do
277              $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished"
278              date +%T
279              sleep 60
280          done
281      fi
282      $ECHO "INFO (${scriptName}): proc_script has finished"
283      $ECHO ">>>>>>>>>>>> Done $sourceRadio $dateDAQ OFF"
284      $ECHO ">>>>>>>>>>>>>>>> Do $sourceRadio $dateDAQ ON"
285      $RM ${tmppublicpath}/proc_script.finished
286     
287      if [ ${simulationMode} = "On" ]; then
288          $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ ON"
289      else
290          ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ ON
291          while [ ! -e "${tmppublicpath}/proc_script.finished"  ]; do
292              $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished"
293              date +%T
294              sleep 60
295          done
296      fi
297      $ECHO "INFO (${scriptName}): proc_script has finished"
298      $RM ${tmppublicpath}/proc_script.finished
299#Todo see if there is errors in the log file before copy
300      $ECHO ">>>>>>>>>>>> Done $sourceRadio $dateDAQ ON"
301  fi
302done
303
304exit 0
Note: See TracBrowser for help on using the repository browser.