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