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 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // This macro is used to read the central control runbook files from
|
---|
28 | // the data center and store their contents in the runbook-database.
|
---|
29 | //
|
---|
30 | // Usage: root readrbk.C("/data/MAGIC/Period014")
|
---|
31 | //
|
---|
32 | // This command will loop over all subdirectories, read all *.rbk files and
|
---|
33 | // store its contents in the database (if an entry with the same date is
|
---|
34 | // already existing it is ignored).
|
---|
35 | //
|
---|
36 | // Make sure, that database and password are corretly set in the macro.
|
---|
37 | //
|
---|
38 | ///////////////////////////////////////////////////////////////////////////
|
---|
39 |
|
---|
40 | // --------------------------------------------------------------------------
|
---|
41 | //
|
---|
42 | // Checks whether an entry for this date is already existing
|
---|
43 | //
|
---|
44 | Bool_t ExistStr(TSQLServer *serv, const char *column, const char *table, const char *test)
|
---|
45 | {
|
---|
46 | TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
|
---|
47 | TSQLResult *res = serv->Query(query);
|
---|
48 | if (!res)
|
---|
49 | return kFALSE;
|
---|
50 |
|
---|
51 | TSQLRow *row;
|
---|
52 |
|
---|
53 | Bool_t rc = kFALSE;
|
---|
54 | while (row=res->Next())
|
---|
55 | {
|
---|
56 | if ((*row)[0])
|
---|
57 | {
|
---|
58 | rc = kTRUE;
|
---|
59 | break;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | delete res;
|
---|
64 |
|
---|
65 | return rc;
|
---|
66 | }
|
---|
67 |
|
---|
68 | // --------------------------------------------------------------------------
|
---|
69 | //
|
---|
70 | // insert the entries from this runbook file into the database
|
---|
71 | //
|
---|
72 | void insert(TString fname)
|
---|
73 | {
|
---|
74 | //cout << endl;
|
---|
75 | //cout << "FILE: " << fname << endl;
|
---|
76 |
|
---|
77 | ifstream fin(fname);
|
---|
78 | if (!fin)
|
---|
79 | {
|
---|
80 | cout << "Could not open file " << fname << endl;
|
---|
81 | return;
|
---|
82 | }
|
---|
83 |
|
---|
84 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
85 | if (!serv)
|
---|
86 | {
|
---|
87 | cout << "Could not connect so mysqld..." << endl;
|
---|
88 | return;
|
---|
89 | }
|
---|
90 |
|
---|
91 | TRegexp regexp("^.20[0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9].$", kFALSE);
|
---|
92 |
|
---|
93 | Int_t num=0;
|
---|
94 |
|
---|
95 | Bool_t valid = kFALSE;
|
---|
96 | TString entry;
|
---|
97 | while (1)
|
---|
98 | {
|
---|
99 | TString line;
|
---|
100 | line.ReadLine(fin);
|
---|
101 | if (!fin)
|
---|
102 | break;
|
---|
103 |
|
---|
104 | TString l0 = line(regexp);
|
---|
105 |
|
---|
106 | if (l0.IsNull())
|
---|
107 | {
|
---|
108 | entry += line;
|
---|
109 | entry += "\n";
|
---|
110 | continue;
|
---|
111 | }
|
---|
112 | if (!valid)
|
---|
113 | {
|
---|
114 | valid = kTRUE;
|
---|
115 | entry = "";
|
---|
116 | //cout << "First entry skipped..." << endl;
|
---|
117 | continue;
|
---|
118 | }
|
---|
119 |
|
---|
120 | if (entry.Contains("Operator names: "))
|
---|
121 | {
|
---|
122 | //cout << "OPERATORS: " << entry << flush;
|
---|
123 | entry="";
|
---|
124 | continue;
|
---|
125 | }
|
---|
126 |
|
---|
127 | if (entry.Contains("CALIBRATION RUN STATISTICS") ||
|
---|
128 | entry.Contains("DATA RUN STATISTICS") ||
|
---|
129 | entry.Contains("PEDESTAL RUN STATISTICS"))
|
---|
130 | {
|
---|
131 | //cout << "Run entry skipped..." << endl;
|
---|
132 | entry ="";
|
---|
133 | continue;
|
---|
134 | }
|
---|
135 |
|
---|
136 | TString date(l0(1, l0.Length()-2));
|
---|
137 |
|
---|
138 | if (ExistStr(serv, "fRunBookDate", "MyMagic.RunBook", date))
|
---|
139 | {
|
---|
140 | entry ="";
|
---|
141 | continue;
|
---|
142 | }
|
---|
143 |
|
---|
144 | entry.ReplaceAll("'", "\\'");
|
---|
145 | entry.ReplaceAll("\"", "\\\"");
|
---|
146 |
|
---|
147 | TString query("INSERT MyMagic.RunBook (fRunBookDate, fRunBookText) VALUES (\"");
|
---|
148 | query += date;
|
---|
149 | query += "\", \"";
|
---|
150 | query += entry;
|
---|
151 | query += "\");";
|
---|
152 |
|
---|
153 | TSQLResult *res = serv->Query(query);
|
---|
154 | if (!res)
|
---|
155 | cout << "ERROR: " << query << endl << endl;
|
---|
156 | else
|
---|
157 | {
|
---|
158 | delete res;
|
---|
159 | num++;
|
---|
160 | }
|
---|
161 |
|
---|
162 | entry = "";
|
---|
163 | }
|
---|
164 |
|
---|
165 | serv->Close();
|
---|
166 | delete serv;
|
---|
167 |
|
---|
168 | cout << fname << " <" << num << ">" << endl;
|
---|
169 | }
|
---|
170 |
|
---|
171 | // --------------------------------------------------------------------------
|
---|
172 | //
|
---|
173 | // loop over all files in this path
|
---|
174 | //
|
---|
175 | void readrbk(TString path="/data/MAGIC/Period017/ccdata")
|
---|
176 | {
|
---|
177 | MDirIter Next(path, "*.rbk", -1);
|
---|
178 |
|
---|
179 | while (1)
|
---|
180 | {
|
---|
181 | TString name = Next();
|
---|
182 | if (name.IsNull())
|
---|
183 | break;
|
---|
184 | insert(name);
|
---|
185 | }
|
---|
186 | }
|
---|