/[CCFs]/bin/mlovccf
ViewVC logotype

Diff of /bin/mlovccf

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by ccflib, Mon Sep 7 13:39:15 2015 UTC revision 1.23 by ccflib, Tue Nov 12 16:00:29 2019 UTC
# Line 7  Line 7 
7  # typically the current date. This list will change with time as far as new  # typically the current date. This list will change with time as far as new
8  # CCFs are issued to deal with new calibration data and/or replace obsolete ones.  # CCFs are issued to deal with new calibration data and/or replace obsolete ones.
9  #  #
10  # To identify the set of CCFs required to process a given ODF is the ijob of task cifbuild.  # To identify the set of CCFs required to process a given ODF is the job of task cifbuild.
11  # To make such identification, cifbuild needs only the start time of the observation.  # To make such identification, cifbuild needs only the start time of the observation.
12  # Therefore, if we provide a list of all observed ODFs at a given date together with their  # 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.  # respective start time, we could compute all the CCFs required to process them.
# Line 16  Line 16 
16  #  #
17  # We need as input the list of all observed ODFs at a given date.  # 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,  # This is obtained from the report of all observations that the XSA makes to CDS,
19  # xsaobslog.txt (ftp://nxsa.esac.esa.int/pub/cfs_obslog/xsaobslog.txt).  # xsaobslog.txt (http://nxsa.esac.esa.int/ftp_public/cfs_obslog/xsaobslog.txt).
20  #  #
21  # $Id: mlovccf,v 1.7 2015/08/27 16:47:16 ccflib Exp $  # $Id: mlovccf,v 1.22 2018/07/25 13:39:41 ccflib Exp $
22    
23  # Next two lines allow to submit this script to the grid  # Next two lines allow to submit this script to the grid
24  # request Bourne shell as shell for job  # request Bourne shell as shell for job
25  #$ -S /bin/bash  #$ -S /bin/bash
26    
27    adminmail="eduardo.ojero@sciops.esa.int"
28    
29    VALID_CCF="$HOME/processing_valid_ccf"
30    
31    mailfile="${VALID_CCF}/mailfile"
32    
33  host=`hostname | cut -d. -f1`  host=`hostname | cut -d. -f1`
34    
35  now=`date +'%Y%m%d_%H%M'`  now=`date +'%Y%m%d_%H%M'`
36  now_table=`date +'%Y-%m-%dT%H:%M:%S'`  now_table=`date +'%Y-%m-%dT%H:%M:%S'`
37    
 # Function find_latest_mif to get the latest XMM_CALINDEX from given directory  
38    
39  find_latest_mif()  # +++ 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  [ -z "$1" ] && return  [ "$#" -ne "2" ] && return
49    
50  CCFPATH="$1"  subject=$1
51    
52  maxissue="0"  bodyfile=$2
53  for mif in `ls -1 ${CCFPATH}/XMM_CALINDEX_*.CCF`  
54  do  [ ! -f "${bodyfile}" ] && return
55          mifbase=`basename $mif`  
56          issue=`echo $mifbase | awk -F"." '{print $1}' | awk -F"_" '{print $3}'`  echo ; echo "Sending message to ${adminmail} with subject ${subject}" ; echo
         [ "$issue" -ge "$maxissue" ] && maxissue="$issue"  
 done  
57    
58  MIF=${CCFPATH}/XMM_CALINDEX_${maxissue}.CCF  mailx -v -s "${subject}" "${adminmail}" < ${bodyfile}
59    
60  }  }
61    
62  # Function get_ccf_list to list on stdout the table of CCFs in a given CIF  
63    
64    # +++ Function getxsaobslog
65    #
66    # 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    wget --quiet ${XSAOBSURL} -O ${VALID_CCF}/xsaobslog.txt
81    
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    
91    # +++Function get_ccf_list to list on stdout the table of CCFs in a given CIF.
92  #  #
93  # Requires that Heasoft is initialised. Otherwise exits with error.  # Requires that Heasoft is initialised. Otherwise exits with error.
94    
# Line 65  noversion=`which fversion | grep -c no` Line 102  noversion=`which fversion | grep -c no`
102    
103  if [ "${noversion}" != "0" ] ; then  if [ "${noversion}" != "0" ] ; then
104          echo "Error: Heasoft not initialised !"          echo "Error: Heasoft not initialised !"
105            [ -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          exit          exit
111  fi  fi
112    
# Line 74  fdump ${cif_to_process} prhead=no showco Line 116  fdump ${cif_to_process} prhead=no showco
116  }  }
117    
118    
 # We need to get the list of all observed ODFs at the current date.  
 # This is obtained from ftp://nxsa.esac.esa.int/pub/cds_obslog/xsaobslog.txt.  
