1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # ========================================================================
|
---|
4 | #
|
---|
5 | # *
|
---|
6 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | # * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | # * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | # *
|
---|
11 | # * Permission to use, copy, modify and distribute this software and its
|
---|
12 | # * documentation for any purpose is hereby granted without fee,
|
---|
13 | # * provided that the above copyright notice appear in all copies and
|
---|
14 | # * that both that copyright notice and this permission notice appear
|
---|
15 | # * in supporting documentation. It is provided "as is" without express
|
---|
16 | # * or implied warranty.
|
---|
17 | # *
|
---|
18 | #
|
---|
19 | #
|
---|
20 | # Author(s): Daniela Dorner 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2006
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This script checks which files are on disk and updates the database
|
---|
28 | # accordingly. It is not yet running automatically.
|
---|
29 | #
|
---|
30 | # It is checking the:
|
---|
31 | # - ccfiles
|
---|
32 | # - cacofiles
|
---|
33 | # this includes also the search for missing cacofiles:
|
---|
34 | # Sometimes the DAQ aborts a run and starts itself a new one. In this
|
---|
35 | # cases the camera controll doesn't start a new file, as the command to
|
---|
36 | # start a new run was not sent by the central control. So the caco
|
---|
37 | # information is stored in the previous caco file, which has a
|
---|
38 | # different runnumber. To be able to merpp the information into the
|
---|
39 | # calibrated data file, the runnumber of the file containing the
|
---|
40 | # information has to be found.
|
---|
41 | # In this script the search and inserting into the database is done
|
---|
42 | # using the macros findcacofiles.C and insertcacofile.C
|
---|
43 | # - rawfiles
|
---|
44 | # The update in the database is done using the macro resetallruns.C
|
---|
45 | #
|
---|
46 |
|
---|
47 | source `dirname $0`/sourcefile
|
---|
48 | printprocesslog "INFO starting $0"
|
---|
49 | program=filesondisk
|
---|
50 |
|
---|
51 | set -C
|
---|
52 |
|
---|
53 | scriptlog=$runlogpath/$program-$datetime.log
|
---|
54 | date >> $scriptlog 2>&1
|
---|
55 |
|
---|
56 | # check if script is already running
|
---|
57 | lockfile=$lockpath/lock-$program.txt
|
---|
58 | checklock >> $scriptlog 2>&1
|
---|
59 |
|
---|
60 | filesondisklogpath=$logpath/$program/`date +%Y/%m`
|
---|
61 | makedir $filesondisklogpath >> $scriptlog 2>&1
|
---|
62 |
|
---|
63 | cd $mars
|
---|
64 |
|
---|
65 | echo "checking disk for ccfiles..." >> $scriptlog 2>&1
|
---|
66 | printprocesslog "INFO checking ccfiles"
|
---|
67 | filename=$filesondisklogpath/ccfilesondisk-$datetime.txt
|
---|
68 | column=fCCFileAvail
|
---|
69 | find $subsystempath/cc/ -name '*_S.rep' | cut -d_ -f2 > $filename
|
---|
70 |
|
---|
71 | echo "resetting runs..." >> $scriptlog 2>&1
|
---|
72 | check3=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | intgrep`
|
---|
73 |
|
---|
74 | case $check3 in
|
---|
75 | 1) echo " check3=$check3 -> everything ok -> reset is done" >> $scriptlog 2>&1
|
---|
76 | printprocesslog "INFO ccfiles resetted successfully"
|
---|
77 | ;;
|
---|
78 | 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
|
---|
79 | printprocesslog "WARN connection to DB failed"
|
---|
80 | ;;
|
---|
81 | *) echo " check3=$check3 -> ERROR -> something went wrong while resetting" >> $scriptlog 2>&1
|
---|
82 | printprocesslog "ERROR resettallruns.C failed for ccfiles"
|
---|
83 | ;;
|
---|
84 | esac
|
---|
85 |
|
---|
86 |
|
---|
87 | echo "checking disk for cacofiles..." >> $scriptlog 2>&1
|
---|
88 | printprocesslog "INFO checking cacofiles"
|
---|
89 | filename=$filesondisklogpath/cacofilesondisk-$datetime.txt
|
---|
90 | column=fCaCoFileAvail
|
---|
91 | find $subsystempath/caco/ -name '*.txt' | cut -d_ -f8 | grep [0-9] > $filename
|
---|
92 |
|
---|
93 | echo "resetting runs..." >> $scriptlog 2>&1
|
---|
94 | check0=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | intgrep`
|
---|
95 |
|
---|
96 | case $check0 in
|
---|
97 | 1) echo " check0=$check0 -> everything ok -> reset is done" >> $scriptlog 2>&1
|
---|
98 | printprocesslog "INFO cacofiles resetted successfully"
|
---|
99 | ;;
|
---|
100 | 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
|
---|
101 | printprocesslog "WARN connection to DB failed"
|
---|
102 | ;;
|
---|
103 | *) echo " check0=$check0 -> ERROR -> something went wrong while resetting" >> $scriptlog 2>&1
|
---|
104 | printprocesslog "ERROR resettallruns.C failed for cacofiles"
|
---|
105 | ;;
|
---|
106 | esac
|
---|
107 |
|
---|
108 | date=`date +%F`
|
---|
109 | echo "checking missing cacofiles..." >> $scriptlog 2>&1
|
---|
110 | printprocesslog "INFO checking missing cacofiles"
|
---|
111 | check1=`root -q -b $macrospath/findcacofiles.C+\("\"$date\""\,"\"$filesondisklogpath\""\) | tee $filesondisklogpath/findcacofiles-$datetime.log | intgrep`
|
---|
112 |
|
---|
113 | case $check1 in
|
---|
114 | 1) echo " check1=$check1 -> everything ok -> missing cacofiles are found" >> $scriptlog 2>&1
|
---|
115 | printprocesslog "INFO missing cacofiles found"
|
---|
116 | ;;
|
---|
117 | 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
|
---|
118 | printprocesslog "WARN connection to DB failed"
|
---|
119 | ;;
|
---|
120 | *) echo " check1=$check1 -> ERROR -> something went wrong while resetting" >> $scriptlog 2>&1
|
---|
121 | printprocesslog "ERROR findcacofiles.C failed"
|
---|
122 | ;;
|
---|
123 | esac
|
---|
124 |
|
---|
125 | printprocesslog "INFO finding missing cacofiles"
|
---|
126 | missingcacoruns=(`cat $filesondisklogpath/findcacofiles-$date.txt`)
|
---|
127 | for missingcacorun in ${missingcacoruns[@]}
|
---|
128 | do
|
---|
129 | runno=$missingcacorun
|
---|
130 | echo "missing cacofile for run "$runno >> $scriptlog 2>&1
|
---|
131 | echo "-> finding cacofile" >> $scriptlog 2>&1
|
---|
132 | ccfile=`find $subsystempath/cc/ -name [2][0][0-2][0-9][0,1][0-9][0-3][0-9]_*${runno}_[P,D,C,S]_*_S.rep -and ! -name [2][0][0-2][0-9][0,1][0-9][0-3][0-9]_*[1-9]${runno}_[P,D,C,S]_*_S.rep` 2>/dev/null
|
---|
133 | echo " ccfile: "$ccfile >> $scriptlog 2>&1
|
---|
134 | if [ "$ccfile" = "" ]
|
---|
135 | then
|
---|
136 | echo " no ccfile found for run "$runno >> $scriptlog 2>&1
|
---|
137 | continue
|
---|
138 | fi
|
---|
139 | for (( i = 0; i <= 10; i++ ))
|
---|
140 | do
|
---|
141 | newrun=`echo $runno - $i | bc`
|
---|
142 | path=`dirname $ccfile`
|
---|
143 | path=`echo $path | sed -e 's/cc/caco/'`
|
---|
144 | cacofile=`find $path -name *$newrun* 2>/dev/null`
|
---|
145 | if [ "$cacofile" = "" ]
|
---|
146 | then
|
---|
147 | continue
|
---|
148 | else
|
---|
149 | printprocesslog "INFO inserting cacofile for run $missingcacorun"
|
---|
150 | echo " inserting cacofile $file for run $missingcacorun..." >> $scriptlog 2>&1
|
---|
151 | check2=`root -q -b $macrospath/insertcacofile.C+\("\"$runno\""\,"\"$newrun\""\) | tee $filesondisklogpath/insertcacofile-$missingcacorun.log | intgrep`
|
---|
152 |
|
---|
153 | case $check2 in
|
---|
154 | 1) echo " check2=$check2 -> everything ok -> insert is done" >> $scriptlog 2>&1
|
---|
155 | printprocesslog "INFO inserted $missingcacorun successfully"
|
---|
156 | ;;
|
---|
157 | 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
|
---|
158 | printprocesslog "WARN connection to DB failed"
|
---|
159 | ;;
|
---|
160 | *) echo " check2=$check2 -> ERROR -> something went wrong while inserting run "$missingcacorun >> $scriptlog 2>&1
|
---|
161 | printprocesslog "ERROR insertcacofile.C failed for run $missingcacorun"
|
---|
162 | ;;
|
---|
163 | esac
|
---|
164 | break
|
---|
165 | fi
|
---|
166 | done
|
---|
167 | if [ "$cacofile" = "" ]
|
---|
168 | then
|
---|
169 | echo " no cacofile found for run "$runno >> $scriptlog 2>&1
|
---|
170 | printprocesslog "WARN no cacofile found for run $runno"
|
---|
171 | else
|
---|
172 | echo " cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
173 | fi
|
---|
174 | done
|
---|
175 |
|
---|
176 |
|
---|
177 | echo "checking disk for rawfiles..." >> $scriptlog 2>&1
|
---|
178 | printprocesslog "INFO checking rawfiles"
|
---|
179 | filename=$filesondisklogpath/rawfilesondisk-$datetime.txt
|
---|
180 | column=fRawFileAvail
|
---|
181 | find $datapath/rawfiles -name '*.raw' -o -name '*.gz' | cut -d_ -f2 > $filename
|
---|
182 |
|
---|
183 | echo "resetting runs..." >> $scriptlog 2>&1
|
---|
184 | check4=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | intgrep`
|
---|
185 |
|
---|
186 | case $check4 in
|
---|
187 | 1) echo " check4=$check4 -> everything ok -> reset is done" >> $scriptlog 2>&1
|
---|
188 | printprocesslog "INFO rawfiles resetted successfully"
|
---|
189 | ;;
|
---|
190 | 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
|
---|
191 | printprocesslog "WARN connection to DB failed"
|
---|
192 | ;;
|
---|
193 | *) echo " check4=$check4 -> ERROR -> something went wrong while resetting" >> $scriptlog 2>&1
|
---|
194 | printprocesslog "ERROR resettallruns.C failed for rawfiles"
|
---|
195 | ;;
|
---|
196 | esac
|
---|
197 |
|
---|
198 | finish >> $scriptlog 2>&1
|
---|
199 |
|
---|