/[CCFs]/bin/mlovccf
ViewVC logotype

Annotation of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations)
Tue Jan 10 16:43:39 2017 UTC (7 years, 10 months ago) by ccflib
Branch: MAIN
Changes since 1.18: +3 -1 lines
Added comment on the removal of CCF in /ccf/valid

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.19 # $Id: mlovccf,v 1.18 2016/11/30 10:29:39 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.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     # Defines HEADAS depending on host
195 ccflib 1.1
196     case "$host" in
197     sasbld01|sasbld02)
198     export HEADAS=/sasbuild/local/${host}/headas/architecture
199     ;;
200 ccflib 1.5 scigrid6|cn-*)
201 ccflib 1.17 export HEADAS=/sasbuild/local/sasbld11/headas/architecture
202 ccflib 1.5 ;;
203 ccflib 1.17 *) echo "Error: Unsupported host $host" ; exit 1 ;;
204 ccflib 1.1 esac
205    
206    
207 ccflib 1.18 headas_output="${VALID_CCF}/headas_output"
208     source $HEADAS/headas-init.sh > ${headas_output} 2>&1
209     headas_ok=`cat ${headas_output}`
210    
211     if [ -n "${headas_ok}" ] ; then
212     echo "mlovccf: HEADAS initialisation failed with error" >> ${mailfile}
213     cat ${headas_output} >> ${mailfile}
214 ccflib 1.17 mailnotify "mlovccf: HEADAS initilisation failed" ${mailfile}
215 ccflib 1.18 rm ${headas_output} ${mailfile}
216 ccflib 1.17 exit 1
217     fi
218 ccflib 1.1
219 ccflib 1.17 # To be able to mix several jobs on the same ccflib account
220     [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}
221     export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"
222     echo -n "HEADAS version: "
223     fversion
224    
225 ccflib 1.18 #
226     # 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
227     #
228     # The SAS initialisation produced by setsas.sh sets SAS_CCFPATH to /ccf/pub.
229     # Hence, if we set SAS_CCFPATH before running setsas.sh, we will always
230     # use /ccf/pub as repository for CCF. This is right as long as /ccf/pub is in
231     # strict sync with /home/ccflib/ccf_ftp/constituents. But if this is not true,
232     # the resulting valid CCFs might be wrong. Therefore, we set it here explicitly.
233     #
234    
235     confsas_output="${VALID_CCF}/confsas_output"
236     /sas/bin/confsas > ${confsas_output} 2>&1
237     confsas_ok=`cat ${confsas_output}`
238    
239     if [ -n "${confsas_ok}" ] ; then
240     echo "mlovccf: SAS initialization failed with error" >> ${mailfile}
241     cat ${confsas_output} >> ${mailfile}
242     mailnotify "mlovccf: SAS initialisation failed" ${mailfile}
243     rm ${confsas_output} ${mailfile}
244     exit 1
245 ccflib 1.17 fi
246    
247     source $HOME/setsas.sh 1> /dev/null
248 ccflib 1.18
249     # Re-sets SAS_CCFPATH
250    
251 ccflib 1.17 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
252 ccflib 1.18
253 ccflib 1.17 echo "SAS Version: "
254     sasversion -V 1
255     export SAS_VERBOSITY=0
256    
257 ccflib 1.18
258 ccflib 1.17 # 3. XMM_CALINDEX file from SAS_CCFPATH
259    
260     MIF=`ls -1 ${SAS_CCFPATH}/XMM_CALINDEX_*.CCF`
261    
262     # 4. For each OBDS ID registered in the XSA observations list, gets the start
263     # time of the observation. Then runs cifbuild to get the respective CIF.
264     # all_ccfs_${now}.txt is filled recursively on each iteration.
265     # Therefore we start with an empty file. The final list will be this one.
266 ccflib 1.13
267     # Output file : ${VALID_CCF}/all_ccfs_${now}.txt
268 ccflib 1.1
269 ccflib 1.3 touch ${VALID_CCF}/all_ccfs_${now}.txt
270 ccflib 1.2
271 ccflib 1.1 n=0
272 ccflib 1.2
273 ccflib 1.1 while read line
274     do
275     obsid=`echo $line | awk -F"|" '{print $2}'`
276     stime=`echo $line | awk -F"|" '{print $9}'`
277     stime=`echo $stime | tr " " "T"`
278     n=$((n+1))
279     echo "($n) Processing $obsid $stime" ; echo
280    
281     # Run cifbuild
282    
283     cif_file=${VALID_CCF}/${obsid}.cif
284    
285     cifbuild --withmasterindexset='yes' \
286     --masterindexset=${MIF} \
287     --withobservationdate='yes' \
288     --observationdate=${stime} \
289     --analysisdate='now' \
290     --calindexset=${cif_file}
291    
292    
293     # Gets the list of CCFs included in the CIF
294    
295     get_ccf_list "${cif_file}" > ${VALID_CCF}/${obsid}_ccfs.tmp
296    
297     while read line
298     do
299     [ "$line" = "" ] && continue
300     class=`echo $line | awk -F" " '{print $1"_"$2}'`
301     issue=`echo $line | awk -F" " '{print $3}'`
302     issue=`printf "%04d" ${issue}`
303     echo ${class}_${issue}.CCF >> ${VALID_CCF}/${obsid}_ccfs.txt
304 ccflib 1.2
305 ccflib 1.1 done < ${VALID_CCF}/${obsid}_ccfs.tmp
306    
307     rm ${VALID_CCF}/${obsid}_ccfs.tmp
308    
309 ccflib 1.3 mv ${VALID_CCF}/all_ccfs_${now}.txt ${VALID_CCF}/all_ccfs_${now}.tmp
310 ccflib 1.2
311 ccflib 1.3 cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u > ${VALID_CCF}/all_ccfs_${now}.txt
312 ccflib 1.1
313 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
314    
315     diffsize=`stat --format=%s ${VALID_CCF}/diff_iteration_${n}.txt`
316    
317     if [ "$diffsize" != "0" ] ; then
318     echo "CCF added in this iteration: "
319     cat ${VALID_CCF}/diff_iteration_${n}.txt
320     fi
321    
322     echo
323     echo "Number of valid CCFs found so far: "`cat ${VALID_CCF}/all_ccfs_${now}.txt | wc -l` ; echo
324    
325     rm ${VALID_CCF}/diff_iteration_${n}.txt
326 ccflib 1.1 rm ${cif_file}
327     rm ${VALID_CCF}/${obsid}_ccfs.txt
328 ccflib 1.3 rm ${VALID_CCF}/all_ccfs_${now}.tmp
329 ccflib 1.1
330 ccflib 1.7 done < ${VALID_CCF}/xsaobslog_${now}.txt
331 ccflib 1.2
332 ccflib 1.13 # 5. Make a table of classes and issues with the style "Pipeline Release Notes"
333     # To get a classification, we need first to obtain all available classes.
334     #
335    
336 ccflib 1.2
337     # Lists all CCF classes
338    
339     ccf_classes="${VALID_CCF}/ccf_classes.txt"
340    
341     while read line
342     do
343     class=`echo $line | awk -F"_" '{print $1"_"$2}'`
344     echo $class >> ${ccf_classes}
345 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
346 ccflib 1.2
347     cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
348     mv ${VALID_CCF}/kk.txt ${ccf_classes}
349    
350 ccflib 1.13
351    
352 ccflib 1.3 # Output final file is named all_ccfs_${now}_table.txt
353    
354     total_number_of_ccfs=0
355 ccflib 1.2
356 ccflib 1.7 all_ccfs_table="${VALID_CCF}/all_ccfs_${now}_table.txt"
357 ccflib 1.2
358     [ -f "${all_ccfs_table}" ] && rm ${all_ccfs_table}
359    
360 ccflib 1.7 echo "Table of valid CCFs at $now_table" >> ${all_ccfs_table}
361     echo >> ${all_ccfs_table}
362     echo "|================================|=============|=======|" >> ${all_ccfs_table}
363     echo "| Calibration File | Issue range | Count |" >> ${all_ccfs_table}
364     echo "|================================|=============|=======|" >> ${all_ccfs_table}
365 ccflib 1.2
366     while read ccf_class
367 ccflib 1.3 do
368     echo -n "Processing class $ccf_class ..."
369 ccflib 1.2 issues_file="${VALID_CCF}/ccf_issues_for_${ccf_class}.txt"
370     [ -f "${issues_file}" ] && rm ${issues_file}
371     while read line
372     do
373     class=`echo $line | awk -F"_" '{print $1"_"$2}'`
374     [ "$class" != "$ccf_class" ] && continue
375     issue=`echo $line | awk -F"_" '{print $3}' | cut -d. -f1`
376     echo $issue >> ${issues_file}
377 ccflib 1.3 done < ${VALID_CCF}/all_ccfs_${now}.txt
378 ccflib 1.2
379     cat ${issues_file} | sort -u > kk.txt
380     mv kk.txt ${issues_file}
381 ccflib 1.3 real_number_of_issues_for_this_class=`wc -l ${issues_file} | awk -F" " '{print $1}'`
382 ccflib 1.2
383     first_issue=`head -1 ${issues_file}`
384     last_issue=`tail -1 ${issues_file}`
385    
386 ccflib 1.3 li=$((10#$last_issue))
387     fi=$((10#$first_issue))
388    
389 ccflib 1.7 sequential_number_of_issues_for_this_class=$((li - fi + 1))
390 ccflib 1.8
391     asterisk=" "
392     [ "${real_number_of_issues_for_this_class}" -lt "${sequential_number_of_issues_for_this_class}" ] && asterisk="(*)"
393    
394 ccflib 1.7 total_number_of_ccfs=$((real_number_of_issues_for_this_class + total_number_of_ccfs))
395    
396     rn=$real_number_of_issues_for_this_class
397 ccflib 1.3
398 ccflib 1.8 if [ "${first_issue}" != "${last_issue}" ] ; then
399     if [ "$asterisk" = "(*)" ] ; then
400     printf "| %-30s | %4s-%4s(*)| %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
401     else
402     printf "| %-30s | %4s-%4s | %4s |\n" ${ccf_class} ${first_issue} ${last_issue} ${rn} >> ${all_ccfs_table}
403     fi
404     else
405     printf "| %-30s | %4s | %4s |\n" ${ccf_class} ${first_issue} ${rn} >> ${all_ccfs_table}
406     fi
407    
408 ccflib 1.7
409     echo "done"
410 ccflib 1.2 done < ${ccf_classes}
411    
412 ccflib 1.7 echo "|================================|=============|=======|" >> ${all_ccfs_table}
413     echo >> ${all_ccfs_table}
414     echo "(*): Incomplete range." >> ${all_ccfs_table}
415     echo "" >> ${all_ccfs_table}
416     echo "Total number of valid CCFs required : ${total_number_of_ccfs}" >> ${all_ccfs_table}
417 ccflib 1.3 rm ${VALID_CCF}/ccf_classes.txt
418     rm ${VALID_CCF}/ccf_issues_for*.txt
419 ccflib 1.11
420 ccflib 1.13
421    
422     # 6. Fill in the Valid CCF Set dir with the proper CCFs
423 ccflib 1.11
424 ccflib 1.12 fillvalidccfdir "all_ccfs_${now}.txt"
425 ccflib 1.13
426     [ -f "${mailfile}" ] && rm -rf ${mailfile}
427     echo "Valid CCF Set successfully copied to ${VALIDCONSTITUENTSDIR}" >> $mailfile
428     echo "Valid CCF Set successfully copied to ${VALIDCCFDIRINTRANET}" >> $mailfile
429     mailnotify "mvloccf: Valid CCF Set created successfully" $mailfile
430     rm ${mailfile}

  ViewVC Help
Powered by ViewVC 1.1.27