Jpp  15.0.2
the software that should make you happy
 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 
8 #include "JTrigger/JMatch.hh"
9 #include "JTrigger/JPMTHeader.hh"
10 #include "JTrigger/JHitToolkit.hh"
11 #include "JTrigger/JCalibration.hh"
12 #include "JLang/JSTDToolkit.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JTRIGGER {}
20 namespace JPP { using namespace JTRIGGER; }
21 
22 namespace JTRIGGER {
23 
24  using KM3NETDAQ::JDAQHit;
25 
26 
27  /**
28  * Data frame for calibrated hits of one PMT.
29  *
30  * Note that the calibration is applied on the fly in the member method JFrame::push_back.
31  */
32  template<class JElement_t, class JAllocator_t = std::allocator<JElement_t> >
33  class JFrame :
34  public JPMTHeader,
35  public JCalibration,
36  public std::vector<JElement_t, JAllocator_t>,
37  public JHitToolkit<JElement_t>
38  {
39  public:
40 
42  typedef JElement_t value_type;
44 
45  typedef typename container_type::iterator iterator;
46  typedef typename container_type::const_iterator const_iterator;
47  typedef typename container_type::reverse_iterator reverse_iterator;
48  typedef typename container_type::const_reverse_iterator const_reverse_iterator;
49 
50  using container_type::push_back;
52 
53 
54  /**
55  * Default constructor.
56  */
57  JFrame() :
58  JPMTHeader (),
59  JCalibration(),
60  std::vector<JElement_t, JAllocator_t>(),
61  JHitToolkit<JElement_t>()
62  {}
63 
64 
65  /**
66  * Constructor.
67  *
68  * \param chronometer DAQ chronometer
69  * \param id PMT identifier
70  * \param axis PMT axis
71  * \param calibration calibration
72  */
73  JFrame(const JDAQChronometer& chronometer,
74  const JDAQPMTIdentifier& id,
75  const JAxis3D& axis,
76  const JCalibration& calibration) :
77  JPMTHeader (chronometer, id, axis),
78  JCalibration(calibration),
79  std::vector<JElement_t, JAllocator_t>(),
80  JHitToolkit<JElement_t>()
81  {}
82 
83 
84  /**
85  * Copy constructor.
86  *
87  * \param input frame
88  */
90  JPMTHeader (input.getPMTHeader()),
92  std::vector<JElement_t, JAllocator_t>(input.begin(), input.end()),
93  JHitToolkit<JElement_t>()
94  {
95  if (input.hasEndMarker()) {
96  this->putEndMarker();
97  }
98  }
99 
100 
101  /**
102  * Append DAQ hit.
103  *
104  * The time calibration is applied before the hit is appended.
105  *
106  * \param hit DAQ hit
107  */
108  void push_back(const JDAQHit& hit)
109  {
110  container_type::push_back(this->getHit(hit, this->getCalibration()));
111  }
112 
113 
114  /**
115  * Check presence of end marker.
116  *
117  * \return true if end marker present; else false
118  */
119  bool hasEndMarker() const
120  {
121  return (this->capacity() > this->size() && this->getT(*(this->end())) == this->getT(this->getEndMarker()));
122  }
123 
124 
125  /**
126  * Append end marker to data.
127  *
128  * Note that the end marker is put within the capacity of the container whilst its size is maintained.
129  */
130  void putEndMarker()
131  {
132  JPP::putEndMarker(*this, this->getEndMarker());
133  }
134 
135 
136  /**
137  * Reset.
138  *
139  * Clear container and put end marker.
140  */
141  void reset()
142  {
143  this->clear();
144  this->putEndMarker();
145  }
146 
147 
148  /**
149  * Apply high-rate veto.
150  *
151  * If vetoed, the container is cleared and an end marker is put.
152  *
153  * \param rate_Hz high-rate veto [Hz]
154  */
155  void applyHighRateVeto(const double rate_Hz)
156  {
158 
159  if (this->size() * 1.0e9 / getFrameTime() > rate_Hz) {
160  this->reset();
161  }
162  }
163 
164 
165  /**
166  * Join consecutive hits when matched according given criterion.
167  *
168  * \param match match criterion
169  */
170  void join(const match_type& match)
171  {
172  iterator out = this->begin();
173 
174  for (const_iterator p = this->begin(); p != this->end(); ) {
175 
176  *out = *p;
177 
178  while (++p != this->end() && match(*out,*p)) {
179  *out = join(*out,*p);
180  }
181 
182  ++out;
183  }
184 
185  if (out != this->end()) {
186  this->erase(out, this->end());
187  this->putEndMarker();
188  }
189  }
190 
191 
192  /**
193  * Filter-out consecutive hits when matched according given criterion.
194  *
195  * Note that all hits which are matched are removed.
196  *
197  * \param match match criterion
198  */
199  void filter(const match_type& match)
200  {
201  iterator out = this->begin();
202 
203  for (const_iterator p = this->begin(); p != this->end(); ) {
204 
205  const_iterator q = p;
206 
207  for (const_iterator i = p; ++q != this->end() && match(*i,*q); ++i) {}
208 
209  if (std::distance(p,q) == 1) {
210  *out = *p;
211  ++out;
212  }
213 
214  p = q;
215  }
216 
217  if (out != this->end()) {
218  this->erase(out, this->end());
219  this->putEndMarker();
220  }
221  }
222  };
223 }
224 
225 #endif
container_type::const_iterator const_iterator
Definition: JFrame.hh:46
void join(const match_type &match)
Join consecutive hits when matched according given criterion.
Definition: JFrame.hh:170
std::vector< JElement_t, JAllocator_t > container_type
Definition: JFrame.hh:41
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
const JPMTHeader & getPMTHeader() const
Get PMT header.
Definition: JPMTHeader.hh:62
const JCalibration & getCalibration() const
Get calibration.
bool hasEndMarker() const
Check presence of end marker.
Definition: JFrame.hh:119
Header for PMT.
Definition: JPMTHeader.hh:26
JElement_t value_type
Definition: JFrame.hh:42
Function object interface for hit matching.
Definition: JMatch.hh:25
Data structure for time calibration.
Tools for handling different hit types.
container_type::reverse_iterator reverse_iterator
Definition: JFrame.hh:47
Axis object.
Definition: JAxis3D.hh:38
JFrame(const JDAQChronometer &chronometer, const JDAQPMTIdentifier &id, const JAxis3D &axis, const JCalibration &calibration)
Constructor.
Definition: JFrame.hh:73
Base class for match operations for cluster and hit-preprocessing methods.
Hit data structure.
Definition: JDAQHit.hh:34
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Data frame for calibrated hits of one PMT.
Definition: JFrame.hh:33
void filter(const match_type &match)
Filter-out consecutive hits when matched according given criterion.
Definition: JFrame.hh:199
JFrame()
Default constructor.
Definition: JFrame.hh:57
container_type::const_reverse_iterator const_reverse_iterator
Definition: JFrame.hh:48
JFrame(const JFrame< JElement_t, JAllocator_t > &input)
Copy constructor.
Definition: JFrame.hh:89
void reset()
Reset.
Definition: JFrame.hh:141
container_type::iterator iterator
Definition: JFrame.hh:45
Template definition of hit toolkit.
Definition: JHitToolkit.hh:60
JMatch< value_type > match_type
Definition: JFrame.hh:43
void putEndMarker(std::vector< JElement_t, JAllocator_t > &buffer, const JElement_t &value)
Put end marker.
Definition: JSTDToolkit.hh:47
void putEndMarker()
Append end marker to data.
Definition: JFrame.hh:130
void applyHighRateVeto(const double rate_Hz)
Apply high-rate veto.
Definition: JFrame.hh:155
void push_back(const JDAQHit &hit)
Append DAQ hit.
Definition: JFrame.hh:108