Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
software/JDB/JPMTThreshold.cc File Reference

Auxiliary program to set PMT thresholds according DAQ configuration. More...

#include <string>
#include <iostream>
#include <vector>
#include <map>
#include "TF1.h"
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JDetectors.hh"
#include "JDB/JRuns.hh"
#include "JDB/JAllParams.hh"
#include "JDB/JRunsetupParams.hh"
#include "JDB/JDetectorIntegration.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JSupport/JMeta.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (const int argc, const char *const argv[])
 

Detailed Description

Auxiliary program to set PMT thresholds according DAQ configuration.

Author
mdejong

Definition in file software/JDB/JPMTThreshold.cc.

Function Documentation

int main ( const int  argc,
const char *const  argv[] 
)

Definition at line 31 of file software/JDB/JPMTThreshold.cc.

32 {
33  using namespace std;
34  using namespace JPP;
35 
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.");
48 
49  zap['u'] = make_field(usr) = "";
50  zap['!'] = make_field(pwd) = "";
51  zap['C'] = make_field(cookie) = "";
52  zap['D'] = make_field(detid);
53  zap['r'] = make_field(run);
54  zap['P'] = make_field(pmtFile, "PMT parameters file") = "";
55  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";
56  zap['d'] = make_field(debug) = 1;
57 
58  zap(argc, argv);
59  }
60  catch(const exception& error) {
61  FATAL(error.what() << endl);
62  }
63 
64 
65  JPMTParametersMap parameters;
66 
67  if (pmtFile != "") {
68  parameters.load(pmtFile.c_str());
69  }
70 
71 
72  TF1 f1("user", formula.c_str());
73 
74  if (!f1.IsValid()) {
75  FATAL("Formula <" << formula << "> invalid." << endl);
76  }
77 
78 
79  try {
80  JDB::reset(usr, pwd, cookie);
81  }
82  catch(const exception& error) {
83  FATAL(error.what() << endl);
84  }
85 
86 
87  string rs_oid;
88 
89  try {
90 
91  JRuns parameters;
92 
93  ResultSet& rs = getResultSet(getTable<JRuns>(), getSelector<JRuns>(is_integer(detid) ? to_value<int>(detid) : getDetector(detid), run));
94 
95  if (rs >> parameters) {
96  rs_oid = parameters.RUNSETUPID;
97  }
98 
99  rs.Close();
100 
101  DEBUG("Run setup " << rs_oid << endl);
102  }
103  catch(const exception& error) {
104  FATAL(error.what() << endl);
105  }
106 
107 
108  JAllParams upars;
109 
110  try {
111 
112  JAllParams parameters;
113 
114  ResultSet& rs = getResultSet(getTable<JAllParams>(), getSelector<JAllParams>("OPTICS"));
115 
116  while (rs >> parameters) {
117  if (parameters.NAME.find("PMT_THRESHOLD") != string::npos) {
118  upars = parameters;
119  }
120  }
121 
122  rs.Close();
123  }
124  catch(const exception& error) {
125  FATAL(error.what() << endl);
126  }
127 
128 
129  map<string, int> umap;
130 
131  try {
132 
133  JRunsetupParams parameters;
134 
135  ResultSet& rs = getResultSet(getTable<JRunsetupParams>(), getSelector<JRunsetupParams>(is_integer(detid) ? getDetector(to_value<int>(detid)) : detid, rs_oid));
136 
137  while (rs >> parameters) {
138 
139  if (parameters.PAR_OID == upars.OID && parameters.ISINPUT == 'Y') {
140  if (parameters.VALUE != "") {
141  umap[parameters.UPIFILTER] = to_value<int>(parameters.VALUE);
142  }
143  }
144  }
145 
146  rs.Close();
147  }
148  catch(const exception& error) {
149  FATAL(error.what() << endl);
150  }
151 
152  for (map<string, int>::const_iterator i = umap.begin(); i != umap.end(); ++i) {
153  DEBUG(left << setw(20) << i->first << ' ' << right << setw(3) << i->second << endl);
154  }
155 
156 
158 
159  try {
160 
161  JDetectorIntegration parameters;
162 
163  ResultSet& rs = getResultSet(getTable<JDetectorIntegration>(), getSelector<JDetectorIntegration>(is_integer(detid) ? to_value<int>(detid) : getDetector(detid)));
164 
165  while (rs >> parameters) {
166  detector.push_back(parameters);
167  }
168 
169  rs.Close();
170  }
171  catch(const exception& error) {
172  FATAL(error.what() << endl);
173  }
174 
175 
176 
177  for (vector<JDetectorIntegration>::const_iterator i = detector.begin(); i != detector.end(); ++i) {
178 
179  if (i->PMTID != -1) {
180 
181  const JUPI_t upi = i->PMTUPI;
182 
183  map<string, int>::const_iterator p = umap.find(upi.toString());
184 
185  bool is_default = (p == umap.end());
186 
187  if (p == umap.end()) {
188 
189  ostringstream os;
190 
191  os << upi.getPBS() << JUPI_t::SEPARATOR
192  << upi.getVariant() << JUPI_t::SEPARATOR
193  << JUPI_t::DOT;
194 
195  p = umap.find(os.str());
196  }
197 
198  if (p != umap.end()) {
199 
200  const double threshold = f1.Eval((double) p->second);
201 
202  if (debug >= debug_t) {
203 
204  cout << setw(4) << i->DUID << ' '
205  << setw(2) << i->FLOORID << ' '
206  << setw(2) << i->CABLEPOS << ' '
207  << setw(3) << p->second << ' '
208  << FIXED(5,2) << threshold << ' ';
209 
210  if (is_default) {
211  cout << "* (" << FIXED(5,2) << JPMTParameters().threshold << ")";
212  }
213 
214  cout << endl;
215  }
216 
217  if (!is_default) {
218 
219  const JPMTIdentifier id(i->DOMID, i->CABLEPOS);
220 
221  parameters[id].threshold = threshold;
222  }
223 
224  } else {
225 
226  ERROR("Missing threshold data PMT " << upi << endl);
227  }
228  }
229  }
230 
231  if (pmtFile != "") {
232 
233  parameters.comment.add(JMeta(argc, argv));
234 
235  parameters.store(pmtFile.c_str());
236 
237  } else {
238 
239  cout << parameters << endl;
240  }
241 }
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
*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:445
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
#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
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
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