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