Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPBS.hh
Go to the documentation of this file.
1 #ifndef __JDB__JPBS__
2 #define __JDB__JPBS__
3 
4 #include <TROOT.h>
5 
6 #include <istream>
7 #include <ostream>
8 #include <sstream>
9 #include <string>
10 #include <vector>
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  {
30  /**
31  * Separator between %PBS values.
32  */
33  static const char DOT = '.';
34 
35 
36  /**
37  * Separator between %PBS and variant.
38  */
39  static const char SEPARATOR = '/';
40 
41 
42  /**
43  * Default constructor.
44  */
45  JPBS()
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param i0 %PBS number
53  * \param i1 %PBS number
54  * \param i2 %PBS number
55  * \param i3 %PBS number
56  * \param i4 %PBS number
57  * \param i5 %PBS number
58  * \param i6 %PBS number
59  * \param i7 %PBS number
60  * \param i8 %PBS number
61  * \param i9 %PBS number
62  */
63  JPBS(const int i0,
64  const int i1 = -1,
65  const int i2 = -1,
66  const int i3 = -1,
67  const int i4 = -1,
68  const int i5 = -1,
69  const int i6 = -1,
70  const int i7 = -1,
71  const int i8 = -1,
72  const int i9 = -1)
73  {
74  if (i0 != -1) { push_back(i0); }
75  if (i1 != -1) { push_back(i1); }
76  if (i2 != -1) { push_back(i2); }
77  if (i3 != -1) { push_back(i3); }
78  if (i4 != -1) { push_back(i4); }
79  if (i5 != -1) { push_back(i5); }
80  if (i6 != -1) { push_back(i6); }
81  if (i7 != -1) { push_back(i7); }
82  if (i8 != -1) { push_back(i8); }
83  if (i9 != -1) { push_back(i9); }
84  }
85 
86 
87  /**
88  * Constructor.
89  *
90  * \param input input text
91  */
92  JPBS(const std::string& input)
93  {
94  std::istringstream is(input);
95 
96  is >> *this;
97  }
98 
99 
100  /**
101  * Get %PBS.
102  *
103  * \return %PBS
104  */
105  const JPBS& getPBS() const
106  {
107  return static_cast<const JPBS&>(*this);
108  }
109 
110 
111  /**
112  * Check validity.
113  *
114  * \return true if valid; else false
115  */
116  bool is_valid() const
117  {
118  return !this->empty();
119  }
120 
121 
122  /**
123  * Equality operator.
124  *
125  * \param first first %PBS
126  * \param second second %PBS
127  * \return true if %PBS is equal; else false
128  */
129  friend inline bool operator==(const JPBS& first, const JPBS& second)
130  {
131  if (first.size() == second.size()) {
132 
133  for (const_iterator p = first.begin(), q = second.begin(); p != first.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  ostringstream os;
213 
214  if (!object.empty()) {
215 
216  const_iterator i = object.begin();
217 
218  os << *i;
219 
220  while (++i != object.end()) {
221  os << JPBS::DOT << *i;
222  }
223  }
224 
225  return out << os.str();
226  }
227 
228  ClassDefNV(JPBS, 1);
229  };
230 
231 
232  namespace PBS {
233  /**
234  * Fixed %PBS.
235  */
236  static const JPBS DETECTOR (0);
237  static const JPBS DETECTION_UNIT (3);
238  static const JPBS BASE (3, 2);
239  static const JPBS BASE_CONTAINER (3, 2, 2);
240  static const JPBS DOM (3, 4);
241  static const JPBS PMT (3, 4, 2, 3);
242  static const JPBS CLB (3, 4, 3, 2);
243  static const JPBS T_SENSOR (3, 4, 3, 2, 1, 1);
244  static const JPBS H_SENSOR (3, 4, 3, 2, 1, 2);
245  static const JPBS FPGA (3, 4, 3, 2, 2);
246  static const JPBS POWER_BOARD (3, 4, 3, 5);
247  static const JPBS NANO_BEACON (3, 4, 3, 7);
248  static const JPBS AHRS (3, 4, 3, 4);
249  }
250 }
251 
252 #endif
253 
static const JPBS NANO_BEACON(3, 4, 3, 7)
set_variable DETECTOR
Definition: JLegolas.sh:31
friend std::ostream & operator<<(std::ostream &out, const JPBS &object)
Write PBS to output stream.
Definition: JPBS.hh:207
static const JPBS POWER_BOARD(3, 4, 3, 5)
const JPBS & getPBS() const
Get PBS.
Definition: JPBS.hh:105
friend bool operator==(const JPBS &first, const JPBS &second)
Equality operator.
Definition: JPBS.hh:129
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
is
Definition: JDAQCHSM.chsm:167
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:63
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
static const JPBS BASE_CONTAINER(3, 2, 2)
static const JPBS FPGA(3, 4, 3, 2, 2)
static const JPBS DETECTION_UNIT(3)
friend bool operator<(const JPBS &first, const JPBS &second)
Less-than operator.
Definition: JPBS.hh:153
static const JPBS H_SENSOR(3, 4, 3, 2, 1, 2)
JPBS(const std::string &input)
Constructor.
Definition: JPBS.hh:92
static const JPBS DOM(3, 4)
Product breakdown structure (PBS).
Definition: JPBS.hh:27
static const JPBS BASE(3, 2)
JDAQPMTIdentifier PMT
Command line options.
static const char DOT
Separator between PBS values.
Definition: JPBS.hh:33
static const JPBS T_SENSOR(3, 4, 3, 2, 1, 1)
friend std::istream & operator>>(std::istream &in, JPBS &object)
Read PBS from input stream.
Definition: JPBS.hh:172
static const JPBS AHRS(3, 4, 3, 4)
bool is_valid() const
Check validity.
Definition: JPBS.hh:116
JPBS()
Default constructor.
Definition: JPBS.hh:45
ClassDefNV(JPBS, 1)
static const char SEPARATOR
Separator between PBS and variant.
Definition: JPBS.hh:39
static const JPBS CLB(3, 4, 3, 2)