Jpp  debug
the software that should make you happy
JPrintAHRSCalibration.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 #include <functional>
6 
7 #include "JDB/JDB.hh"
8 #include "JDB/JSelector.hh"
10 #include "JDB/JAHRSCalibration.hh"
12 #include "JDB/JDBToolkit.hh"
13 
15 #include "JDB/JPBSSequence.hh"
16 #include "JDB/JProductRouter.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 /**
22  * \file
23  *
24  * Example program for compass calibration.
25  * \author mdejong
26  */
27 int main(int argc, char **argv)
28 {
29  using namespace std;
30  using namespace JPP;
31 
32  JServer server;
33  string usr;
34  string pwd;
35  string cookie;
36  string detid;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Example program for compass calibration.");
42 
43  zap['s'] = make_field(server) = getServernames();
44  zap['u'] = make_field(usr) = "";
45  zap['!'] = make_field(pwd) = "";
46  zap['C'] = make_field(cookie) = "";
47  zap['D'] = make_field(detid, "Detector identifier") = "";
48  zap['d'] = make_field(debug) = 2;
49 
50  zap(argc, argv);
51  }
52  catch(const exception &error) {
53  FATAL(error.what() << endl);
54  }
55 
56 
58 
59  try {
60 
61  JDB::reset(usr, pwd, cookie);
62 
63  ResultSet& rs = getResultSet(getTable<JAHRSCalibration>());
64 
65  rs >> calibration;
66 
67  rs.Close();
68  }
69  catch(const exception& error) {
70  FATAL(error.what() << endl);
71  }
72 
74 
75  JDBToolkit::initialise(getUPI, PBS::AHRS);
76 
77 
79 
80  if (detid != "") {
81 
82  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << endl);
83 
84  try {
85 
86  JDB::reset(usr, pwd, cookie);
87 
88  detid = getDetector<string>(detid);
89 
90  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
91 
92  if (! (rs >> detector)) {
93  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
94  }
95  }
96  catch(const exception& error) {
97  FATAL(error.what() << endl);
98  }
99 
100  detector.configure(detid);
101  }
102 
103 
105 
106  sort(calibration.begin(), calibration.end(), JAHRSCalibrationComparator());
107 
108 
110 
111  for (vector<JAHRSCalibration>::const_iterator p = calibration.begin(); p != calibration.end(); ) {
112 
114 
115  for (++q; q != calibration.end() && q->SERIALNUMBER == p->SERIALNUMBER; ++q) {}
116 
117  const JUPI_t upi = getUPI(PBS::AHRS, p->SERIALNUMBER);
118  const JLocation_t location = router.getLocation(upi);
119 
120  if (location.is_valid()) {
121 
122  for (vector<JAHRSCalibration>::const_iterator i = p; i != q; ++i) {
123 
124  if (is_valid(*i)) {
125 
126  if (i != p) {
127  WARNING("AHRS " << location << ' ' << upi << ' '
128  << "invalid calibration" << ' '
129  << p->TESTEND << " v" << getVersion(p->TESTNAME) << " -> "
130  << i->TESTEND << " v" << getVersion(i->TESTNAME) << endl);
131  DEBUG(*p << endl);
132  }
133 
134  zmap[location] = *i;
135 
136  break;
137  }
138  }
139  }
140 
141  for (vector<JAHRSCalibration>::const_iterator i = p; i != q; ++i) {
142 
143  const bool valid = is_valid(*i) || (i != p);
144 
145  if (debug >= debug_t) {
146 
147  cout << setw(8) << i->SERIALNUMBER << ' '
148  << setw(22) << left << upi << right << ' '
149  << setw(8) << i->TESTEND << ' '
150  << setw(8) << i->FIRMWARE_VERSION << ' '
151  << setw(2) << getVersion(i->TESTNAME) << ' '
152  << setw(10) << i->TESTOPID << ' '
153  << (valid ? "" : "*") << endl;
154 
155  if (!valid) {
156  //cout << " -> " << *i << endl;
157  }
158  }
159  }
160 
161  p = q;
162  }
163 
164  for (map<JLocation_t, JAHRSCalibration>::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
165 
166  const JLocation_t& location = i->first;
167  const JAHRSCalibration& calibration = i->second;
168  const JUPI_t upi = getUPI(PBS::AHRS, calibration.SERIALNUMBER);
169 
170  cout << location << " ";
171 
173 
174  r1 = detector.find(upi);
175 
176  if (distance(r1.first, r1.second) == 1) {
177 
178  r2 = detector.find(detector[r1.first->second].container.getUPI());
179 
180  if (distance(r2.first, r2.second) == 1) {
181  cout << setw(22) << left << detector[r2.first->second].container.getUPI() << right << ' ';
182  cout << setw(22) << left << detector[r1.first->second].container.getUPI() << right << ' ';
183  cout << setw(22) << left << upi << right << ' ';
184  }
185  }
186 
187  cout << setw(3) << (calibration.FIRMWARE_VERSION != "" ?
188  calibration.FIRMWARE_VERSION :
189  "?") << ' ';
190  cout << setw(2) << getVersion(calibration.TESTNAME) << ' ';
191  cout << setw(10) << calibration.TESTOPID << ' ';
192  cout << endl;
193  }
194 
195  return 0;
196 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
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
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
int main(int argc, char **argv)
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Database exception.
Definition: JException.hh:684
Utility class to parse command line options.
Definition: JParser.hh:1714
static const JPBS_t AHRS(3, 4, 3, 4)
PBS of compass
int getVersion(const std::string &version)
Get numerical value of AHRS calibration version.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:436
static JGetPBSSequences getPBSSequences
Function object to get PBS sequences as a function of PBS.
JUPIHelper & getUPI()
Auxiliary function for helper object initialisation.
Definition: JDBToolkit.hh:472
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).
bool is_valid(const json &js)
Check validity of JSon data.
void reset(T &value)
Reset value.
Definition: JSTDTypes.hh:14
Calibration.
Definition: JHead.hh:330
Detector file.
Definition: JHead.hh:227
Auxiliary data structure for sorting of AHRS calibrations.
Auxiliary data structure to check validity of AHRS calibration data.
Auxiliary data structure for location of product in detector.
Definition: JLocation_t.hh:26
bool is_valid() const
Check validity of location.
Definition: JLocation_t.hh:59
Auxiliary class to map UPI to location in detector.
JLocation_t getLocation(const JUPI_t &upi) const
Get location of product with given UPI.
Wrapper class for server name.
Definition: JDB.hh:52
Universal product identifier (UPI).
Definition: JUPI_t.hh:32