Jpp
JDAQTriggerCounter.hh
Go to the documentation of this file.
1 #ifndef __JDAQTRIGGERCOUNTER__
2 #define __JDAQTRIGGERCOUNTER__
3 
4 #include "JIO/JSerialisable.hh"
5 #include "JDAQ/JDAQRoot.hh"
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace KM3NETDAQ {
13 
14  using JIO::JReader;
15  using JIO::JWriter;
16 
17 
18  /**
19  * Type definition of trigger counter.
20  */
21  typedef unsigned long long int JTriggerCounter_t;
22 
23 
24  /**
25  * Auxiliary class to count triggers.
26  */
28  private:
29  /**
30  * Constructor.
31  *
32  * \param counter counter value
33  */
35  {
36  this->trigger_counter = counter;
37  }
38 
39 
40  public:
41  /**
42  * Default constructor.
43  *
44  * This constructor increments the counter of the unique instance
45  * of this class and stores the result in this object.
46  */
48  {
50  }
51 
52 
53  /**
54  * Virtual destructor.
55  */
57  {}
58 
59 
60  /**
61  * Get reference to unique instance of this class object.
62  *
63  * \return reference to this class object
64  */
66  {
67  static JDAQTriggerCounter counter(0);
68 
69  return counter;
70  }
71 
72 
73  /**
74  * Get DAQ trigger counter.
75  *
76  * \return DAQ trigger counter
77  */
79  {
80  return static_cast<const JDAQTriggerCounter&>(*this);
81  }
82 
83 
84  /**
85  * Reset counter of unique instance of this class object.
86  */
87  static void reset()
88  {
90  }
91 
92 
93  /**
94  * Get trigger counter.
95  *
96  * \return counter value
97  */
99  {
100  return trigger_counter;
101  }
102 
103 
104  /**
105  * Set trigger counter.
106  *
107  * \param counter counter value
108  */
109  void setCounter(const JTriggerCounter_t counter)
110  {
111  this->trigger_counter = counter;
112  }
113 
114 
115  /**
116  * Increment trigger counter.
117  *
118  * \return counter value
119  */
121  {
122  return trigger_counter++;
123  }
124 
125 
126  /**
127  * Read JDAQTriggerCounter from input.
128  *
129  * \param in JReader
130  * \param counter JDAQTriggerCounter
131  * \return JReader
132  */
133  friend inline JReader& operator>>(JReader& in, JDAQTriggerCounter& counter)
134  {
135  in >> counter.trigger_counter;
136 
137  return in;
138  }
139 
140 
141  /**
142  * Write JDAQTriggerCounter to output.
143  *
144  * \param out JWriter
145  * \param counter JDAQTriggerCounter
146  * \return JWriter
147  */
148  friend inline JWriter& operator<<(JWriter& out, const JDAQTriggerCounter& counter)
149  {
150  out << counter.trigger_counter;
151 
152  return out;
153  }
154 
155 
156  /**
157  * Get size of object.
158  *
159  * \return number of bytes
160  */
161  static int sizeOf()
162  {
163  return sizeof(JTriggerCounter_t);
164  }
165 
166 
168 
169 
170  protected:
172  };
173 
174 
175  /**
176  * Equal operator for DAQ trigger counters.
177  *
178  * \param first trigger counter
179  * \param second trigger counter
180  * \result true if first trigger counter equal to second; else false
181  */
182  inline bool operator==(const JDAQTriggerCounter& first,
183  const JDAQTriggerCounter& second)
184  {
185  return (first.getCounter() == second.getCounter());
186  }
187 
188 
189  /**
190  * Not-equal operator for DAQ trigger counters.
191  *
192  * \param first trigger counter
193  * \param second trigger counter
194  * \result true if first trigger counter not equal to second; else false
195  */
196  inline bool operator!=(const JDAQTriggerCounter& first,
197  const JDAQTriggerCounter& second)
198  {
199  return !(first == second);
200  }
201 }
202 
203 #endif
KM3NETDAQ::JDAQTriggerCounter::ClassDef
ClassDef(JDAQTriggerCounter, 1)
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
KM3NETDAQ::JDAQTriggerCounter::sizeOf
static int sizeOf()
Get size of object.
Definition: JDAQTriggerCounter.hh:161
KM3NETDAQ::JDAQTriggerCounter::getCounter
JTriggerCounter_t getCounter() const
Get trigger counter.
Definition: JDAQTriggerCounter.hh:98
KM3NETDAQ::JDAQTriggerCounter::trigger_counter
JTriggerCounter_t trigger_counter
Definition: JDAQTriggerCounter.hh:171
KM3NETDAQ::JDAQTriggerCounter::~JDAQTriggerCounter
virtual ~JDAQTriggerCounter()
Virtual destructor.
Definition: JDAQTriggerCounter.hh:56
KM3NETDAQ::JDAQTriggerCounter::JDAQTriggerCounter
JDAQTriggerCounter()
Default constructor.
Definition: JDAQTriggerCounter.hh:47
KM3NETDAQ::JDAQTriggerCounter::getDAQTriggerCounter
const JDAQTriggerCounter & getDAQTriggerCounter() const
Get DAQ trigger counter.
Definition: JDAQTriggerCounter.hh:78
JSerialisable.hh
KM3NETDAQ::JDAQTriggerCounter
Auxiliary class to count triggers.
Definition: JDAQTriggerCounter.hh:27
KM3NETDAQ::JDAQTriggerCounter::next
JTriggerCounter_t next()
Increment trigger counter.
Definition: JDAQTriggerCounter.hh:120
KM3NETDAQ::operator!=
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
Definition: JDAQChronometer.hh:303
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
KM3NETDAQ::JDAQTriggerCounter::operator>>
friend JReader & operator>>(JReader &in, JDAQTriggerCounter &counter)
Read JDAQTriggerCounter from input.
Definition: JDAQTriggerCounter.hh:133
KM3NETDAQ::JDAQTriggerCounter::operator<<
friend JWriter & operator<<(JWriter &out, const JDAQTriggerCounter &counter)
Write JDAQTriggerCounter to output.
Definition: JDAQTriggerCounter.hh:148
KM3NETDAQ::JDAQTriggerCounter::setCounter
void setCounter(const JTriggerCounter_t counter)
Set trigger counter.
Definition: JDAQTriggerCounter.hh:109
JDAQRoot.hh
KM3NETDAQ::operator==
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
Definition: JDAQChronometer.hh:286
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
KM3NETDAQ::JTriggerCounter_t
unsigned long long int JTriggerCounter_t
Type definition of trigger counter.
Definition: JDAQTriggerCounter.hh:21
KM3NETDAQ::JDAQTriggerCounter::JDAQTriggerCounter
JDAQTriggerCounter(const JTriggerCounter_t counter)
Constructor.
Definition: JDAQTriggerCounter.hh:34
KM3NETDAQ::JDAQTriggerCounter::reset
static void reset()
Reset counter of unique instance of this class object.
Definition: JDAQTriggerCounter.hh:87
KM3NETDAQ::JDAQTriggerCounter::getInstance
static JDAQTriggerCounter & getInstance()
Get reference to unique instance of this class object.
Definition: JDAQTriggerCounter.hh:65