source: BAORadio/AmasNancay/trunk/anagainmaker.sh @ 579

Last change on this file since 579 was 579, checked in by torrento, 13 years ago

version adaptee a grid engin (ana)

  • Property svn:executable set to *
File size: 7.1 KB
Line 
1#!/bin/sh -xvf
2#download SCA file, proceed to introspection, and upload results
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
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)
33sourceRadio=
34dateSelected=
35#use -sim option to simulate processing (debug the script as if...)
36simulationMode=Off
37while [ $# -gt 0 ]
38do
39  case "$1" in
40      -src)  sourceRadio=$2; shift;;
41      -date) dateSelected=$2;     shift;;
42       -sim) simulationMode=On;;
43        -h)
44            echo >&2 \
45            "usage: $0 -src souce -date YYYYMMDD [-sim]"
46            exit 1;;
47        *)  break;;     # terminate while loop
48    esac
49    shift
50done
51
52if [ ${simulationMode} = "On" ]; then
53    $ECHO "INFO ${scriptName} running in SIMUL mode"
54fi
55
56
57if [ "<${sourceRadio}>" = "<>" ]; then
58    $ECHO "FATAL: You have forgotten to select the source option (-src)"
59    exit 1
60fi
61
62case ${sourceRadio} in
63    Abell85) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
64    Abell2440) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
65    Abell1205) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
66    *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen"
67    exit 1;;
68esac
69
70
71srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
72
73#Path to public backupable path
74publicpath="/afs/in2p3.fr/home/c/campagne/public"
75
76
77#temporary files to synchronize scripts
78tmppublicpath=${TMPPUBLICPATH}
79$LS -l ${tmppublicpath} > /dev/null
80#clean previous spurious files
81$RM -f ${tmppublicpath}/*.finished
82
83
84#Path where the job will do temporary IO
85. ${SCRIPTPATH}/isInteractive.sh
86isInteractive=$(isInteractive)
87if [ ${isInteractive} == "1" ]; then
88  $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!"
89   exit 0;
90fi
91
92. ${SCRIPTPATH}/set_iojobpath.sh
93iojobpath=$(set_iojobpath)
94cd ${iojobpath}
95
96localpath="${sourceRadio}"
97$MKDIR -p ./${localpath}
98cd ./${localpath}
99
100#save the top directory
101topDir=`pwd`
102
103#Path of the utility scripts
104scriptpath=${SCRIPTPATH}
105
106
107#JEC 1/10/11 Use generic baodaqstatus name
108#get the daq current irod status
109#tag=`${DATE} +%F`
110#OUT1=${publicpath}/baodaqstatus-${tag}.txt
111OUT1=${publicpath}/baodaqstatus-current.txt
112
113if [ ! -e ${OUT1}  -o ! -r ${OUT1} ]; then
114    $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
115    exit 1
116fi
117
118#
119$ECHO "You have selected sourceRadio = $sourceRadio [date = ${dateSelected}]"
120tableau=( `$GREP -i "${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# start a "fresh" session 
130  cd ${topDir}
131  $LS | $XARGS -i $RM -rf {}
132
133  $ECHO "DEBUG (${scriptName}): irods root dir $i"
134  dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
135
136  $LS -lrt
137
138######
139  $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}"
140#go to the .../source/date-sourcelowercase directory
141  $MKDIR -p ${topDir}/${dateDAQ}${srclower}
142  cd ${topDir}/${dateDAQ}${srclower}
143  aboveOnOffDir=`pwd`
144  $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>"
145# So the input files are there, so the fits file can be determined
146  mode="Off"
147  spectraGenDirName=`$ECHO ${gaincycle} | $AWK '{match($0,"[a-zA-Z]+",arr); print arr[0]}'`
148  cycleNumber=`$ECHO ${gaincycle} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
149#care: the gaincycle variable contains the cycle number
150  $ECHO "DEBUG (${scriptName}): START download the fits files"
151  inFileDirectory="./${mode}"
152  $MKDIR -p ${inFileDirectory}
153  irodsDownDir="${i}/${mode}/${gaincycle}"
154  OUT=./getInFits.$$
155  iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
156  $LS ${inFileDirectory}/${gaincycle}
157  igetStatus=`$GREP "^ERROR" ${OUT}`
158  if [ "<$igetStatus>" != "<>" ]; then
159      $ECHO "FATAL (${scriptName}): error while iget fits files:"
160      $ECHO $igetStatus
161      continue
162  fi
163  $RM -f ${OUT}
164  $ECHO "DEBUG (${scriptName}): END download the fits files"
165#Get sca files
166  $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}"
167  OUT1=./getScaStatus.$$
168  $RM -f ${tmppublicpath}/getscafiles.finished
169  ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
170  while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
171      $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
172      date +%T
173      sleep 30
174  done
175  $RM ${tmppublicpath}/getscafiles.finished
176  $ECHO "DEBUG (${scriptName}): END"
177#
178  getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
179#       
180  if [ "<${getScaStatus}>" != "<>" ]; then
181      $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ"
182      $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
183      $CAT ${OUT1}
184      $ECHO "DEBUG (${scriptName}): END"
185      continue
186  fi
187  $RM -f ${OUT1}
188  $ECHO "DEBUG (${scriptName}): where am i `pwd`"
189  $LS -lrt
190 
191  scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}`
192#       
193#the default spectra name is medfiltmtx, otherwise use -specname <a_string>
194  logFile="analyse_GAIN_${sourceRadio}_${dateDAQ}.log"
195  $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`"
196  if [ ${simulationMode} = "On" ]; then
197      $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}"
198      cat > ${logFile} <<EOF
199      Ok gain finished
200EOF
201
202  else
203      ${scriptpath}/Objs/analyse -act gain  -inPath ${iojobpath} -source  ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir ${spectraGenDirName} -mode ${mode} -numcycle ${cycleNumber},${cycleNumber} -debuglev 1 >& ${logFile}
204  fi
205#
206  $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods"
207  rcstatus=`$GREP -i "OK gain finished" ${logFile} | $WC -l`
208  if [ ${rcstatus} -eq 0 ]; then
209      $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}"
210      $ECHO "                      START logfile"
211      $CAT ${logFile}
212      $ECHO "                      END   logFile"
213#clean and leave
214      cd ${aboveOnOffDir}
215      $RM -rf ./*
216      continue
217  fi
218#Save into Irods
219  $ECHO "DEBUG (${scriptName}): START save output files"
220  $LS ${aboveOnOffDir}
221#use -f option of iput ONLY to force override
222  if [ ${simulationMode} = "On" ]; then
223      $ECHO "SIMUL: here we look for gain file and put them in Irods"
224  else
225      $FIND . -name "gain_*" -print | $XARGS -i  iput -f -v -K {} ${i}
226  fi
227#save analysis logfile
228  $LS -l ${tmppublicpath} > /dev/null
229  $CP ${logFile} ${tmppublicpath}
230  $ECHO "DEBUG (${scriptName}): END save output files"
231#clean
232  cd ${aboveOnOffDir}
233  $LS | $XARGS -i $RM -rf {}
234
235done
236
237exit 0
Note: See TracBrowser for help on using the repository browser.