128{
131
134
136 string usr;
137 string pwd;
138 string cookie;
139 string inputFile;
141 string detid;
142 JRange_t runs;
144 JCondition_t condition;
145 JCondition_t veto;
146 TRegexp regexp(".");
147 JSelector selection;
149
150 try {
151
152 JParser<> zap(
"Main program to evaluate quality data from data base."\
153 "\nThe condition and veto can be any TFormula compatible expression involving QA/QC parameters (see e.g. JQAQC.sh -h).");
154
159 zap[
'f'] =
make_field(inputFile,
"Optional input file instead of database.") =
"";
160 zap[
'o'] =
make_field(
outputFile,
"ROOT file with histograms and n-tuple or ASCII file with QA/QC data.") =
"quality.root";
162 zap[
'R'] =
make_field(runs,
"Run range") = JRange_t(1, JRange_t::getMaximum());
163 zap[
'S'] =
make_field(source,
"GIT versions") =
getGITTags(TRegexp(
"v[0-9]*\\.[0-9]*\\.[0-9]*$"), JGITTags_t::key_type(
"2019-04-12"));
169
170 zap(argc, argv);
171 }
172 catch(const exception &error) {
173 FATAL(error.what() << endl);
174 }
175
176
177 double W = 0.0;
178
179 for (JCondition_t::const_iterator i = condition.begin(); i != condition.end(); ++i) {
180 W += i->weight;
181 }
182
183 if (getFilenameExtension(
outputFile) == ROOT_FILE_FORMAT) {
184 if (W <= 0.0) {
185 FATAL(
"Invalid total weight: " << W << endl);
186 }
187 }
188
189
192
193
194 if (inputFile == "") {
195
197
198 try {
199
200 JDB::reset(usr, pwd, cookie);
201
202 const int ID = getDetector<int> (detid);
203 detid = getDetector<string>(detid);
204
205
206
208
209 NOTICE(
"Extracting run information from database... " << flush);
210
211 ResultSet& rs =
getResultSet(getTable<JRuns>(), selection);
212
213 for (
JRuns parameters; rs >> parameters; ) {
214 if (TString(parameters.RUNSETUPNAME.c_str()).Contains(regexp)) {
215 setups.
put(parameters);
216 }
217 }
218
219 rs.Close();
220
222
223
224
225 for (vector<string>::const_iterator git = source.begin(); git != source.end(); ++git) {
226
229
230 map_type zmap;
231
233
234 selector.add(&JRunSummaryNumbers::SOURCE_NAME, *git);
235
236 try {
237
238 NOTICE(
"Extracting run summmary information with source " << *git <<
" from database... " << flush);
239
240 ResultSet& rs =
getResultSet(getTable<JRunSummaryNumbers>(), selector);
241
243 if (setups.
has(parameters.RUN)) {
244 zmap[parameters.RUN].insert(make_pair(parameters.PARAMETER_NAME, parameters.DATA_VALUE));
245 }
246 }
247
248 rs.Close();
249
251 }
252 catch(
const exception& error) {
NOTICE(endl); }
253
254 for (map_type::const_iterator run = zmap.begin(); run != zmap.end(); ++run) {
255
257
260 quality.
run = run->first;
261 quality.
name = setups[run->first].name;
262 quality.
value = setups[run->first].value;
263
264 for (data_type::const_iterator i = run->second.begin(); i != run->second.end(); ++i) {
265 quality.
put(i->first, i->second);
266 }
267
269
270 buffer.insert(quality);
271 }
272 }
273 }
274 catch(const exception& error) {
275 FATAL(error.what() << endl);
276 }
277
278 } else {
279
281 WARNING(
"Detector identifier \"" << detid <<
"\" discarded." << endl);
282 }
283
284 const int ID = (
is_integer(detid) ? to_value<int>(detid) : -1);
285
287
289
290 in >> comment;
291
293 if (
ID == -1 ||
ID == quality.detector) {
294 if (runs(quality.run)) {
295 buffer.insert(quality);
296 }
297 }
298 }
299
300 in.close();
301 }
302
303
304 if (buffer.empty()) {
305 FATAL(
"No data." << endl);
306 }
307
308 if (
debug >= debug_t) {
309
311
313 writer.put(*quality);
314 }
315 }
316
317
318 if (getFilenameExtension(
outputFile) == ROOT_FILE_FORMAT) {
319
320 runs = JRange_t(buffer.begin()->run, buffer.rbegin()->run);
321
322 TH1D h0("h0", NULL, 1000, 0.0, 1.01);
323 TH1D h1("h1", NULL, condition.size(), -0.5, condition.size() - 0.5);
324
325 for (size_t i = 0; i != condition.size(); ++i) {
326 h1.GetXaxis()->SetBinLabel(i+1, condition[i].formula.c_str());
327 }
328
329 h0.SetMinimum(0.0);
330 h0.SetMaximum(1.1 * (runs.getUpperLimit() - runs.getLowerLimit() + 1));
331
332 h1.SetMinimum(0.0);
333 h1.SetMaximum(1.1 * (runs.getUpperLimit() - runs.getLowerLimit() + 1));
334
335 const Double_t
xmin = runs.getLowerLimit() - 0.5;
336 const Double_t
xmax = runs.getUpperLimit() + 0.5;
337
338 JManager<TString, TH1D> H1(new TH1D("%", NULL, runs.getLength() + 1, xmin, xmax));
339
340
341
342 for (JCondition_t::const_iterator i = condition.begin(); i != condition.end();++i) {
343 H1[i->formula]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(
"C " << i->formula <<
":upper"),
MAKE_CSTRING(i->range.getUpperLimit()), xmin, xmax));
344 H1[i->formula]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(
"C " << i->formula <<
":lower"),
MAKE_CSTRING(i->range.getLowerLimit()), xmin, xmax));
345 }
346
347 for (JCondition_t::const_iterator i = veto.begin(); i != veto.end();++i) {
348 H1[i->formula]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(
"V " << i->formula <<
":upper"),
MAKE_CSTRING(i->range.getUpperLimit()), xmin, xmax));
349 H1[i->formula]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(
"V " << i->formula <<
":lower"),
MAKE_CSTRING(i->range.getLowerLimit()), xmin, xmax));
350 }
351
352 ostringstream os;
353
354 os << "run";
355
356 for (size_t i = 0; i != condition.size(); ++i) {
357 os << ":" << (char) ('a' + i);
358 }
359
360 os << ":Q:V:R";
361
362 TNtuple n1("n1", "quality", os.str().c_str());
363
364
365
366
368
370
372
373 for (size_t i = 0; i != condition.size(); ++i) {
374
375 const JCondition& ps = condition[i];
376 const double y =
getResult(ps.formula, *quality);
377
378 DEBUG(ps.formula <<
' ' << y << endl);
379
380 tuple.push_back((Float_t) y);
381
382 TH1D* p = H1[ps.formula];
383
384 p->SetBinContent(p->FindBin((double) quality->run), y);
385 p->SetBinError (p->FindBin((double) quality->run), numeric_limits<double>::epsilon());
386
387 if (ps.range(y)) {
389 }
390
391 h1.AddBinContent(i + 1, ps.range(y) ? 1.0 : 0.0);
392 }
393
394 const double Q =
w/W;
395
396 tuple.push_back((Float_t) Q);
397
398 int V = 0;
399
400 for (size_t i = 0; i != veto.size(); ++i) {
401
402 const JCondition& ps = veto[i];
403 const double y =
getResult(ps.formula, *quality);
404
405 DEBUG(ps.formula <<
' ' << y << endl);
406
407 TH1D* p = NULL;
408
409 p = H1[ps.formula];
410
411 p->SetBinContent(p->FindBin((double) quality->run), y);
412 p->SetBinError (p->FindBin((double) quality->run), numeric_limits<double>::epsilon());
413
415
416 p->SetBinContent(p->FindBin((double) quality->run), ps.range(y) ? 0.0 : 1.0);
417 p->SetBinError (p->FindBin((double) quality->run), numeric_limits<double>::epsilon());
418
419 if (!ps.range(y)) {
420 ++V;
421 }
422 }
423
424 tuple.push_back((Float_t) V);
425 tuple.push_back((Float_t) setups.
get(quality->run));
426
427 h0.Fill(Q);
428 n1.Fill(tuple.data());
429
430 cout << setw(8) << quality->run <<
' ' <<
FIXED(5,3) << Q <<
' ' << setw(2) << V << endl;
431 }
432
434
435 for (Int_t i = 0; i <= h0.GetXaxis()->GetNbins(); ++i) {
436 h0.SetBinContent(i, (w += h0.GetBinContent(i)));
437 }
438
439
440
442
443 out << h0 << h1 << n1 << H1;
444
445 out.Write();
446 out.Close();
447 }
448
449
450 if (getFilenameExtension(
outputFile) == ASCII_FILE_FORMAT) {
451
452
453
455
456 out.setf(ios::fixed);
457
459
461
462 out << comment;
463
465 out << *i << endl;
466 }
467
468 out.close();
469 }
470}
#define DEBUG(A)
Message macros.
#define ASSERT(A,...)
Assert macro.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
TString replace(const TString &target, const TRegexp ®exp, const T &replacement)
Replace regular expression in input by given replacement.
#define MAKE_CSTRING(A)
Make C-string.
#define MAKE_STRING(A)
Make string.
Object reading from ASCII file.
Object(s) writing to ASCII file.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Utility class to parse command line options.
Implementation for ASCII output of objects with ROOT dictionary.
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.
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
bool is_integer(const std::string &buffer)
Check if string is an integer.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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 value
setup identifier (see JRunsetups)
void put(const std::string &key, const std::string &value)
Put value at given key.
std::string name
setup name (see JRunsetups)
std::string GIT
GIT version used to write QA/QC data.
int detector
detector identifier
Auxiliary class for run setup evaluation.
void put(const int run, const std::string setup)
Put run parameters.
bool has(const int run) const
Check if run setup is vailable.
float get(const int run) const
Get run setup value.
Wrapper class for server name.
Template definition for getting table specific selector.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...