Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JFrame.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JFRAME__
2 #define __JTRIGGER__JFRAME__
3 
4 #include <vector>
5 
6 #include "JDAQ/JDAQHit.hh"
7 #include "JDAQ/JDAQClock.hh"
8 #include "JTrigger/JPMTHeader.hh"
10 #include "JTrigger/JCalibration.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JTRIGGER {}
18 namespace JPP { using namespace JTRIGGER; }
19 
20 namespace JTRIGGER {
21 
22  using KM3NETDAQ::JDAQHit;
23 
24 
25  /**
26  * Data frame for calibrated hits of one PMT.
27  *
28  * Note that the calibration is applied on the fly in the method JFrame::push_back.
29  */
30  template<class JElement_t, class JAllocator_t = std::allocator<JElement_t> >
31  class JFrame :
32  public JPMTHeader,
33  public JCalibration,
34  public std::vector<JElement_t, JAllocator_t>,
35  public JHitToolkit<JElement_t>
36  {
37  public:
38 
40 
41  /**
42  * Default constructor.
43  */
44  JFrame() :
45  JPMTHeader (),
46  JCalibration(),
47  std::vector<JElement_t, JAllocator_t>(),
48  JHitToolkit<JElement_t>()
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param chronometer DAQ chronometer
56  * \param id PMT identifier
57  * \param axis PMT axis
58  * \param calibration calibration
59  */
60  JFrame(const JDAQChronometer& chronometer,
61  const JDAQPMTIdentifier& id,
62  const JAxis3D& axis,
63  const JCalibration& calibration) :
64  JPMTHeader (chronometer, id, axis),
65  JCalibration(calibration),
66  std::vector<JElement_t, JAllocator_t>(),
67  JHitToolkit<JElement_t>()
68  {}
69 
70 
71  /**
72  * Append DAQ hit.
73  *
74  * The time calibration is applied before the hit is appended.
75  *
76  * \param hit DAQ hit
77  */
78  void push_back(const JDAQHit& hit)
79  {
81  }
82 
83 
84  /**
85  * Append end marker to data.
86  */
87  void putEndMarker()
88  {
90  }
91 
92 
93  /**
94  * Reset.\n
95  * The contents of this frame is reduced to a single end marker.
96  */
97  void reset()
98  {
99  this->clear();
100  this->putEndMarker();
101  }
102 
103 
104  /**
105  * Apply high-rate veto.\n
106  * If vetoed, the contents of this frame is reduced to a single end marker.
107  *
108  * \param rate_Hz high-rate veto [Hz]
109  */
110  void applyHighRateVeto(const double rate_Hz)
111  {
113 
114  if (this->size() * 1.0e9 / getFrameTime() > rate_Hz) {
115  this->reset();
116  }
117  }
118 
119 
120  /**
121  * Join consecutive hits when matched according given criterion.
122  *
123  * The template argument <tt>JMatch_t</tt> refers to a data structure which should have the following operator:
124  * - <tt>bool %operator()(const JElement_t&, const JElement_t) const;</tt>
125  *
126  * The element of this container should provide for the member method:
127  * - <tt>void %join(const JElement_t&);</tt>
128  *
129  * \param match match criterion
130  */
131  template<class JMatch_t>
132  void join(const JMatch_t& match)
133  {
134  typename std::vector<JElement_t, JAllocator_t>::iterator out = this->begin();
135 
136  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator p = this->begin(); p != this->end(); ) {
137 
138  *out = *p;
139 
140  while (++p != this->end() && match(*out,*p)) {
141  out->join(*p);
142  }
143 
144  ++out;
145  }
146 
147  this->erase(out, this->end());
148  }
149 
150 
151  /**
152  * Filter consecutive hits when matched according given criterion.
153  *
154  * The template argument <tt>JMatch_t</tt> refers to a data structure which should have the following operator:
155  * - <tt>bool %operator()(const JElement_t&, const JElement_t) const;</tt>
156  *
157  * \param match match criterion
158  */
159  template<class JMatch_t>
160  void filter(const JMatch_t& match)
161  {
162  using namespace std;
163 
164  typename std::vector<JElement_t, JAllocator_t>::iterator out = this->begin();
165 
166  for (typename std::vector<JElement_t, JAllocator_t>::const_iterator p = this->begin(); p != this->end(); ) {
167 
169 
170  while (++q != this->end() && match(*p,*q)) {}
171 
172  if (distance(p,q) == 1) {
173 
174  *out = *p;
175 
176  ++out;
177  }
178 
179  p = q;
180  }
181 
182  this->erase(out, this->end());
183  }
184  };
185 }
186 
187 #endif
const JCalibration & getCalibration() const
Get calibration.
Header for PMT.
Definition: JPMTHeader.hh:26
Data structure for PMT calibration.
Tools for handling different hit types.
Axis object.
Definition: JAxis3D.hh:37
JFrame(const JDAQChronometer &chronometer, const JDAQPMTIdentifier &id, const JAxis3D &axis, const JCalibration &calibration)
Constructor.
Definition: JFrame.hh:60
Hit data structure.
Definition: JDAQHit.hh:36
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Data frame for calibrated hits of one PMT.
Definition: JFrame.hh:31
void join(const JMatch_t &match)
Join consecutive hits when matched according given criterion.
Definition: JFrame.hh:132
JFrame()
Default constructor.
Definition: JFrame.hh:44
void reset()
Reset.
Definition: JFrame.hh:97
Auxiliary class to check whether two consecutive hits should be joined.
Definition: JHit.hh:275
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60
JHitL0 getHit(const Hit &hit)
Get transformation.
void putEndMarker()
Append end marker to data.
Definition: JFrame.hh:87
void filter(const JMatch_t &match)
Filter consecutive hits when matched according given criterion.
Definition: JFrame.hh:160
void applyHighRateVeto(const double rate_Hz)
Apply high-rate veto.
Definition: JFrame.hh:110
void push_back(const JDAQHit &hit)
Append DAQ hit.
Definition: JFrame.hh:78