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