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 |
|
---|
49 | set -C
|
---|
50 |
|
---|
51 | cd $mars
|
---|
52 |
|
---|
53 | program=filesondisk
|
---|
54 |
|
---|
55 | lockfile=$lockpath/lock-$program.txt
|
---|
56 |
|
---|
57 | scriptlogpath=$logpath/run/$program/`date +%Y`
|
---|
58 | makedir $scriptlogpath
|
---|
59 | scriptlog=$scriptlogpath/$program-$datetime.log
|
---|
60 |
|
---|
61 | date >> $scriptlog 2>&1
|
---|
62 |
|
---|
63 | # check if script is already running
|
---|
64 | checklock >> $scriptlog 2>&1
|
---|
65 |
|
---|
66 | date=`date +%F`
|
---|
67 |
|
---|
68 | subsystemdir=/magic/subsystemdata
|
---|
69 | filesondisklogpath=$logpath/$program/`date +%Y/%m`
|
---|
70 | makedir $filesondisklogpath
|
---|
71 |
|
---|
72 |
|
---|
73 | echo "checking disk for ccfiles..." >> $scriptlog 2>&1
|
---|
74 | filename=$filesondisklogpath/ccfilesondisk-$datetime.txt
|
---|
75 | column=fCCFileAvail
|
---|
76 | find $subsystemdir/cc/ -name '*_S.rep' | cut -d_ -f2 > $filename
|
---|
77 |
|
---|
78 | echo "resetting runs..." >> $scriptlog 2>&1
|
---|
79 | check3=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | grep int | sed -e 's/(int)//'`
|
---|
80 |
|
---|
81 | case $check3 in
|
---|
82 | 1) echo "check3=$check3 -> everything ok -> reset is done" >> $scriptlog 2>&1 ;;
|
---|
83 | *) echo "check3=$check3 -> ERROR -> something went wrong while resetting" >> $scriptlog 2>&1 ;;
|
---|
84 | esac
|
---|
85 |
|
---|
86 |
|
---|
87 | echo "checking disk for cacofiles..." >> $scriptlog 2>&1
|
---|
88 | filename=$filesondisklogpath/cacofilesondisk-$datetime.txt
|
---|
89 | column=fCaCoFileAvail
|
---|
90 | find $subsystemdir/caco/ -name '*.txt' | cut -d_ -f8 | grep [0-9] > $filename
|
---|
91 |
|
---|
92 | echo "resetting runs..." >> $scriptlog 2>&1
|
---|
93 | check0=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | grep int | sed -e 's/(int)//'`
|
---|
94 |
|
---|
95 | case $check0 in
|
---|
96 | 1) echo "check0=$check0 -> everything ok -> reset is done" >> $scriptlog 2>&1 ;;
|
---|
97 | *) echo "check0=$check0 -> ERROR -> something went wrong while resetting" >> $scriptlog 2>&1 ;;
|
---|
98 | esac
|
---|
99 |
|
---|
100 | echo "checking missing cacofiles..." >> $scriptlog 2>&1
|
---|
101 | check1=`root -q -b $macrospath/findcacofiles.C+\("\"$date\""\,"\"$filesondisklogpath\""\) | tee $filesondisklogpath/findcacofiles-$datetime.log | grep int | sed -e 's/(int)//'`
|
---|
102 |
|
---|
103 | case $check1 in
|
---|
104 | 1) echo "check1=$check1 -> everything ok -> missing cacofiles are found" >> $scriptlog 2>&1 ;;
|
---|
105 | *) echo "check1=$check1 -> ERROR -> something went wrong while resetting" >> $scriptlog 2>&1 ;;
|
---|
106 | esac
|
---|
107 |
|
---|
108 | missingcacoruns=(`cat $filesondisklogpath/findcacofiles-$date.txt`)
|
---|
109 | for missingcacorun in ${missingcacoruns[@]}
|
---|
110 | do
|
---|
111 | runno=$missingcacorun
|
---|
112 | echo "missing cacofile for run "$runno >> $scriptlog 2>&1
|
---|
113 | echo "-> finding cacofile" >> $scriptlog 2>&1
|
---|
114 | ccfile=`find $subsystemdir/cc/ -name [2][0][0-2][0-9][0,1][0-9][0-3][0-9]_*${runno}_[P,D,C,S]_*_S.rep` 2>/dev/null
|
---|
115 | echo " ccfile: "$ccfile >> $scriptlog 2>&1
|
---|
116 | if [ "$ccfile" = "" ]
|
---|
117 | then
|
---|
118 | echo " no ccfile found for run "$runno >> $scriptlog 2>&1
|
---|
119 | continue
|
---|
120 | fi
|
---|
121 | for (( i = 0; i <= 10; i++ ))
|
---|
122 | do
|
---|
123 | newrun=`echo $runno - $i | bc`
|
---|
124 | path=`dirname $ccfile`
|
---|
125 | path=`echo $path | sed -e 's/cc/caco/'`
|
---|
126 | cacofile=`find $path -name *$newrun*` 2>/dev/null
|
---|
127 | if [ "$cacofile" = "" ]
|
---|
128 | then
|
---|
129 | continue
|
---|
130 | else
|
---|
131 | echo " inserting cacofile $file for run $missingcacorun..." >> $scriptlog 2>&1
|
---|
132 | check2=`root -q -b $macrospath/insertcacofile.C+\("\"$runno\""\,"\"$newrun\""\) | tee $filesondisklogpath/insertcacofile-$missingcacorun.log | grep int | sed -e 's/(int)//'`
|
---|
133 |
|
---|
134 | case $check2 in
|
---|
135 | 1) echo " check2=$check2 -> everything ok -> insert is done" >> $scriptlog 2>&1 ;;
|
---|
136 | *) echo " check2=$check2 -> ERROR -> something went wrong while inserting run "$missingcacorun >> $scriptlog 2>&1 ;;
|
---|
137 | esac
|
---|
138 | break
|
---|
139 | fi
|
---|
140 | done
|
---|
141 | if [ "$cacofile" = "" ]
|
---|
142 | then
|
---|
143 | echo " no cacofile found for run "$runno >> $scriptlog 2>&1
|
---|
144 | else
|
---|
145 | echo " cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
146 | fi
|
---|
147 | done
|
---|
148 |
|
---|
149 |
|
---|
150 | echo "checking disk for rawfiles..." >> $scriptlog 2>&1
|
---|
151 | filename=$filesondisklogpath/rawfilesondisk-$datetime.txt
|
---|
152 | column=fRawFileAvail
|
---|
153 | find $datapath -name '*.raw' -o -name '*.gz' | cut -d_ -f2 > $filename
|
---|
154 |
|
---|
155 | echo "resetting runs..." >> $scriptlog 2>&1
|
---|
156 | check4=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | grep int | sed -e 's/(int)//'`
|
---|
157 |
|
---|
158 | case $check4 in
|
---|
159 | 1) echo "check4=$check4 -> everything ok -> reset is done" >> $scriptlog 2>&1 ;;
|
---|
160 | *) echo "check4=$check4 -> ERROR -> something went wrong while resetting" >> $scriptlog 2>&1 ;;
|
---|
161 | esac
|
---|
162 |
|
---|
163 | finish >> $scriptlog 2>&1
|
---|
164 |
|
---|
165 |
|
---|