source: branches/Corsika7500Compatibility/datacenter/macros/fillcmt.C@ 19940

Last change on this file since 19940 was 9284, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.4 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, 01/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2009
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// fillcmt.C
28// =========
29//
30// This macro is used to read an extinction file from the CMT and fill
31// its contents into the db.
32//
33// Usage:
34// .x fillcmt.C("camext.06", kTRUE)
35//
36// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
37// switched on and nothing will be written into the database. This is usefull
38// for tests.
39//
40// Filling the database is done with 'UPADTE' for _all_ columns
41// matching the date!
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 fillcmt.C+\(\"filename\"\,kFALSE\) 2>&1 | tee fillcmt.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 2 in case of failure, 1 in case of success and 0 if the connection
52// to the database is not working.
53//
54/////////////////////////////////////////////////////////////////////////////
55
56#include <fstream>
57#include <iostream>
58#include <errno.h>
59
60#include <TEnv.h>
61#include <TSystem.h>
62
63#include "MLog.h"
64#include "MLogManip.h"
65
66#include "MTime.h"
67#include "MSQLMagic.h"
68
69using namespace std;
70
71int fillcmt(TString fname, Bool_t dummy=kTRUE)
72{
73 TEnv env("sql.rc");
74
75 MSQLMagic serv(env);
76 if (!serv.IsConnected())
77 {
78 cout << "ERROR - Connection to database failed." << endl;
79 return 0;
80 }
81
82 serv.SetIsDummy(dummy);
83
84 gSystem->ExpandPathName(fname);
85
86 cout << "fillcmt" << endl;
87 cout << "-------" << endl;
88 cout << endl;
89 cout << "Connected to " << serv.GetName() << endl;
90 cout << "File: " << fname << endl;
91 cout << endl;
92
93
94 ifstream fin(fname);
95 if (!fin)
96 {
97 gLog << err << "Cannot open file " << fname << ": ";
98 gLog << strerror(errno) << endl;
99 return 2;
100 }
101
102 TString line;
103 for (int i=0; i<23; i++)
104 line.ReadLine(fin);
105
106 if (!fin)
107 {
108 gLog << err << "File " << fname << ": Not enough lines." << endl;
109 return 2;
110 }
111
112 while (1)
113 {
114 line.ReadLine(fin);
115 if (!fin)
116 break;
117
118 const_cast<char&>(line.Data()[ 6]) = 0;
119 const_cast<char&>(line.Data()[10]) = 0;
120 const_cast<char&>(line.Data()[19]) = 0;
121 const_cast<char&>(line.Data()[35]) = 0;
122 const_cast<char&>(line.Data()[39]) = 0;
123 const_cast<char&>(line.Data()[45]) = 0;
124 const_cast<char&>(line.Data()[51]) = 0;
125
126 const Int_t checked = atoi(line.Data()+7);
127 if (checked==0)
128 continue;
129
130 const TString date = line.Data();
131 const Float_t extr = atof(line.Data()+11); //5.3
132 const Int_t phot = line.Data()[18] == ':';
133 const Float_t extrerr = atof(line.Data()+20); //5.3
134 const Float_t tmphot = atof(line.Data()+40); //5.2
135 const Float_t tmnphot = atof(line.Data()+46); //5.2
136
137 MTime t;
138 t.SetStringFmt(date, "%y%m%d");
139
140 const TString vars = Form("fExtinctionR=%.3f, "
141 "fExtinctionRerr=%.3f, "
142 "fIsPhotometric=%d, "
143 "fTimePhotometric=%.2f, "
144 "fTimeNonPhotometric=%.2f",
145 extr, extrerr, phot, tmphot, tmnphot);
146
147
148 const TString where = Form("fData='%s'", t.GetSqlDateTime().Data());
149
150 if (!serv.InsertUpdate("ExtinctionCMT", vars, where))
151 return 2;
152 }
153
154 return 1;
155}
Note: See TracBrowser for help on using the repository browser.