Jpp
 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  string usr;
50  string pwd;
51  string cookie;
52  int debug;
53 
54  try {
55 
56  JParser<> zap("Auxiliary program to check trigger parameters in a given ROOT files against the values from the database.");
57 
58  zap['f'] = make_field(inputFile);
59  zap['u'] = make_field(usr) = "";
60  zap['!'] = make_field(pwd) = "";
61  zap['C'] = make_field(cookie) = "";
62  zap['o'] = make_field(outputFile) = "";
63  zap['d'] = make_field(debug) = 1;
64 
65  zap(argc, argv);
66  }
67  catch(const exception& error) {
68  FATAL(error.what() << endl);
69  }
70 
71 
72  const double Dmax_m = 9999.0;
73 
74  JTriggerParameters parametersA;
75  JTriggerParameters parametersB;
76 
77 
78  DEBUG("Get trigger parameters from input file." << endl);
79 
80  try {
81  parametersA = getTriggerParameters(inputFile);
82  }
83  catch(const JException& error) {
84  FATAL("No trigger parameters from input." << endl);
85  }
86 
87  parametersA.set(Dmax_m);
88 
89  DEBUG(parametersA);
90 
91 
92  int detector_id = 0;
93  int run_number = 0;
94 
96 
97  if (in.hasNext()) {
98 
99  detector_id = in.next()->getDetectorID();
100  run_number = in.next()->getRunNumber();
101 
102  } else {
103 
104  FATAL("File does not contain a valid run number. Aborting" << endl);
105  }
106 
107 
108  try {
109  JDB::reset(usr, pwd, cookie);
110  }
111  catch(const exception& error) {
112  FATAL(error.what() << endl);
113  }
114 
115 
116  string detid = "";
117 
118  try {
119 
120  JDetectors buffer;
121 
122  ResultSet& rs = getResultSet(getTable<JDetectors>(), getSelector<JDetectors>(detector_id));
123 
124  if (rs >> buffer) {
125  detid = buffer.OID;
126  }
127 
128  rs.Close();
129 
130  DEBUG("Detector " << detector_id << " -> " << detid << endl);
131  }
132  catch(const exception& error) {
133  FATAL(error.what() << endl);
134  }
135 
136 
137  string rs_oid;
138 
139  try {
140 
141  JRuns buffer;
142 
143  ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(detector_id, run_number));
144 
145  if (rs >> buffer) {
146  rs_oid = buffer.RUNSETUPID;
147  }
148 
149  rs.Close();
150 
151  DEBUG("Run setup " << rs_oid << endl);
152  }
153  catch(const exception& error) {
154  FATAL(error.what() << endl);
155  }
156 
157 
158  map<string, string> umap;
159  map<string, string> zmap;
160 
161  try {
162 
163  JAllParams buffer;
164 
165  ResultSet& rs = getResultSet(getTable<JAllParams>(), getSelector<JAllParams>("DATAACQUISITION"));
166 
167  while (rs >> buffer) {
168 
169  umap[buffer.OID] = buffer.NAME;
170 
171  string::size_type pos = buffer.NAME.find(PREFIX_DATAFILTER);
172 
173  if (pos != string::npos) {
174 
175  string::size_type len = PREFIX_DATAFILTER.length();
176 
177  while (pos + len != buffer.NAME.length() && buffer.NAME[pos + len] != '=') {
178  ++len;
179  }
180 
181  zmap[buffer.OID] = buffer.NAME.erase(pos, len + 1);
182  }
183  }
184 
185  rs.Close();
186 
187  DEBUG("Parameters map " << zmap.size() << endl);
188  }
189  catch(const exception& error) {
190  FATAL(error.what() << endl);
191  }
192 
193 
194  stringstream data;
195 
196  try {
197 
198  JRunsetupParams buffer;
199 
200  ResultSet& rs = getResultSet(getTable<JRunsetupParams>(), getSelector<JRunsetupParams>(detid, rs_oid));
201 
202  while (rs >> buffer) {
203 
204  DEBUG(buffer.PAR_OID << "->" << umap[buffer.PAR_OID] << " = " << buffer.VALUE << endl);
205 
206  map<string, string>::const_iterator i = zmap.find(buffer.PAR_OID);
207 
208  if (i != zmap.end()) {
209  data << i->second << "=" << buffer.VALUE << ";\n";
210  }
211  }
212  }
213  catch(const exception& error) {
214  FATAL(error.what() << endl);
215  }
216 
217  DEBUG("Raw data" << endl << "<<" << endl << data.str() << ">>" << endl);
218 
219 
220  data >> parametersB;
221 
222  parametersB.set(Dmax_m);
223  parametersB.actionAtFileRead();
224 
225  DEBUG(parametersB);
226 
227 
228  if (outputFile.getFilename() != "") {
229 
230  DEBUG("Write to " << outputFile << "... " << flush);
231 
232  outputFile.open();
233 
234  outputFile.put(parametersB);
235 
237 
238  io >> outputFile;
239 
240  outputFile.close();
241 
242  DEBUG("OK" << endl);
243  }
244 
245 
246  const bool is_equal = (parametersA == parametersB);
247 
248  if (is_equal)
249  NOTICE(GREEN << "The parameters for run " << run_number << " are equivalent." << RESET << endl);
250  else
251  ERROR (RED << "The parameters for run " << run_number << " are NOT equivalent." << RESET << endl);
252 
253  return (is_equal ? 0 : 1);
254 }
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
ROOT TTree parameter settings.
Recording of objects on file according a format that follows from the file name extension.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
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:1954
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()
Get next element.
int debug
debug level
Definition: JSirene.cc:61
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:65
Utility class to parse command line options.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
virtual bool hasNext()
Check availability of next element.
Object reading from a list of files.
Template definition for getting table specific selector.
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std::string RUNSETUPID
Definition: JRuns.hh:26
int main(int argc, char *argv[])
Definition: Main.cpp:15