119    
 VALID_CCF="$HOME/valid_ccf"  
120    
121  cd ${VALID_CCF}  # +++ 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    
130  # Remove any xsaobslog.txt previously downloaded.  fillvalidccfdir()
131    {
132    
133  [ -f "xsaobslog.txt" ] && rm -rf xsaobslog.txt  [ -z "$1" ] && return
134    
135  # Get the list latest list of ODFs available from nXSA server.  validccflist=$1
   
 wget -q ftp://nxsa.esac.esa.int/pub/cds_obslog/xsaobslog.txt  
136    
137  # Rename xsaobslog.txt to xsaobslog_${now}.txt just to have a reference  if [ ! -f "${VALID_CCF}/${validccflist}" -o ! -s "${VALID_CCF}/${validccflist}"  ] ; then
138  # of which list of ODFs was used to compute the list of valid CCFs.          echo "Error: ${VALID_CCF}/${validccflist} not found or empty - Abort!"
139            [ -f "${mailfile}" ] && rm -rf ${mailfile}
140            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            rm ${mailfile}
143            exit
144    fi
145    
146    VALIDCONSTITUENTSDIR="/home/ccflib/ftp-area/valid_constituents"
147    rm -rf ${VALIDCONSTITUENTSDIR}/*
148    
149    # 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    VALIDCCFDIRINTRANET="/ccf/valid"
152    rm -rf ${VALIDCCFDIRINTRANET}/*
153    
154    CONSTITUENTSDIR="/home/ccflib/ftp-area/constituents"
155    n=0
156    while read ccf
157    do
158            n=$((n + 1))
159            echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/"
160            cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCONSTITUENTSDIR}/
161            echo "$n cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCCFDIRINTRANET}/"
162            cp -a ${CONSTITUENTSDIR}/${ccf} ${VALIDCCFDIRINTRANET}/
163    done < ${VALID_CCF}/${validccflist}
164    
165    }
166    
167    
168    #
169    #   M a i n    p r o g r a m
170    #
171    # 1. Get the list of all ODFs
172    
173    
174    xsaobslogsize="0"
175    
176    getxsaobslog
177    
178    xsaobslogsize=`stat --format=%s ${VALID_CCF}/xsaobslog_${now}.txt`
179    
180    if [ "$xsaobslogsize"  = "0" ] ; then
181            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            exit
188    fi
189    
190  mv xsaobslog.txt xsaobslog_${now}.txt  #
191    # 2. Initialises HEADAS and SAS
192    #
193    
194  # Sets SAS_CCFPATH and initialises HEADAS and SAS depending on host  # Defines SASBUILD_LOCAL depending on host.
195    # Then uses it to build up HEADAS and setup LD_LIBRARY_PATH accordingly.
196    
197  case "$host" in  case "$host" in
198          xvsoc01|xmm)          sasbld01n|sasbld02n)
199                  export SAS_CCFPATH="/data/xmm/ccflib/ftp-area/constituents"                  export SASBUILD_LOCAL="/sasbuild/local/${host}/GNU_CC_CXX_7.1"
                 export SAS_DIR=/data/xmm/ccflib/sas  
                 export SAS_PATH=$SAS_DIR  
                 source $SAS_DIR/sas-setup.sh  
200                  ;;                  ;;
201          sasbld01|sasbld02)          sciggw7|scigvn7-*)
202                  export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"                  export SASBUILD_LOCAL="/sasbuild/local/sasbld02n/GNU_CC_CXX_7.1"
                 /sas/bin/confsas  
                 export HEADAS=/sasbuild/local/${host}/headas/architecture  
                 . $HEADAS/headas-init.sh  
                 # To be able to mix several jobs on the same ccflib account  
                 [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}  
                 export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"  
                 echo -n "HEADAS version: "  
                 fversion  
                 source $HOME/setsas.sh 1> /dev/null  
                 echo "SAS Version: "  
                 sasversion -V 1  
                 export SAS_VERBOSITY=0  
203                  ;;                  ;;
204          scigrid6|cn-*)          *) echo "Error: Unsupported host $host" ; exit 1 ;;
                 export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"  
                 /sas/bin/confsas  
                 export HEADAS=/sasbuild/local/sasbld02/headas/architecture  
                 . $HEADAS/headas-init.sh  
                 # To be able to mix several jobs on the same ccflib account  
                 [ ! -d "${HOME}/pfiles/${host}" ] && mkdir ${HOME}/pfiles/${host}  
                 export PFILES="${HOME}/pfiles/${host};${HEADAS}/syspfiles"  
                 echo -n "HEADAS version: "  
                 fversion  
                 source $HOME/setsas.sh 1> /dev/null  
                 echo "SAS Version: "  
                 sasversion -V 1  
                 export SAS_VERBOSITY=0  
                 ;;  
         *) echo "Error: Do not know how to do it in host $host" ; exit ;;  
205  esac  esac
206    
207  # Finds the latest MIF issue  export HEADAS=${SASBUILD_LOCAL}/headas/architecture
208    
209    headas_output="${VALID_CCF}/headas_output"
210    source $HEADAS/headas-init.sh > ${headas_output} 2>&1
211    
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  find_latest_mif "${SAS_CCFPATH}"  export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${SASBUILD_LOCAL}/gcc/lib64
220    
221    
222  # Now scans the list of OBDS ID registered in the previous list to get the start time  headas_ok=`cat ${headas_output}`
223  # and then runs cifbuild to get the respective CIF  
224    if [ -n "${headas_ok}" ] ; then
225            echo "mlovccf: HEADAS initialisation failed with error" >> ${mailfile}
226            cat ${headas_output}                                    >> ${mailfile}
227            mailnotify "mlovccf: HEADAS initilisation failed" ${mailfile}
228            rm ${headas_output} ${mailfile}
229            exit 1
230    fi
231    
232    # 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    #
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    fi
259    
260    source $HOME/setsas.sh 1> /dev/null
261    
262    # Re-sets SAS_CCFPATH
263    
264    export SAS_CCFPATH="/home/ccflib/ftp-area/constituents"
265    
266    echo "SAS Version: "
267    sasversion -V 1
268    export SAS_VERBOSITY=0
269    
270    
271    # 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    
280    #    Output file :          ${VALID_CCF}/all_ccfs_${now}.txt
281    
 # Output file  
282  touch ${VALID_CCF}/all_ccfs_${now}.txt  touch ${VALID_CCF}/all_ccfs_${now}.txt
283    
284  n=0  n=0
# Line 189  do Line 323  do
323    
324          cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u  >  ${VALID_CCF}/all_ccfs_${now}.txt          cat ${VALID_CCF}/${obsid}_ccfs.txt ${VALID_CCF}/all_ccfs_${now}.tmp | sort -u  >  ${VALID_CCF}/all_ccfs_${now}.txt
325    
326            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          rm ${cif_file}          rm ${cif_file}
340          rm ${VALID_CCF}/${obsid}_ccfs.txt          rm ${VALID_CCF}/${obsid}_ccfs.txt
341          rm ${VALID_CCF}/all_ccfs_${now}.tmp          rm ${VALID_CCF}/all_ccfs_${now}.tmp
342    
343  done < ${VALID_CCF}/xsaobslog_${now}.txt  done < ${VALID_CCF}/xsaobslog_${now}.txt
344    
345  # Make a table of classes and issues type "Pipeline Release Notes"  # 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    
350  # Lists all CCF classes  # Lists all CCF classes
351    
# Line 210  done < ${VALID_CCF}/all_ccfs_${now}.txt Line 360  done < ${VALID_CCF}/all_ccfs_${now}.txt
360  cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt  cat ${ccf_classes} | sort -u > ${VALID_CCF}/kk.txt
361  mv ${VALID_CCF}/kk.txt ${ccf_classes}  mv ${VALID_CCF}/kk.txt ${ccf_classes}
362    
363    
364    
365  # Output final file is named all_ccfs_${now}_table.txt  # Output final file is named all_ccfs_${now}_table.txt
366    
367  total_number_of_ccfs=0  total_number_of_ccfs=0
# Line 277  echo "" Line 429  echo ""
429  echo "Total number of valid CCFs required : ${total_number_of_ccfs}"                                            >> ${all_ccfs_table}  echo "Total number of valid CCFs required : ${total_number_of_ccfs}"                                            >> ${all_ccfs_table}
430  rm ${VALID_CCF}/ccf_classes.txt  rm ${VALID_CCF}/ccf_classes.txt
431  rm ${VALID_CCF}/ccf_issues_for*.txt  rm ${VALID_CCF}/ccf_issues_for*.txt
432    
433    
434    
435    # 6. Fill in the Valid CCF Set dir with the proper CCFs
436    
437    fillvalidccfdir "all_ccfs_${now}.txt"
438    
439    
440    [ -f "${mailfile}" ] && rm -rf ${mailfile}
441    echo "Valid CCF Set successfully copied to ${VALIDCONSTITUENTSDIR}" >> $mailfile
442    echo "Valid CCF Set successfully copied to ${VALIDCCFDIRINTRANET}"  >> $mailfile
443    mailnotify "mvloccf: Valid CCF Set created successfully" $mailfile
444    rm ${mailfile}

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.23

  ViewVC Help
Powered by ViewVC 1.1.27