/[CCFs]/bin/mlovccf
ViewVC logotype

Annotation of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (hide annotations)
Tue Nov 29 13:44:41 2016 UTC (8 years ago) by ccflib
Branch: MAIN
Changes since 1.16: +64 -64 lines
Added checking of HEADAS and SAS initialization failure

1 ccflib 1.1 #! /bin/bash
2    
3     # mlovccf (make list of valid ccfs)
4     #
5 ccflib 1.7 # Makes the list of valid CCFs. These are all CCFs, among those published since the
6 ccflib 1.2 # beginning of the project, that are required to process any ODF at a given date,
7 ccflib 1.7 # typically the current date. This list will change with time as far as new
8 ccflib 1.2 # CCFs are issued to deal with new calibration data and/or replace obsolete ones.
9 ccflib 1.1 #
10 ccflib 1.10 # To identify the set of CCFs required to process a given ODF is the job of task cifbuild.
11 ccflib 1.2 # To make such identification, cifbuild needs only the start time of the observation.
12 ccflib 1.7 # Therefore, if we provide a list of all observed ODFs at a given date together with their
13     # respective start time, we could compute all the CCFs required to process them.
14     # For such a moment, that list is the list of valid CCFs required to process
15     # any observed ODF.
16 ccflib 1.1 #
17 ccflib 1.7 # We need as input the list of all observed ODFs at a given date.
18     # This is obtained from the report of all observations that the XSA makes to CDS,
19 ccflib 1.10 # xsaobslog.txt (http://nxsa.esac.esa.int/ftp_public/cfs_obslog/xsaobslog.txt).
20 ccflib 1.2 #
21 ccflib 1.17 # $Id: mlovccf,v 1.16 2016/09/19 12:36:15 ccflib Exp $
22 ccflib 1.4
23     # Next two lines allow to submit this script to the grid
24     # request Bourne shell as shell for job
25 ccflib 1.6 #$ -S /bin/bash
26 ccflib 1.1
27 ccflib 1.16 adminmail="eduardo.ojero@sciops.esa.int"
28 ccflib 1.5
29 ccflib 1.17 VALID_CCF="$HOME/processing_valid_ccf"
30 ccflib 1.10
31 ccflib 1.13 mailfile="${VALID_CCF}/mailfile"
32    
33 ccflib 1.1 host=`hostname | cut -d. -f1`
34    
35 ccflib 1.5 now=`date +'%Y%m%d_%H%M'`
36 ccflib 1.7 now_table=`date +'%Y-%m-%dT%H:%M:%S'`
37 ccflib 1.3
38 ccflib 1.10
39 ccflib 1.13 # +++ Function mailnotify
40     #
41     # This function is used to notify adminmail on any issue while runnning this procedure
42     #
43     # Needs a subject as $1 and body as local file to be send.
44    
45     mailnotify ()
46     {
47    
48     [ "$#" -ne "2" ] && return
49    
50     subject=$1
51    
52     bodyfile=$2
53    
54     [ ! -f "${bodyfile}" ] && return
55    
56 ccflib 1.15 echo ; echo "Sending message to ${adminmail} with subject ${subject}" ; echo
57    
58 ccflib 1.16 mailx -v -s "${subject}" "${adminmail}" < ${bodyfile}
59 ccflib 1.13
60     }
61    
62    
63    
64     # +++ Function getxsaobslog
65     #
66 ccflib 1.10 # We need to get the list of all observed ODFs at the current date.
67     # This is obtained from http://nxsa.esac.esa.int/ftp_public/cds_obslog/xsaobslog.txt.
68    
69     getxsaobslog ()
70     {
71    
72     XSAOBSURL="http://nxsa.esac.esa.int/ftp_public/cds_obslog/xsaobslog.txt"
73    
74     # Remove any xsaobslog.txt previously downloaded.
75    
76     [ -f "${VALID_CCF}/xsaobslog.txt" ] && rm -rf ${VALID_CCF}/xsaobslog.txt
77    
78     # Get the list latest list of ODFs available from nXSA server.
79    
80 ccflib 1.11 wget -q ${XSAOBSURL} -O ${VALID_CCF}/xsaobslog.txt
81 ccflib 1.10
82     # Rename xsaobslog.txt to xsaobslog_${now}.txt just to have a reference
83     # of which list of ODFs was used to compute the list of valid CCFs.
84    
85     mv ${VALID_CCF}/xsaobslog.txt ${VALID_CCF}/xsaobslog_${now}.txt
86    
87     }
88    
89    
90 ccflib 1.13
91     # +++Function get_ccf_list to list on stdout the table of CCFs in a given CIF.
92     #
93 ccflib 1.2 # Requires that Heasoft is initialised. Otherwise exits with error.
94 ccflib 1.1
95     get_ccf_list()
96     {
97     [ -z "$1" ] && return
98    
99     cif_to_process="$1"
100    
101     noversion=`which fversion | grep -c no`
102    
103     if [ "${noversion}" != "0" ] ; then
104     echo "Error: Heasoft not initialised !"
105 ccflib 1.13 [ -f "${mailfile}" ] && rm -rf ${mailfile}
106     echo "Running of fversion produced the following output:" >> $mailfile
107     echo "$noversion" >> $mailfile
108     mailnotify "mvloccf: Error: Heasoft not initialised!" $mailfile
109     rm ${mailfile}
110 ccflib 1.1 exit
111     fi
112    
113     fdump ${cif_to_process} prhead=no showcol=no showrow=no page=no \
114     columns="SCOPE TYPEID ISSUE" \
115     rows=- STDOUT
116     }
117    
118 ccflib 1.13
119    
120    
121     # +++ Fill in the valid_constituents directory with the Valid CCF set
122     #
123     # The directory to be filled in is ${VALIDCONSTITUENTSDISR}.
124     # This directory is synchronized with the similar directory in the
125     # external ftp server.
126     #
127     # In addition to that, we also use this function to fill in the
128     # /ccf/valid directory available for users in the intranet.
129 ccflib 1.11
130     fillvalidccfdir()
131     {
132    
133     [ -z "$1" ] && return
134    
135     validccflist=$1
136    
137     if [ ! -f "${VALID_CCF}/${validccflist}" ] ; then
138 ccflib 1.12 echo "Error: ${VALID_CCF}/${validccflist} not found - Abort!"
139 ccflib 1.13 [ -f "${mailfile}" ] && rm -rf ${mailfile}
140     echo "The list of valid CCF ${VALID_CCF}/${validccflist} is not found" >> $mailfile
141     mailnotify "mvloccf: Error: ${VALID_CCF}/${validccflist} not found - Abort!" $mailfile
142     rm ${mailfile}
143 ccflib 1.11 exit
144     fi
145    
146 ccflib 1.13 VALIDCONSTITUENTSDIR="/home/ccflib/ftp-area/valid_constituents"
147 ccflib 1.11 rm -rf ${VALIDCONSTITUENTSDIR}/*
148    
149 ccflib 1.13 VALIDCCFDIRINTRANET="/ccf/valid"
150     rm -rf ${VALIDCCFDIRINTRANET}/*
151    
152 ccflib 1.11 CONSTITUENTSDIR="/home/ccflib/ftp-area/constituents"
153 ccflib 1.12 n=0
154 ccflib 1.11 while read ccf
155     do
156 ccflib 1.12 n=$((n + 1))
157     echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/"
158 ccflib 1.11 cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/
159 ccflib 1.13 echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCCFDIRINTRANET}/"
160     cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCCFDIRINTRANET}/
161 ccflib 1.12 done < ${VALID_CCF}/${validccflist}
162 ccflib 1.11
163     }
164    
165    
166 ccflib 1.13 #
167     # M a i n p r o g r a m
168     #
169     # 1. Get the list of all ODFs
170    
171 ccflib 1.1
172 ccflib 1.10 xsaobslogsize="0"
173 ccflib 1.1
174 ccflib 1.10 getxsaobslog
175 ccflib 1.1
176 ccflib 1.10 xsaobslogsize=`stat --format=%s ${VALID_CCF}/xsaobslog_${now}.txt`
177 ccflib 1.1
178 ccflib 1.10 if [ "$xsaobslogsize" = "0" ] ; then
179 ccflib 1.13 echo "Error: Failure to download the XSA Obs. Log file - Abort"
180     [ -f "${mailfile}" ] && rm -rf ${mailfile}
181     echo "The XSA Obs. Log file has 0 size - Not downloaded?" >> $mailfile
182     echo "." >> $mailfile
183     mailnotify "mlovccf: Error: Failure to download the XSA Obs. Log file - Abort" "$mailfile"
184     rm ${mailfile}
185 ccflib 1.10 exit
186     fi
187 ccflib 1.1
188 ccflib 1.17 # 2. Sets HEADAS depending on host or aborts in case of unexpected host
189     #
190 ccflib 1.1
191     case "$host" in
192     sasbld01|sasbld02)
193     export HEADAS=/sasbuild/local/${host}/headas/architecture
194     ;;
195 ccflib 1.5 scigrid6|cn-*)
196 ccflib 1.17 export HEADAS=/sasbuild/local/sasbld11/headas/architecture
197 ccflib 1.5 ;;
198 ccflib 1.17 *) echo "Error: Unsupported host $host" ; exit 1 ;;
199 ccflib 1.1 esac
200    
201 ccflib 1.17 # W a r n i n g
202     #
203     # The SAS initialisation produced by setsas.sh sets SAS_CCFPATH to /ccf/pub.
204     # Hence, if we set SAS_CCFPATH before running setsas.sh, we will always
205     # use /ccf/pub as repository for CCF. This is right as long as /ccf/pub is in
206     # strict sync with /home/ccflib/ccf_ftp/constituents. But if this is not true,
207     # the resulting valid CCFs might be wrong.
208     #
209 ccflib 1.1
210 ccflib 1.17 headas_output=`. $HEADAS/headas-init.sh`
211 ccflib 1.1
212 ccflib 1.17 if [ "$?" != "0" ] ; then
213     echo "mlovccf: HEADAS initialisation failed with error" >> ${mailfile}
214     echo " ${headas_output}" >> ${mailfile}
215     mailnotify "mlovccf: HEADAS initilisation failed" ${mailfile}
216     rm ${mailfile}
217     exit 1
218     fi
219 ccflib 1.1
220 ccflib 1.17 # To be able to mix several jobs on the same ccflib account
221     [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
222     export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
223     echo -n "HEADAS version: "
224     fversion
225    
226     confsas_output=`/sas/bin/confsas`
227     if [ -n "${confsas_output}" ] ; then
228     echo "mlovccf: SAS initialization failed with error" >> ${mailfile}
229     echo " ${confsas_output}" >> ${mailfile}
230     mailnotify "mlovccf: SAS initialisation failed" ${mailfile}
231     rm ${mailfile}
232     exit 1
233     fi
234    
235     source $HOME/setsas.sh 1> /dev/null
236     export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
237     echo "SAS Version: "
238     sasversion -V 1
239     export SAS_VERBOSITY=0
240    
241     # 3. XMM_CALINDEX file from SAS_CCFPATH
242    
243     MIF=`ls -1 ${SAS_CCFPATH}/XMM_CALINDEX_*.CCF`
244    
245     # 4. For each OBDS ID registered in the XSA observations list, gets the start
246     # time of the observation. Then runs cifbuild to get the respective CIF.
247     # all_ccfs_${now}.txt is filled recursively on each iteration.
248     # Therefore we start with an empty file. The final list will be this one.
249 ccflib 1.13
250     # Output file : ${VALID_CCF}/all_ccfs_${now}.txt
251 ccflib 1.1
252 ccflib 1.3 touch ${VALID_CCF}/all_ccfs_${now}.txt
253 ccflib 1.2
254 ccflib 1.1 n=0
255 ccflib 1.2
256 ccflib 1.1 while read line
257     do
258     obsid=`echo $line | awk -F"|" '{print $2}'`
259     stime=`echo $line | awk -F"|" '{print $9}'`
260     stime=`echo $stime | tr " " "T"`
261     n=$((n+1))
262     echo "($n) Processing $obsid $stime" ; echo
263    
264     # Run cifbuild
265    
266     cif_file=${VALID_CCF}/${obsid}.cif
267    
268     cifbuild --withmasterindexset='yes' \
269     --masterindexset=${MIF} \
270     --withobservationdate='yes' \
271     --observationdate=${stime} \
272     --analysisdate='now' \
273     --calindexset=${cif_file}
274    
275    
276     # Gets the list of CCFs included in the CIF
277    
278     get_ccf_list "${cif_file}" > ${VALID_CCF}/${obsid}_ccfs.tmp
279    
280     while read line
281     do
282     [ "$line" = "" ] && continue
283     class=`echo $line | awk -F" " '{print $1"_"$2}'`
284     issue=`echo $line | awk -F" " '{print $3}'`
285     issue=`printf "%04d" ${issue}`
286     echo ${class}_${issue}.CCF >> ${VALID_CCF}/${obsid}_ccfs.txt
287 ccflib 1.2
288 ccflib 1.1 done < ${VALID_CCF}/${obsid}_ccfs.tmp
289    
290     rm ${VALID_CCF}/${obsid}_ccfs.tmp
291    
292 ccflib 1.3 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
293 ccflib 1.2
294 ccflib 1.3 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
295 ccflib 1.1
296 ccflib 1.17 comm -1 -3 --nocheck-order ${VALID_CCF}/all_ccfs_${now}.tmp ${VALID_CCF}/all_ccfs_${now}.txt > ${VALID_CCF}/diff_iteration_${n}.txt
297    
298     diffsize=`stat --format=%s ${VALID_CCF}/diff_iteration_${n}.txt`
299    
300     if [ "$diffsize" != "0" ] ; then
301     echo "CCF added in this iteration: "
302     cat ${VALID_CCF}/diff_iteration_${n}.txt
303     fi
304    
305     echo
306     echo "Number of valid CCFs found so far: "`cat ${VALID_CCF}/all_ccfs_${now}.txt | wc -l` ; echo
307    
308     rm ${VALID_CCF}/diff_iteration_${n}.txt
309 ccflib 1.1 rm ${cif_file}
310     rm ${VALID_CCF}/${obsid}_ccfs.txt
311 ccflib 1.3 rm ${VALID_CCF}/all_ccfs_${now}.tmp
312 ccflib 1.1
313 ccflib 1.7 done < ${VALID_CCF}/xsaobslog_${now}.txt
314 ccflib 1.2
315 ccflib 1.13 # 5. Make a table of classes and issues with the style "Pipeline Release Notes"
316     # To get a classification, we need first to obtain all available classes.
317     #
318    
319 ccflib 1.2
320     # Lists all CCF classes
321    
322     ccf_classes="${VALID_CCF}/ccf_classes.txt"
323    
324     while read line
325     do
326     class=`echo $line | awk -F"_" '{print $1"_"$2}'`
327     echo $class >> ${ccf_classes}
328 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
329 ccflib 1.2
330     cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
331     mv ${VALID_CCF}/kk.txt ${ccf_classes}
332    
333 ccflib 1.13
334    
335 ccflib 1.3 # Output final file is named all_ccfs_${now}_table.txt
336    
337     total_number_of_ccfs=0
338 ccflib 1.2
339 ccflib 1.7 all_ccfs_table="${VALID_CCF}/all_ccfs_${now}_table.txt"
340 ccflib 1.2
341     [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
342    
343 ccflib 1.7 echo "Table of valid CCFs at $now_table" >> ${all_ccfs_table}
344     echo >> ${all_ccfs_table}
345     echo "|================================|=============|=======|" >> ${all_ccfs_table}
346     echo "| Calibration File | Issue range | Count |" >> ${all_ccfs_table}
347     echo "|================================|=============|=======|" >> ${all_ccfs_table}
348 ccflib 1.2
349     while read ccf_class
350 ccflib 1.3 do
351     echo -n "Processing class $ccf_class ..."
352 ccflib 1.2 issues_file="${VALID_CCF}/ccf_issues_for_${ccf_class}.txt"
353     [ -f "${issues_file}" ] && rm ${issues_file}
354     while read line
355     do
356     class=`echo $line | awk -F"_" '{print $1"_"$2}'`
357     [ "$class" != "$ccf_class" ] && continue
358     issue=`echo $line | awk -F"_" '{print $3}' | cut -d. -f1`
359     echo $issue >> ${issues_file}
360 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
361 ccflib 1.2
362     cat ${issues_file} | sort -u > kk.txt
363     mv kk.txt ${issues_file}
364 ccflib 1.3 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
365 ccflib 1.2
366     first_issue=`head -1 ${issues_file}`
367     last_issue=`tail -1 ${issues_file}`
368    
369 ccflib 1.3 li=$((10#$last_issue))
370     fi=$((10#$first_issue))
371    
372 ccflib 1.7 sequential_number_of_issues_for_this_class=$((li - fi + 1))
373 ccflib 1.8
374     asterisk=" "
375     [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] && asterisk="(*)"
376    
377 ccflib 1.7 total_number_of_ccfs=$((real_number_of_issues_for_this_class + total_number_of_ccfs))
378    
379     rn=$real_number_of_issues_for_this_class
380 ccflib 1.3
381 ccflib 1.8 if [ "${first_issue}" != "${last_issue}" ] ; then
382     if [ "$asterisk" = "(*)" ] ; then
383     printf "| %-30s | %4s-%4s(*)| %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
384     else
385     printf "| %-30s | %4s-%4s | %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
386     fi
387     else
388     printf "| %-30s | %4s | %4s |\n" ${ccf_class} ${first_issue} ${rn} >> ${all_ccfs_table}
389     fi
390    
391 ccflib 1.7
392     echo "done"
393 ccflib 1.2 done < ${ccf_classes}
394    
395 ccflib 1.7 echo "|================================|=============|=======|" >> ${all_ccfs_table}
396     echo >> ${all_ccfs_table}
397     echo "(*): Incomplete range." >> ${all_ccfs_table}
398     echo "" >> ${all_ccfs_table}
399     echo "Total number of valid CCFs required : ${total_number_of_ccfs}" >> ${all_ccfs_table}
400 ccflib 1.3 rm ${VALID_CCF}/ccf_classes.txt
401     rm ${VALID_CCF}/ccf_issues_for*.txt
402 ccflib 1.11
403 ccflib 1.13
404    
405     # 6. Fill in the Valid CCF Set dir with the proper CCFs
406 ccflib 1.11
407 ccflib 1.12 fillvalidccfdir "all_ccfs_${now}.txt"
408 ccflib 1.13
409     [ -f "${mailfile}" ] && rm -rf ${mailfile}
410     echo "Valid CCF Set successfully copied to ${VALIDCONSTITUENTSDIR}" >> $mailfile
411     echo "Valid CCF Set successfully copied to ${VALIDCCFDIRINTRANET}" >> $mailfile
412     mailnotify "mvloccf: Valid CCF Set created successfully" $mailfile
413     rm ${mailfile}

  ViewVC Help
Powered by ViewVC 1.1.27