/[CCFs]/bin/mlovccf
ViewVC logotype

Annotation of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (hide annotations)
Wed Jul 25 12:06:24 2018 UTC (6 years, 4 months ago) by ccflib
Branch: MAIN
Changes since 1.20: +5 -5 lines
check that validccflist is not empty

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.21 # $Id: mlovccf,v 1.20 2018/07/25 10:24: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.20 wget --quiet ${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 ccflib 1.21 if [ ! -f "${VALID_CCF}/${validccflist}" -o ! -s "${VALID_CCF}/${validccflist}" ] ; then
138     echo "Error: ${VALID_CCF}/${validccflist} not found or empty - Abort!"
139 ccflib 1.13 [ -f "${mailfile}" ] && rm -rf ${mailfile}
140 ccflib 1.21 echo "The list of valid CCF ${VALID_CCF}/${validccflist} is not found or it is empty" >> $mailfile
141     mailnotify "mvloccf: Error: ${VALID_CCF}/${validccflist} not found or it is empty - Abort!" $mailfile
142 ccflib 1.13 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.19 # This operation can only succeed because the subdir valid has enable the write permission
150     # for the group "sas" (g=rwx), provided that CCFs belong to sasbuild(5153):sas.
151 ccflib 1.13 VALIDCCFDIRINTRANET="/ccf/valid"
152     rm -rf ${VALIDCCFDIRINTRANET}/*
153    
154 ccflib 1.11 CONSTITUENTSDIR="/home/ccflib/ftp-area/constituents"
155 ccflib 1.12 n=0
156 ccflib 1.11 while read ccf
157     do
158 ccflib 1.12 n=$((n + 1))
159     echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/"
160 ccflib 1.11 cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/
161 ccflib 1.13 echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCCFDIRINTRANET}/"
162     cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCCFDIRINTRANET}/
163 ccflib 1.12 done < ${VALID_CCF}/${validccflist}
164 ccflib 1.11
165     }
166    
167    
168 ccflib 1.13 #
169     # M a i n p r o g r a m
170     #
171     # 1. Get the list of all ODFs
172    
173 ccflib 1.1
174 ccflib 1.10 xsaobslogsize="0"
175 ccflib 1.1
176 ccflib 1.10 getxsaobslog
177 ccflib 1.1
178 ccflib 1.10 xsaobslogsize=`stat --format=%s ${VALID_CCF}/xsaobslog_${now}.txt`
179 ccflib 1.1
180 ccflib 1.10 if [ "$xsaobslogsize" = "0" ] ; then
181 ccflib 1.13 echo "Error: Failure to download the XSA Obs. Log file - Abort"
182     [ -f "${mailfile}" ] && rm -rf ${mailfile}
183     echo "The XSA Obs. Log file has 0 size - Not downloaded?" >> $mailfile
184     echo "." >> $mailfile
185     mailnotify "mlovccf: Error: Failure to download the XSA Obs. Log file - Abort" "$mailfile"
186     rm ${mailfile}
187 ccflib 1.10 exit
188     fi
189 ccflib 1.1
190 ccflib 1.17 #
191 ccflib 1.18 # 2. Initialises HEADAS and SAS
192     #
193    
194 ccflib 1.20 # Defines SASBUILD_LOCAL depending on host.
195     # Then uses it to build up HEADAS and setup LD_LIBRARY_PATH accordingly.
196 ccflib 1.1
197     case "$host" in
198 ccflib 1.20 sasbld01n|sasbld02n)
199     export SASBUILD_LOCAL="/sasbuild/local/${host}/GNU_CC_CXX_7.1"
200 ccflib 1.1 ;;
201 ccflib 1.5 scigrid6|cn-*)
202 ccflib 1.20 export SASBUILD_LOCAL="/sasbuild/local/sasbld02n/GNU_CC_CXX_7.1"
203 ccflib 1.5 ;;
204 ccflib 1.17 *) echo "Error: Unsupported host $host" ; exit 1 ;;
205 ccflib 1.1 esac
206    
207 ccflib 1.20 export HEADAS=${SASBUILD_LOCAL}/headas/architecture
208 ccflib 1.1
209 ccflib 1.18 headas_output="${VALID_CCF}/headas_output"
210     source $HEADAS/headas-init.sh > ${headas_output} 2>&1
211 ccflib 1.20
212     # The next statement should not be necessary because the SAS initialisation
213     # provides under $SAS_DIR/libextra all the necessary libraries from GNU C/C++
214     # which were required to build Heasoft. But, in order to make the HEADAS
215     # initialisation independent of the SAS initialisation, we set the
216     # LD_LIBRARY_PATH as it has to be to run Headas by itself without SAS been
217     # ready.
218    
219     export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${SASBUILD_LOCAL}/gcc/lib64
220    
221    
222 ccflib 1.18 headas_ok=`cat ${headas_output}`
223    
224     if [ -n "${headas_ok}" ] ; then
225     echo "mlovccf: HEADAS initialisation failed with error" >> ${mailfile}
226     cat ${headas_output} >> ${mailfile}
227 ccflib 1.17 mailnotify "mlovccf: HEADAS initilisation failed" ${mailfile}
228 ccflib 1.18 rm ${headas_output} ${mailfile}
229 ccflib 1.17 exit 1
230     fi
231 ccflib 1.1
232 ccflib 1.17 # To be able to mix several jobs on the same ccflib account
233     [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
234     export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
235     echo -n "HEADAS version: "
236     fversion
237    
238 ccflib 1.18 #
239     # W a r n i n g o n S A S i n i t i a l i s a t i o n
240     #
241     # The SAS initialisation produced by setsas.sh sets SAS_CCFPATH to /ccf/pub.
242     # Hence, if we set SAS_CCFPATH before running setsas.sh, we will always
243     # use /ccf/pub as repository for CCF. This is right as long as /ccf/pub is in
244     # strict sync with /home/ccflib/ccf_ftp/constituents. But if this is not true,
245     # the resulting valid CCFs might be wrong. Therefore, we set it here explicitly.
246     #
247    
248     confsas_output="${VALID_CCF}/confsas_output"
249     /sas/bin/confsas > ${confsas_output} 2>&1
250     confsas_ok=`cat ${confsas_output}`
251    
252     if [ -n "${confsas_ok}" ] ; then
253     echo "mlovccf: SAS initialization failed with error" >> ${mailfile}
254     cat ${confsas_output} >> ${mailfile}
255     mailnotify "mlovccf: SAS initialisation failed" ${mailfile}
256     rm ${confsas_output} ${mailfile}
257     exit 1
258 ccflib 1.17 fi
259    
260     source $HOME/setsas.sh 1> /dev/null
261 ccflib 1.18
262     # Re-sets SAS_CCFPATH
263    
264 ccflib 1.17 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
265 ccflib 1.18
266 ccflib 1.17 echo "SAS Version: "
267     sasversion -V 1
268     export SAS_VERBOSITY=0
269    
270 ccflib 1.18
271 ccflib 1.17 # 3. XMM_CALINDEX file from SAS_CCFPATH
272    
273     MIF=`ls -1 ${SAS_CCFPATH}/XMM_CALINDEX_*.CCF`
274    
275     # 4. For each OBDS ID registered in the XSA observations list, gets the start
276     # time of the observation. Then runs cifbuild to get the respective CIF.
277     # all_ccfs_${now}.txt is filled recursively on each iteration.
278     # Therefore we start with an empty file. The final list will be this one.
279 ccflib 1.13
280     # Output file : ${VALID_CCF}/all_ccfs_${now}.txt
281 ccflib 1.1
282 ccflib 1.3 touch ${VALID_CCF}/all_ccfs_${now}.txt
283 ccflib 1.2
284 ccflib 1.1 n=0
285 ccflib 1.2
286 ccflib 1.1 while read line
287     do
288     obsid=`echo $line | awk -F"|" '{print $2}'`
289     stime=`echo $line | awk -F"|" '{print $9}'`
290     stime=`echo $stime | tr " " "T"`
291     n=$((n+1))
292     echo "($n) Processing $obsid $stime" ; echo
293    
294     # Run cifbuild
295    
296     cif_file=${VALID_CCF}/${obsid}.cif
297    
298     cifbuild --withmasterindexset='yes' \
299     --masterindexset=${MIF} \
300     --withobservationdate='yes' \
301     --observationdate=${stime} \
302     --analysisdate='now' \
303     --calindexset=${cif_file}
304    
305    
306     # Gets the list of CCFs included in the CIF
307    
308     get_ccf_list "${cif_file}" > ${VALID_CCF}/${obsid}_ccfs.tmp
309    
310     while read line
311     do
312     [ "$line" = "" ] && continue
313     class=`echo $line | awk -F" " '{print $1"_"$2}'`
314     issue=`echo $line | awk -F" " '{print $3}'`
315     issue=`printf "%04d" ${issue}`
316     echo ${class}_${issue}.CCF >> ${VALID_CCF}/${obsid}_ccfs.txt
317 ccflib 1.2
318 ccflib 1.1 done < ${VALID_CCF}/${obsid}_ccfs.tmp
319    
320     rm ${VALID_CCF}/${obsid}_ccfs.tmp
321    
322 ccflib 1.3 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
323 ccflib 1.2
324 ccflib 1.3 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
325 ccflib 1.1
326 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
327    
328     diffsize=`stat --format=%s ${VALID_CCF}/diff_iteration_${n}.txt`
329    
330     if [ "$diffsize" != "0" ] ; then
331     echo "CCF added in this iteration: "
332     cat ${VALID_CCF}/diff_iteration_${n}.txt
333     fi
334    
335     echo
336     echo "Number of valid CCFs found so far: "`cat ${VALID_CCF}/all_ccfs_${now}.txt | wc -l` ; echo
337    
338     rm ${VALID_CCF}/diff_iteration_${n}.txt
339 ccflib 1.1 rm ${cif_file}
340     rm ${VALID_CCF}/${obsid}_ccfs.txt
341 ccflib 1.3 rm ${VALID_CCF}/all_ccfs_${now}.tmp
342 ccflib 1.1
343 ccflib 1.7 done < ${VALID_CCF}/xsaobslog_${now}.txt
344 ccflib 1.2
345 ccflib 1.13 # 5. Make a table of classes and issues with the style "Pipeline Release Notes"
346     # To get a classification, we need first to obtain all available classes.
347     #
348    
349 ccflib 1.2
350     # Lists all CCF classes
351    
352     ccf_classes="${VALID_CCF}/ccf_classes.txt"
353    
354     while read line
355     do
356     class=`echo $line | awk -F"_" '{print $1"_"$2}'`
357     echo $class >> ${ccf_classes}
358 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
359 ccflib 1.2
360     cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
361     mv ${VALID_CCF}/kk.txt ${ccf_classes}
362    
363 ccflib 1.13
364    
365 ccflib 1.3 # Output final file is named all_ccfs_${now}_table.txt
366    
367     total_number_of_ccfs=0
368 ccflib 1.2
369 ccflib 1.7 all_ccfs_table="${VALID_CCF}/all_ccfs_${now}_table.txt"
370 ccflib 1.2
371     [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
372    
373 ccflib 1.7 echo "Table of valid CCFs at $now_table" >> ${all_ccfs_table}
374     echo >> ${all_ccfs_table}
375     echo "|================================|=============|=======|" >> ${all_ccfs_table}
376     echo "| Calibration File | Issue range | Count |" >> ${all_ccfs_table}
377     echo "|================================|=============|=======|" >> ${all_ccfs_table}
378 ccflib 1.2
379     while read ccf_class
380 ccflib 1.3 do
381     echo -n "Processing class $ccf_class ..."
382 ccflib 1.2 issues_file="${VALID_CCF}/ccf_issues_for_${ccf_class}.txt"
383     [ -f "${issues_file}" ] && rm ${issues_file}
384     while read line
385     do
386     class=`echo $line | awk -F"_" '{print $1"_"$2}'`
387     [ "$class" != "$ccf_class" ] && continue
388     issue=`echo $line | awk -F"_" '{print $3}' | cut -d. -f1`
389     echo $issue >> ${issues_file}
390 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
391 ccflib 1.2
392     cat ${issues_file} | sort -u > kk.txt
393     mv kk.txt ${issues_file}
394 ccflib 1.3 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
395 ccflib 1.2
396     first_issue=`head -1 ${issues_file}`
397     last_issue=`tail -1 ${issues_file}`
398    
399 ccflib 1.3 li=$((10#$last_issue))
400     fi=$((10#$first_issue))
401    
402 ccflib 1.7 sequential_number_of_issues_for_this_class=$((li - fi + 1))
403 ccflib 1.8
404     asterisk=" "
405     [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] && asterisk="(*)"
406    
407 ccflib 1.7 total_number_of_ccfs=$((real_number_of_issues_for_this_class + total_number_of_ccfs))
408    
409     rn=$real_number_of_issues_for_this_class
410 ccflib 1.3
411 ccflib 1.8 if [ "${first_issue}" != "${last_issue}" ] ; then
412     if [ "$asterisk" = "(*)" ] ; then
413     printf "| %-30s | %4s-%4s(*)| %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
414     else
415     printf "| %-30s | %4s-%4s | %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
416     fi
417     else
418     printf "| %-30s | %4s | %4s |\n" ${ccf_class} ${first_issue} ${rn} >> ${all_ccfs_table}
419     fi
420    
421 ccflib 1.7
422     echo "done"
423 ccflib 1.2 done < ${ccf_classes}
424    
425 ccflib 1.7 echo "|================================|=============|=======|" >> ${all_ccfs_table}
426     echo >> ${all_ccfs_table}
427     echo "(*): Incomplete range." >> ${all_ccfs_table}
428     echo "" >> ${all_ccfs_table}
429     echo "Total number of valid CCFs required : ${total_number_of_ccfs}" >> ${all_ccfs_table}
430 ccflib 1.3 rm ${VALID_CCF}/ccf_classes.txt
431     rm ${VALID_CCF}/ccf_issues_for*.txt
432 ccflib 1.11
433 ccflib 1.13
434    
435     # 6. Fill in the Valid CCF Set dir with the proper CCFs
436 ccflib 1.11
437 ccflib 1.12 fillvalidccfdir "all_ccfs_${now}.txt"
438 ccflib 1.13
439     [ -f "${mailfile}" ] && rm -rf ${mailfile}
440     echo "Valid CCF Set successfully copied to ${VALIDCONSTITUENTSDIR}" >> $mailfile
441     echo "Valid CCF Set successfully copied to ${VALIDCCFDIRINTRANET}" >> $mailfile
442     mailnotify "mvloccf: Valid CCF Set created successfully" $mailfile
443     rm ${mailfile}

  ViewVC Help
Powered by ViewVC 1.1.27