source: trunk/MagicSoft/Mars/datacenter/macros/fillstar.C@ 7019

Last change on this file since 7019 was 7019, checked in by Daniela Dorner, 20 years ago
*** empty log message ***
File size: 4.8 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, 05/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Daniela Dorner, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2005
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// fillstar.C
29// ==========
30//
31// This macro is used to read the star-output files.
32// These files are automatically called star00000.root.
33//
34// Make sure, that database and password are corretly set in a resource
35// file called sql.rc and the resource file is found.
36//
37// Returns 0 in case of failure and 1 in case of success.
38//
39/////////////////////////////////////////////////////////////////////////////
40#include <iostream>
41
42#include <TEnv.h>
43#include <TRegexp.h>
44
45#include <TH1.h>
46#include <TProfile.h>
47#include <TFile.h>
48#include <TSQLResult.h>
49#include <TSQLRow.h>
50
51#include "MSQLServer.h"
52
53#include "MStatusArray.h"
54#include "MGeomCamMagic.h"
55#include "MBadPixelsCam.h"
56
57using namespace std;
58
59// --------------------------------------------------------------------------
60//
61// Checks whether an entry is already existing
62//
63Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
64{
65 TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
66 TSQLResult *res = serv.Query(query);
67 if (!res)
68 return kFALSE;
69
70 TSQLRow *row;
71
72 Bool_t rc = kFALSE;
73 while ((row=res->Next()))
74 {
75 if ((*row)[0])
76 {
77 rc = kTRUE;
78 break;
79 }
80 }
81
82 delete res;
83
84 return rc;
85}
86
87
88int Process(MSQLServer &serv, TString fname, Bool_t dummy)
89{
90 TFile file(fname, "READ");
91
92 MStatusArray arr;
93 if (arr.Read()<=0)
94 {
95 cout << "ERROR - Reading of MStatusDisplay failed." << endl;
96 return 0;
97 }
98
99 TProfile *h1 = (TProfile*)arr.FindObjectInCanvas("RingBroadening", "TProfile", "MHMuonPar");
100 if (!h1)
101 {
102 cout << "WARNING - Reading of RingBroadening failed." << endl;
103 return 0;
104 }
105
106 Float_t psf = (h1->Integral(5, 14) - 0.837)/0.0252;
107 psf = TMath::Nint(psf*10)/10.;
108 TString PSF = Form("%5.1f", psf);
109
110 TH1 *h = (TH1*)arr.FindObjectInCanvas("Islands", "TH1F", "MHImagePar");
111 if (!h)
112 {
113 cout << "WARNING - Reading of Islands failed." << endl;
114 return 0;
115 }
116
117 Float_t quality = h->GetMean();
118 quality = TMath::Nint(quality*10)/10.;
119 TString islands = Form("%5.1f", quality);
120
121 TString sequence = fname(TRegexp("star[0-9]+[.]root$"));
122 if (sequence.IsNull())
123 {
124 cout << "WARNING - Could get sequence# from filename: " << fname << endl;
125 return 0;
126 }
127
128 Int_t seq = atoi(sequence.Data()+5);
129
130 cout << "Sequence #" << seq << endl;
131 cout << " PSF [mm] " << Form("%5.1f", psf) << endl;
132 cout << " Island Quality " << Form("%5.1f", quality) << endl;
133
134 TString query;
135 if (!ExistStr(serv, "fSequenceFirst", "MyMagic.Star", seq))
136 {
137 query = Form("INSERT MyMagic.Star SET"
138 " fSequenceFirst=%d,"
139 " fMeanNumberIslands=%s, "
140 " fPSF=%s ",
141 seq, islands.Data(), PSF.Data());
142 }
143 else
144 {
145 query = Form("UPDATE MyMagic.Star SET"
146 " fMeanNumberIslands=%s, "
147 " fPSF=%s "
148 " WHERE fSequenceFirst=%d ",
149 islands.Data(), PSF.Data(), seq);
150 }
151
152 if (dummy)
153 return 0;
154
155 TSQLResult *res = serv.Query(query);
156 if (!res)
157 {
158 cout << "ERROR - Query failed: " << query << endl;
159 return 0;
160 }
161
162 return 1;
163}
164
165int fillstar(TString fname, Bool_t dummy=kTRUE)
166{
167 TEnv env("sql.rc");
168
169 MSQLServer serv(env);
170 if (!serv.IsConnected())
171 {
172 cout << "ERROR - Connection to database failed." << endl;
173 return 0;
174 }
175
176 cout << "fillstar" << endl;
177 cout << "---------" << endl;
178 cout << endl;
179 cout << "Connected to " << serv.GetName() << endl;
180 cout << "File: " << fname << endl;
181 cout << endl;
182
183 return Process(serv, fname, dummy);
184}
Note: See TracBrowser for help on using the repository browser.