Jpp  16.0.0
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 <algorithm>
5 
6 #include "JDB/JDB.hh"
7 #include "JDB/JSelector.hh"
9 #include "JDB/JDBToolkit.hh"
10 #include "JDB/JPMTThreshold.hh"
12 
13 #include "Jeep/JPrint.hh"
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 namespace {
18 
20 
21  /**
22  * Compare detector integration by string number, floor and PMT position.
23  *
24  * \param first detector integration
25  * \param second detector integration
26  * \return true if first detector integration before second; else false
27  */
28  inline bool compare(const JDetectorIntegration& first, const JDetectorIntegration& second)
29  {
30  if (first.DUID == second.DUID) {
31 
32  if (first.FLOORID == second.FLOORID)
33  return first.CABLEPOS < second.CABLEPOS;
34  else
35  return first.FLOORID < second.FLOORID;
36 
37  } else {
38 
39  return first.DUID < second.DUID;
40  }
41  }
42 }
43 
44 
45 /**
46  * \file
47  * Auxiliary program to print run setup parameters from the database.
48  * \author mdejong
49  */
50 int main(const int argc, const char * const argv[])
51 {
52  using namespace std;
53  using namespace JPP;
54 
55  JServer server;
56  string usr;
57  string pwd;
58  string cookie;
59  string detid;
60  int run;
61  int debug;
62 
63  try {
64 
65  JParser<> zap("Auxiliary program to print run setup parameters from the database.");
66 
67  zap['s'] = make_field(server) = getServernames();
68  zap['u'] = make_field(usr) = "";
69  zap['!'] = make_field(pwd) = "";
70  zap['C'] = make_field(cookie) = "";
71  zap['D'] = make_field(detid);
72  zap['r'] = make_field(run);
73  zap['d'] = make_field(debug) = 1;
74 
75  zap(argc, argv);
76  }
77  catch(const exception& error) {
78  FATAL(error.what() << endl);
79  }
80 
81 
82  typedef vector<JDetectorIntegration> detector_type;
83 
84  JPMTThreshold getPMTThreshold;
85  detector_type detector;
86 
87  try {
88 
89  JDB::reset(usr, pwd, cookie);
90 
91  const int id = getDetector<int>(detid);
92 
93  getPMTThreshold.configure(id, run);
94 
95  DEBUG(getPMTThreshold);
96 
97  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(id));
98 
99  for (JDetectorIntegration parameters; rs >> parameters; ) {
100  detector.push_back(parameters);
101  }
102 
103  rs.Close();
104  }
105  catch(const exception& error) {
106  FATAL(error.what() << endl);
107  }
108 
109  sort(detector.begin(), detector.end(), compare);
110 
111  for (detector_type::const_iterator i = detector.begin(); i != detector.end(); ++i) {
112 
113  if (i->PMTID != -1) {
114 
115  try {
116 
117  const JPMTThreshold::result_type threshold = getPMTThreshold(i->PMTUPI);
118 
119  if (debug >= debug_t || !threshold.is_default) {
120  cout << setw(4) << i->DUID << ' '
121  << setw(2) << i->FLOORID << ' '
122  << setw(2) << i->CABLEPOS << ' '
123  << setw(3) << threshold.value << ' '
124  << (threshold.is_default ? "" : "*") << endl;
125  }
126  }
127  catch(const exception& error) {
128  ERROR(error.what() << endl);
129  }
130  }
131  }
132 }
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
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
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