Jpp
JChecksum.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JCHECKSUM__
2 #define __JTRIGGER__JCHECKSUM__
3 
4 #include <vector>
5 #include <limits>
6 
7 #include "JDAQ/JDAQ.hh"
8 #include "JDAQ/JDAQClock.hh"
9 #include "JDAQ/JDAQHit.hh"
10 #include "JDAQ/JDAQSuperFrame.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JTRIGGER {}
18 namespace JPP { using namespace JTRIGGER; }
19 
20 /**
21  * Checksum.
22  */
23 namespace JTRIGGER {
24 
25  using KM3NETDAQ::JDAQHit;
28 
31 
32 
33  /**
34  * Auxiliary class to perform check-sum on raw data.
35  */
36  struct JChecksum {
37  /**
38  * Error types.
39  */
40  enum error_types {
41  EPMT_t = 1, //!< PMT error
42  ETDC_t, //!< TDC error
43  ETOT_t //!< time-over-threshold error
44  };
45 
46 
47  /**
48  * Error.
49  */
50  struct error {
51  /**
52  * Default constructor.
53  */
54  error() :
55  pos (-1),
56  type(-1)
57  {}
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param pos index in frame
64  * \param type error type
65  */
66  error(const int pos,
67  const int type) :
68  pos (pos),
69  type(type)
70  {}
71 
72 
73  int pos; //!< index in frame
74  int type; //!< error type
75  };
76 
77 
79  typedef result_type::const_iterator const_iterator;
80  typedef result_type::const_reverse_iterator const_reverse_iterator;
81 
82 
83  /**
84  * Default constructor.
85  */
87  {
88  t0.resize(NUMBER_OF_PMTS, 0);
89  }
90 
91 
92  /**
93  * Check sum.
94  *
95  * \param frame DAQ frame
96  * \return list of errors; empty if all okay
97  */
98  const result_type& get(const JDAQSuperFrame& frame) const
99  {
100  using namespace KM3NETDAQ;
101 
102  //const double Tmin = getTimeSinceRTS(frame.getFrameIndex()) - 0.05 * getFrameTime(); // [ns]
103  const double Tmax = getTimeSinceRTS(frame.getFrameIndex()) + 1.05 * getFrameTime(); // [ns]
104 
105  buffer.clear();
106 
107  for (std::vector<JDAQHit::JTDC_t>::iterator i = t0.begin(); i != t0.end(); ++i) {
108  *i = 0;
109  }
110 
111  for (JDAQSuperFrame::const_iterator hit = frame.begin(); hit != frame.end(); ++hit) {
112 
113  const JDAQHit::JTDC_t pmt = hit->getPMT();
114  const JDAQHit::JTDC_t tdc = hit->getT();
115 
116  if (pmt < NUMBER_OF_PMTS) {
117 
118  if (tdc < t0[pmt]) {
119  buffer.push_back(error(std::distance(frame.begin(), hit), ETDC_t));
120  }
121 
122  t0[pmt] = tdc;
123 
124  } else {
125 
126  buffer.push_back(error(std::distance(frame.begin(), hit), EPMT_t));
127  }
128  }
129 
130  for (std::vector<JDAQHit::JTDC_t>::const_iterator i = t0.begin(); i != t0.end(); ++i) {
131  if (*i > Tmax) {
132  buffer.push_back(error(frame.size(), ETDC_t));
133  }
134  }
135 
136  return buffer;
137  }
138 
139 
140  /**
141  * Check sum.
142  *
143  * \param frame DAQ frame
144  * \return true if okay; else false
145  */
146  bool operator()(const JDAQSuperFrame& frame) const
147  {
148  return get(frame).empty();
149  }
150 
151 
152  private:
155  };
156 
157 
158  /**
159  * Function object to perform check-sum of raw data.
160  */
161  static const JChecksum checksum;
162 }
163 
164 #endif
JTRIGGER::JChecksum::const_iterator
result_type::const_iterator const_iterator
Definition: JChecksum.hh:79
JDAQ.hh
JTRIGGER::JChecksum::EPMT_t
PMT error.
Definition: JChecksum.hh:41
JLANG::JIndexOutOfRange
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
JTRIGGER::JChecksum::const_reverse_iterator
result_type::const_reverse_iterator const_reverse_iterator
Definition: JChecksum.hh:80
KM3NETDAQ::JDAQFrame::size
int size() const
Definition: JDAQFrame.hh:157
std::vector< error >
KM3NETDAQ::JDAQChronometer::getFrameIndex
int getFrameIndex() const
Get frame index.
Definition: JDAQChronometer.hh:132
KM3NETDAQ::NUMBER_OF_PMTS
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
JDAQClock.hh
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JTRIGGER::JChecksum::error::error
error(const int pos, const int type)
Constructor.
Definition: JChecksum.hh:66
JTRIGGER::JChecksum::ETDC_t
TDC error.
Definition: JChecksum.hh:42
KM3NETDAQ::getFrameTime
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
KM3NETDAQ::JDAQSuperFrame::const_iterator
JDAQFrame::const_iterator const_iterator
Definition: JDAQSuperFrame.hh:34
JTRIGGER::JChecksum::get
const result_type & get(const JDAQSuperFrame &frame) const
Check sum.
Definition: JChecksum.hh:98
JTRIGGER::JChecksum
Auxiliary class to perform check-sum on raw data.
Definition: JChecksum.hh:36
JLANG::JValueOutOfRange
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
JTRIGGER::JChecksum::result_type
std::vector< error > result_type
Definition: JChecksum.hh:78
JTRIGGER::checksum
static const JChecksum checksum
Function object to perform check-sum of raw data.
Definition: JChecksum.hh:161
JTRIGGER::JChecksum::error_types
error_types
Error types.
Definition: JChecksum.hh:40
JTRIGGER::JChecksum::error::type
int type
error type
Definition: JChecksum.hh:74
KM3NETDAQ::getTimeSinceRTS
double getTimeSinceRTS(const int frame_index)
Get time in ns since last RTS for a given frame index.
Definition: JDAQClock.hh:263
KM3NETDAQ::JDAQHit::JTDC_t
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:45
JTRIGGER::JChecksum::buffer
result_type buffer
Definition: JChecksum.hh:154
JDAQSuperFrame.hh
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JTRIGGER::JChecksum::t0
std::vector< JDAQHit::JTDC_t > t0
Definition: JChecksum.hh:153
JTRIGGER::JChecksum::error
Error.
Definition: JChecksum.hh:50
KM3NETDAQ::JDAQSuperFrame
Data frame of one optical module.
Definition: JDAQSuperFrame.hh:27
JTRIGGER::JChecksum::ETOT_t
time-over-threshold error
Definition: JChecksum.hh:43
KM3NETDAQ::JDAQHit
Hit data structure.
Definition: JDAQHit.hh:40
JDAQHit.hh
JTRIGGER
Checksum.
Definition: JSupport/JSupport.hh:35
KM3NETDAQ::JDAQFrame::begin
const_iterator begin() const
Definition: JDAQFrame.hh:139
JTRIGGER::JChecksum::JChecksum
JChecksum()
Default constructor.
Definition: JChecksum.hh:86
JTRIGGER::JChecksum::operator()
bool operator()(const JDAQSuperFrame &frame) const
Check sum.
Definition: JChecksum.hh:146
KM3NETDAQ::JDAQFrame::end
const_iterator end() const
Definition: JDAQFrame.hh:140
JTRIGGER::JChecksum::error::pos
int pos
index in frame
Definition: JChecksum.hh:73
JTRIGGER::JChecksum::error::error
error()
Default constructor.
Definition: JChecksum.hh:54