Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/JDetectors.hh"
13 #include "JDB/JRuns.hh"
14 #include "JDB/JAllParams.hh"
15 #include "JDB/JRunsetupParams.hh"
17 
19 
20 #include "JSystem/JStat.hh"
21 
22 #include "JSupport/JMeta.hh"
23 
24 #include "Jeep/JParser.hh"
25 #include "Jeep/JMessage.hh"
26 
27 
28 /**
29  * \file
30  * Auxiliary program to set PMT thresholds according DAQ configuration.
31  * \author mdejong
32  */
33 int main(const int argc, const char * const argv[])
34 {
35  using namespace std;
36  using namespace JPP;
37 
38  JServer server;
39  string usr;
40  string pwd;
41  string cookie;
42  string detid;
43  int run;
44  string pmtFile;
45  string formula;
46  int debug;
47 
48  try {
49 
50  JParser<> zap("Auxiliary program to set PMT thresholds according DAQ configuration.");
51 
52  zap['s'] = make_field(server) = getServernames();
53  zap['u'] = make_field(usr) = "";
54  zap['!'] = make_field(pwd) = "";
55  zap['C'] = make_field(cookie) = "";
56  zap['D'] = make_field(detid);
57  zap['r'] = make_field(run);
58  zap['P'] = make_field(pmtFile, "PMT parameters file") = "";
59  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";
60  zap['d'] = make_field(debug) = 1;
61 
62  zap(argc, argv);
63  }
64  catch(const exception& error) {
65  FATAL(error.what() << endl);
66  }
67 
68 
69  JPMTParametersMap parameters;
70 
71  if (pmtFile != "" && getFileStatus(pmtFile.c_str())) {
72  parameters.load(pmtFile.c_str());
73  }
74 
75 
76  TF1 f1("user", formula.c_str());
77 
78  if (!f1.IsValid()) {
79  FATAL("Formula <" << formula << "> invalid." << endl);
80  }
81 
82 
83  try {
84  JDB::reset(usr, pwd, cookie);
85  }
86  catch(const exception& error) {
87  FATAL(error.what() << endl);
88  }
89 
90 
91  string rs_oid;
92 
93  try {
94 
95  JRuns parameters;
96 
97  ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(is_integer(detid) ? to_value<int>(detid) : getDetector(detid), run));
98 
99  if (rs >> parameters) {
100  rs_oid = parameters.RUNSETUPID;
101  }
102 
103  rs.Close();
104 
105  DEBUG("Run setup " << rs_oid << endl);
106  }
107  catch(const exception& error) {
108  FATAL(error.what() << endl);
109  }
110 
111 
112  JAllParams upars;
113 
114  try {
115 
116  JAllParams parameters;
117 
118  ResultSet& rs = getResultSet(getTable<JAllParams>(), getSelector<JAllParams>("OPTICS"));
119 
120  while (rs >> parameters) {
121  if (parameters.NAME.find("PMT_THRESHOLD") != string::npos) {
122  upars = parameters;
123  }
124  }
125 
126  rs.Close();
127  }
128  catch(const exception& error) {
129  FATAL(error.what() << endl);
130  }
131 
132 
133  map<string, int> umap;
134 
135  try {
136 
137  JRunsetupParams parameters;
138 
139  ResultSet& rs = getResultSet(getTable<JRunsetupParams>(), getSelector<JRunsetupParams>(is_integer(detid) ? getDetector(to_value<int>(detid)) : detid, rs_oid));
140 
141  while (rs >> parameters) {
142 
143  if (parameters.PAR_OID == upars.OID && parameters.ISINPUT == 'Y') {
144  if (parameters.VALUE != "") {
145  umap[parameters.UPIFILTER] = to_value<int>(parameters.VALUE);
146  }
147  }
148  }
149 
150  rs.Close();
151  }
152  catch(const exception& error) {
153  FATAL(error.what() << endl);
154  }
155 
156  for (map<string, int>::const_iterator i = umap.begin(); i != umap.end(); ++i) {
157  DEBUG(left << setw(20) << i->first << ' ' << right << setw(3) << i->second << endl);
158  }
159 
160 
162 
163  try {
164 
165  JDetectorIntegration parameters;
166 
167  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(is_integer(detid) ? to_value<int>(detid) : getDetector(detid)));
168 
169  while (rs >> parameters) {
170  detector.push_back(parameters);
171  }
172 
173  rs.Close();
174  }
175  catch(const exception& error) {
176  FATAL(error.what() << endl);
177  }
178 
179 
180 
181  for (vector<JDetectorIntegration>::const_iterator i = detector.begin(); i != detector.end(); ++i) {
182 
183  if (i->PMTID != -1) {
184 
185  const JUPI_t upi = i->PMTUPI;
186 
187  map<string, int>::const_iterator p = umap.find(upi.toString());
188 
189  bool is_default = (p == umap.end());
190 
191  if (p == umap.end()) {
192 
193  ostringstream os;
194 
195  os << upi.getPBS() << JUPI_t::SEPARATOR
196  << upi.getVariant() << JUPI_t::SEPARATOR
197  << JUPI_t::DOT;
198 
199  p = umap.find(os.str());
200  }
201 
202  if (p != umap.end()) {
203 
204  const double threshold = f1.Eval((double) p->second);
205 
206  if (debug >= debug_t) {
207 
208  cout << setw(4) << i->DUID << ' '
209  << setw(2) << i->FLOORID << ' '
210  << setw(2) << i->CABLEPOS << ' '
211  << setw(3) << p->second << ' '
212  << FIXED(5,2) << threshold << ' ';
213 
214  if (is_default) {
215  cout << "* (" << FIXED(5,2) << JPMTParameters().threshold << ")";
216  }
217 
218  cout << endl;
219  }
220 
221  if (!is_default) {
222 
223  const JPMTIdentifier id(i->DOMID, i->CABLEPOS);
224 
225  parameters[id].threshold = threshold;
226  }
227 
228  } else {
229 
230  ERROR("Missing threshold data PMT " << upi << endl);
231  }
232  }
233  }
234 
235  if (pmtFile != "") {
236 
237  parameters.comment.add(JMeta(argc, argv));
238 
239  parameters.store(pmtFile.c_str());
240 
241  } else {
242 
243  cout << parameters << endl;
244  }
245 }
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
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT I/O of application specific meta data.
#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
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
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
File status.