Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JStatus.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JSTATUS__
2 #define __JDETECTOR__JSTATUS__
3 
4 #include <istream>
5 #include <ostream>
6 #include <iomanip>
7 #include <string>
8 #include <vector>
9 #include <map>
10 
11 #include "JLang/JEquals.hh"
12 #include "JLang/JType.hh"
13 #include "JLang/JVectorize.hh"
14 #include "JLang/JSTDToolkit.hh"
15 #include "JIO/JSerialisable.hh"
16 #include "Jeep/JeepToolkit.hh"
17 
18 
19 /**
20  * \author mdejong
21  */
22 
23 namespace JDETECTOR {}
24 namespace JPP { using namespace JDETECTOR; }
25 
26 namespace JDETECTOR {
27 
28  using JLANG::JType;
29  using JLANG::JEquals;
30  using JIO::JReader;
31  using JIO::JWriter;
32 
33 
34  /**
35  * Auxiliary class for controlling PMT status.
36  *
37  * The various status are controlled using a bitwise data field.\n
38  * The corresponding bits are defined via an internal enumeration.
39  */
40  struct JStatus :
41  public JEquals<JStatus>
42  {
43  /**
44  * Enumeration of status bits.
45  *
46  * Additional status bits should be included in JGetPMTStatusBit::JGetPMTStatusBit.
47  */
49  PMT_DISABLE = 0, //!< Enable (disable) use of this PMT if this status bit is 0 (1);
50  HIGH_RATE_VETO_DISABLE = 1, //!< Enable (disable) use of high-rate veto test if this status bit is 0 (1);
51  FIFO_FULL_DISABLE = 2, //!< Enable (disable) use of FIFO (almost) full test if this status bit is 0 (1);
52  UDP_COUNTER_DISABLE = 3, //!< Enable (disable) use of UDP packet counter test if this status bit is 0 (1);
53  UDP_TRAILER_DISABLE = 4 //!< Enable (disable) use of UDP packet trailer test if this status bit is 0 (1);
54  };
55 
56 
57  /**
58  * Default constructor.
59  */
60  JStatus() :
61  status(0)
62  {}
63 
64 
65  /**
66  * Constructor.
67  *
68  * \param status status
69  */
70  JStatus(const int status) :
71  status(status)
72  {}
73 
74 
75  /**
76  * Get status.
77  *
78  * \return status
79  */
80  const JStatus& getStatus() const
81  {
82  return *this;
83  }
84 
85 
86  /**
87  * Get status.
88  *
89  * \return status
90  */
92  {
93  return *this;
94  }
95 
96 
97  /**
98  * Set status.
99  *
100  * \param status status
101  */
102  void setStatus(const JStatus& status)
103  {
104  this->status = status.status;
105  }
106 
107 
108  /**
109  * Equal method.
110  *
111  * \param status status
112  * \result true if this status equal to given status; else false
113  */
114  inline bool equals(const JStatus& status) const
115  {
116  return this->status == status.status;
117  }
118 
119 
120  /**
121  * Test PMT status.
122  *
123  * \param bit bit
124  */
125  bool has(const JPMTStatusBits_t bit) const
126  {
127  return (this->status & (1<<bit)) != 0;
128  }
129 
130 
131  /**
132  * Set PMT status.
133  *
134  * \param bit bit
135  */
136  void set(const JPMTStatusBits_t bit)
137  {
138  this->status |= (1<<bit);
139  }
140 
141 
142  /**
143  * Reset PMT status.
144  *
145  * \param bit bit
146  */
147  void reset(const JPMTStatusBits_t bit)
148  {
149  this->status &= ~(1<<bit);
150  }
151 
152 
153  /**
154  * Print status.
155  *
156  * \param out output stream
157  */
158  inline void print(std::ostream& out) const;
159 
160 
161  /**
162  * Read status from input.
163  *
164  * \param in input stream
165  * \param status status
166  * \return input stream
167  */
168  friend inline std::istream& operator>>(std::istream& in, JStatus& status)
169  {
170  return in >> status.status;
171  }
172 
173 
174  /**
175  * Write status to output.
176  *
177  * \param out output stream
178  * \param status status
179  * \return output stream
180  */
181  friend inline std::ostream& operator<<(std::ostream& out, const JStatus& status)
182  {
183  return out << status.status;
184  }
185 
186 
187  /**
188  * Read status from input.
189  *
190  * \param in reader
191  * \param status status
192  * \return reader
193  */
195  {
196  return in >> status.status;
197  }
198 
199 
200  /**
201  * Write status to output.
202  *
203  * \param out writer
204  * \param status status
205  * \return writer
206  */
207  friend inline JWriter& operator<<(JWriter& out, const JStatus& status)
208  {
209  return out << status.status;
210  }
211 
212  protected:
213  int status;
214  };
215 
216 
217  /**
218  * Auxiliary class to map key to PMT status bit.
219  */
221  public std::map<std::string, JStatus::JPMTStatusBits_t>
222  {
223  /**
224  * Default constructor.
225  */
227  {
228  using namespace JPP;
229 
230 #define MAKE_ENTRY(A) std::make_pair(getClassname(#A), A)
231 
232  this->insert(MAKE_ENTRY(JStatus::PMT_DISABLE));
234  this->insert(MAKE_ENTRY(JStatus::FIFO_FULL_DISABLE));
237 
238 #undef MAKE_ENTRY
239  }
240 
241 
242  /**
243  * Get PMT status bit.
244  *
245  * \param key key
246  * \return bit
247  */
248  JStatus::JPMTStatusBits_t operator()(const std::string& key) const
249  {
250  return JPP::get_key(*this, key);
251  }
252  };
253 
254 
255  /**
256  * Auxiliary class to map PMT status bit to key.
257  */
259  public std::map<JStatus::JPMTStatusBits_t, std::string>
260  {
261  /**
262  * Constructor.
263  *
264  * \param input PMT status bits
265  */
267  {
268  using namespace std;
269 
270  for (JGetPMTStatusBit::const_iterator i = input.begin(); i != input.end(); ++i) {
271  this->insert(make_pair(i->second, i->first));
272  }
273  }
274 
275 
276  /**
277  * Put PMT status bit.
278  *
279  * \param bit bit
280  * \return bit
281  */
282  const std::string& operator()(const JStatus::JPMTStatusBits_t bit) const
283  {
284  return JPP::get_key(*this, bit);
285  }
286  };
287 
288 
289  /**
290  * Function object to map key to PMT status bit.
291  */
293 
294 
295  /**
296  * Function object to map PMT status bit to key.
297  */
299 
300 
301  /**
302  * Get PMT status bits.
303  *
304  * \param type type
305  * \return status bits
306  */
308  {
310  }
311 
312 
313  /**
314  * Get PMT status bits.
315  *
316  * \param type type
317  * \return status bits
318  */
320  {
321  return JPP::make_array(getPMTStatusBit.begin(), getPMTStatusBit.end(), &JGetPMTStatusBit::value_type::second);
322  }
323 
324 
325  /**
326  * Get PMT status bits.
327  *
328  * \return status bits
329  */
330  template<class T>
332  {
333  return getPMTStatusBits(JType<T>());
334  }
335 
336 
337  /**
338  * Print PMT status.
339  *
340  * \param out output stream
341  */
342  inline void JStatus::print(std::ostream& out) const
343  {
344  using namespace std;
345 
346  for (int i = 0; i != sizeof(JStatus) * 8; ++i) {
347 
348  try {
349 
350  const JPMTStatusBits_t bit = (JPMTStatusBits_t) i;
351 
352  out << setw(24) << left << putPMTStatusBit(bit) << right << this->has(bit) << endl;
353  }
354  catch(const exception&) {}
355  }
356  }
357 }
358 
359 #endif
static const JGetPMTStatusBit getPMTStatusBit
Function object to map key to PMT status bit.
Definition: JStatus.hh:292
Interface for binary output.
const JStatus & getStatus() const
Get status.
Definition: JStatus.hh:80
JStatus()
Default constructor.
Definition: JStatus.hh:60
std::vector< std::string > getPMTStatusBits(const JType< std::string > &type)
Get PMT status bits.
Definition: JStatus.hh:307
void setStatus(const JStatus &status)
Set status.
Definition: JStatus.hh:102
#define MAKE_ENTRY(A)
JStatus::JPMTStatusBits_t operator()(const std::string &key) const
Get PMT status bit.
Definition: JStatus.hh:248
const std::vector< JValue_t > make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:27
Enable (disable) use of this PMT if this status bit is 0 (1);.
Definition: JStatus.hh:49
friend JWriter & operator<<(JWriter &out, const JStatus &status)
Write status to output.
Definition: JStatus.hh:207
void reset(const JPMTStatusBits_t bit)
Reset PMT status.
Definition: JStatus.hh:147
void set(const JPMTStatusBits_t bit)
Set PMT status.
Definition: JStatus.hh:136
Auxiliary class to map PMT status bit to key.
Definition: JStatus.hh:258
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
friend std::ostream & operator<<(std::ostream &out, const JStatus &status)
Write status to output.
Definition: JStatus.hh:181
Auxiliary class to map key to PMT status bit.
Definition: JStatus.hh:220
Auxiliary class for controlling PMT status.
Definition: JStatus.hh:40
Auxiliary class for a type holder.
Definition: JType.hh:19
friend std::istream & operator>>(std::istream &in, JStatus &status)
Read status from input.
Definition: JStatus.hh:168
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
friend JReader & operator>>(JReader &in, JStatus &status)
Read status from input.
Definition: JStatus.hh:194
bool equals(const JStatus &status) const
Equal method.
Definition: JStatus.hh:114
JPutPMTStatusBit(const JGetPMTStatusBit &input)
Constructor.
Definition: JStatus.hh:266
static const JPutPMTStatusBit putPMTStatusBit(getPMTStatusBit)
Function object to map PMT status bit to key.
void print(std::ostream &out) const
Print status.
Definition: JStatus.hh:342
Auxiliary methods for handling file names, type names and environment.
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
Interface for binary input.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
JStatus(const int status)
Constructor.
Definition: JStatus.hh:70
Enable (disable) use of FIFO (almost) full test if this status bit is 0 (1);.
Definition: JStatus.hh:51
Enable (disable) use of UDP packet trailer test if this status bit is 0 (1);.
Definition: JStatus.hh:53
JGetPMTStatusBit()
Default constructor.
Definition: JStatus.hh:226
JPMTStatusBits_t
Enumeration of status bits.
Definition: JStatus.hh:48
JStatus getStatus()
Get status.
Definition: JStatus.hh:91
const std::string & operator()(const JStatus::JPMTStatusBits_t bit) const
Put PMT status bit.
Definition: JStatus.hh:282
bool has(const JPMTStatusBits_t bit) const
Test PMT status.
Definition: JStatus.hh:125
Enable (disable) use of high-rate veto test if this status bit is 0 (1);.
Definition: JStatus.hh:50
const JValue_t & get_key(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &map, const JKey_t key)
Get value in map.
Definition: JSTDToolkit.hh:31
Enable (disable) use of UDP packet counter test if this status bit is 0 (1);.
Definition: JStatus.hh:52