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

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