115{
118
120
122 string usr;
123 string pwd;
124 string cookie;
125 string inputFile;
127 string detid;
128 JRange_t UTC;
130 double Tmin_s;
132
133 try {
134
135 JParser<> zap(
"Example program to plot quality data from data base or input file.");
136
141 zap[
'f'] =
make_field(inputFile,
"Optional input file instead of database.") =
"";
142 zap[
'o'] =
make_field(
outputFile,
"ROOT file with histograms and n-tuple or ASCII file with QA/QC data.") =
"monitor.root";
143 zap[
'D'] =
make_field(detid,
"detector identifier");
144 zap[
'S'] =
make_field(source,
"GIT versions") =
getGITTags(TRegexp(
"v[0-9]*\\.[0-9]*\\.[0-9]*$"), JGITTags_t::key_type(
"2019-04-12"));
146 zap[
'T'] =
make_field(Tmin_s,
"minimal run duration [s]") = 60;
148
149 zap(argc, argv);
150 }
151 catch(const exception &error) {
152 FATAL(error.what() << endl);
153 }
154
155
158
159 try {
160
161 JDB::reset(usr, pwd, cookie);
162
163 const int ID = getDetector<int >(detid);
164 detid = getDetector<string>(detid);
165
166
167
168 NOTICE(
"Extracting run information from database... " << flush);
169
171
172 for (
JRuns parameters; rs >> parameters; ) {
173
174 parameters.DETID =
ID;
175
176 if (UTC(parameters.getRunStartTime())) {
177 runs.insert(parameters);
178 }
179 }
180
181 rs.Close();
182
184
185 if (runs.empty()) {
186 FATAL(
"No runs for detector " << detid << endl);
187 }
188
189 NOTICE(
"Run range " << runs.begin()->RUN <<
' ' << runs.rbegin()->RUN << endl);
190
191 if (inputFile == "") {
192
193
194
195 for (vector<string>::const_iterator git = source.begin(); git != source.end(); ++git) {
196
199
200 map_type zmap;
201
203
204 selector.add(&JRunSummaryNumbers::SOURCE_NAME, *git);
205
206 try {
207
208 NOTICE(
"Extracting run summmary information with source " << *git <<
" from database... " << flush);
209
210 ResultSet& rs =
getResultSet(getTable<JRunSummaryNumbers>(), selector);
211
213 zmap[parameters.RUN].insert(make_pair(parameters.PARAMETER_NAME, parameters.DATA_VALUE));
214 }
215
216 rs.Close();
217
219 }
220 catch(
const exception& error) {
NOTICE(endl); }
221
222 for (map_type::const_iterator run = zmap.begin(); run != zmap.end(); ++run) {
223
225
228 quality.
run = run->first;
229
230 for (data_type::const_iterator p = run->second.begin(); p != run->second.end(); ++p) {
231 quality.
put(p->first, p->second);
232 }
233
234 if (UTC(TTimeStamp(quality.
UTCMin_s, 0)) &&
235 UTC(TTimeStamp(quality.
UTCMax_s, 0))) {
236 buffer.insert(quality);
237 }
238 }
239 }
240
241 } else {
242
244
246
247 in >> comment;
248
250 if (UTC(TTimeStamp(quality.UTCMin_s, 0)) &&
251 UTC(TTimeStamp(quality.UTCMax_s, 0))) {
252 buffer.insert(quality);
253 }
254 }
255
256 in.close();
257 }
258 }
259 catch(const exception& error) {
260 FATAL(error.what() << endl);
261 }
262
263
264 if (getFilenameExtension(
outputFile) == ROOT_FILE_FORMAT) {
265
266
267
269
270 X.push_back(runs. begin()->getRunStartTime());
271
273 X.push_back(quality->UTCMin_s);
274 X.push_back(quality->UTCMax_s);
275 }
276
277 X.push_back(runs.rbegin()->getRunStartTime());
278
279 sort(X.begin(), X.end());
280
281 struct Xmin {
282 Xmin(double xmin) :
284 {}
285
286 bool operator()(const double x1, const double x2)
287 {
288 return x2 - x1 <=
xmin;
289 }
290
292 };
293
294 X.erase(unique(X.begin(), X.end(), Xmin(Tmin_s)), X.end());
295
296 TH1D h0("livetime_s", NULL, X.size() - 1, X.data());
297 TH1D h1("QAQC", NULL, X.size() - 1, X.data());
298
300
302
303 if (
debug >= debug_t) {
304
305 cout << "Run "
306 << setw(8) << i->RUN << ' '
307 << TTimeStamp((time_t) i->UNIXSTARTTIME/1000).AsString("c") << ' ';
308
309 if (quality != buffer.end())
310 cout << "[" << TTimeStamp((time_t) quality->UTCMin_s).AsString("c") << "," << TTimeStamp((time_t) quality->UTCMax_s).AsString("c") << "]";
311 else
312 cout << "missing QA/QC data";
313
314 cout << endl;
315 }
316
317 h1.Fill(i->getRunStartTime() + Tmin_s, (quality != buffer.end() ? 1.0 : -1.0));
318 }
319
320 JManager<string, TH1D> H1(new TH1D("H[%]", NULL, X.size() - 1, X.data()));
321 JManager<string, TH1D>
R1(
new TH1D(
"R[%]", NULL, X.size() - 1, X.data()));
322
324
325 const double x = 0.5 * (quality->UTCMin_s + quality->UTCMax_s);
326
327 h0.Fill(x, 100.0 * quality->livetime_s / (quality->UTCMax_s - quality->UTCMin_s));
328
329 H1["JDAQEvent"] -> Fill(x, quality->JDAQEvent);
330 H1["JTrigger3DShower"] -> Fill(x, quality->JTrigger3DShower);
331 H1["JTrigger3DMuon"] -> Fill(x, quality->JTrigger3DMuon);
332 H1["JTriggerMXShower"] -> Fill(x, quality->JTriggerMXShower);
333
334 if (quality->livetime_s > 0.0) {
335 R1[
"JDAQEvent"] -> Fill(x, quality->JDAQEvent / quality->livetime_s);
336 R1[
"JTrigger3DShower"] -> Fill(x, quality->JTrigger3DShower / quality->livetime_s);
337 R1[
"JTrigger3DMuon"] -> Fill(x, quality->JTrigger3DMuon / quality->livetime_s);
338 R1[
"JTriggerMXShower"] -> Fill(x, quality->JTriggerMXShower / quality->livetime_s);
339 }
340 }
341
342
343 Double_t W[2] = { 0.0 };
344
345 W[0] = *X.rbegin() - *X.begin();
346
348 W[1] += quality->livetime_s;
349 }
350
351 NOTICE(
"Average data taking efficiency " <<
FIXED(5,1) << 100.0*W[1]/W[0] <<
" %." << endl);
352
353
354 for (TH1* p : { &h0, &h1 }) {
355 p->GetXaxis()->SetTimeDisplay(1);
356 p->GetXaxis()->SetTimeFormat(TIMESTAMP);
357 p->Sumw2(false);
358 }
359
360 for (JManager<string, TH1D>::iterator p = H1.begin(); p != H1.end(); ++p) {
361
362 Double_t W = 0.0;
363
364 for (Int_t i = 1; i <= p->second->GetXaxis()->GetNbins(); ++i) {
365 p->second->SetBinContent(i, (W += p->second->GetBinContent(i)));
366 }
367
368 p->second->GetXaxis()->SetTimeDisplay(1);
369 p->second->GetXaxis()->SetTimeFormat(TIMESTAMP);
370 p->second->Sumw2(false);
371 }
372
373 for (JManager<string, TH1D>::iterator p =
R1.begin(); p !=
R1.end(); ++p) {
374
375 p->second->GetXaxis()->SetTimeDisplay(1);
376 p->second->GetXaxis()->SetTimeFormat(TIMESTAMP);
377 p->second->Sumw2(false);
378 }
379
381
382 out << h0 << h1 << H1 <<
R1;
383
384 out.Write();
385 out.Close();
386 }
387
388
389 if (getFilenameExtension(
outputFile) == ASCII_FILE_FORMAT) {
390
391
392
394
395 out.setf(ios::fixed);
396
398
400
401 out << comment;
402
404 out << *i << endl;
405 }
406
407 out.close();
408 }
409}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Object reading from ASCII file.
Object(s) writing to ASCII file.
Utility class to parse command line options.
ResultSet & getResultSet(const std::string &query)
Get result set.
std::vector< JServer > getServernames()
Get list of names of available database servers.
std::vector< std::string > getGITTags(const TRegexp ®exp, const JGITTags_t::key_type &date)
Get selection of GIT tags.
Auxiliary data structure for floating point format specification.
Data structure for measured coincidence rates of all pairs of PMTs in optical module.
Auxiliary data structure for data quality.
double UTCMin_s
minimal UTC time (from "runs" table)
void put(const std::string &key, const std::string &value)
Put value at given key.
double UTCMax_s
maximal UTC time (from "runs" table)
std::string GIT
GIT version used to write QA/QC data.
int detector
detector identifier
Wrapper class for server name.
Template definition for getting table specific selector.