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