source: trunk/MagicSoft/Mars/datacenter/scripts/fillcamera@ 9217

Last change on this file since 9217 was 9217, checked in by hoehne, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.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): Daniel Hoehne 06/2008 <mailto:hoehne@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2008
23#
24#
25# ========================================================================
26#
27# This script launches the inserting of mc parameters into the db by
28# starting fillcamera.C
29#
30
31source `dirname $0`/sourcefile
32printprocesslog "INFO starting $0"
33program=fillcamera
34
35set -C
36
37scriptlog=$runlogpath/$program-$datetime.log
38date >> $scriptlog 2>&1
39
40# check if script is already running
41lockfile=$lockpath/lock-$program.txt
42checklock >> $scriptlog 2>&1
43
44getdbsetup
45
46#mccampath=$mcpath/camera
47mccampath=/magic/montecarlo/camera
48#workaround
49cameradirs=`find /magic/montecarlo/camera -maxdepth 4 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton ! -name Spot_?.?`
50echo "camera dirs: "${cameradirs[@]} >> $scriptlog 2>&1
51echo "" >> $scriptlog 2>&1
52
53cd $mars
54
55# process directories
56for cameradir in ${cameradirs[@]}
57do
58 printprocesslog "INFO inserting information for all root camera files in $cameradir"
59 cam=`basename $cameradir`
60 spot=`echo $cameradir | cut -d/ -f7` #spotsize
61 par=`echo $cameradir | cut -d/ -f6` #particle name
62 if [ $cam = "Cal_and_Ped" ]
63 then
64 par=""
65 spot=""
66 fi
67 epo=`echo $cameradir | cut -d/ -f5` #epoch
68 echo "dir: "$cameradir >> $scriptlog 2>&1
69 fillcamerapath=$logpath/$program
70 makedir $fillcamerapath >> $scriptlog 2>&1
71 fillcameralog=$fillcamerapath/$program-$epo-$par-$spot-$cam.log
72
73 check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kFALSE\) | tee $fillcameralog | intgrep`
74# check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kTRUE\) | tee $fillcameralog | intgrep`
75 case $check0 in
76 1) echo "check0=$check0 -> everything ok " >> $scriptlog 2>&1
77 printprocesslog "INFO fillcamera run successfully for dir $cameradir"
78 ;;
79 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
80 printprocesslog "WARN connection to DB failed"
81 check="no"
82 ;;
83 *) echo "check0=$check0 -> ERROR " >> $scriptlog 2>&1
84 printprocesslog "ERROR $program.C failed for dir $cameradir"
85 ;;
86 esac
87
88 printprocesslog "INFO linking cal and ped files"
89 echo "linking cal and ped files" >> $scriptlog 2>&1
90
91 if [ $cam = "Cal_and_Ped" ];
92 then
93 echo "Cal_and_Ped folder, no cal and ped files will be linked" >> $scriptlog 2>&1
94 else
95
96 epo=`echo $cameradir | cut -d/ -f5` #filename
97 #epo=`basename $cameradir` #filename
98 pedfile=`find $mccampath/$epo/Cal_and_Ped -name *_P_*.root`
99 calfile=`find $mccampath/$epo/Cal_and_Ped -name *_C_*.root`
100
101 echo "calfile for epoch $epo : " $calfile >> $scriptlog 2>&1
102 echo "pedfile for epoch $epo : " $pedfile >> $scriptlog 2>&1
103
104 #check number of files
105 numfiles=`echo $pedfile $calfile | wc -w`
106
107 if [ "$numfiles" != "2" ]
108 then
109 echo "too many or too less files in the directory $epo/Cal_and_Ped -> exit" >> $scriptlog 2>&1
110 rm -v $lockfile >> $scriptlog 2>&1
111 exit
112 printprocesslog "ERROR too many ped and cal files found in $epo/Cal_and_Ped"
113 finish >> $scriptlog 2>&1
114 fi
115
116
117 cquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$calfile\" "
118 pquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$pedfile\" "
119
120 crun=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $cquery "`
121 prun=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $pquery "`
122 cnum=`printf %08d $crun`
123 pnum=`printf %08d $prun`
124 echo "calrun number: " $cnum >> $scriptlog 2>&1
125 echo "pedrun number: " $pnum >> $scriptlog 2>&1
126 #get all directories in the linked structure for the epoch
127 #dirs=`find $mcrawpath/ -mindepth 3 -maxdepth 3 -type d`
128 files=`find $mcrawpath/ -lname *$epo*.root`
129
130 for file in ${files[@]}
131 do
132 dir=`dirname $file`
133 #datacenter
134 date=`echo $file | cut -c 28-31,33,34,36,37`
135 #for tests
136 #date=`echo $file | cut -c 57-60,62,63,65,66`
137
138 newpedfile="${dir}/${date}_${pnum}_P_MonteCarlo_E.root"
139 newcalfile="${dir}/${date}_${cnum}_C_MonteCarlo_E.root"
140 pupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newpedfile\" where fRunNumber=\"$prun\" "
141 cupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newcalfile\" where fRunNumber=\"$crun\" "
142 if ls $dir | grep MonteCarlo | grep $pnum
143 then
144 echo "P run already there, do mysql update" >> $scriptlog 2>&1
145 # continue
146 mysql -ss -u $us --password=$pw --host=$ho $db -e " $pupdate "
147 else
148 echo "linking P run for epoch $epo" >> $scriptlog 2>&1
149 ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
150 mysql -ss -u $us --password=$pw --host=$ho $db -e " $pupdate "
151 fi
152
153 if ls $dir | grep MonteCarlo | grep $cnum
154 then
155 echo "C run already there, do mysql update" >> $scriptlog 2>&1
156 # continue
157 mysql -ss -u $us --password=$pw --host=$ho $db -e " $cupdate "
158 else
159 echo "linking C run for epoch $epo" >> $scriptlog 2>&1
160 ln -sv $calfile $newcalfile >> $scriptlog 2>&1
161 mysql -ss -u $us --password=$pw --host=$ho $db -e " $cupdate "
162 fi
163
164 done
165
166 fi
167
168done
169
170readme=$mcrawpath/README.txt #file in which the information about the properties of the files is redirected to have always an updated explanation
171
172# observation epochs
173epochs=("" "After January 07 (MUX FADCs)," "From April 06 to January 07 (Siegen FADCs with splitters)," "Before April 06 (Siegen FADCs)")
174
175# print information and explanation of structure into README.txt
176date >| $readme 2>&1
177echo "" >> $readme 2>&1
178echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
179echo "--------------------------------------------------------------" >> $readme 2>&1
180echo "" >> $readme 2>&1
181echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
182echo "YYYY represents 19zbin" >> $readme 2>&1
183echo "MM represents the epoch" >> $readme 2>&1
184echo "DD represents the additional spot size in mm" >> $readme 2>&1
185echo "" >> $readme 2>&1
186echo "explanation of the epochs" >> $readme 2>&1
187echo "epochs: "${epochs[@]} >> $readme 2>&1
188echo "" >> $readme 2>&1
189for (( i=1 ; i <= 3 ; i++ ))
190do
191 if [ "${epochs[i]}" != "" ]
192 then
193 numofepoch=`printf %02d $i`
194 echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1
195 fi
196done
197echo "" >> $readme 2>&1
198echo "the epoch is indicating " >> $readme 2>&1
199echo " - the time for which the MCs are produced" >> $readme 2>&1
200echo " the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1
201echo "" >> $readme 2>&1
202echo "----------------" >> $readme 2>&1
203echo "" >> $readme 2>&1
204echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1
205echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD_<RunNumber>_<P/C/D>_<Particle><Spectrum><ObservationMode>_E.root" >> $readme 2>&1
206echo "<P/C/D> indicates the run type" >> $readme 2>&1
207echo "<Particle>: Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1
208echo "<Spectrum>: 'empty' or HE, depending on the simulated MC spectrum" >> $readme 2>&1
209echo "<ObservationMode>: 'empty' (On), W1/W2 (Wobble), FW (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
210echo "" >> $readme 2>&1
211
212
213finish >> $scriptlog 2>&1
214
Note: See TracBrowser for help on using the repository browser.