Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JAHRSCalibration_t.hh
Go to the documentation of this file.
1#ifndef __JDB_JAHRSCALIBRATION_T__
2#define __JDB_JAHRSCALIBRATION_T__
3
4#include <istream>
5#include <ostream>
6#include <fstream>
7#include <map>
8#include <vector>
9
10#include "JLang/JException.hh"
12
13#include "JDB/JDB.hh"
14#include "JDB/JDBToolkit.hh"
15#include "JDB/JPBS_t.hh"
19
20
21/**
22 * \author mdejong
23 */
24namespace JDATABASE {}
25namespace JPP { using namespace JDATABASE; }
26
27namespace JDATABASE {
28
31
32
33 /**
34 * Auxiliary class to map module identifier to AHRS calibration.
35 */
37 public std::map<int, JAHRSCalibration>,
38 public JObjectStreamIO<JAHRSCalibration_t>
39 {
40 /**
41 * Default constructor.
42 */
45
46
47 /**
48 * Constructor.
49 *
50 * \param id detector identifier
51 * \param option option
52 */
53 JAHRSCalibration_t(const int id, const int option)
54 {
55 using namespace std;
56 using namespace JPP;
57
59
61
62 rs >> detector;
63
64 detector.configure(getDetector(id));
65
66 this->configure(detector, option);
67 }
68
69
70 /**
71 * Constructor.
72 *
73 * \param detector detector integration
74 * \param option option
75 */
77 {
78 this->configure(detector, option);
79 }
80
81
82 /**
83 * Constructor.
84 *
85 * \param file_name input file
86 */
87 JAHRSCalibration_t(const char* file_name)
88 {
89 load(file_name);
90 }
91
92
93 /**
94 * Configure.
95 *
96 * The latest <em>valid</em> AHRS calibration data to the identifier of the parent module.\n
97 * In this, the time order and validity of the AHRS calibration data are defined by AHRSComparator and JAHRSValidity, respectively.\n
98 * The option corresponds to the maximal difference between latest version and latest valid version.
99 *
100 * \param detector detector integration
101 * \param option option
102 */
103 void configure(const JDetectorIntegration_t& detector, const int option)
104 {
105 using namespace std;
106 using namespace JPP;
107
108 const JAHRSCalibrationValidity is_valid;
109
112
113 this->clear();
114
116
117 ResultSet& rs = getResultSet(getTable<JAHRSCalibration>());
118
119 rs >> calibration;
120
121 rs.Close();
122
123
124 sort(calibration.begin(), calibration.end(), JAHRSCalibrationComparator());
125
126
127 for (vector<JAHRSCalibration>::const_iterator p = calibration.begin(); p != calibration.end(); ) {
128
129 vector<JAHRSCalibration>::const_iterator q = p;
130
131 for (++q; q != calibration.end() && q->SERIALNUMBER == p->SERIALNUMBER; ++q) {}
132
133 const JUPI_t upi = getUPI(PBS::AHRS, p->SERIALNUMBER);
134
135 const JDetectorIntegration_t::range_type r1 = detector.find(upi);
136
137 if (distance(r1.first, r1.second) == 1) {
138
139 const int id = getCLBID(detector[r1.first->second].container.getUPI());
140
141 for (vector<JAHRSCalibration>::const_iterator i = p; i != q; ++i) {
142
143 if (is_valid(*i) && distance(p,i) <= option) {
144
145 this->insert(make_pair(id, *i));
146
147 break;
148 }
149 }
150 }
151
152 p = q;
153 }
154 }
155
156
157 /**
158 * Check availability of AHRS calibration for given module identifier.
159 *
160 * \param id module identifier
161 * \return true if AHRS calibration available; else false
162 */
163 bool has(int id) const
164 {
165 return (this->find(id) != this->end());
166 }
167
168
169 /**
170 * Get AHRS calibration for given module identifier.
171 *
172 * \param id module identifier
173 * \return AHRS calibration
174 */
175 const JAHRSCalibration& get(int id) const
176 {
177 const_iterator i = this->find(id);
178
179 if (i != this->end())
180 return i->second;
181 else
182 THROW(JValueOutOfRange, "Invalid module identifier " << id);
183 }
184
185
186 /**
187 * Read AHRS calibration from input stream.
188 *
189 * \param in input stream
190 * \param calibration AHRS calibration
191 * \return input stream
192 */
193 friend inline std::istream& operator>>(std::istream& in, JAHRSCalibration_t& calibration)
194 {
195 int id;
196 JAHRSCalibration buffer;
197
198 while (in >> id >> buffer) {
199 calibration[id] = buffer;
200 }
201
202 return in;
203 }
204
205
206 /**
207 * Write AHRS calibration to output stream.
208 *
209 * \param out output stream
210 * \param calibration AHRS calibration
211 * \return output stream
212 */
213 friend inline std::ostream& operator<<(std::ostream& out, const JAHRSCalibration_t& calibration)
214 {
215 using namespace std;
216
217 for (JAHRSCalibration_t::const_iterator i = calibration.begin(); i != calibration.end(); ++i) {
218 out << i->first << ' ' << i->second << endl;
219 }
220
221 return out;
222 }
223 };
224}
225
226#endif
227
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Exception for accessing a value in a collection that is outside of its range.
static const JPBS_t AHRS(3, 4, 3, 4)
PBS of compass
Auxiliary classes and methods for database I/O.
Definition JAHRS.hh:14
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition JDB.hh:438
const char * getTable()
Get table name.
Definition JDB.hh:373
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
JUPIHelper & getUPI()
Auxiliary function for helper object initialisation.
JCLBIDHelper & getCLBID()
Auxiliary function for helper object initialisation.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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 class to map module identifier to AHRS calibration.
void configure(const JDetectorIntegration_t &detector, const int option)
Configure.
JAHRSCalibration_t(const int id, const int option)
Constructor.
JAHRSCalibration_t()
Default constructor.
friend std::istream & operator>>(std::istream &in, JAHRSCalibration_t &calibration)
Read AHRS calibration from input stream.
JAHRSCalibration_t(const JDetectorIntegration_t &detector, const int option)
Constructor.
const JAHRSCalibration & get(int id) const
Get AHRS calibration for given module identifier.
friend std::ostream & operator<<(std::ostream &out, const JAHRSCalibration_t &calibration)
Write AHRS calibration to output stream.
JAHRSCalibration_t(const char *file_name)
Constructor.
bool has(int id) const
Check availability of AHRS calibration for given module identifier.
static void initialise(JHelper_t &helper, const Args &...args)
Initialise.
Universal product identifier (UPI).
Definition JUPI_t.hh:32
Auxiliary base class for storing and loading a single object to and from an ASCII file,...
void load(const char *file_name)
Load from input file.