source: tags/Mars-V1.1/datacenter/scripts/filesondisk

Last change on this file was 8410, checked in by snruegam, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.0 KB
Line 
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
47source `dirname $0`/sourcefile
48printprocesslog "INFO starting $0"
49program=filesondisk
50
51set -C
52
53scriptlog=$runlogpath/$program-$datetime.log
54date >> $scriptlog 2>&1
55
56# check if script is already running
57lockfile=$lockpath/lock-$program.txt
58checklock >> $scriptlog 2>&1
59
60filesondisklogpath=$logpath/$program/`date +%Y/%m`
61makedir $filesondisklogpath >> $scriptlog 2>&1
62
63cd $mars
64
65echo "checking disk for ccfiles..." >> $scriptlog 2>&1
66printprocesslog "INFO checking ccfiles"
67filename=$filesondisklogpath/ccfilesondisk-$datetime.txt
68column=fCCFileAvail
69find $subsystempath/cc/ -name '*_S.rep' | cut -d_ -f2 > $filename
70
71echo "resetting runs..." >> $scriptlog 2>&1
72check3=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | intgrep`
73
74case $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 ;;
84esac
85
86
87echo "checking disk for cacofiles..." >> $scriptlog 2>&1
88printprocesslog "INFO checking cacofiles"
89filename=$filesondisklogpath/cacofilesondisk-$datetime.txt
90column=fCaCoFileAvail
91find $subsystempath/caco/ -name '*.txt' | cut -d_ -f8 | grep [0-9] > $filename
92
93echo "resetting runs..." >> $scriptlog 2>&1
94check0=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | intgrep`
95
96case $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 ;;
106esac
107
108date=`date +%F`
109echo "checking missing cacofiles..." >> $scriptlog 2>&1
110printprocesslog "INFO checking missing cacofiles"
111check1=`root -q -b $macrospath/findcacofiles.C+\("\"$date\""\,"\"$filesondisklogpath\""\) | tee $filesondisklogpath/findcacofiles-$datetime.log | intgrep`
112
113case $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 ;;
123esac
124
125printprocesslog "INFO finding missing cacofiles"
126missingcacoruns=(`cat $filesondisklogpath/findcacofiles-$date.txt`)
127for missingcacorun in ${missingcacoruns[@]}
128do
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
174done
175
176
177echo "checking disk for rawfiles..." >> $scriptlog 2>&1
178printprocesslog "INFO checking rawfiles"
179filename=$filesondisklogpath/rawfilesondisk-$datetime.txt
180column=fRawFileAvail
181find $datapath/rawfiles -name '*.raw' -o -name '*.gz' | cut -d_ -f2 > $filename
182
183echo "resetting runs..." >> $scriptlog 2>&1
184check4=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | intgrep`
185
186case $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 ;;
196esac
197
198finish >> $scriptlog 2>&1
199
Note: See TracBrowser for help on using the repository browser.