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

Last change on this file since 9135 was 8759, checked in by hoehne, 17 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.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 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 28-31,33,34,36,37`
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
142done
143
144readme=$mcrawpath/README.txt #file in which the information about the properties of the files is redirected to have always an updated explanation
145
146# observation epochs
147epochs=("" "After January 07 (new MUX)," "From April 06 to January 07," "Before April 06")
148
149# print information and explanation of structure into README.txt
150date >| $readme 2>&1
151echo "" >> $readme 2>&1
152echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
153echo "--------------------------------------------------------------" >> $readme 2>&1
154echo "" >> $readme 2>&1
155echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
156echo "YYYY represents 19zbin" >> $readme 2>&1
157echo "MM represents the epoch" >> $readme 2>&1
158echo "DD represents the psf in mm" >> $readme 2>&1
159echo "" >> $readme 2>&1
160echo "explanation of the epochs" >> $readme 2>&1
161echo "epochs: "${epochs[@]} >> $readme 2>&1
162echo "" >> $readme 2>&1
163for (( i=1 ; i <= 3 ; i++ ))
164do
165 if [ "${epochs[i]}" != "" ]
166 then
167 numofepoch=`printf %02d $i`
168 echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1
169 fi
170done
171echo "" >> $readme 2>&1
172echo "the epoch is indicating " >> $readme 2>&1
173echo " - the time for which the MCs are produced" >> $readme 2>&1
174echo " the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1
175echo "" >> $readme 2>&1
176echo "----------------" >> $readme 2>&1
177echo "" >> $readme 2>&1
178echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1
179echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD_<RunNumber>_<P/C/D>_<Particle><Spectrum><ObservationMode>_E.root" >> $readme 2>&1
180echo "<P/C/D> indicates the run type" >> $readme 2>&1
181echo "<Particle>: Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1
182echo "<Spectrum>: empty or HE, depending on the simulated MC spectrum" >> $readme 2>&1
183echo "<ObservationMode>: empty (On), W1/W2 (Wobble), FW1/FW2 (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
184echo "" >> $readme 2>&1
185echo "Run numbers for Cal and Ped files are linked depending on the epoch:" >> $readme 2>&1
186echo "MC_old: P=1, C=2" >> $readme 2>&1
187echo "MC_up_to_April06: P=1, C=2" >> $readme 2>&1
188echo "MC_April_May06: P=3, C=4" >> $readme 2>&1
189echo "MC_post_June06: P=3, C=4" >> $readme 2>&1
190echo "MC_MuxFADCs: P=5, C=6" >> $readme 2>&1
191echo "MC_MuxFADCs_NEW: P=5, C=6" >> $readme 2>&1
192echo "" >> $readme 2>&1
193
194
195finish >> $scriptlog 2>&1
196
Note: See TracBrowser for help on using the repository browser.