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

Last change on this file since 9154 was 9147, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 8.5 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
44#mccampath=$mcpath/camera
45mccampath=/magic/montecarlo/camera
46#workaround
47cameradirs=`find /magic/montecarlo/camera -maxdepth 4 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton ! -name Spot_?.?`
48#cameradirs=`find /magic/montecarlo/camera -maxdepth 3 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton`
49#cameradirs=`find $mccampath -maxdepth 1 -mindepth 1 -type d`
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 # user="test"
118 # db="TestMonteCarlo"
119 # pw="Ics+eaTD"
120 user="operator"
121 db="MyMagicMonteCarlo"
122 pw="Ics+eMM!"
123 cquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$calfile\" "
124 pquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$pedfile\" "
125
126 crun=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $cquery "`
127 prun=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $pquery "`
128 cnum=`printf %08d $crun`
129 pnum=`printf %08d $prun`
130 echo "calrun number: " $cnum >> $scriptlog 2>&1
131 echo "pedrun number: " $pnum >> $scriptlog 2>&1
132 #get all directories in the linked structure for the epoch
133 #dirs=`find $mcrawpath/ -mindepth 3 -maxdepth 3 -type d`
134 files=`find $mcrawpath/ -lname *$epo*.root`
135
136 for file in ${files[@]}
137 do
138 dir=`dirname $file`
139 #datacenter
140 date=`echo $file | cut -c 28-31,33,34,36,37`
141 #for tests
142 #date=`echo $file | cut -c 57-60,62,63,65,66`
143
144 newpedfile="${dir}/${date}_${pnum}_P_MonteCarlo_E.root"
145 newcalfile="${dir}/${date}_${cnum}_C_MonteCarlo_E.root"
146 pupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newpedfile\" where fRunNumber=\"$prun\" "
147 cupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newcalfile\" where fRunNumber=\"$crun\" "
148 if ls $dir | grep MonteCarlo | grep $pnum
149 then
150 echo "P run already there, do mysql update" >> $scriptlog 2>&1
151 # continue
152 mysql -ss -u $user --password=$pw --host=$ho $db -e " $pupdate "
153 else
154 echo "linking P run for epoch $epo" >> $scriptlog 2>&1
155 ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
156 mysql -ss -u $user --password=$pw --host=$ho $db -e " $pupdate "
157 fi
158
159 if ls $dir | grep MonteCarlo | grep $cnum
160 then
161 echo "C run already there, do mysql update" >> $scriptlog 2>&1
162 # continue
163 mysql -ss -u $user --password=$pw --host=$ho $db -e " $cupdate "
164 else
165 echo "linking C run for epoch $epo" >> $scriptlog 2>&1
166 ln -sv $calfile $newcalfile >> $scriptlog 2>&1
167 mysql -ss -u $user --password=$pw --host=$ho $db -e " $cupdate "
168 fi
169
170 done
171
172 fi
173
174done
175
176readme=$mcrawpath/README.txt #file in which the information about the properties of the files is redirected to have always an updated explanation
177
178# observation epochs
179epochs=("" "After January 07 (MUX FADCs)," "From April 06 to January 07 (Siegen FADCs with splitters)," "Before April 06 (Siegen FADCs)")
180
181# print information and explanation of structure into README.txt
182date >| $readme 2>&1
183echo "" >> $readme 2>&1
184echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
185echo "--------------------------------------------------------------" >> $readme 2>&1
186echo "" >> $readme 2>&1
187echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
188echo "YYYY represents 19zbin" >> $readme 2>&1
189echo "MM represents the epoch" >> $readme 2>&1
190echo "DD represents the additional spot size in mm" >> $readme 2>&1
191echo "" >> $readme 2>&1
192echo "explanation of the epochs" >> $readme 2>&1
193echo "epochs: "${epochs[@]} >> $readme 2>&1
194echo "" >> $readme 2>&1
195for (( i=1 ; i <= 3 ; i++ ))
196do
197 if [ "${epochs[i]}" != "" ]
198 then
199 numofepoch=`printf %02d $i`
200 echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1
201 fi
202done
203echo "" >> $readme 2>&1
204echo "the epoch is indicating " >> $readme 2>&1
205echo " - the time for which the MCs are produced" >> $readme 2>&1
206echo " the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1
207echo "" >> $readme 2>&1
208echo "----------------" >> $readme 2>&1
209echo "" >> $readme 2>&1
210echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1
211echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD_<RunNumber>_<P/C/D>_<Particle><Spectrum><ObservationMode>_E.root" >> $readme 2>&1
212echo "<P/C/D> indicates the run type" >> $readme 2>&1
213echo "<Particle>: Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1
214echo "<Spectrum>: 'empty' or HE, depending on the simulated MC spectrum" >> $readme 2>&1
215echo "<ObservationMode>: 'empty' (On), W1/W2 (Wobble), FW (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
216echo "" >> $readme 2>&1
217
218
219finish >> $scriptlog 2>&1
220
Note: See TracBrowser for help on using the repository browser.