Jpp
JPBS.hh
Go to the documentation of this file.
1 #ifndef __JDB__JPBS__
2 #define __JDB__JPBS__
3 
4 #include <istream>
5 #include <ostream>
6 #include <sstream>
7 #include <string>
8 #include <vector>
9 
10 #include "JLang/JEquals.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 namespace JDATABASE {}
17 namespace JPP { using namespace JDATABASE; }
18 
19 namespace JDATABASE {
20 
21  /**
22  * Product breakdown structure (%PBS).
23  *
24  * The %PBS consists of one (or more) integer value(s), separated by JPBS::DOT.\n
25  * The ASCII format should therefore read <tt>"<int>[.<int>]+"</tt>.
26  */
27  struct JPBS :
28  public std::vector<int>,
29  public JLANG::JEquals<JPBS>
30  {
31  /**
32  * Separator between %PBS values.
33  */
34  static const char DOT = '.';
35 
36 
37  /**
38  * Separator between %PBS and variant.
39  */
40  static const char SEPARATOR = '/';
41 
42 
43  /**
44  * Default constructor.
45  */
46  JPBS()
47  {}
48 
49 
50  /**
51  * Constructor.
52  *
53  * \param i0 %PBS number
54  * \param i1 %PBS number
55  * \param i2 %PBS number
56  * \param i3 %PBS number
57  * \param i4 %PBS number
58  * \param i5 %PBS number
59  * \param i6 %PBS number
60  * \param i7 %PBS number
61  * \param i8 %PBS number
62  * \param i9 %PBS number
63  */
64  JPBS(const int i0,
65  const int i1 = -1,
66  const int i2 = -1,
67  const int i3 = -1,
68  const int i4 = -1,
69  const int i5 = -1,
70  const int i6 = -1,
71  const int i7 = -1,
72  const int i8 = -1,
73  const int i9 = -1)
74  {
75  if (i0 != -1) { push_back(i0); }
76  if (i1 != -1) { push_back(i1); }
77  if (i2 != -1) { push_back(i2); }
78  if (i3 != -1) { push_back(i3); }
79  if (i4 != -1) { push_back(i4); }
80  if (i5 != -1) { push_back(i5); }
81  if (i6 != -1) { push_back(i6); }
82  if (i7 != -1) { push_back(i7); }
83  if (i8 != -1) { push_back(i8); }
84  if (i9 != -1) { push_back(i9); }
85  }
86 
87 
88  /**
89  * Constructor.
90  *
91  * \param input input text
92  */
93  JPBS(const std::string& input)
94  {
95  std::istringstream is(input);
96 
97  is >> *this;
98  }
99 
100 
101  /**
102  * Get %PBS.
103  *
104  * \return %PBS
105  */
106  const JPBS& getPBS() const
107  {
108  return static_cast<const JPBS&>(*this);
109  }
110 
111 
112  /**
113  * Check validity.
114  *
115  * \return true if valid; else false
116  */
117  bool is_valid() const
118  {
119  return !this->empty();
120  }
121 
122 
123  /**
124  * Equality.
125  *
126  * \param pbs %PBS
127  * \return true if %PBS is equal; else false
128  */
129  bool equals(const JPBS& pbs) const
130  {
131  if (this->size() == pbs.size()) {
132 
133  for (const_iterator p = this->begin(), q = pbs.begin(); p != this->end(); ++p, ++q) {
134  if (*p != *q) {
135  return false;
136  }
137  }
138 
139  return true;
140  }
141 
142  return false;
143  }
144 
145 
146  /**
147  * Less-than operator.
148  *
149  * \param first first %PBS
150  * \param second second %PBS
151  * \return true if first %PBS higher in hierarchy; else false
152  */
153  friend inline bool operator<(const JPBS& first, const JPBS& second)
154  {
155  for (const_iterator p = first.begin(), q = second.begin(); p != first.end() && q != second.end(); ++p, ++q) {
156  if (*p != *q) {
157  return *p < *q;
158  }
159  }
160 
161  return first.size() < second.size();
162  }
163 
164 
165  /**
166  * Read %PBS from input stream.
167  *
168  * \param in input stream
169  * \param object %PBS
170  * \return input stream
171  */
172  friend inline std::istream& operator>>(std::istream& in, JPBS& object)
173  {
174  using namespace std;
175 
176  object.clear();
177 
178  int pbs;
179 
180  if (in >> pbs) {
181 
182  object.push_back(pbs);
183 
184  while (in.peek() == (int) JPBS::DOT) {
185  if (in.ignore() && in >> pbs)
186  object.push_back(pbs);
187  else
188  in.setstate(ios::failbit);
189  }
190 
191  } else {
192 
193  in.setstate(ios::failbit);
194  }
195 
196  return in;
197  }
198 
199 
200  /**
201  * Write %PBS to output stream.
202  *
203  * \param out output stream
204  * \param object %PBS
205  * \return output stream
206  */
207  friend inline std::ostream& operator<<(std::ostream& out, const JPBS& object)
208  {
209  using namespace std;
210  using namespace JPP;
211 
212  if (!object.empty()) {
213 
214  const_iterator i = object.begin();
215 
216  out << *i;
217 
218  while (++i != object.end()) {
219  out << JPBS::DOT << *i;
220  }
221  }
222 
223  return out;
224  }
225  };
226 
227 
228  namespace PBS {
229  /**
230  * Fixed %PBS.
231  */
232  static const JPBS DETECTOR (0);
233  static const JPBS DETECTION_UNIT (3);
234  static const JPBS BASE (3, 2);
235  static const JPBS BASE_CONTAINER (3, 2, 2);
236  static const JPBS DOM (3, 4);
237  static const JPBS PMT (3, 4, 2, 3);
238  static const JPBS CLB (3, 4, 3, 2);
239  static const JPBS T_SENSOR (3, 4, 3, 2, 1, 1);
240  static const JPBS H_SENSOR (3, 4, 3, 2, 1, 2);
241  static const JPBS FPGA (3, 4, 3, 2, 2);
242  static const JPBS POWER_BOARD (3, 4, 3, 5);
243  static const JPBS NANO_BEACON (3, 4, 3, 7);
244  }
245 }
246 
247 #endif
248 
JDATABASE::JPBS::operator<<
friend std::ostream & operator<<(std::ostream &out, const JPBS &object)
Write PBS to output stream.
Definition: JPBS.hh:207
JDATABASE::PBS::FPGA
static const JPBS FPGA(3, 4, 3, 2, 2)
JDATABASE::PBS::H_SENSOR
static const JPBS H_SENSOR(3, 4, 3, 2, 1, 2)
JDATABASE::JPBS::SEPARATOR
static const char SEPARATOR
Separator between PBS and variant.
Definition: JPBS.hh:40
JDATABASE::PBS::NANO_BEACON
static const JPBS NANO_BEACON(3, 4, 3, 7)
JLANG::JEquals
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
std::vector
Definition: JSTDTypes.hh:12
JDATABASE::PBS::DETECTION_UNIT
static const JPBS DETECTION_UNIT(3)
JDATABASE::PBS::POWER_BOARD
static const JPBS POWER_BOARD(3, 4, 3, 5)
JDATABASE::JPBS::DOT
static const char DOT
Separator between PBS values.
Definition: JPBS.hh:34
JDATABASE::PBS::T_SENSOR
static const JPBS T_SENSOR(3, 4, 3, 2, 1, 1)
JDATABASE::JPBS::equals
bool equals(const JPBS &pbs) const
Equality.
Definition: JPBS.hh:129
JEquals.hh
PMT
JDAQPMTIdentifier PMT
Command line options.
Definition: JDAQTimesliceSelector.cc:35
JDATABASE
Auxiliary classes and methods for database I/O.
Definition: JAHRS.hh:12
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDATABASE::JPBS::is_valid
bool is_valid() const
Check validity.
Definition: JPBS.hh:117
JDATABASE::PBS::DOM
static const JPBS DOM(3, 4)
JDATABASE::JPBS::JPBS
JPBS(const std::string &input)
Constructor.
Definition: JPBS.hh:93
JDATABASE::JPBS::operator<
friend bool operator<(const JPBS &first, const JPBS &second)
Less-than operator.
Definition: JPBS.hh:153
JDATABASE::JPBS
Product breakdown structure (PBS).
Definition: JPBS.hh:27
JDATABASE::JPBS::JPBS
JPBS(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.hh:64
JDATABASE::JPBS::operator>>
friend std::istream & operator>>(std::istream &in, JPBS &object)
Read PBS from input stream.
Definition: JPBS.hh:172
JDATABASE::PBS::DETECTOR
static const JPBS DETECTOR(0)
Fixed PBS.
std
Definition: jaanetDictionary.h:36
JDATABASE::PBS::BASE_CONTAINER
static const JPBS BASE_CONTAINER(3, 2, 2)
JDATABASE::PBS::CLB
static const JPBS CLB(3, 4, 3, 2)
JDATABASE::JPBS::getPBS
const JPBS & getPBS() const
Get PBS.
Definition: JPBS.hh:106
JDATABASE::JPBS::JPBS
JPBS()
Default constructor.
Definition: JPBS.hh:46
JDATABASE::PBS::BASE
static const JPBS BASE(3, 2)