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