Jpp  debug
the software that should make you happy
software/JDB/JPMTThreshold.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <vector>
4 #include <map>
5 
6 #include "TF1.h"
7 
8 #include "JDB/JDB.hh"
9 #include "JDB/JSelector.hh"
11 #include "JDB/JDBToolkit.hh"
12 #include "JDB/JPMTThreshold.hh"
14 
16 
17 #include "JSystem/JStat.hh"
18 
19 #include "JSupport/JMeta.hh"
20 
21 #include "Jeep/JParser.hh"
22 #include "Jeep/JMessage.hh"
23 
24 
25 /**
26  * \file
27  * Auxiliary program to set PMT thresholds according DAQ configuration of a given data taking run.
28  * \author mdejong
29  */
30 int main(const int argc, const char * const argv[])
31 {
32  using namespace std;
33  using namespace JPP;
34 
35  JServer server;
36  string usr;
37  string pwd;
38  string cookie;
39  string detid;
40  int run;
41  string pmtFile;
42  string formula;
43  int debug;
44 
45  try {
46 
47  JParser<> zap("Auxiliary program to set PMT thresholds according DAQ configuration of a given data taking run.");
48 
49  zap['s'] = make_field(server) = getServernames();
50  zap['u'] = make_field(usr) = "";
51  zap['!'] = make_field(pwd) = "";
52  zap['C'] = make_field(cookie) = "";
53  zap['D'] = make_field(detid);
54  zap['r'] = make_field(run);
55  zap['P'] = make_field(pmtFile, "PMT parameters file") = "";
56  zap['F'] = make_field(formula, "transfer function") = "((x * 1.0)/255.0 * 1.6 + 0.8 - 0.989) / 0.44"; // "((x * 1.0)/255.0 * 1.6 + 0.8 - 1) / 0.44";
57  zap['d'] = make_field(debug) = 1;
58 
59  zap(argc, argv);
60  }
61  catch(const exception& error) {
62  FATAL(error.what() << endl);
63  }
64 
65 
66  JPMTParametersMap parameters;
67 
68  if (pmtFile != "" && getFileStatus(pmtFile.c_str())) {
69  parameters.load(pmtFile.c_str());
70  }
71 
72 
73  TF1 f1("user", formula.c_str());
74 
75  if (!f1.IsValid()) {
76  FATAL("Formula <" << formula << "> invalid." << endl);
77  }
78 
79 
80  typedef vector<JDetectorIntegration> detector_type;
81 
82  JPMTThreshold getPMTThreshold;
83  detector_type detector;
84 
85 
86  try {
87 
88  JDB::reset(usr, pwd, cookie);
89 
90  const int id = getDetector<int>(detid);
91 
92  getPMTThreshold.configure(id, run);
93 
94  DEBUG(getPMTThreshold);
95 
96  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(id));
97 
98  for (JDetectorIntegration parameters; rs >> parameters; ) {
99  detector.push_back(parameters);
100  }
101 
102  rs.Close();
103  }
104  catch(const exception& error) {
105  FATAL(error.what() << endl);
106  }
107 
108 
109  for (vector<JDetectorIntegration>::const_iterator i = detector.begin(); i != detector.end(); ++i) {
110 
111  if (i->PMTID != -1) {
112 
113  try {
114 
115  const JPMTThreshold::result_type threshold = getPMTThreshold(i->PMTUPI);
116 
117  const double value = f1.Eval((double) threshold.value);
118 
119  if (debug >= debug_t) {
120 
121  cout << FILL(4,'0') << i->DUID << FILL() << '.'
122  << FILL(2,'0') << i->FLOORID << FILL() << '['
123  << FILL(2,'0') << i->CABLEPOS << FILL() << ']'
124  << ' '
125  << setw(3) << threshold.value << ' '
126  << FIXED(5,2) << value << ' ';
127 
128  if (threshold.is_default) {
129  cout << "* (" << FIXED(5,2) << JPMTParameters().threshold << ")";
130  }
131 
132  cout << endl;
133  }
134 
135  if (!threshold.is_default) {
136 
137  const JPMTIdentifier id(i->DOMID, i->CABLEPOS);
138 
139  parameters[id].threshold = value;
140  }
141  }
142  catch(const exception& error) {
143  WARNING("Error at "
144  << FILL(4,'0') << i->DUID << FILL() << '.'
145  << FILL(2,'0') << i->FLOORID << FILL() << '['
146  << FILL(2,'0') << i->CABLEPOS << FILL() << ']'
147  << ' '
148  << error.what() << endl);
149  }
150  }
151  }
152 
153  if (pmtFile != "") {
154 
155  parameters.comment.add(JMeta(argc, argv));
156 
157  parameters.store(pmtFile.c_str());
158 
159  } else {
160 
161  cout << parameters << endl;
162  }
163 }
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define WARNING(A)
Definition: JMessage.hh:65
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
File status.
Auxiliary class for PMT thresholds.
void configure(const int id, const int run)
Configure PMT thresholds for given detector and run.
Auxiliary class for map of PMT parameters.
Data structure for PMT parameters.
double threshold
threshold [npe]
Utility class to parse command line options.
Definition: JParser.hh:1714
const JPolynome f1(1.0, 2.0, 3.0)
Function.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:436
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:106
@ debug_t
debug
Definition: JMessage.hh:29
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
void reset(T &value)
Reset value.
Definition: JSTDTypes.hh:14
int main(const int argc, const char *const argv[])
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Detector file.
Definition: JHead.hh:227
Wrapper class for server name.
Definition: JDB.hh:52
Template definition for getting table specific selector.
JComment & add(const std::string &comment)
Add comment.
Definition: JComment.hh:100
void store(const char *file_name) const
Store to output file.
void load(const char *file_name)
Load from input file.
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72