source: BAORadio/AmasNancay/v4/hdrfitsextractor.sh@ 615

Last change on this file since 615 was 575, checked in by campagne, 14 years ago

introduce SCRIPTPATH environment variable (jec)

File size: 4.6 KB
Line 
1#!/bin/sh
2#download SCA file, proceed to introspection, and upload results
3DATE=/bin/date
4GREP=/bin/grep
5AWK=/bin/awk
6ECHO=/bin/echo
7WC=/usr/bin/wc
8CAT=/bin/cat
9PRINTF=/usr/bin/printf
10MKDIR=/bin/mkdir
11XARGS=/usr/bin/xargs
12SORT=/bin/sort
13RM=/bin/rm
14defaultIFS=$IFS
15
16#set Irods environment
17. /usr/local/shared/bin/irods_env.sh -noverbose
18
19scriptName="`basename $0`"
20$ECHO "Processing script ${scriptName} at `date`"
21
22#which source to analyse
23sourceRadio=$1
24
25#Path to public backupable path
26publicpath="/afs/in2p3.fr/home/c/campagne/public"
27
28
29#Path where the job will do temporary IO
30if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then
31 iojobpath="/sps/baoradio/AmasNancay/JEC"
32 $MKDIR -p $iojobpath
33elif [ ${ENVIRONMENT} = "BATCH" ] ; then
34 iojobpath=${TMPBATCH}
35else
36 $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
37 exit 1
38fi
39cd ${iojobpath}
40
41localpath="${sourceRadio}"
42$MKDIR -p ./${localpath}
43cd ./${localpath}
44
45
46#Path of the utility scripts
47scriptpath=${SCRIPTPATH}
48
49
50#JEC 1/10/11 Use generic baodaqstatus name
51#get the daq current irod status
52#tag=`${DATE} +%F`
53#OUT1=${publicpath}/baodaqstatus-${tag}.txt
54OUT1=${publicpath}/baodaqstatus-current.txt
55
56if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
57 $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
58 exit 1
59fi
60
61#if [ ! -e ${OUT1} ]; then
62# $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
63# ${scriptpath}/statusdaq.sh > ${OUT1}
64#fi
65
66if [ ! "<${sourceRadio}>" = "<>" ]; then
67 $ECHO "You have selected sourceRadio = $sourceRadio"
68 tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
69else
70 tableau=( `$CAT ${OUT1} | $AWK '( NF==4 ) { print $2 }'` )
71fi
72IFS='
73'
74tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
75
76
77workArea="headers"
78$MKDIR -p ./${workArea}
79cd ./${workArea}
80
81
82nloop4dbg=0
83
84
85for i in ${tableau[@]}
86do
87#look if the headers have been already extracted
88 $ECHO "DEBUG (${scriptName}): irods root dir $i"
89 for fibdir in Fiber1 Fiber2; do
90 $ECHO "DEBUG (${scriptName}): Fiber $fibdir"
91#NB: care should be taken to the fact that ILS returns all the instance of the file (HPSS, disk...)
92# so one should use a trick to count unique instance
93 listOfsig=( `ils ${i}/${fibdir} | $GREP -i "signal" | $XARGS -i basename {} | $SORT -k1.7n` )
94 IFS='
95'
96 listOfsig=( $( $PRINTF "%s\n" "${listOfsig[@]}" | $AWK 'x[$0]++ == 0' ) )
97 nblinesSIG=${#listOfsig[@]}
98 listOfhdr=( `ils ${i}/${fibdir} | $GREP -i "header" | $XARGS -i basename {} | $SORT -k1.7n` )
99 IFS='
100'
101 listOfhdr=( $( $PRINTF "%s\n" "${listOfhdr[@]}" | $AWK 'x[$0]++ == 0' ) )
102 nblinesHDR=${#listOfhdr[@]}
103 $ECHO "(DEBUG) (${scriptName}: test if $nblinesHDR != $nblinesSIG "
104 if [ $nblinesHDR != $nblinesSIG ]; then
105#do the header extraction
106#build signal files list
107#loop on signal files
108 $ECHO "(DEBUG) (${scriptName}): ${listOfsig[@]}"
109
110 for sigfname in ${listOfsig[@]}
111 do
112 filename=$(basename $sigfname)
113 extension=${filename##*.}
114 filename=${filename%.*}
115 number=`$ECHO $filename | $AWK '{len=length("signal");len=len+1;a=substr($1,len);print a}'`
116 hdrname="header${number}.txt"
117#look if header file already exists: if so skip it
118 hdrIsthere=`ils ${i}/${fibdir}/${hdrname} 2>&1 | $GREP -i "^ERROR" | $WC -l`
119 $ECHO "(DEBUG) (${scriptName}): look if ${hdrname} exist (${hdrIsthere})"
120 if [ $hdrIsthere -eq 0 ]; then
121 continue
122 fi
123#get the signal file
124 $ECHO "DEBUG (${scriptName}): iget $sigfname (dgg = ${nloop4dbg})"
125 OUT3=./igetlog${nloop4dbg}.$$
126 iget -f -v -K ${i}/${fibdir}/${sigfname} . >${OUT3} 2>&1
127 igetStatus=`$GREP "^ERROR" ${OUT3}`
128 if [ "<$igetStatus>" != "<>" ]; then
129 $ECHO "INFO (${scriptName}): error while iget:"
130 $ECHO $igetStatus
131 continue
132 fi
133 $RM $OUT3
134#extract the header part of the signal file
135 $ECHO "DEBUG (${scriptName}): get header from ${sigfname} and put it in ${hdrname}"
136 IFS=$defaultIFS
137 while read -n80 L
138 do
139 [ "${L::3}" = "END" ] && break
140 $ECHO $L
141 done < ${sigfname} > ${hdrname}
142 $RM ${sigfname}
143 nhdrlines=`$WC -l ${hdrname} | $AWK '{print $1}' `
144 if [ "${nhdrlines}" = "0" ]; then
145 $ECHO "WARNING (${scriptName}): ${sigfname} has no valid header"
146 else
147#transfert to irod the header
148 $ECHO "INFO (${scriptName}): transfert ${hdrname} to ${i}/${fibdir}"
149#use -f option ONLY to force override
150 iput -v -K ${hdrname} ${i}/${fibdir}
151 fi
152 $RM ${hdrname}
153 nloop4dbg=$(expr $nloop4dbg + 1)
154 done
155 else
156 $ECHO "INFO (${scriptName}): nothing to do for ${i}/${fibdir}"
157 fi
158 done
159done
Note: See TracBrowser for help on using the repository browser.