Jpp - the software that should make you happy
 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 "JSystem/JStat.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 33 of file software/JDB/JPMTThreshold.cc.

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