source: BAORadio/AmasNancay/v3/scaextractor.sh@ 607

Last change on this file since 607 was 547, checked in by campagne, 14 years ago

move to trunk the previous HEAD (jec)

File size: 4.6 KB
Line 
1#!/bin/sh -xvf
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
11RM=/bin/rm
12LS=/bin/ls
13DefaultIFS=$' \t\n'
14IFS=$DefaultIFS
15
16
17#set Irods environment
18. /usr/local/shared/bin/irods_env.sh -noverbose
19
20scriptName="`basename $0`"
21$ECHO "Processing script ${scriptName} at `date`"
22
23#which source to analyse
24sourceRadio=$1
25
26#Path to public backupable path
27publicpath="/afs/in2p3.fr/home/c/campagne/public"
28
29#temporary files to synchronize scripts
30tmppublicpath=${TMPPUBLICPATH}
31$LS -l ${tmppublicpath} > /dev/null
32
33
34#Path where the job will do temporary IO
35if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then
36 iojobpath="/sps/baoradio/AmasNancay/JEC"
37 $MKDIR -p $iojobpath
38elif [ ${ENVIRONMENT} = "BATCH" ] ; then
39 iojobpath=${TMPBATCH}
40else
41 $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
42#JEC 29/9/11 avoid finished stuff
43# touch ${tmppublicpath}/scaextractor.finished
44 exit 1
45fi
46cd ${iojobpath}
47
48
49localpath="${sourceRadio}"
50$MKDIR -p ./${localpath}
51cd ./${localpath}
52
53
54#Path of the utility scripts
55scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
56
57
58#JEC 1/10/11 Use generic baodaqstatus name
59#get the daq current irod status
60#tag=`${DATE} +%F`
61#OUT1=${publicpath}/baodaqstatus-${tag}.txt
62OUT1=${publicpath}/baodaqstatus-current.txt
63
64
65if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
66 $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
67 exit 1
68# $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
69# $RM -f ${tmppublicpath}/statusdaq.finished
70# ${scriptpath}/statusdaq.sh > ${OUT1}
71# while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
72# $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished"
73# date +%T
74# sleep 30
75# done
76# $RM ${tmppublicpath}/statusdaq.finished
77# $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..."
78#JEC 29/9/11 avoid finished stuff
79# touch ${tmppublicpath}/scaextractor.finished
80# exit 1
81fi
82
83if [ ! "<${sourceRadio}>" = "<>" ]; then
84 $ECHO "You have selected sourceRadio = $sourceRadio"
85 tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
86else
87 tableau=( `$CAT ${OUT1} | $AWK'( NF==4 ) { print $2 }'` )
88fi
89IFS='
90'
91tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
92IFS=$DefaultIFS
93
94for i in ${tableau[@]}
95do
96OUT2=./baodir.$$
97#scrutinize irods directory
98#Nb: we do not care here if ILS returns non unique instance of a file
99 ils -l $i 2>&1 | $GREP -i "sca" > ${OUT2}
100 $CAT ${OUT2}
101#test if the SCA file has been already processed
102 scatrans=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $NF}'`
103#test if the file is empty due to previous processing dysfunction
104 emptyfile=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $4}'`
105# echo "scrutinize directory <$i>: [$nblines] [$scatrans]"
106 if [ "<${scatrans}>" = "<>" -o "<${emptyfile}>" = "<0>" ]; then
107 $ECHO "$i may be non prepared for analysis..."
108 scafile=`$GREP -i "sca[0-9][0-9]*\.[0-9][0-9]*" ${OUT2} | $AWK '{print $NF}'`
109 if [ "<${scafile}>" = "<>" ]; then
110 $ECHO "WARNING (${scriptName}): Cannot download a SCA file for $i"
111 else
112#get sca file
113 iget -r -f -v -K ${i}/${scafile} ${iojobpath}
114#extract summary (sum extension)
115#JEC 29/9/11 avoid finished stuff
116 $RM -f ${tmppublicpath}/sca.finished
117 ${scriptpath}/sca.sh ${scafile}
118# while [ ! -e "${tmppublicpath}/sca.finished" ]; do
119# $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/sca.finished"
120# date +%T
121# sleep 30
122# done
123 $ECHO "INFO (${scriptName}): sca.sh has finished"
124# $RM ${tmppublicpath}/sca.finished
125#TODO see if there is errors...
126 scaFileName=$(basename $scafile)
127 scaFileName=${scaFileName%.*}
128#transform the date (sum.trans extension)
129#JEC 29/9/11 avoid finished stuff
130# $RM -f ${tmppublicpath}/transdate.finished
131 ${scriptpath}/transdate.sh ${scaFileName}.sum
132# while [ ! -e "${tmppublicpath}/transdate.finished" ]; do
133# $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/transdate.finished"
134# date +%T
135# sleep 30
136# done
137 $ECHO "INFO (${scriptName}): transdate.sh has finished"
138# $RM ${tmppublicpath}/transdate.finished
139#TODO see if there is errors...
140#put back into Irod
141# $ECHO "INFO (${scriptName}): where am i: `pwd`"
142# $LS -lrt
143# $ECHO "INFO (${scriptName}): see up directory"
144# $LS -lrt ..
145 iput -f -v -K ${iojobpath}/${scaFileName}.sum $i
146 iput -f -v -K ${iojobpath}/${scaFileName}.sum.trans $i
147 fi
148 fi
149$RM ${OUT2}
150done
151
152
153#JEC 29/9/11 avoid finished stuff
154#touch ${tmppublicpath}/scaextractor.finished
155exit 0
Note: See TracBrowser for help on using the repository browser.