1 | #!/bin/sh
|
---|
2 | #Get SCA file and summary + transformed date file
|
---|
3 | #
|
---|
4 | DATE=/bin/date
|
---|
5 | GREP=/bin/grep
|
---|
6 | AWK=/bin/awk
|
---|
7 | ECHO=/bin/echo
|
---|
8 | TR=/usr/bin/tr
|
---|
9 | MKDIR=/bin/mkdir
|
---|
10 | CAT=/bin/cat
|
---|
11 | PRINTF=/usr/bin/printf
|
---|
12 | RM=/bin/rm
|
---|
13 | LS=/bin/ls
|
---|
14 | DefaultIFS=$' \t\n'
|
---|
15 | IFS=$DefaultIFS
|
---|
16 |
|
---|
17 | scriptName="`basename $0`"
|
---|
18 | $ECHO "Processing script ${scriptName} at `date`"
|
---|
19 |
|
---|
20 |
|
---|
21 | if [ ! $# = 2 ]; then
|
---|
22 | $ECHO "usage: ${script
|
---|
23 | Name} <source:ex. Abell85> <date:YYYYMMDD>"
|
---|
24 | touch ${tmppublicpath}/getscafiles.finished
|
---|
25 | exit 0
|
---|
26 | fi
|
---|
27 |
|
---|
28 | # Irods environment settings
|
---|
29 | #export PATH=$PATH:/home/bao/irods2.5_LinuxSL5
|
---|
30 | . /usr/local/shared/bin/irods_env.sh -noverbose
|
---|
31 |
|
---|
32 |
|
---|
33 | sourceRadio=$1
|
---|
34 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
|
---|
35 | dateDAQ=$2
|
---|
36 |
|
---|
37 |
|
---|
38 | #Path to public backupable path
|
---|
39 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
|
---|
40 |
|
---|
41 | #temporary files to synchronize scripts
|
---|
42 | tmppublicpath=${TMPPUBLICPATH}
|
---|
43 | $LS -l ${tmppublicpath} > /dev/null
|
---|
44 |
|
---|
45 |
|
---|
46 | #Path where the job will do temporary IO
|
---|
47 | if [ ${ENVIRONMENT} == "INTERACTIVE" ]; then
|
---|
48 | iojobpath="/sps/baoradio/AmasNancay/JEC"
|
---|
49 | $MKDIR -p $iojobpath
|
---|
50 | elif [ ${ENVIRONMENT} == "BATCH" ] ; then
|
---|
51 | iojobpath=${TMPBATCH}
|
---|
52 | else
|
---|
53 | $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
|
---|
54 | touch ${tmppublicpath}/getscafiles.finished
|
---|
55 | exit 1
|
---|
56 | fi
|
---|
57 | cd ${iojobpath}
|
---|
58 |
|
---|
59 | localpath="${sourceRadio}/${dateDAQ}${srclower}"
|
---|
60 | $MKDIR -p ./${localpath}
|
---|
61 | cd ./${localpath}
|
---|
62 |
|
---|
63 |
|
---|
64 | #Path of the utility scripts
|
---|
65 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
|
---|
66 |
|
---|
67 | #look if the run exists
|
---|
68 | tag=`${DATE} +%F`
|
---|
69 | OUT1=${publicpath}/baodaqstatus-${tag}.txt
|
---|
70 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
|
---|
71 | # $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
|
---|
72 | # $RM -f ${tmppublicpath}/statusdaq.finished
|
---|
73 | # ${scriptpath}/statusdaq.sh > ${OUT1}
|
---|
74 | # while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
|
---|
75 | # $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished"
|
---|
76 | # date +%T
|
---|
77 | # sleep 30
|
---|
78 | # done
|
---|
79 | # $RM ${tmppublicpath}/statusdaq.finished
|
---|
80 | $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..."
|
---|
81 | touch ${tmppublicpath}/getscafiles.finished
|
---|
82 | exit 1
|
---|
83 | fi
|
---|
84 |
|
---|
85 | nfiles=`${GREP} "${sourceRadio}.*${dateDAQ}" ${OUT1} | ${AWK} '(NF==4){print $4}'`
|
---|
86 |
|
---|
87 | if [ "<${nfiles}>" = "<>" ]; then
|
---|
88 | $ECHO "FATAL (${scriptName}): No run found for <${sourceRadio}> and date <${dateDAQ}>"
|
---|
89 | touch ${tmppublicpath}/getscafiles.finished
|
---|
90 | exit 1
|
---|
91 | fi
|
---|
92 |
|
---|
93 |
|
---|
94 | #Look if the run should/can be prepared wrt SCA file transformation
|
---|
95 | OUT2=./scaStatus.$$
|
---|
96 | $RM -f ${tmppublicpath}/scaextractor.finished
|
---|
97 | ${scriptpath}/scaextractor.sh $sourceRadio > ${OUT2} 2>&1
|
---|
98 | while [ ! -f "${tmppublicpath}/scaextractor.finished" ]; do
|
---|
99 | $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/scaextractor.finished"
|
---|
100 | date +%T
|
---|
101 | sleep 30
|
---|
102 | done
|
---|
103 | $RM ${tmppublicpath}/scaextractor.finished
|
---|
104 |
|
---|
105 |
|
---|
106 | status=`$GREP "^FATAL.*${sourceRadio}.*${dateDAQ}" ${OUT2}`
|
---|
107 |
|
---|
108 | if [ "<$status>" != "<>" ]; then
|
---|
109 | $ECHO "FATAL (${scriptName}): connot proceed further with $sourceRadio $dateDAQ"
|
---|
110 | touch ${tmppublicpath}/getscafiles.finished
|
---|
111 | exit 1
|
---|
112 | fi
|
---|
113 | $RM $OUT2
|
---|
114 |
|
---|
115 | #dowload sca files...
|
---|
116 | dirIrod="/baoradio/data/AmasNancay/${sourceRadio}/${dateDAQ}${srclower}"
|
---|
117 | dirLocal="."
|
---|
118 |
|
---|
119 | if [ ! -e $dirLocal ]; then
|
---|
120 | $MKDIR -p $dirLocal
|
---|
121 | fi
|
---|
122 |
|
---|
123 | cd $dirLocal
|
---|
124 |
|
---|
125 | OUT3=./scaFiles.$$
|
---|
126 | ils $dirIrod | $GREP -i "sca" > ${OUT3}
|
---|
127 | tableau=( `$CAT ${OUT3}` )
|
---|
128 | IFS='
|
---|
129 | '
|
---|
130 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
|
---|
131 | IFS=$DefaultIFS
|
---|
132 | $RM $OUT3
|
---|
133 |
|
---|
134 | OUT4=./igetStatus.$$
|
---|
135 | for i in ${tableau[@]}
|
---|
136 | do
|
---|
137 | if [ ! -e $i ]; then
|
---|
138 | iget -r -f -v -K ${dirIrod}/$i ${dirLocal} > ${OUT4} 2>&1
|
---|
139 | fi
|
---|
140 | done
|
---|
141 |
|
---|
142 | igetStatus=`$GREP "^ERROR" ${OUT4}`
|
---|
143 | if [ "<$igetStatus>" != "<>" ]; then
|
---|
144 | $ECHO "FATAL (${scriptName}): error while iget:"
|
---|
145 | $ECHO $igetStatus
|
---|
146 | touch ${tmppublicpath}/getscafiles.finished
|
---|
147 | exit 1
|
---|
148 | fi
|
---|
149 |
|
---|
150 | $RM -f $OUT4
|
---|
151 |
|
---|
152 | touch ${tmppublicpath}/getscafiles.finished
|
---|
153 | exit 0
|
---|