Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JPBS_t.hh
Go to the documentation of this file.
1#ifndef __JDB__JPBS_T__
2#define __JDB__JPBS_T__
3
4#include <istream>
5#include <ostream>
6#include <sstream>
7#include <string>
8#include <vector>
9
10#include <TROOT.h>
11
12
13/**
14 * \author mdejong
15 */
16namespace JDATABASE {}
17namespace JPP { using namespace JDATABASE; }
18
19namespace JDATABASE {
20
21 /**
22 * Product breakdown structure (%PBS).
23 *
24 * The %PBS consists of one (or more) integer value(s), separated by JPBS_t::DOT.\n
25 * The corresponding ASCII format reads <tt>\"<int>[.<int>]*\"</tt>.
26 */
27 struct JPBS_t :
28 public std::vector<int>
29 {
30 /**
31 * Separator between %PBS values.
32 */
33 static const char DOT = '.';
34
35
36 /**
37 * Default constructor.
38 */
40 {}
41
42
43 /**
44 * Constructor.
45 *
46 * Note that the parsing of arguments terminates at the first occurrence of a negative value.
47 *
48 * \param i0 %PBS number
49 * \param i1 %PBS number
50 * \param i2 %PBS number
51 * \param i3 %PBS number
52 * \param i4 %PBS number
53 * \param i5 %PBS number
54 * \param i6 %PBS number
55 * \param i7 %PBS number
56 * \param i8 %PBS number
57 * \param i9 %PBS number
58 */
59 JPBS_t(const int i0,
60 const int i1 = -1,
61 const int i2 = -1,
62 const int i3 = -1,
63 const int i4 = -1,
64 const int i5 = -1,
65 const int i6 = -1,
66 const int i7 = -1,
67 const int i8 = -1,
68 const int i9 = -1)
69 {
70 if (i0 >= 0) { push_back(i0); } else { return; }
71 if (i1 >= 0) { push_back(i1); } else { return; }
72 if (i2 >= 0) { push_back(i2); } else { return; }
73 if (i3 >= 0) { push_back(i3); } else { return; }
74 if (i4 >= 0) { push_back(i4); } else { return; }
75 if (i5 >= 0) { push_back(i5); } else { return; }
76 if (i6 >= 0) { push_back(i6); } else { return; }
77 if (i7 >= 0) { push_back(i7); } else { return; }
78 if (i8 >= 0) { push_back(i8); } else { return; }
79 if (i9 >= 0) { push_back(i9); } else { return; }
80 }
81
82
83 /**
84 * Constructor.
85 *
86 * \param input input text
87 */
88 JPBS_t(const std::string& input)
89 {
90 std::istringstream is(input);
91
92 is >> *this;
93 }
94
95
96 /**
97 * Get %PBS.
98 *
99 * \return %PBS
100 */
101 const JPBS_t& getPBS() const
102 {
103 return static_cast<const JPBS_t&>(*this);
104 }
105
106
107 /**
108 * Check validity.
109 *
110 * \return true if valid; else false
111 */
112 bool is_valid() const
113 {
114 return !this->empty();
115 }
116
117
118 /**
119 * Equality operator.
120 *
121 * \param first first %PBS
122 * \param second second %PBS
123 * \return true if %PBS is equal; else false
124 */
125 friend inline bool operator==(const JPBS_t& first, const JPBS_t& second)
126 {
127 if (first.size() == second.size()) {
128
129 for (const_iterator p = first.begin(), q = second.begin(); p != first.end(); ++p, ++q) {
130 if (*p != *q) {
131 return false;
132 }
133 }
134
135 return true;
136 }
137
138 return false;
139 }
140
141
142 /**
143 * Less-than operator.
144 *
145 * \param first first %PBS
146 * \param second second %PBS
147 * \return true if first %PBS higher in hierarchy; else false
148 */
149 friend inline bool operator<(const JPBS_t& first, const JPBS_t& second)
150 {
151 for (const_iterator p = first.begin(), q = second.begin(); p != first.end() && q != second.end(); ++p, ++q) {
152 if (*p != *q) {
153 return *p < *q;
154 }
155 }
156
157 return first.size() < second.size();
158 }
159
160
161 /**
162 * Read %PBS from input stream.
163 *
164 * \param in input stream
165 * \param object %PBS
166 * \return input stream
167 */
168 friend inline std::istream& operator>>(std::istream& in, JPBS_t& object)
169 {
170 using namespace std;
171
172 object.clear();
173
174 int pbs;
175
176 if (in >> pbs) {
177
178 object.push_back(pbs);
179
180 while (in.peek() == (int) JPBS_t::DOT) {
181 if (in.ignore() && in >> pbs)
182 object.push_back(pbs);
183 else
184 in.setstate(ios::failbit);
185 }
186
187 } else {
188
189 in.setstate(ios::failbit);
190 }
191
192 return in;
193 }
194
195
196 /**
197 * Write %PBS to output stream.
198 *
199 * \param out output stream
200 * \param object %PBS
201 * \return output stream
202 */
203 friend inline std::ostream& operator<<(std::ostream& out, const JPBS_t& object)
204 {
205 using namespace std;
206 using namespace JPP;
207
208 ostringstream os;
209
210 if (!object.empty()) {
211
212 const_iterator i = object.begin();
213
214 os << *i;
215
216 while (++i != object.end()) {
217 os << JPBS_t::DOT << *i;
218 }
219 }
220
221 return out << os.str();
222 }
223
225 };
226
227 /**
228 * Namespace for predefined %PBS values.
229 */
230 namespace PBS {
231 static const JPBS_t DETECTOR (0); //!< %PBS of detector
232 static const JPBS_t DETECTION_UNIT (3); //!< %PBS of detection unit
233 static const JPBS_t BASE (3, 2); //!< %PBS of detection unit base
234 static const JPBS_t BASE_CONTAINER (3, 2, 2); //!< %PBS of detection unit base container
235 static const JPBS_t DOM (3, 4); //!< %PBS of optical module
236 static const JPBS_t PMT (3, 4, 2, 3); //!< %PBS of photo-multiplier tube (PMT)
237 static const JPBS_t CLB (3, 4, 3, 2); //!< %PBS of central-logic board
238 static const JPBS_t T_SENSOR (3, 4, 3, 2, 1, 1); //!< %PBS of temperature sensor
239 static const JPBS_t H_SENSOR (3, 4, 3, 2, 1, 2); //!< %PBS of magnetic field sensor
240 static const JPBS_t FPGA (3, 4, 3, 2, 2); //!< %PBS of FPGA
241 static const JPBS_t POWER_BOARD (3, 4, 3, 5); //!< %PBS of power board
242 static const JPBS_t NANO_BEACON (3, 4, 3, 7); //!< %PBS of nano-beacon
243 static const JPBS_t AHRS (3, 4, 3, 4); //!< %PBS of compass
244 static const JPBS_t ACOUSTIC_SENSOR(3, 4, 3, 6, 2); //!< %PBS of piezo sensor
245 static const JPBS_t HYDROPHONE (4, 5); //!< %PBS of hydrophone
246 }
247
248
249 /**
250 * Test if given %PBS corresponds to a detector.
251 *
252 * \param pbs %PBS
253 * \return true if detector; else false
254 */
255 inline bool is_detector(const JPBS_t& pbs)
256 {
257 return (pbs == PBS::DETECTOR);
258 }
259
260
261 /**
262 * Test if given %PBS corresponds to a string.
263 *
264 * \param pbs %PBS
265 * \return true if string; else false
266 */
267 inline bool is_string(const JPBS_t& pbs)
268 {
269 return (pbs == PBS::DETECTION_UNIT);
270 }
271
272
273 /**
274 * Test if given %PBS corresponds to a optical module.
275 *
276 * \param pbs %PBS
277 * \return true if optical module; else false
278 */
279 inline bool is_optical_module(const JPBS_t& pbs)
280 {
281 return (pbs == PBS::DOM);
282 }
283
284
285 /**
286 * Test if given %PBS corresponds to a base module.
287 *
288 * \param pbs %PBS
289 * \return true if base module; else false
290 */
291 inline bool is_base_module(const JPBS_t& pbs)
292 {
293 return (pbs == PBS::BASE ||
294 pbs == PBS::BASE_CONTAINER);
295 }
296}
297
298#endif
299
static const JPBS_t DOM(3, 4)
PBS of optical module
static const JPBS_t H_SENSOR(3, 4, 3, 2, 1, 2)
PBS of magnetic field sensor
static const JPBS_t HYDROPHONE(4, 5)
PBS of hydrophone
static const JPBS_t CLB(3, 4, 3, 2)
PBS of central-logic board
static const JPBS_t FPGA(3, 4, 3, 2, 2)
PBS of FPGA
static const JPBS_t BASE(3, 2)
PBS of detection unit base
static const JPBS_t DETECTION_UNIT(3)
PBS of detection unit
static const JPBS_t ACOUSTIC_SENSOR(3, 4, 3, 6, 2)
PBS of piezo sensor
static const JPBS_t NANO_BEACON(3, 4, 3, 7)
PBS of nano-beacon
static const JPBS_t POWER_BOARD(3, 4, 3, 5)
PBS of power board
static const JPBS_t PMT(3, 4, 2, 3)
PBS of photo-multiplier tube (PMT)
static const JPBS_t T_SENSOR(3, 4, 3, 2, 1, 1)
PBS of temperature sensor
static const JPBS_t DETECTOR(0)
PBS of detector
static const JPBS_t AHRS(3, 4, 3, 4)
PBS of compass
static const JPBS_t BASE_CONTAINER(3, 2, 2)
PBS of detection unit base container
Auxiliary classes and methods for database I/O.
Definition JAHRS.hh:14
bool is_base_module(const JPBS_t &pbs)
Test if given PBS corresponds to a base module.
Definition JPBS_t.hh:291
bool is_string(const JPBS_t &pbs)
Test if given PBS corresponds to a string.
Definition JPBS_t.hh:267
bool is_detector(const JPBS_t &pbs)
Test if given PBS corresponds to a detector.
Definition JPBS_t.hh:255
bool is_optical_module(const JPBS_t &pbs)
Test if given PBS corresponds to a optical module.
Definition JPBS_t.hh:279
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Product breakdown structure (PBS).
Definition JPBS_t.hh:29
JPBS_t(const int i0, const int i1=-1, const int i2=-1, const int i3=-1, const int i4=-1, const int i5=-1, const int i6=-1, const int i7=-1, const int i8=-1, const int i9=-1)
Constructor.
Definition JPBS_t.hh:59
friend bool operator==(const JPBS_t &first, const JPBS_t &second)
Equality operator.
Definition JPBS_t.hh:125
JPBS_t()
Default constructor.
Definition JPBS_t.hh:39
friend std::ostream & operator<<(std::ostream &out, const JPBS_t &object)
Write PBS to output stream.
Definition JPBS_t.hh:203
friend std::istream & operator>>(std::istream &in, JPBS_t &object)
Read PBS from input stream.
Definition JPBS_t.hh:168
friend bool operator<(const JPBS_t &first, const JPBS_t &second)
Less-than operator.
Definition JPBS_t.hh:149
ClassDefNV(JPBS_t, 1)
static const char DOT
Separator between PBS values.
Definition JPBS_t.hh:33
JPBS_t(const std::string &input)
Constructor.
Definition JPBS_t.hh:88
bool is_valid() const
Check validity.
Definition JPBS_t.hh:112
const JPBS_t & getPBS() const
Get PBS.
Definition JPBS_t.hh:101