Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JEditTuneHV.cc File Reference

Auxiliary program to treat failed HV-tuning calibrations. More...

#include <iostream>
#include <iomanip>
#include <set>
#include "km3net-dataformat/online/JDAQ.hh"
#include "JSystem/JTime.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JProperties.hh"
#include "JLang/JPredicate.hh"
#include "JSupport/JFilenameSupportkit.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JDB/JDB.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JDBincludes.hh"
#include "JDB/JProductRouter.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDetectorIntegration.hh"
#include "JDB/JDetectorIntegration_t.hh"
#include "JSon/JSon.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to treat failed HV-tuning calibrations.

Possible operations are to update according to:

Definition in file JEditTuneHV.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 46 of file JEditTuneHV.cc.

47 {
48  using namespace std;
49  using namespace JPP;
50  using namespace KM3NETDAQ;
51 
52  string usr;
53  string pwd;
54  string cookie;
55 
56  string inputFile;
57  string outputFile;
58 
59  set<JUPI_t> pmtSet;
60 
61  double minHV = -1500;
62  double maxHV = - 800;
63 
64  int detID;
65  int runNr;
66 
67  int debug;
68 
69  try {
70 
71  JProperties properties;
72 
73  properties.insert(gmake_property(minHV));
74  properties.insert(gmake_property(maxHV));
75 
76  JParser<> zap("Auxiliary program to treat failed high-voltage tuning results.");
77 
78  zap['u'] = make_field(usr) = "";
79  zap['!'] = make_field(pwd) = "";
80  zap['C'] = make_field(cookie) = "";
81  zap['f'] = make_field(inputFile, "input file");
82  zap['o'] = make_field(outputFile, "output file");
83  zap['D'] = make_field(detID, "detector identifier") = -1;
84  zap['r'] = make_field(runNr, "run number") = -1;
85  zap['P'] = make_field(pmtSet, "Set of PMT UPIs") = JPARSER::initialised();
86  zap['@'] = make_field(properties) = JPARSER::initialised();
87  zap['d'] = make_field(debug, "debug") = 2;
88 
89  zap(argc, argv);
90 
91  } catch(const exception &error) {
92 
93  FATAL(error.what() << endl);
94  }
95 
96  JDateAndTime timer;
97 
98  string testType;
99  JHVCalibration toEdit;
100 
101  if (isJSONFile(inputFile.c_str())) {
102 
103  json js;
104 
105  ifstream ifs(inputFile.c_str());
106 
107  ifs >> js;
108  ifs.close();
109 
110  JHVCalibration HVcals;
111 
112  json::const_iterator data = js.find(Tests_t);
113 
114  if (data != js.end()) {
115 
116  HVcals = data->get<JHVCalibration>();
117 
118  } else {
119 
120  ERROR("HV calibration data could not be found!");
121  }
122 
123  json::const_iterator DBtype = js.find(Test_t + Type_t);
124 
125  if (DBtype != js.end()) {
126 
127  testType = DBtype->get<string>();
128 
129  } else {
130 
131  WARNING("No database test type specified.");
132  }
133 
134  if (pmtSet.empty()) {
135 
136  for (JHVCalibration::iterator it = HVcals.begin(); it != HVcals.end(); ++it) {
137 
138  if (it->result != OK_t) {
139  toEdit.push_back(*it);
140  }
141  }
142 
143  } else {
144 
145  for (set<JUPI_t>::const_iterator it = pmtSet.cbegin(); it != pmtSet.cend(); ++it) {
146 
147  JHVCalibration::iterator pmt = find_if(HVcals.begin(), HVcals.end(),
148  make_predicate(&JHVCalibration_t::getNumber, it->getNumber()));
149  if (pmt != HVcals.end()) {
150 
151  if (pmt->result == OK_t) {
152  WARNING("Editing " << OK_t << " result for " << pmt->getUPI() << endl);
153  }
154 
155  toEdit.push_back(*pmt);
156  }
157  }
158  }
159 
160  } else {
161 
162  ERROR(inputFile << " is not a JSON file." << endl);
163  }
164 
165 
166  JPersons person;
167 
168  try {
169 
170  JDB::reset(usr, pwd, cookie);
171 
172  {
173  JSelector selector = getSelector<JPersons>(JDB::get()->User());
174  ResultSet& rs = getResultSet(getTable<JPersons>(), selector);
175  rs >> person;
176  rs.Close();
177  }
178 
179  if (detID > 0 && runNr > 0) {
180 
181  NOTICE("Setting high-voltages corresponding to run " << runNr << "..." << endl);
182 
183  JSelector selector = getSelector<JPMTHVRunSettings>(getDetector(detID), runNr);
184  ResultSet& rs = getResultSet(getTable<JPMTHVRunSettings>(), selector);
185 
186  for (JPMTHVRunSettings table; rs >> table; ) {
187 
188  JHVCalibration::iterator cal = find_if(toEdit.begin(), toEdit.end(),
189  make_predicate(&JHVCalibration_t::getNumber, table.PMTSERIAL));
190  if (cal != toEdit.end()) {
191 
192  cal->supplyVoltage = table.HV_VALUE;
193  cal->result = OK_t;
194  }
195  }
196 
197  rs.Close();
198 
199  } else if (detID > 0) {
200 
201  NOTICE("Setting vendor high-voltages..." << endl);
202 
203  JSelector selector = getSelector<JVendorHV>(detID);
204  ResultSet& rs = getResultSet(getTable<JVendorHV>(), selector);
205 
206  for (JVendorHV table; rs >> table; ) {
207 
208  JHVCalibration::iterator cal = find_if(toEdit.begin(), toEdit.end(),
209  make_predicate(&JHVCalibration_t::getNumber, table.PMTSERIAL));
210  if (cal != toEdit.end()) {
211 
212  cal->supplyVoltage = table.PMT_SUPPLY_VOLTAGE;
213  cal->result = OK_t;
214  }
215  }
216 
217  rs.Close();
218 
219  } else {
220 
221  NOTICE("Setting high-voltages manually..." << endl);
222 
223  for (JHVCalibration::iterator cal = toEdit.begin(); cal != toEdit.end(); ++cal) {
224 
225  NOTICE("Please specify high-voltage for " << RIGHT(30) << cal->getUPI() << ":" << endl);
226 
227  double manualHV;
228  cin >> manualHV;
229 
230  if (manualHV > minHV && manualHV < maxHV) {
231 
232  cal->supplyVoltage = manualHV;
233  cal->result = OK_t;
234 
235  } else {
236 
237  WARNING("Specified high-voltage is not within range [" << minHV << ", " << maxHV << "]; skip.");
238  }
239 
240  NOTICE(endl);
241  }
242  }
243 
244  } catch (const exception& error) {
245 
246  FATAL(error.what() << endl);
247  }
248 
249  json js;
250 
251  js[User_t] = person.LOGIN;
252  js[Location_t] = person.LOCATIONID;
253  js[StartTime_t] = timer.toString();
254  js[EndTime_t] = timer().toString();
255  js[Test_t + Type_t] = testType;
256  js[Tests_t] = json(toEdit);
257 
258  ofstream ofs(outputFile.c_str());
259 
260  ofs << setw(2) << setprecision(8);
261  ofs << js;
262 
263  ofs.close();
264 
265  return 0;
266 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define WARNING(A)
Definition: JMessage.hh:65
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
static const std::string Tests_t
static const std::string OK_t
Utility class to parse parameter values.
Definition: JProperties.hh:496
T get(const JHead &header)
Get object from header.
static const std::string Location_t
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
string outputFile
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
std::vector< JHVCalibration_t > JHVCalibration
PMT high voltage calibration.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
static const std::string Test_t
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
static const std::string EndTime_t
nlohmann::json json
static const std::string Type_t
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
static const std::string StartTime_t
static const std::string User_t
Detector calibration key words for JSON I/O.
bool isJSONFile(const char *file_name)
Check file format.