Jpp
 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  string usr;
59  string pwd;
60  string cookie;
61  string detid;
62  int run;
63  int debug;
64 
65  try {
66 
67  JParser<> zap("Auxiliary program to print run setup parameters from the database.");
68 
69  zap['u'] = make_field(usr) = "";
70  zap['!'] = make_field(pwd) = "";
71  zap['C'] = make_field(cookie) = "";
72  zap['D'] = make_field(detid);
73  zap['r'] = make_field(run);
74  zap['d'] = make_field(debug) = 1;
75 
76  zap(argc, argv);
77  }
78  catch(const exception& error) {
79  FATAL(error.what() << endl);
80  }
81 
82 
83  JRootWriter writer(cout, JEquationParameters(), JDBDictionary::getInstance());
84 
85 
86  try {
87  JDB::reset(usr, pwd, cookie);
88  }
89  catch(const exception& error) {
90  FATAL(error.what() << endl);
91  }
92 
93 
94  string rs_oid;
95 
96  try {
97 
98  JRuns parameters;
99 
100  ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(is_integer(detid) ? to_value<int>(detid) : getDetector(detid), run));
101 
102  if (rs >> parameters) {
103  rs_oid = parameters.RUNSETUPID;
104  }
105 
106  rs.Close();
107 
108  DEBUG("Run setup " << rs_oid << endl);
109  }
110  catch(const exception& error) {
111  FATAL(error.what() << endl);
112  }
113 
114 
115  JAllParams upars;
116 
117  try {
118 
119  JAllParams parameters;
120 
121  ResultSet& rs = getResultSet(getTable<JAllParams>(), getSelector<JAllParams>("OPTICS"));
122 
123  while (rs >> parameters) {
124  if (parameters.NAME.find("PMT_THRESHOLD") != string::npos) {
125  upars = parameters;
126  }
127  }
128 
129  rs.Close();
130 
131  if (debug >= debug_t) {
132  writer.put(upars);
133  }
134  }
135  catch(const exception& error) {
136  FATAL(error.what() << endl);
137  }
138 
139 
140  map<string, int> umap;
141 
142  try {
143 
144  JRunsetupParams parameters;
145 
146  ResultSet& rs = getResultSet(getTable<JRunsetupParams>(), getSelector<JRunsetupParams>(is_integer(detid) ? getDetector(to_value<int>(detid)) : detid, rs_oid));
147 
148  while (rs >> parameters) {
149 
150  if (parameters.PAR_OID == upars.OID && parameters.ISINPUT == 'Y') {
151 
152  if (debug >= debug_t) {
153  writer.put(parameters);
154  }
155 
156  if (parameters.VALUE != "") {
157  umap[parameters.UPIFILTER] = to_value<int>(parameters.VALUE);
158  }
159  }
160  }
161 
162  rs.Close();
163  }
164  catch(const exception& error) {
165  FATAL(error.what() << endl);
166  }
167 
168  for (map<string, int>::const_iterator i = umap.begin(); i != umap.end(); ++i) {
169  DEBUG(left << setw(20) << i->first << ' ' << right << setw(3) << i->second << endl);
170  }
171 
172 
174 
175  try {
176 
177  JDetectorIntegration parameters;
178 
179  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(is_integer(detid) ? to_value<int>(detid) : getDetector(detid)));
180 
181  while (rs >> parameters) {
182  detector.push_back(parameters);
183  }
184 
185  rs.Close();
186  }
187  catch(const exception& error) {
188  FATAL(error.what() << endl);
189  }
190 
191 
192  sort(detector.begin(), detector.end(), compare);
193 
194  for (vector<JDetectorIntegration>::const_iterator i = detector.begin(); i != detector.end(); ++i) {
195 
196  if (i->PMTID != -1) {
197 
198  const JUPI_t upi = i->PMTUPI;
199 
200  map<string, int>::const_iterator p = umap.find(upi.toString());
201 
202  bool is_default = (p == umap.end());
203 
204  if (p == umap.end()) {
205 
206  ostringstream os;
207 
208  os << upi.getPBS() << JUPI_t::SEPARATOR
209  << upi.getVariant() << JUPI_t::SEPARATOR
210  << JUPI_t::DOT;
211 
212  p = umap.find(os.str());
213  }
214 
215  if (p != umap.end()) {
216 
217  if (debug >= debug_t || !is_default) {
218  cout << setw(4) << i->DUID << ' '
219  << setw(2) << i->FLOORID << ' '
220  << setw(2) << i->CABLEPOS << ' '
221  << setw(3) << p->second << ' '
222  << (is_default ? "" : "*") << endl;
223  }
224 
225  } else {
226 
227  ERROR("Missing threshold data PMT " << upi << endl);
228  }
229  }
230  }
231 }
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.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
do set_variable DETECTOR_TXT $WORKDIR detector
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62