Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCheckParameters.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <sstream>
4 
5 #include "evt/Head.hh"
6 #include "evt/Evt.hh"
7 
8 #include "JDAQ/JDAQTimeslice.hh"
9 #include "JDAQ/JDAQEvent.hh"
10 #include "JDAQ/JDAQSummaryslice.hh"
11 
13 
17 #include "JSupport/JTreeScanner.hh"
18 #include "JSupport/JSupport.hh"
19 
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 #include "KM3NeTDBClient.h"
24 #include "JDB/JDB.hh"
25 #include "JDB/JSelector.hh"
26 
27 #include "JDBTriggerParameters.hh"
28 
29 /**
30  * \file
31  * Auxiliary program to check trigger parameters in ROOT files against the DB values.
32  * \author lnauta
33  */
34 int main(int argc, char **argv)
35 {
36  using namespace std;
37  using namespace JPP;
38  using namespace KM3NETDB;
39  using namespace JDBTRIGGERPARAMETERS;
40 
41  JMultipleFileScanner<JDAQTimeslice> inputFile;
42  string detid;
43  string usr;
44  string pwd;
45  int debug;
46 
47  try {
48 
49  JParser<> zap("Auxiliary program to check trigger parameters in ROOT files against the DB value.");
50 
51  zap['f'] = make_field(inputFile);
52  zap['D'] = make_field(detid) = "D_ORCA002", "D_ARCA001";
53  zap['u'] = make_field(usr);
54  zap['!'] = make_field(pwd);
55  zap['d'] = make_field(debug) = 1;
56 
57  zap(argc, argv);
58  }
59  catch(const exception& error) {
60  FATAL(error.what() << endl);
61  }
62 
63  JTriggerParameters parameters;
64 
65  try {
66  parameters = getTriggerParameters(inputFile);
67  NOTICE("Get trigger parameters from input." << endl);
68  }
69  catch(const JException& error) {
70  FATAL("No trigger parameters from input." << endl);
71  }
72 
73  int runNumber = 0;
74  while (inputFile.hasNext()) {
75  JDAQTimeslice* timeslice = inputFile.next();
76  runNumber = timeslice->getRunNumber();
77  break;
78  }
79  if (runNumber == 0) {
80  FATAL("File does not contain a valid run number. Aborting" << endl);
81  }
82 
83 
84  // Make streams for DB interaction
85  istringstream detector_selector_stream(DETECTOR_SELECTOR + detid);
86  JSelector detector_selector;
87  detector_selector_stream >> detector_selector;
88 
89  string run_setup_id;
90 
91  // Connecting to DB
92  try {
93  // Get run setup information
94  JDB::reset(usr, pwd);
95  ResultSet& rs = JDB::get()->StreamDS(DB_TABLE_RUNS, detector_selector);
96 
97  std::map<string, int> run_column_map;
98  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
99  run_column_map[rs.FieldName(i)] = i;
100  }
101  while (rs.Next()) {
102  if (std::stoi(rs.GetString(run_column_map[RUN_TABLE_RUN_COLUMN])) == runNumber) {
103  run_setup_id = rs.GetString(run_column_map[RUN_TABLE_SETUPID_COLUMN]);
104  }
105  }
106  rs.Close();
107  }
108  catch(const exception& error) {
109  FATAL(error.what() << endl);
110  }
111 
112  stringstream buffer;
113  std::map<string, string> ParameterMap;
114 
115  try {
116  // Get parameter map
117  istringstream param_selector_stream(DAQ_SELECTOR);
118  JSelector param_selector;
119  param_selector_stream >> param_selector;
120 
121  JDB::reset(usr, pwd);
122  ResultSet& rs_allparams = JDB::get()->StreamDS(DB_TABLE_ALL_PARAMETERS, param_selector);
123 
124  std::map<string, int> parameter_column_map;
125  for (unsigned int i = 0; i != rs_allparams.FieldCount(); ++i) {
126  parameter_column_map[rs_allparams.FieldName(i)] = i;
127  }
128  while (rs_allparams.Next()) {
129  if (rs_allparams.GetString(parameter_column_map[ALL_PARAMETERS_TABLE_NAME_COLUMN]).find(DAQ_FILTER_STRING) != std::string::npos) {
130  ParameterMap[rs_allparams.GetString(parameter_column_map[ALL_PARAMETERS_TABLE_OID_COLUMN])] =
131  rs_allparams.GetString(parameter_column_map[ALL_PARAMETERS_TABLE_NAME_COLUMN]).erase(0, std::strlen(DAQ_FILTER_STRING));
132  }
133  }
134  rs_allparams.Close();
135  }
136  catch(const exception& error) {
137  FATAL(error.what() << endl);
138  }
139 
140 
141  try {
142  // Get trigger parameter information
143  istringstream run_setup_selector_stream(DETECTOR_SELECTOR + detid + SELECTOR_SEPERATOR + RUN_SETUP_OID_SELECTOR + run_setup_id);
144  JSelector run_setup_selector;
145  run_setup_selector_stream >> run_setup_selector;
146 
147  JDB::reset(usr, pwd);
148  ResultSet& rs_params = JDB::get()->StreamDS(DB_TABLE_RUN_SETUP_PARAMETERS, run_setup_selector);
149 
150  std::map<string, int> rs_params_column_map;
151  for (unsigned int i = 0; i != rs_params.FieldCount(); ++i) {
152  rs_params_column_map[rs_params.FieldName(i)] = i;
153  }
154  while (rs_params.Next()) {
155  for(map<string, string>::const_iterator it = ParameterMap.begin(); it != ParameterMap.end(); ++it) {
156  if (rs_params.GetString(rs_params_column_map[RUN_SETUP_TABLE_PAR_OID_COLUMN]) == it->first) {
157  buffer << it->second << "=" << rs_params.GetString(rs_params_column_map[RUN_SETUP_TABLE_VALUE_COLUMN]) << ";\n";
158  }
159  }
160  }
161  }
162  catch(const exception& error) {
163  FATAL(error.what() << endl);
164  }
165 
166  cout << buffer.str() << endl;
167 
168  JTriggerParameters parameters_from_db;
169  buffer >> parameters_from_db;
170 
171  bool return_file_is_db;
172  return_file_is_db = parameters.equals(parameters_from_db);
173  if (return_file_is_db) NOTICE("The parameters for run " << runNumber << "are equivalent" << endl);
174  else NOTICE("The parameters for run " << runNumber << " are NOT equivalent." << endl);
175  return return_file_is_db;
176 }
Utility class to parse command line options.
Definition: JParser.hh:1410
const char * ALL_PARAMETERS_TABLE_NAME_COLUMN
Data structure for all trigger parameters.
const char * DB_TABLE_RUN_SETUP_PARAMETERS
Auxiliary class for specifying selection of database data.
const char * DB_TABLE_ALL_PARAMETERS
Recording of objects on file according a format that follows from the file name extension.
void reset(JCLBInput &data, size_t size)
Reset CLB buffers.
const char * RUN_SETUP_OID_SELECTOR
int getRunNumber() const
Get run number.
const char * RUN_TABLE_SETUPID_COLUMN
T get(const JHead &head)
Get object from header.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
const char * RUN_SETUP_TABLE_VALUE_COLUMN
#define NOTICE(A)
Definition: JMessage.hh:62
Data time slice.
int debug
debug level
Definition: JSirene.cc:59
const char * ALL_PARAMETERS_TABLE_OID_COLUMN
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
ROOT TTree parameter settings.
bool equals(const JTriggerParameters &parameters) const
Equality.
const char * RUN_SETUP_TABLE_PAR_OID_COLUMN
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
int main(int argc, char *argv[])
Definition: Main.cpp:15