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 09/2007 <mailto:hoehne@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2007
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This script launches the inserting of mc parameters into the db by
|
---|
28 | # starting fillcamera.C
|
---|
29 | #
|
---|
30 |
|
---|
31 | source `dirname $0`/sourcefile
|
---|
32 | printprocesslog "INFO starting $0"
|
---|
33 | program=fillcamera
|
---|
34 |
|
---|
35 | set -C
|
---|
36 |
|
---|
37 | scriptlog=$runlogpath/$program-$datetime.log
|
---|
38 | date >> $scriptlog 2>&1
|
---|
39 |
|
---|
40 | # check if script is already running
|
---|
41 | lockfile=$lockpath/lock-$program.txt
|
---|
42 | checklock >> $scriptlog 2>&1
|
---|
43 |
|
---|
44 | #mccampath=$mcpath/camera
|
---|
45 | mccampath=/magic/montecarlo/camera
|
---|
46 | cameradirs=`find $mccampath -maxdepth 1 -mindepth 1 -type d`
|
---|
47 | echo "camera dirs: "${cameradirs[@]} >> $scriptlog 2>&1
|
---|
48 | echo "" >> $scriptlog 2>&1
|
---|
49 |
|
---|
50 | cd $mars
|
---|
51 |
|
---|
52 | # process directories
|
---|
53 | for cameradir in ${cameradirs[@]}
|
---|
54 | do
|
---|
55 | printprocesslog "INFO inserting information for all root camera files in $cameradir"
|
---|
56 | cam=`basename $cameradir`
|
---|
57 | echo "dir: "$cameradir >> $scriptlog 2>&1
|
---|
58 | fillcamerapath=$logpath/$program
|
---|
59 | makedir $fillcamerapath >> $scriptlog 2>&1
|
---|
60 | fillcameralog=$fillcamerapath/$program-$cam.log
|
---|
61 |
|
---|
62 | check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kFALSE\) | tee $fillcameralog | intgrep`
|
---|
63 | case $check0 in
|
---|
64 | 1) echo "check0=$check0 -> everything ok " >> $scriptlog 2>&1
|
---|
65 | printprocesslog "INFO fillcamera run successfully for dir $cameradir"
|
---|
66 | ;;
|
---|
67 | 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
|
---|
68 | printprocesslog "WARN connection to DB failed"
|
---|
69 | check="no"
|
---|
70 | ;;
|
---|
71 | *) echo "check0=$check0 -> ERROR " >> $scriptlog 2>&1
|
---|
72 | printprocesslog "ERROR $program.C failed for dir $cameradir"
|
---|
73 | ;;
|
---|
74 | esac
|
---|
75 |
|
---|
76 | printprocesslog "INFO linking cal and ped files"
|
---|
77 | echo "linking cal and ped files" >> $scriptlog 2>&1
|
---|
78 |
|
---|
79 | epo=`basename $cameradir` #filename
|
---|
80 | pedfile=`find $cameradir/Cal_and_Ped -name *_P_*.root`
|
---|
81 | calfile=`find $cameradir/Cal_and_Ped -name *_C_*.root`
|
---|
82 |
|
---|
83 | echo "calfile for epoch $epo : " $calfile >> $scriptlog 2>&1
|
---|
84 | echo "pedfile for epoch $epo : " $pedfile >> $scriptlog 2>&1
|
---|
85 |
|
---|
86 | #check number of files
|
---|
87 | numfiles=`echo $pedfile $calfile | wc -w`
|
---|
88 |
|
---|
89 | if [ "$numfiles" != "2" ]
|
---|
90 | then
|
---|
91 | echo "too many files in the directory $epoch/Cal_and_Ped -> exit" >> $scriptlog 2>&1
|
---|
92 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
93 | exit
|
---|
94 | printprocesslog "ERROR too many ped and cal files found in $epoch/Cal_and_Ped"
|
---|
95 | finish >> $scriptlog 2>&1
|
---|
96 | fi
|
---|
97 |
|
---|
98 |
|
---|
99 | user="test"
|
---|
100 | db="TestMonteCarlo"
|
---|
101 | pw="Ics+eaTD"
|
---|
102 | cquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$calfile\" "
|
---|
103 | pquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$pedfile\" "
|
---|
104 |
|
---|
105 | crun=`mysql -ss -u $user --password=$pw --host=vela $db -e " $cquery "`
|
---|
106 | prun=`mysql -ss -u $user --password=$pw --host=vela $db -e " $pquery "`
|
---|
107 | cnum=`printf %08d $crun`
|
---|
108 | pnum=`printf %08d $prun`
|
---|
109 | echo "calrun number: " $cnum >> $scriptlog 2>&1
|
---|
110 | echo "pedrun number: " $pnum >> $scriptlog 2>&1
|
---|
111 | #get all directories in the linked structure for the epoch
|
---|
112 | # dirs=`find $mcrawpath/ -mindepth 3 -maxdepth 3 -type d`
|
---|
113 | files=`find $mcrawpath/ -lname *$epo*.root`
|
---|
114 |
|
---|
115 | for file in ${files[@]}
|
---|
116 | do
|
---|
117 | dir=`dirname $file`
|
---|
118 | date=`echo $file | cut -c 57-60,62,63,65,66`
|
---|
119 |
|
---|
120 | if ls $dir | grep MonteCarlo | grep $pnum
|
---|
121 | then
|
---|
122 | # echo "P run already there, do nothing" >> $scriptlog 2>&1
|
---|
123 | continue
|
---|
124 | else
|
---|
125 | echo "linking P run for epoch $epo" >> $scriptlog 2>&1
|
---|
126 | newpedfile="${dir}/${date}_${pnum}_P_MonteCarlo_E.root"
|
---|
127 | ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
128 | fi
|
---|
129 |
|
---|
130 | if ls $dir | grep MonteCarlo | grep $cnum
|
---|
131 | then
|
---|
132 | # echo "C run already there, do nothing" >> $scriptlog 2>&1
|
---|
133 | continue
|
---|
134 | else
|
---|
135 | echo "linking C run for epoch $epo" >> $scriptlog 2>&1
|
---|
136 | newcalfile="${dir}/${date}_${cnum}_C_MonteCarlo_E.root"
|
---|
137 | ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
138 | fi
|
---|
139 |
|
---|
140 | done
|
---|
141 |
|
---|
142 |
|
---|
143 | # for dir in ${dirs[@]}
|
---|
144 | # do
|
---|
145 |
|
---|
146 | # #continue, if directory has already linked C and P run
|
---|
147 | # cont=`ls $dir/*_0000000[1-9]_[CP]_MonteCarlo_E.root 2>/dev/null | wc -w`
|
---|
148 | # if [ "$cont" == "6" ] >> $scriptlog 2>&1
|
---|
149 | # then
|
---|
150 | # continue
|
---|
151 | # fi
|
---|
152 |
|
---|
153 | # #continue, if directory is not at the lowest level of the structure
|
---|
154 | # cont=`echo $dir | cut -d/ -f10`
|
---|
155 | # if [ "$cont" == "" ]
|
---|
156 | # then
|
---|
157 | # continue
|
---|
158 | # fi
|
---|
159 |
|
---|
160 | #get date for filename from directory name
|
---|
161 | # date=`echo $dir | cut -c 57-60,62,63,65,66`
|
---|
162 | # time=`echo $dir | cut -c 62,63`
|
---|
163 | # psf=`echo $dir | cut -c 65,66`
|
---|
164 | # date=`echo $dir | cut -c 28-31,33,34,36,37`
|
---|
165 |
|
---|
166 |
|
---|
167 | #create new filenames and link files depending on the epoch
|
---|
168 | # case "$epo" in
|
---|
169 | #
|
---|
170 | # "MC_up_to_April06")
|
---|
171 | # echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
|
---|
172 | # newcalfile="${dir}/${date}_00000002_C_MonteCarlo_E.root"
|
---|
173 | # ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
174 | # newpedfile="${dir}/${date}_00000001_P_MonteCarlo_E.root"
|
---|
175 | # ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
176 | # ;;
|
---|
177 | # "MC_old")
|
---|
178 | # echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
|
---|
179 | # newcalfile="${dir}/${date}_00000002_C_MonteCarlo_E.root"
|
---|
180 | # ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
181 | # newpedfile="${dir}/${date}_00000001_P_MonteCarlo_E.root"
|
---|
182 | # ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
183 | # ;;
|
---|
184 | # "MC_April_May06")
|
---|
185 | # echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
|
---|
186 | # newcalfile="${dir}/${date}_00000004_C_MonteCarlo_E.root"
|
---|
187 | # ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
188 | # newpedfile="${dir}/${date}_00000003_P_MonteCarlo_E.root"
|
---|
189 | # ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
190 | # ;;
|
---|
191 | # "MC_post_June06")
|
---|
192 | # echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
|
---|
193 | # newcalfile="${dir}/${date}_00000004_C_MonteCarlo_E.root"
|
---|
194 | # ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
195 | # newpedfile="${dir}/${date}_00000003_P_MonteCarlo_E.root"
|
---|
196 | # ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
197 | # ;;
|
---|
198 | # "MC_MuxFADCs")
|
---|
199 | # echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
|
---|
200 | # newcalfile="${dir}/${date}_00000006_C_MonteCarlo_E.root"
|
---|
201 | # ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
202 | # newpedfile="${dir}/${date}_00000005_P_MonteCarlo_E.root"
|
---|
203 | # ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
204 | # ;;
|
---|
205 | # "MC_MuxFADCs_NEW")
|
---|
206 | # echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
|
---|
207 | # newcalfile="${dir}/${date}_00000006_C_MonteCarlo_E.root"
|
---|
208 | # ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
209 | # newpedfile="${dir}/${date}_00000005_P_MonteCarlo_E.root"
|
---|
210 | # ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
211 | # ;;
|
---|
212 | # *)
|
---|
213 | # echo "No epoch found"
|
---|
214 | # printprocesslog "ERROR wrong epoch for linking Cal and Ped, epoch: $cameradir"
|
---|
215 | # finish >> $scriptlog 2>&1
|
---|
216 | # ;;
|
---|
217 | # esac
|
---|
218 |
|
---|
219 | # done
|
---|
220 | done
|
---|
221 |
|
---|
222 | readme=$mcrawpath/README.txt #file in which the information about the properties of the files is redirected to have always an updated explanation
|
---|
223 |
|
---|
224 | # observation epochs
|
---|
225 | epochs=("" "After January 07 (new MUX)," "From April 06 to January 07," "Before April 06")
|
---|
226 |
|
---|
227 | # print information and explanation of structure into README.txt
|
---|
228 | date >| $readme 2>&1
|
---|
229 | echo "" >> $readme 2>&1
|
---|
230 | echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
|
---|
231 | echo "--------------------------------------------------------------" >> $readme 2>&1
|
---|
232 | echo "" >> $readme 2>&1
|
---|
233 | echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
|
---|
234 | echo "YYYY represents 19zbin" >> $readme 2>&1
|
---|
235 | echo "MM represents the epoch" >> $readme 2>&1
|
---|
236 | echo "DD represents the psf in mm" >> $readme 2>&1
|
---|
237 | echo "" >> $readme 2>&1
|
---|
238 | echo "explanation of the epochs" >> $readme 2>&1
|
---|
239 | echo "epochs: "${epochs[@]} >> $readme 2>&1
|
---|
240 | echo "" >> $readme 2>&1
|
---|
241 | for (( i=1 ; i <= 3 ; i++ ))
|
---|
242 | do
|
---|
243 | if [ "${epochs[i]}" != "" ]
|
---|
244 | then
|
---|
245 | numofepoch=`printf %02d $i`
|
---|
246 | echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1
|
---|
247 | fi
|
---|
248 | done
|
---|
249 | echo "" >> $readme 2>&1
|
---|
250 | echo "the epoch is indicating " >> $readme 2>&1
|
---|
251 | echo " - the time for which the MCs are produced" >> $readme 2>&1
|
---|
252 | echo " the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1
|
---|
253 | echo "" >> $readme 2>&1
|
---|
254 | echo "----------------" >> $readme 2>&1
|
---|
255 | echo "" >> $readme 2>&1
|
---|
256 | echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1
|
---|
257 | echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD_<RunNumber>_<P/C/D>_<Particle><Spectrum><ObservationMode>_E.root" >> $readme 2>&1
|
---|
258 | echo "<P/C/D> indicates the run type" >> $readme 2>&1
|
---|
259 | echo "<Particle>: Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1
|
---|
260 | echo "<Spectrum>: empty or HE, depending on the simulated MC spectrum" >> $readme 2>&1
|
---|
261 | echo "<ObservationMode>: empty (On), W1/W2 (Wobble), FW1/FW2 (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
|
---|
262 | echo "" >> $readme 2>&1
|
---|
263 | echo "Run numbers for Cal and Ped files are linked depending on the epoch:" >> $readme 2>&1
|
---|
264 | echo "MC_old: P=1, C=2" >> $readme 2>&1
|
---|
265 | echo "MC_up_to_April06: P=1, C=2" >> $readme 2>&1
|
---|
266 | echo "MC_April_May06: P=3, C=4" >> $readme 2>&1
|
---|
267 | echo "MC_post_June06: P=3, C=4" >> $readme 2>&1
|
---|
268 | echo "MC_MuxFADCs: P=5, C=6" >> $readme 2>&1
|
---|
269 | echo "MC_MuxFADCs_NEW: P=5, C=6" >> $readme 2>&1
|
---|
270 | echo "" >> $readme 2>&1
|
---|
271 |
|
---|
272 |
|
---|
273 | finish >> $scriptlog 2>&1
|
---|
274 |
|
---|