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 | TList rows;
|
---|
54 | while (row=res->Next())
|
---|
55 | {
|
---|
56 | if ((*row)[0])
|
---|
57 | return kTRUE;
|
---|
58 | }
|
---|
59 |
|
---|
60 | return kFALSE;
|
---|
61 | }
|
---|
62 |
|
---|
63 | // --------------------------------------------------------------------------
|
---|
64 | //
|
---|
65 | // insert the entries from this runbook file into the database
|
---|
66 | //
|
---|
67 | void insert(TString fname)
|
---|
68 | {
|
---|
69 | //cout << endl;
|
---|
70 | //cout << "FILE: " << fname << endl;
|
---|
71 |
|
---|
72 | ifstream fin(fname);
|
---|
73 | if (!fin)
|
---|
74 | {
|
---|
75 | cout << "Could not open file " << fname << endl;
|
---|
76 | return;
|
---|
77 | }
|
---|
78 |
|
---|
79 | TSQLServer *serv = TSQLServer::Connect("mysql://localhost:3306", "hercules", "d99swMT!");
|
---|
80 | if (!serv)
|
---|
81 | {
|
---|
82 | cout << "Could not connect so mysqld..." << endl;
|
---|
83 | return;
|
---|
84 | }
|
---|
85 |
|
---|
86 | 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);
|
---|
87 |
|
---|
88 | Int_t num=0;
|
---|
89 |
|
---|
90 | Bool_t valid = kFALSE;
|
---|
91 | TString entry;
|
---|
92 | while (1)
|
---|
93 | {
|
---|
94 | TString line;
|
---|
95 | line.ReadLine(fin);
|
---|
96 | if (!fin)
|
---|
97 | break;
|
---|
98 |
|
---|
99 | TString l0 = line(regexp);
|
---|
100 |
|
---|
101 | if (l0.IsNull())
|
---|
102 | {
|
---|
103 | entry += line;
|
---|
104 | entry += "\n";
|
---|
105 | continue;
|
---|
106 | }
|
---|
107 | if (!valid)
|
---|
108 | {
|
---|
109 | valid = kTRUE;
|
---|
110 | entry = "";
|
---|
111 | //cout << "First entry skipped..." << endl;
|
---|
112 | continue;
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (entry.Contains("Operator names: "))
|
---|
116 | {
|
---|
117 | //cout << "OPERATORS: " << entry << flush;
|
---|
118 | entry="";
|
---|
119 | continue;
|
---|
120 | }
|
---|
121 |
|
---|
122 | if (entry.Contains("CALIBRATION RUN STATISTICS") ||
|
---|
123 | entry.Contains("DATA RUN STATISTICS") ||
|
---|
124 | entry.Contains("PEDESTAL RUN STATISTICS"))
|
---|
125 | {
|
---|
126 | //cout << "Run entry skipped..." << endl;
|
---|
127 | entry ="";
|
---|
128 | continue;
|
---|
129 | }
|
---|
130 |
|
---|
131 | TString date(l0(1, l0.Length()-2));
|
---|
132 |
|
---|
133 | if (ExistStr(serv, "fRunBookDate", "MyMagic.RunBook", date))
|
---|
134 | {
|
---|
135 | entry ="";
|
---|
136 | continue;
|
---|
137 | }
|
---|
138 |
|
---|
139 | entry.ReplaceAll("'", "\\'");
|
---|
140 | entry.ReplaceAll("\"", "\\\"");
|
---|
141 |
|
---|
142 | TString query("INSERT MyMagic.RunBook (fRunBookDate, fRunBookText) VALUES (\"");
|
---|
143 | query += date;
|
---|
144 | query += "\", \"";
|
---|
145 | query += entry;
|
---|
146 | query += "\");";
|
---|
147 |
|
---|
148 | if (!serv->Query(query))
|
---|
149 | cout << "ERROR: " << query << endl << endl;
|
---|
150 | else
|
---|
151 | num++;
|
---|
152 |
|
---|
153 | entry = "";
|
---|
154 | }
|
---|
155 |
|
---|
156 | serv->Close();
|
---|
157 | delete serv;
|
---|
158 |
|
---|
159 | cout << fname << " <" << num << ">" << endl;
|
---|
160 | }
|
---|
161 |
|
---|
162 | // --------------------------------------------------------------------------
|
---|
163 | //
|
---|
164 | // loop over all files in this path
|
---|
165 | //
|
---|
166 | void readrbk(TString path="/data/MAGIC/Period014")
|
---|
167 | {
|
---|
168 | MDirIter Next(path, "*.rbk", -1);
|
---|
169 |
|
---|
170 | while (1)
|
---|
171 | {
|
---|
172 | TString name = Next();
|
---|
173 | if (name.IsNull())
|
---|
174 | break;
|
---|
175 | insert(name);
|
---|
176 | }
|
---|
177 | }
|
---|