source: trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C@ 6940

Last change on this file since 6940 was 6933, checked in by Daniela Dorner, 20 years ago
*** empty log message ***
File size: 4.6 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, 04/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Daniela Dorner, 04/2005 <mailto:dorner@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// fillsignal.C
29// ============
30//
31// This macro is used to read the calibration-/callisto-output files
32// signal00000.root.
33//
34// From this file the Mean PedRms for the inner and outer camera is extracted.
35//
36// Usage:
37// .x fillsignal.C("/data/MAGIC/Period014/signal00000.root", kTRUE)
38//
39// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
40// switched on and nothing will be written into the database. This is usefull
41// for tests.
42//
43// The macro can also be run without ACLiC but this is a lot slower...
44//
45// Remark: Running it from the commandline looks like this:
46// root -q -l -b fillsignal.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillsignal.log
47//
48// Make sure, that database and password are corretly set in a resource
49// file called sql.rc and the resource file is found.
50//
51// Returns 0 in case of failure and 1 in case of success.
52//
53/////////////////////////////////////////////////////////////////////////////
54#include <iostream>
55
56#include <TEnv.h>
57#include <TRegexp.h>
58
59#include <TFile.h>
60#include <TSQLResult.h>
61
62#include "MSQLServer.h"
63
64#include "MStatusArray.h"
65#include "MHCamera.h"
66
67using namespace std;
68
69int Process(MSQLServer &serv, TString fname, Bool_t dummy)
70{
71 TFile file(fname, "READ");
72 MStatusArray *arr = (MStatusArray*)file.Get("MStatusDisplay");
73 if (!arr)
74 {
75 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
76 return 0;
77 }
78
79 MHCamera *cam = (MHCamera*)arr->FindObjectInCanvas("PedRMS;avg", "MHCamera", "PedRMS");
80 if (!cam)
81 {
82 cout << "WARNING - Reading of PedRMS;avg failed." << endl;
83 return 0;
84 }
85
86 TArrayI inner(1);
87 inner[0] = 0;
88
89 TArrayI outer(1);
90 outer[0] = 1;
91
92 Int_t s0[] = { 1, 2, 3, 4, 5, 6 };
93
94 Stat_t meani = cam->GetMeanSectors(TArrayI(6, s0), inner);
95 Stat_t meano = cam->GetMeanSectors(TArrayI(6, s0), outer);
96
97 if (meani<0 || meano<0)
98 {
99 cout << "WARNING - MeanPedRMS inner or outer < 0 " << endl;
100 cout << "MeanPedRMS inner " << meani << endl;
101 cout << "MeanPedRMS outer " << meano << endl;
102 return 0;
103 }
104
105 meani = TMath::Nint(meani*10)/10.;
106 meano = TMath::Nint(meano*10)/10.;
107
108 TString sequence = fname(TRegexp("signal[0-9]+[.]root$"));
109 if (sequence.IsNull())
110 {
111 cout << "WARNING - Sequ# empty" << endl;
112 cout << "Sequ# " << sequence << endl;
113 return 0;
114 }
115
116 Int_t seq = atoi(sequence.Data()+6);
117 TString meaninner=Form("%4.1f", meani);
118 TString meanouter=Form("%4.1f", meano);
119
120 cout << "Sequence #" << seq << endl;
121 cout << " Mean Ped RMS inner [phe] " << Form("%4.1f", meani) << endl; // Unbrauchbar
122 cout << " Mean Ped RMS outer [phe] " << Form("%4.1f", meano) << endl; // Unbrauchbar
123
124 TString query = Form("UPDATE MyMagic.Calibration SET fMeanPedRmsInner=%s, "
125 " fMeanPedRmsOuter=%s WHERE fSequenceFirst='%d' ",
126 meaninner.Data(), meanouter.Data(), seq);
127
128 if (dummy)
129 return 0;
130
131 TSQLResult *res = serv.Query(query);
132 if (!res)
133 {
134 cout << "ERROR - Query failed: " << query << endl;
135 return 0;
136 }
137
138 return 1;
139}
140
141int fillsignal(TString fname, Bool_t dummy=kTRUE)
142{
143 TEnv env("sql.rc");
144
145 MSQLServer serv(env);
146 if (!serv.IsConnected())
147 {
148 cout << "ERROR - Connection to database failed." << endl;
149 return 0;
150 }
151
152 cout << "fillsignal" << endl;
153 cout << "----------" << endl;
154 cout << endl;
155 cout << "Connected to " << serv.GetName() << endl;
156 cout << "File: " << fname << endl;
157 cout << endl;
158
159 return Process(serv, fname, dummy);
160}
Note: See TracBrowser for help on using the repository browser.