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