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 |
|
---|
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 | getdbsetup
|
---|
45 |
|
---|
46 | #mccampath=$mcpath/camera
|
---|
47 | mccampath=/magic/montecarlo/camera
|
---|
48 | #workaround
|
---|
49 | cameradirs=`find /magic/montecarlo/camera -maxdepth 4 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton ! -name Spot_?.?`
|
---|
50 | echo "camera dirs: "${cameradirs[@]} >> $scriptlog 2>&1
|
---|
51 | echo "" >> $scriptlog 2>&1
|
---|
52 |
|
---|
53 | cd $mars
|
---|
54 |
|
---|
55 | # process directories
|
---|
56 | for cameradir in ${cameradirs[@]}
|
---|
57 | do
|
---|
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 |
|
---|
168 | done
|
---|
169 |
|
---|
170 | readme=$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
|
---|
173 | epochs=("" "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
|
---|
176 | date >| $readme 2>&1
|
---|
177 | echo "" >> $readme 2>&1
|
---|
178 | echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
|
---|
179 | echo "--------------------------------------------------------------" >> $readme 2>&1
|
---|
180 | echo "" >> $readme 2>&1
|
---|
181 | echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
|
---|
182 | echo "YYYY represents 19zbin" >> $readme 2>&1
|
---|
183 | echo "MM represents the epoch" >> $readme 2>&1
|
---|
184 | echo "DD represents the additional spot size in mm" >> $readme 2>&1
|
---|
185 | echo "" >> $readme 2>&1
|
---|
186 | echo "explanation of the epochs" >> $readme 2>&1
|
---|
187 | echo "epochs: "${epochs[@]} >> $readme 2>&1
|
---|
188 | echo "" >> $readme 2>&1
|
---|
189 | for (( i=1 ; i <= 3 ; i++ ))
|
---|
190 | do
|
---|
191 | if [ "${epochs[i]}" != "" ]
|
---|
192 | then
|
---|
193 | numofepoch=`printf %02d $i`
|
---|
194 | echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1
|
---|
195 | fi
|
---|
196 | done
|
---|
197 | echo "" >> $readme 2>&1
|
---|
198 | echo "the epoch is indicating " >> $readme 2>&1
|
---|
199 | echo " - the time for which the MCs are produced" >> $readme 2>&1
|
---|
200 | echo " the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1
|
---|
201 | echo "" >> $readme 2>&1
|
---|
202 | echo "----------------" >> $readme 2>&1
|
---|
203 | echo "" >> $readme 2>&1
|
---|
204 | echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1
|
---|
205 | echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD_<RunNumber>_<P/C/D>_<Particle><Spectrum><ObservationMode>_E.root" >> $readme 2>&1
|
---|
206 | echo "<P/C/D> indicates the run type" >> $readme 2>&1
|
---|
207 | echo "<Particle>: Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1
|
---|
208 | echo "<Spectrum>: 'empty' or HE, depending on the simulated MC spectrum" >> $readme 2>&1
|
---|
209 | echo "<ObservationMode>: 'empty' (On), W1/W2 (Wobble), FW (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
|
---|
210 | echo "" >> $readme 2>&1
|
---|
211 |
|
---|
212 |
|
---|
213 | finish >> $scriptlog 2>&1
|
---|
214 |
|
---|