source: trunk/MagicSoft/Mars/macros/sql/fillcalib.C@ 6549

Last change on this file since 6549 was 4879, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 5.7 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// fillcalib.C
29// ===========
30//
31// This macro is used to read the calibartion-/callisto-output files.
32// These files are automatically called calib00000.root.
33//
34// From this file the MBadPixelsCam and the MGeomCam is extracted. If
35// the geometry isn't found MGeomCamMagic is used as a default.
36//
37// Usage:
38// .x fillcalib.C("/data/MAGIC/Period014/calib00000.root", kTRUE)
39//
40// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
41// switched on and nothing will be written into the database. This is usefull
42// for tests.
43//
44// The corresponding sequence number is extracted from the filename...
45// FIXME: MSeqeuence should be stored in the calib-file?
46//
47// The macro can also be run without ACLiC but this is a lot slower...
48//
49// Remark: Running it from the commandline looks like this:
50// root -q -l -b fillcalib.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillcalib.log
51//
52// Make sure, that database and password are corretly set in a resource
53// file called sql.rc and the resource file is found.
54//
55// Returns 0 in case of failure and 1 in case of success.
56//
57/////////////////////////////////////////////////////////////////////////////
58#include <iostream>
59
60#include <TEnv.h>
61#include <TRegexp.h>
62
63#include <TFile.h>
64#include <TSQLResult.h>
65
66#include "MSQLServer.h"
67
68#include "MGeomCamMagic.h"
69#include "MBadPixelsCam.h"
70
71using namespace std;
72
73Bool_t Process(MSQLServer &serv, TString fname, Bool_t dummy)
74{
75 MBadPixelsCam badpix;
76
77 TFile file(fname, "READ");
78 if (badpix.Read("MBadPixelsCam")<=0)
79 {
80 cout << "ERROR - Reading of MBadPixelsCam failed." << endl;
81 return kFALSE;
82 }
83
84 MGeomCamMagic def;
85
86 MGeomCam *geom = (MGeomCam*)file.Get("MGeomCam");
87 if (!geom)
88 {
89 cout << "WARNING - Reading of MGeomCam failed... using default <MGeomCamMagic>" << endl;
90 geom = &def;
91 }
92
93 cout << "Camera Geometry: " << geom->ClassName() << endl;
94
95 const Short_t unsin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 0);
96 const Short_t unsout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnsuitableRun, geom, 1);
97
98 const Short_t unrin = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 0);
99 const Short_t unrout = badpix.GetNumUnsuitable(MBadPixelsPix::kUnreliableRun, geom, 1);
100
101 const Short_t isoin = badpix.GetNumIsolated(*geom, 0);
102 const Short_t isoout = badpix.GetNumIsolated(*geom, 1);
103
104 const Short_t clumax = badpix.GetNumMaxCluster(*geom);
105
106 if (unsin<0 || unsout<0 || unrin<0 || unrout<0 || isoin<0 || isoout<0 || clumax<0)
107 return kFALSE;
108
109 // MHCamera hist(geom);
110 // hist.SetCamContent(badpix, 1);
111 // hist.DrawCopy();
112 // hist.SetCamContent(badpix, 3);
113 // hist.DrawCopy();
114
115 TString sequence = fname(TRegexp("calib[0-9]+[.]root$"));
116 if (sequence.IsNull())
117 return kTRUE;
118
119 Int_t seq = atoi(sequence.Data()+5);
120
121 cout << "Sequence #" << seq << endl;
122 cout << " Unsuitable: (i/o) " << Form("%3d %3d", (int)unsin, (int)unsout) << endl; // Unbrauchbar
123 cout << " Unreliable: (i/o) " << Form("%3d %3d", (int)unrin, (int)unrout) << endl; // Unzuverlaessig
124 cout << " Isolated: (i/o) " << Form("%3d %3d", (int)isoin, (int)isoout) << endl; // Isolated (unbrauchbar)
125 cout << " Max.Cluseter: (i/o) " << Form("%3d", (int)clumax) << endl; // Max Cluster
126
127 if (dummy)
128 return kTRUE;
129
130 TString query = Form("INSERT MyMagic.Calibration SET"
131 " fSequenceFirst=%d,"
132 " fUnsuitableInner=%d, "
133 " fUnsuitableOuter=%d, "
134 " fUnreliableInner=%d, "
135 " fUnreliableOuter=%d, "
136 " fIsolatedInner=%d, "
137 " fIsolatedOuter=%d, "
138 " fIsolatedMaxCluster=%d",
139 seq, (int)unsin, (int)unsout, (int)unrin,
140 (int)unrout, (int)isoin, (int)isoout, (int)clumax);
141
142
143 TSQLResult *res = serv.Query(query);
144 if (!res)
145 {
146 cout << "ERROR - Query failed: " << query << endl;
147 return kFALSE;
148 }
149
150 return kTRUE;
151}
152
153void fillcallisto(TString fname, Bool_t dummy=kTRUE)
154{
155 TEnv env("sql.rc");
156
157 MSQLServer serv(env);
158 if (!serv.IsConnected())
159 {
160 cout << "ERROR - Connection to database failed." << endl;
161 return;
162 }
163
164 cout << "fillcalib" << endl;
165 cout << "---------" << endl;
166 cout << endl;
167 cout << "Connected to " << serv.GetName() << endl;
168 cout << "File: " << fname << endl;
169 cout << endl;
170
171 cout << (Process(serv, fname, dummy) ? "Done." : "failed!") << endl << endl;
172}
Note: See TracBrowser for help on using the repository browser.