Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQHit.hh
Go to the documentation of this file.
1 #ifndef __JDAQHIT__
2 #define __JDAQHIT__
3 
4 #ifndef __CINT__
5 #include <netinet/in.h>
6 #endif
7 
8 #include "JIO/JSerialisable.hh"
9 #include "JDAQ/JDAQ.hh"
10 #include "JDAQ/JDAQRoot.hh"
11 #include "JDAQ/JDAQException.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace KM3NETDAQ {
19 
20  using JIO::JReader;
21  using JIO::JWriter;
22 
23 
24  /**
25  * Hit data structure.
26  *
27  * N.B.
28  * The size of this data structure (i.e. the value obtained with the <tt>sizeof()</tt> operator
29  * should exactly match the preset number of bytes from the DAQ system.
30  * The <tt>pragma</tt> statement is necessary to ensure the correct size of this object.
31  * Furthermore, this data structure should have no virtual methods and no virtual destructor.
32  * Consequently, the standard ROOT <tt>CLassDef()</tt> macro is replaced by
33  * the designated <tt>ClassDefNV()</tt> macro.
34  */
35 #pragma pack(push,1)
36  class JDAQHit
37  {
38  public:
39 
40  typedef unsigned char JPMT_t; //!< PMT channel in FPGA
41  typedef unsigned int JTDC_t; //!< leading edge [ns]
42  typedef unsigned char JTOT_t; //!< time over threshold [ns]
43 
44 
45  /**
46  * Default constructor.
47  */
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param pmt_id PMT channel
56  * \param tdc_ns time of hit [ns]
57  * \param tot_ns time over threshold [ns]
58  */
59  JDAQHit(const JPMT_t pmt_id,
60  const JTDC_t tdc_ns,
61  const JTOT_t tot_ns) :
62  pmt(pmt_id),
63  tdc(htonl(tdc_ns)),
64  //tdc(tdc_ns),
65  tot(tot_ns)
66  {}
67 
68 
69  /**
70  * Get PMT.
71  *
72  * \return PMT
73  */
74  inline JPMT_t getPMT() const
75  {
76  return pmt;
77  }
78 
79 
80  /**
81  * Get time.
82  *
83  * \return time [ns]
84  */
85  inline JTDC_t getT() const
86  {
87  return ntohl(tdc);
88  }
89 
90 
91  /**
92  * Get time-over-threshold.
93  *
94  * \return time-over-threshold [ns]
95  */
96  inline JTOT_t getToT() const
97  {
98  return tot;
99  }
100 
101 
102  /**
103  * Get maximal time-over-threshold.
104  *
105  * \return time-over-threshold [ns]
106  */
108  {
109  return 0xFF;
110  }
111 
112 
113  /**
114  * Read DAQ hit from input.
115  *
116  * \param in JReader
117  * \param hit JDAQHit
118  * \return JReader
119  */
120  friend inline JReader& operator>>(JReader& in, JDAQHit& hit)
121  {
122  in >> hit.pmt;
123  in >> hit.tdc;
124  in >> hit.tot;
125 
126  return in;
127  }
128 
129 
130  /**
131  * Write DAQ hit to output.
132  *
133  * \param out JWriter
134  * \param hit JDAQHit
135  * \return JWriter
136  */
137  friend inline JWriter& operator<<(JWriter& out, const JDAQHit& hit)
138  {
139  out << hit.pmt;
140  out << hit.tdc;
141  out << hit.tot;
142 
143  return out;
144  }
145 
146 
147  /**
148  * Get size of object.
149  *
150  * \return number of bytes
151  */
152  static int sizeOf()
153  {
154  return sizeof(JDAQHit);
155  }
156 
157 
158  ClassDefNV(JDAQHit,1);
159 
160 
161  protected:
162  JPMT_t pmt; //!< PMT readout channel in FPGA
163  JTDC_t tdc; //!< leading edge [ns]
164  JTOT_t tot; //!< time over threshold [ns]
165  };
166 #pragma pack(pop)
167 
168 
169  /**
170  * Less than operator for DAQ hits.
171  *
172  * The less than operator is applied first to the time and then to the PMT channel of the hits.
173  *
174  * \param first hit
175  * \param second hit
176  * \result true if first hit earlier than second; else false
177  */
178  inline bool operator<(const JDAQHit& first,
179  const JDAQHit& second)
180  {
181  if (first.getT() != second.getT())
182  return first.getT() < second.getT();
183  else
184  return first.getPMT() < second.getPMT();
185  }
186 
187 
188  /**
189  * Equal operator for DAQ hits.
190  *
191  * \param first hit
192  * \param second hit
193  * \result true if first hit equal to second; else false
194  */
195  inline bool operator==(const JDAQHit& first,
196  const JDAQHit& second)
197  {
198  return (first.getPMT() == second.getPMT() &&
199  first.getT() == second.getT() &&
200  first.getToT() == second.getToT());
201  }
202 
203 
204  /**
205  * Not-equal operator for DAQ hits.
206  *
207  * \param first hit
208  * \param second hit
209  * \result true if first hit not equal to second; else false
210  */
211  inline bool operator!=(const JDAQHit& first,
212  const JDAQHit& second)
213  {
214  return !(first == second);
215  }
216 }
217 
218 #endif
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
Interface for binary output.
JDAQHit()
Default constructor.
Definition: JDAQHit.hh:48
JTDC_t getT() const
Get time.
Definition: JDAQHit.hh:85
JPMT_t getPMT() const
Get PMT.
Definition: JDAQHit.hh:74
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:41
JTOT_t tot
time over threshold [ns]
Definition: JDAQHit.hh:164
JTOT_t getToT() const
Get time-over-threshold.
Definition: JDAQHit.hh:96
unsigned char JTOT_t
time over threshold [ns]
Definition: JDAQHit.hh:42
Hit data structure.
Definition: JDAQHit.hh:36
JDAQHit(const JPMT_t pmt_id, const JTDC_t tdc_ns, const JTOT_t tot_ns)
Constructor.
Definition: JDAQHit.hh:59
Interface for binary input.
static int sizeOf()
Get size of object.
Definition: JDAQHit.hh:152
JTDC_t tdc
leading edge [ns]
Definition: JDAQHit.hh:163
ClassDefNV(JDAQHit, 1)
friend JWriter & operator<<(JWriter &out, const JDAQHit &hit)
Write DAQ hit to output.
Definition: JDAQHit.hh:137
KM3NeT DAQ constants, bit handling, etc.
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
JPMT_t pmt
PMT readout channel in FPGA.
Definition: JDAQHit.hh:162
bool operator<(const JDAQHit &first, const JDAQHit &second)
Less than operator for DAQ hits.
Definition: JDAQHit.hh:178
unsigned char JPMT_t
PMT channel in FPGA.
Definition: JDAQHit.hh:40
static JTOT_t getMaximalToT()
Get maximal time-over-threshold.
Definition: JDAQHit.hh:107
friend JReader & operator>>(JReader &in, JDAQHit &hit)
Read DAQ hit from input.
Definition: JDAQHit.hh:120