Jpp  17.1.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPrintAHRSCalibration.cc File Reference

Example program for compass calibration. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <functional>
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JAHRSCalibration.hh"
#include "JDB/JAHRSCalibrationToolkit.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JDetectorIntegration_t.hh"
#include "JDB/JPBSSequence.hh"
#include "JDB/JProductRouter.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program for compass calibration.

Author
mdejong

Definition in file JPrintAHRSCalibration.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file JPrintAHRSCalibration.cc.

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 
57  vector<JAHRSCalibration> calibration;
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 
73  const JAHRSCalibrationValidity is_valid;
74 
76 
77 
78  JDetectorIntegration_t detector;
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 
104  const JProductRouter router(detector, getPBSSequences(PBS::AHRS));
105 
106  sort(calibration.begin(), calibration.end(), binary_negate<JAHRSCalibrationComparator>(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  }
132 
133  zmap[location] = *p;
134 
135  break;
136  }
137  }
138  }
139 
140  for (vector<JAHRSCalibration>::const_iterator i = p; i != q; ++i) {
141 
142  const bool valid = is_valid(*i) || (i != p);
143 
144  if (debug >= debug_t) {
145 
146  cout << setw(8) << i->SERIALNUMBER << ' '
147  << setw(22) << left << upi << right << ' '
148  << setw(8) << i->TESTEND << ' '
149  << setw(8) << i->FIRMWARE_VERSION << ' '
150  << setw(2) << getVersion(i->TESTNAME) << ' '
151  << setw(10) << i->TESTOPID << ' '
152  << (valid ? "" : "*") << endl;
153 
154  if (!valid) {
155  //cout << " -> " << *i << endl;
156  }
157  }
158  }
159 
160  p = q;
161  }
162 
163  for (map<JLocation_t, JAHRSCalibration>::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
164 
165  const JLocation_t& location = i->first;
166  const JAHRSCalibration& calibration = i->second;
167  const JUPI_t upi = getUPI(PBS::AHRS, calibration.SERIALNUMBER);
168 
169  cout << location << " ";
170 
171  JDetectorIntegration_t::range_type r1, r2;
172 
173  r1 = detector.find(upi);
174 
175  if (distance(r1.first, r1.second) == 1) {
176 
177  r2 = detector.find(detector[r1.first->second].container.getUPI());
178 
179  if (distance(r2.first, r2.second) == 1) {
180  cout << setw(22) << left << detector[r2.first->second].container.getUPI() << right << ' ';
181  cout << setw(22) << left << detector[r1.first->second].container.getUPI() << right << ' ';
182  cout << setw(22) << left << upi << right << ' ';
183  }
184  }
185 
186  cout << setw(3) << (calibration.FIRMWARE_VERSION != "" ?
187  calibration.FIRMWARE_VERSION :
188  "?") << ' ';
189  cout << setw(2) << getVersion(calibration.TESTNAME) << ' ';
190  cout << setw(10) << calibration.TESTOPID << ' ';
191  cout << endl;
192  }
193 
194  return 0;
195 }
Utility class to parse command line options.
Definition: JParser.hh:1517
#define WARNING(A)
Definition: JMessage.hh:65
debug
Definition: JMessage.hh:29
static JGetPBSSequences getPBSSequences
Function object to get PBS sequences as a function of PBS.
int getVersion(const std::string &version)
Get numerical value of AHRS calibration version.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
JUPIHelper & getUPI()
Auxiliary function for helper object initialisation.
Definition: JDBToolkit.hh:459
then usage source $script nThis script contains auxiliary functions for the pre calibration of specific detectors nIt should be sourced by the detector specific scripts fi source JAcousticsToolkit sh set_variable WORKDIR pwd set_variable TMPDIR $WORKDIR typeset A TRIPODS typeset a CHI2 set_variable PRECISION set_variable EPSILON set_variable RADIUS_M function initialise()
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
bool is_valid(const json &js)
Check validity of JSon data.
#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:432
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:98
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level
static const JPBS_t AHRS(3, 4, 3, 4)
PBS of compass
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62