Jpp  16.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "JDB/JGITTags.hh"
#include "JLang/JLangToolkit.hh"
#include "JTools/JRange.hh"
#include "JROOT/JRootPrinter.hh"
#include "JROOT/JRootToolkit.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

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file JPrintDataQuality.cc.

34 {
35  using namespace std;
36  using namespace JPP;
37 
38  typedef JRange<int> JRange_t;
39 
40  JServer server;
41  string usr;
42  string pwd;
43  string cookie;
44  string inputFile;
45  string outputFile;
46  string detid;
47  JRange_t runs;
48  vector<string> source;
49  TRegexp regexp(".");
50  JSelector selection;
51  vector<string> format;
52  int debug;
53 
54  try {
55 
56  JParser<> zap("Main program to print quality data from data base.");
57 
58  zap['s'] = make_field(server) = getServernames();
59  zap['u'] = make_field(usr) = "";
60  zap['!'] = make_field(pwd) = "";
61  zap['C'] = make_field(cookie) = "";
62  zap['D'] = make_field(detid);
63  zap['R'] = make_field(runs, "Run range") = JRange_t(1, JRange_t::getMaximum());
64  zap['S'] = make_field(source, "GIT versions") = getGITTags(TRegexp("v[0-9]*\\.[0-9]*\\.[0-9]*$"), JGITTags_t::key_type("2019-04-12"));
65  zap['r'] = make_field(regexp, "TRegexp for selection of run setup names.") = JPARSER::initialised();
66  zap['F'] = make_field(format, "column names: " << JEEPZ() << getColumns<JRunQuality>()) = JPARSER::initialised();
67  zap['@'] = make_field(selection) = JPARSER::initialised();
68  zap['d'] = make_field(debug, "Debug level") = 1;
69 
70  zap(argc, argv);
71  }
72  catch(const exception &error) {
73  FATAL(error.what() << endl);
74  }
75 
76 
77  JRunsetups setups; // run -> value
78  set<JRunQuality> buffer; // storage
79 
80  try {
81 
82  JDB::reset(usr, pwd, cookie);
83 
84  const int ID = getDetector<int> (detid);
85  detid = getDetector<string>(detid);
86 
87  // run setups
88 
89  selection += getSelector<JRuns>(ID, runs.getLowerLimit(), runs.getUpperLimit());
90 
91  ResultSet& rs = getResultSet(getTable<JRuns>(), selection);
92 
93  for (JRuns parameters; rs >> parameters; ) {
94  if (TString(parameters.RUNSETUPNAME.c_str()).Contains(regexp)) {
95  setups.put(parameters);
96  }
97  }
98 
99  rs.Close();
100 
101  // run summary data
102 
103  for (vector<string>::const_iterator git = source.begin(); git != source.end() && buffer.size() < setups.size(); ++git) {
104 
105  typedef map<string, string> data_type;
106  typedef map<int, data_type> map_type;
107 
108  map_type zmap;
109 
110  JSelector selector = getSelector<JRunSummaryNumbers>(detid, runs.getLowerLimit(), runs.getUpperLimit());
111 
112  selector.add(&JRunSummaryNumbers::SOURCE_NAME, *git);
113 
114  try {
115 
116  ResultSet& rs = getResultSet(getTable<JRunSummaryNumbers>(), selector);
117 
118  for (JRunSummaryNumbers parameters; rs >> parameters; ) {
119  if (setups.count(parameters.RUN) != 0) {
120  zmap[parameters.RUN].insert(make_pair(parameters.PARAMETER_NAME, parameters.DATA_VALUE));
121  }
122  }
123 
124  rs.Close();
125  }
126  catch(const exception& error) {}
127 
128  for (map_type::const_iterator run = zmap.begin(); run != zmap.end(); ++run) {
129 
130  JRunQuality quality;
131 
132  quality.GIT = *git;
133  quality.detector = ID;
134  quality.run = run->first;
135  quality.name = setups[run->first].name;
136  quality.value = setups[run->first].value;
137 
138  for (data_type::const_iterator i = run->second.begin(); i != run->second.end(); ++i) {
139  quality.put(i->first, i->second);
140  }
141 
142  buffer.insert(quality); // only insert if absent
143  }
144  }
145  }
146  catch(const exception& error) {
147  FATAL(error.what() << endl);
148  }
149 
150 
151  for (set<JRunQuality>::const_iterator quality = buffer.begin(); quality != buffer.end(); ++quality) {
152 
153  for (vector<string>::const_iterator i = format.begin(); i != format.end(); ++i) {
154  JRootPrinter::print(cout, *quality, *i);
155  }
156 
157  cout << endl;
158  }
159 
160  return 0;
161 }
Utility class to parse command line options.
Definition: JParser.hh:1500
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
then let ID
Definition: JAcoustics.sh:31
string outputFile
std::vector< std::string > getGITTags(const TRegexp &regexp, const JGITTags_t::key_type &date)
Get selection of GIT tags.
Definition: JDB/JGITTags.hh:34
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:65
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:432
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:98