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

Last change on this file since 8758 was 8758, checked in by hoehne, 17 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 10.3 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 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
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
44#mccampath=$mcpath/camera
45mccampath=/magic/montecarlo/camera
46cameradirs=`find $mccampath -maxdepth 1 -mindepth 1 -type d`
47echo "camera dirs: "${cameradirs[@]} >> $scriptlog 2>&1
48echo "" >> $scriptlog 2>&1
49
50cd $mars
51
52# process directories
53for cameradir in ${cameradirs[@]}
54do
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
220done
221
222readme=$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
225epochs=("" "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
228date >| $readme 2>&1
229echo "" >> $readme 2>&1
230echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
231echo "--------------------------------------------------------------" >> $readme 2>&1
232echo "" >> $readme 2>&1
233echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
234echo "YYYY represents 19zbin" >> $readme 2>&1
235echo "MM represents the epoch" >> $readme 2>&1
236echo "DD represents the psf in mm" >> $readme 2>&1
237echo "" >> $readme 2>&1
238echo "explanation of the epochs" >> $readme 2>&1
239echo "epochs: "${epochs[@]} >> $readme 2>&1
240echo "" >> $readme 2>&1
241for (( i=1 ; i <= 3 ; i++ ))
242do
243 if [ "${epochs[i]}" != "" ]
244 then
245 numofepoch=`printf %02d $i`
246 echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1
247 fi
248done
249echo "" >> $readme 2>&1
250echo "the epoch is indicating " >> $readme 2>&1
251echo " - the time for which the MCs are produced" >> $readme 2>&1
252echo " the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1
253echo "" >> $readme 2>&1
254echo "----------------" >> $readme 2>&1
255echo "" >> $readme 2>&1
256echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1
257echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD_<RunNumber>_<P/C/D>_<Particle><Spectrum><ObservationMode>_E.root" >> $readme 2>&1
258echo "<P/C/D> indicates the run type" >> $readme 2>&1
259echo "<Particle>: Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1
260echo "<Spectrum>: empty or HE, depending on the simulated MC spectrum" >> $readme 2>&1
261echo "<ObservationMode>: empty (On), W1/W2 (Wobble), FW1/FW2 (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
262echo "" >> $readme 2>&1
263echo "Run numbers for Cal and Ped files are linked depending on the epoch:" >> $readme 2>&1
264echo "MC_old: P=1, C=2" >> $readme 2>&1
265echo "MC_up_to_April06: P=1, C=2" >> $readme 2>&1
266echo "MC_April_May06: P=3, C=4" >> $readme 2>&1
267echo "MC_post_June06: P=3, C=4" >> $readme 2>&1
268echo "MC_MuxFADCs: P=5, C=6" >> $readme 2>&1
269echo "MC_MuxFADCs_NEW: P=5, C=6" >> $readme 2>&1
270echo "" >> $readme 2>&1
271
272
273finish >> $scriptlog 2>&1
274
Note: See TracBrowser for help on using the repository browser.