source: trunk/MagicSoft/Mars/datacenter/scripts/filesondisk@ 7938

Last change on this file since 7938 was 7938, checked in by hoehne, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 6.1 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
48
49set -C
50
51cd $mars
52
53program=filesondisk
54
55lockfile=$lockpath/lock-$program.txt
56
57scriptlogpath=$runlogpath/$program
58makedir $scriptlogpath
59scriptlog=$scriptlogpath/$program-$datetime.log
60
61date >> $scriptlog 2>&1
62
63# check if script is already running
64checklock >> $scriptlog 2>&1
65
66date=`date +%F`
67
68subsystemdir=/magic/subsystemdata
69filesondisklogpath=$logpath/$program/`date +%Y/%m`
70makedir $filesondisklogpath
71
72
73echo "checking disk for ccfiles..." >> $scriptlog 2>&1
74filename=$filesondisklogpath/ccfilesondisk-$datetime.txt
75column=fCCFileAvail
76find $subsystemdir/cc/ -name '*_S.rep' | cut -d_ -f2 > $filename
77
78echo "resetting runs..." >> $scriptlog 2>&1
79check3=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | grep int | sed -e 's/(int)//'`
80
81case $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 ;;
84esac
85
86
87echo "checking disk for cacofiles..." >> $scriptlog 2>&1
88filename=$filesondisklogpath/cacofilesondisk-$datetime.txt
89column=fCaCoFileAvail
90find $subsystemdir/caco/ -name '*.txt' | cut -d_ -f8 | grep [0-9] > $filename
91
92echo "resetting runs..." >> $scriptlog 2>&1
93check0=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | grep int | sed -e 's/(int)//'`
94
95case $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 ;;
98esac
99
100echo "checking missing cacofiles..." >> $scriptlog 2>&1
101check1=`root -q -b $macrospath/findcacofiles.C+\("\"$date\""\,"\"$filesondisklogpath\""\) | tee $filesondisklogpath/findcacofiles-$datetime.log | grep int | sed -e 's/(int)//'`
102
103case $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 ;;
106esac
107
108missingcacoruns=(`cat $filesondisklogpath/findcacofiles-$date.txt`)
109for missingcacorun in ${missingcacoruns[@]}
110do
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
147done
148
149
150echo "checking disk for rawfiles..." >> $scriptlog 2>&1
151filename=$filesondisklogpath/rawfilesondisk-$datetime.txt
152column=fRawFileAvail
153find $datapath -name '*.raw' -o -name '*.gz' | cut -d_ -f2 > $filename
154
155echo "resetting runs..." >> $scriptlog 2>&1
156check4=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $filesondisklogpath/resetall-$column-$datetime.log | grep int | sed -e 's/(int)//'`
157
158case $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 ;;
161esac
162
163finish >> $scriptlog 2>&1
164
165
Note: See TracBrowser for help on using the repository browser.