Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
examples/JDB/JPMTThreshold.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <vector>
4 #include <map>
5 #include <algorithm>
6 
7 #include "JDB/JDB.hh"
8 #include "JDB/JSelector.hh"
10 #include "JDB/JDBToolkit.hh"
11 #include "JDB/JDetectors.hh"
12 #include "JDB/JRuns.hh"
13 #include "JDB/JAllParams.hh"
14 #include "JDB/JRunsetupParams.hh"
16 
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 
20 namespace {
21 
23 
24  /**
25  * Compare detector integration by string number, floor and PMT position.
26  *
27  * \param first detector integration
28  * \param second detector integration
29  * \return true if first detector integration before second; else false
30  */
31  bool compare(const JDetectorIntegration& first, const JDetectorIntegration& second)
32  {
33  if (first.DUID == second.DUID) {
34 
35  if (first.FLOORID == second.FLOORID)
36  return first.CABLEPOS < second.CABLEPOS;
37  else
38  return first.FLOORID < second.FLOORID;
39 
40  } else {
41 
42  return first.DUID < second.DUID;
43  }
44  }
45 }
46 
47 
48 /**
49  * \file
50  * Auxiliary program to print run setup parameters from the database.
51  * \author mdejong
52  */
53 int main(const int argc, const char * const argv[])
54 {
55  using namespace std;
56  using namespace JPP;
57 
58  JServer server;
59  string usr;
60  string pwd;
61  string cookie;
62  string detid;
63  int run;
64  int debug;
65 
66  try {
67 
68  JParser<> zap("Auxiliary program to print run setup parameters from the database.");
69 
70  zap['s'] = make_field(server) = getServernames();
71  zap['u'] = make_field(usr) = "";
72  zap['!'] = make_field(pwd) = "";
73  zap['C'] = make_field(cookie) = "";
74  zap['D'] = make_field(detid);
75  zap['r'] = make_field(run);
76  zap['d'] = make_field(debug) = 1;
77 
78  zap(argc, argv);
79  }
80  catch(const exception& error) {
81  FATAL(error.what() << endl);
82  }
83 
84 
85  JRootWriter writer(cout, JEquationParameters(), JDBDictionary::getInstance());
86 
87 
88  try {
89  JDB::reset(usr, pwd, cookie);
90  }
91  catch(const exception& error) {
92  FATAL(error.what() << endl);
93  }
94 
95 
96  string rs_oid;
97 
98  try {
99 
100  JRuns parameters;
101 
102  ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(is_integer(detid) ? to_value<int>(detid) : getDetector(detid), run));
103 
104  if (rs >> parameters) {
105  rs_oid = parameters.RUNSETUPID;
106  }
107 
108  rs.Close();
109 
110  DEBUG("Run setup " << rs_oid << endl);
111  }
112  catch(const exception& error) {
113  FATAL(error.what() << endl);
114  }
115 
116 
117  JAllParams upars;
118 
119  try {
120 
121  JAllParams parameters;
122 
123  ResultSet& rs = getResultSet(getTable<JAllParams>(), getSelector<JAllParams>("OPTICS"));
124 
125  while (rs >> parameters) {
126  if (parameters.NAME.find("PMT_THRESHOLD") != string::npos) {
127  upars = parameters;
128  }
129  }
130 
131  rs.Close();
132 
133  if (debug >= debug_t) {
134  writer.put(upars);
135  }
136  }
137  catch(const exception& error) {
138  FATAL(error.what() << endl);
139  }
140 
141 
142  map<string, int> umap;
143 
144  try {
145 
146  JRunsetupParams parameters;
147 
148  ResultSet& rs = getResultSet(getTable<JRunsetupParams>(), getSelector<JRunsetupParams>(is_integer(detid) ? getDetector(to_value<int>(detid)) : detid, rs_oid));
149 
150  while (rs >> parameters) {
151 
152  if (parameters.PAR_OID == upars.OID && parameters.ISINPUT == 'Y') {
153 
154  if (debug >= debug_t) {
155  writer.put(parameters);
156  }
157 
158  if (parameters.VALUE != "") {
159  umap[parameters.UPIFILTER] = to_value<int>(parameters.VALUE);
160  }
161  }
162  }
163 
164  rs.Close();
165  }
166  catch(const exception& error) {
167  FATAL(error.what() << endl);
168  }
169 
170  for (map<string, int>::const_iterator i = umap.begin(); i != umap.end(); ++i) {
171  DEBUG(left << setw(20) << i->first << ' ' << right << setw(3) << i->second << endl);
172  }
173 
174 
176 
177  try {
178 
179  JDetectorIntegration parameters;
180 
181  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(is_integer(detid) ? to_value<int>(detid) : getDetector(detid)));
182 
183  while (rs >> parameters) {
184  detector.push_back(parameters);
185  }
186 
187  rs.Close();
188  }
189  catch(const exception& error) {
190  FATAL(error.what() << endl);
191  }
192 
193 
194  sort(detector.begin(), detector.end(), compare);
195 
196  for (vector<JDetectorIntegration>::const_iterator i = detector.begin(); i != detector.end(); ++i) {
197 
198  if (i->PMTID != -1) {
199 
200  const JUPI_t upi = i->PMTUPI;
201 
202  map<string, int>::const_iterator p = umap.find(upi.toString());
203 
204  bool is_default = (p == umap.end());
205 
206  if (p == umap.end()) {
207 
208  ostringstream os;
209 
210  os << upi.getPBS() << JUPI_t::SEPARATOR
211  << upi.getVariant() << JUPI_t::SEPARATOR
212  << JUPI_t::DOT;
213 
214  p = umap.find(os.str());
215  }
216 
217  if (p != umap.end()) {
218 
219  if (debug >= debug_t || !is_default) {
220  cout << setw(4) << i->DUID << ' '
221  << setw(2) << i->FLOORID << ' '
222  << setw(2) << i->CABLEPOS << ' '
223  << setw(3) << p->second << ' '
224  << (is_default ? "" : "*") << endl;
225  }
226 
227  } else {
228 
229  ERROR("Missing threshold data PMT " << upi << endl);
230  }
231  }
232  }
233 }
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
*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
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
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
do set_variable DETECTOR_TXT $WORKDIR detector