Jpp  15.0.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCheckTriggerParameters.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <vector>
4 #include <map>
5 
8 
10 #include "JDAQ/JDAQEventIO.hh"
12 
14 
19 #include "JSupport/JSupport.hh"
20 #include "JSupport/JMeta.hh"
21 
23 
24 #include "JDB/JDB.hh"
25 #include "JDB/JSelector.hh"
27 #include "JDB/JDetectors.hh"
28 #include "JDB/JRuns.hh"
29 #include "JDB/JAllParams.hh"
30 #include "JDB/JRunsetupParams.hh"
31 
32 #include "Jeep/JParser.hh"
33 #include "Jeep/JMessage.hh"
34 
35 
36 /**
37  * \file
38  * Auxiliary program to check trigger parameters in a given ROOT files against the values from the database.
39  * \author lnauta
40  */
41 int main(const int argc, const char * const argv[])
42 {
43  using namespace std;
44  using namespace JPP;
45  using namespace KM3NETDAQ;
46 
49  JServer server;
50  string usr;
51  string pwd;
52  string cookie;
53  int debug;
54 
55  try {
56 
57  JParser<> zap("Auxiliary program to check trigger parameters in a given ROOT files against the values from the database.");
58 
59  zap['f'] = make_field(inputFile);
60  zap['s'] = make_field(server) = getServernames();
61  zap['u'] = make_field(usr) = "";
62  zap['!'] = make_field(pwd) = "";
63  zap['C'] = make_field(cookie) = "";
64  zap['o'] = make_field(outputFile) = "";
65  zap['d'] = make_field(debug) = 1;
66 
67  zap(argc, argv);
68  }
69  catch(const exception& error) {
70  FATAL(error.what() << endl);
71  }
72 
73 
74  const double Dmax_m = 9999.0;
75 
76  JTriggerParameters parametersA;
77  JTriggerParameters parametersB;
78 
79 
80  DEBUG("Get trigger parameters from input file." << endl);
81 
82  try {
83  parametersA = getTriggerParameters(inputFile);
84  }
85  catch(const JException& error) {
86  FATAL("No trigger parameters from input." << endl);
87  }
88 
89  parametersA.set(Dmax_m);
90 
91  DEBUG(parametersA);
92 
93 
94  int detector_id = 0;
95  int run_number = 0;
96 
98 
99  if (in.hasNext()) {
100 
101  detector_id = in.next()->getDetectorID();
102  run_number = in.next()->getRunNumber();
103 
104  } else {
105 
106  FATAL("File does not contain a valid run number. Aborting" << endl);
107  }
108 
109 
110  try {
111  JDB::reset(usr, pwd, cookie);
112  }
113  catch(const exception& error) {
114  FATAL(error.what() << endl);
115  }
116 
117 
118  string detid = "";
119 
120  try {
121 
122  JDetectors buffer;
123 
124  ResultSet& rs = getResultSet(getTable<JDetectors>(), getSelector<JDetectors>(detector_id));
125 
126  if (rs >> buffer) {
127  detid = buffer.OID;
128  }
129 
130  rs.Close();
131 
132  DEBUG("Detector " << detector_id << " -> " << detid << endl);
133  }
134  catch(const exception& error) {
135  FATAL(error.what() << endl);
136  }
137 
138 
139  string rs_oid;
140 
141  try {
142 
143  JRuns buffer;
144 
145  ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(detector_id, run_number));
146 
147  if (rs >> buffer) {
148  rs_oid = buffer.RUNSETUPID;
149  }
150 
151  rs.Close();
152 
153  DEBUG("Run setup " << rs_oid << endl);
154  }
155  catch(const exception& error) {
156  FATAL(error.what() << endl);
157  }
158 
159 
160  map<string, string> umap;
161  map<string, string> zmap;
162 
163  try {
164 
165  JAllParams buffer;
166 
167  ResultSet& rs = getResultSet(getTable<JAllParams>(), getSelector<JAllParams>("DATAACQUISITION"));
168 
169  while (rs >> buffer) {
170 
171  umap[buffer.OID] = buffer.NAME;
172 
173  string::size_type pos = buffer.NAME.find(PREFIX_DATAFILTER);
174 
175  if (pos != string::npos) {
176 
177  string::size_type len = PREFIX_DATAFILTER.length();
178 
179  while (pos + len != buffer.NAME.length() && buffer.NAME[pos + len] != '=') {
180  ++len;
181  }
182 
183  zmap[buffer.OID] = buffer.NAME.erase(pos, len + 1);
184  }
185  }
186 
187  rs.Close();
188 
189  DEBUG("Parameters map " << zmap.size() << endl);
190  }
191  catch(const exception& error) {
192  FATAL(error.what() << endl);
193  }
194 
195 
196  stringstream data;
197 
198  try {
199 
200  JRunsetupParams buffer;
201 
202  ResultSet& rs = getResultSet(getTable<JRunsetupParams>(), getSelector<JRunsetupParams>(detid, rs_oid));
203 
204  while (rs >> buffer) {
205 
206  DEBUG(buffer.PAR_OID << "->" << umap[buffer.PAR_OID] << " = " << buffer.VALUE << endl);
207 
208  map<string, string>::const_iterator i = zmap.find(buffer.PAR_OID);
209 
210  if (i != zmap.end()) {
211  data << i->second << "=" << buffer.VALUE << ";\n";
212  }
213  }
214 
215  rs.Close();
216  }
217  catch(const exception& error) {
218  FATAL(error.what() << endl);
219  }
220 
221  DEBUG("Raw data" << endl << "<<" << endl << data.str() << ">>" << endl);
222 
223 
224  data >> parametersB;
225 
226  parametersB.set(Dmax_m);
227  parametersB.actionAtFileRead();
228 
229  DEBUG(parametersB);
230 
231 
232  if (outputFile.getFilename() != "") {
233 
234  DEBUG("Write to " << outputFile << "... " << flush);
235 
236  outputFile.open();
237 
238  outputFile.put(parametersB);
239 
241 
242  io >> outputFile;
243 
244  outputFile.close();
245 
246  DEBUG("OK" << endl);
247  }
248 
249 
250  const bool is_equal = (parametersA == parametersB);
251 
252  if (is_equal)
253  NOTICE(GREEN << "The parameters for run " << run_number << " are equivalent." << RESET << endl);
254  else
255  ERROR (RED << "The parameters for run " << run_number << " are NOT equivalent." << RESET << endl);
256 
257  return (is_equal ? 0 : 1);
258 }
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
Recording of objects on file according a format that follows from the file name extension.
Auxiliary class for multiplexing object iterators.
string outputFile
Scanning of objects from a single file according a format that follows from the extension of each fil...
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
virtual const pointer_type & next() override
Get next element.
int debug
debug level
Definition: JSirene.cc:63
virtual bool hasNext() override
Check availability of next element.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
static const std::string PREFIX_DATAFILTER
This string is prepended to every parameter in the database output for the corresponding process...
Definition: JDB.hh:174
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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
Wrapper class for server name.
Definition: JDB.hh:42
Object reading from a list of files.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
Template definition for getting table specific selector.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
std::string RUNSETUPID
Definition: JRuns.hh:26