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