Jpp  master_rocky-43-ge265d140c
the software that should make you happy
Functions
JPrintDataQuality.cc File Reference

Main program to print quality data from data base. More...

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JRunQuality.hh"
#include "JDB/JRunsetups.hh"
#include "JDB/JDBToolkit.hh"
#include "JLang/JLangToolkit.hh"
#include "JTools/JRange.hh"
#include "JROOT/JRootPrinter.hh"
#include "JROOT/JRootToolkit.hh"
#include "JDataQuality/JGITTags.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Main program to print quality data from data base.

Author
mdejong

Definition in file JPrintDataQuality.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file JPrintDataQuality.cc.

35 {
36  using namespace std;
37  using namespace JPP;
38 
39  typedef JRange<int> JRange_t;
40 
41  JServer server;
42  string usr;
43  string pwd;
44  string cookie;
45  string inputFile;
46  string outputFile;
47  string detid;
48  JRange_t runs;
49  vector<string> source;
50  TRegexp regexp(".");
51  JSelector selection;
52  vector<string> format;
53  int debug;
54 
55  try {
56 
57  JParser<> zap("Main program to print quality data from data base.");
58 
59  zap['s'] = make_field(server) = getServernames();
60  zap['u'] = make_field(usr) = "";
61  zap['!'] = make_field(pwd) = "";
62  zap['C'] = make_field(cookie) = "";
63  zap['D'] = make_field(detid);
64  zap['R'] = make_field(runs, "Run range") = JRange_t(1, JRange_t::getMaximum());
65  zap['S'] = make_field(source, "GIT versions") = getGITTags(TRegexp("v[0-9]*\\.[0-9]*\\.[0-9]*$"), JGITTags_t::key_type("2019-04-12"));
66  zap['r'] = make_field(regexp, "TRegexp for selection of run setup names.") = JPARSER::initialised();
67  zap['F'] = make_field(format, "column names: " << JEEPZ() << getColumns<JRunQuality>()) = JPARSER::initialised();
68  zap['@'] = make_field(selection) = JPARSER::initialised();
69  zap['d'] = make_field(debug, "Debug level") = 1;
70 
71  zap(argc, argv);
72  }
73  catch(const exception &error) {
74  FATAL(error.what() << endl);
75  }
76 
77 
78  JRunsetups setups; // run -> value
79  set<JRunQuality> buffer; // storage
80 
81  try {
82 
83  JDB::reset(usr, pwd, cookie);
84 
85  const int ID = getDetector<int> (detid);
86  detid = getDetector<string>(detid);
87 
88  // run setups
89 
90  selection += getSelector<JRuns>(ID, runs.getLowerLimit(), runs.getUpperLimit());
91 
92  ResultSet& rs = getResultSet(getTable<JRuns>(), selection);
93 
94  for (JRuns parameters; rs >> parameters; ) {
95  if (TString(parameters.RUNSETUPNAME.c_str()).Contains(regexp)) {
96  setups.put(parameters);
97  }
98  }
99 
100  rs.Close();
101 
102  // run summary data
103 
104  for (vector<string>::const_iterator git = source.begin(); git != source.end() && buffer.size() < setups.size(); ++git) {
105 
108 
109  map_type zmap;
110 
111  JSelector selector = getSelector<JRunSummaryNumbers>(detid, runs.getLowerLimit(), runs.getUpperLimit());
112 
113  selector.add(&JRunSummaryNumbers::SOURCE_NAME, *git);
114 
115  try {
116 
117  ResultSet& rs = getResultSet(getTable<JRunSummaryNumbers>(), selector);
118 
119  for (JRunSummaryNumbers parameters; rs >> parameters; ) {
120  if (setups.count(parameters.RUN) != 0) {
121  zmap[parameters.RUN].insert(make_pair(parameters.PARAMETER_NAME, parameters.DATA_VALUE));
122  }
123  }
124 
125  rs.Close();
126  }
127  catch(const exception& error) {}
128 
129  for (map_type::const_iterator run = zmap.begin(); run != zmap.end(); ++run) {
130 
131  JRunQuality quality;
132 
133  quality.GIT = *git;
134  quality.detector = ID;
135  quality.run = run->first;
136  quality.name = setups[run->first].name;
137  quality.value = setups[run->first].value;
138 
139  for (data_type::const_iterator i = run->second.begin(); i != run->second.end(); ++i) {
140  quality.put(i->first, i->second);
141  }
142 
143  buffer.insert(quality); // only insert if absent
144  }
145  }
146  }
147  catch(const exception& error) {
148  FATAL(error.what() << endl);
149  }
150 
151 
152  for (set<JRunQuality>::const_iterator quality = buffer.begin(); quality != buffer.end(); ++quality) {
153 
154  for (vector<string>::const_iterator i = format.begin(); i != format.end(); ++i) {
155  JRootPrinter::print(cout, *quality, *i);
156  }
157 
158  cout << endl;
159  }
160 
161  return 0;
162 }
string outputFile
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Auxiliary class for specifying selection of database data.
JSelector & add(const JSelector &selection)
Add selection.
Utility class to parse command line options.
Definition: JParser.hh:1698
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter=' ', const bool useColors=true)
Print test summary.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:437
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:107
std::vector< std::string > getGITTags(const TRegexp &regexp, const JGITTags_t::key_type &date)
Get selection of GIT tags.
T getMaximum(const array_type< T > &buffer, const T value)
Get maximum of values.
Definition: JVectorize.hh:218
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< event_type > data_type
Definition: JPerth.cc:82
void reset(T &value)
Reset value.
std::map< int, range_type > map_type
Definition: JSTDTypes.hh:14
Type definition of range.
Definition: JHead.hh:43
Auxiliary data structure for data quality.
Definition: JRunQuality.hh:36
double value
setup identifier (see JRunsetups)
Definition: JRunQuality.hh:183
void put(const std::string &key, const std::string &value)
Put value at given key.
Definition: JRunQuality.cc:25
std::string name
setup name (see JRunsetups)
Definition: JRunQuality.hh:182
std::string GIT
GIT version used to write QA/QC data.
Definition: JRunQuality.hh:139
int detector
detector identifier
Definition: JRunQuality.hh:143
Auxiliary class for run setup evaluation.
Definition: JRunsetups.hh:36
void put(const int run, const std::string setup)
Put run parameters.
Definition: JRunsetups.hh:105
Wrapper class for server name.
Definition: JDB.hh:53
Template definition for getting table specific selector.
Auxiliary data structure for streaming of STL containers.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68