Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JTimesliceRouter.hh
Go to the documentation of this file.
1#ifndef __JTRIGGER__JTIMESLICEROUTER__
2#define __JTRIGGER__JTIMESLICEROUTER__
3
4#include <vector>
5#include <iterator>
6#include <utility>
7#include <limits>
8#include <algorithm>
9
14
15#include "JTools/JHashMap.hh"
16#include "JTools/JElement.hh"
17#include "JTools/JGrid.hh"
21#include "JLang/JPointer.hh"
22
23
24/**
25 * \author mdejong
26 */
27
28namespace JTRIGGER {}
29namespace JPP { using namespace JTRIGGER; }
30
31namespace JTRIGGER {
32
33 using JLANG::JPointer;
38
39 /**
40 * Auxiliary base class for JTimesliceRouter.
41 */
43 /**
44 * Constructor.
45 *
46 * \param numberOfBins number of bins of the hit look-up table
47 */
49 TMIN_NS(std::numeric_limits<JDAQHit::JTDC_t>::min()),
50 TMAX_NS(std::numeric_limits<JDAQHit::JTDC_t>::max()),
51 DAQHIT_MIN(0, TMIN_NS, 0),
52 DAQHIT_MAX(0, TMAX_NS, 0),
54 {}
55
56 const JDAQHit::JTDC_t TMIN_NS; //!< minimal TDC value
57 const JDAQHit::JTDC_t TMAX_NS; //!< maximal TDC value
58
59 const JDAQHit DAQHIT_MIN; //!< begin hit marker
60 const JDAQHit DAQHIT_MAX; //!< end hit marker
61
62 protected:
64 };
65
66
67 /**
68 * Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure
69 * as a function of the optical module identifier and time.
70 *
71 * Note that the data in a frame from the same PMT are time ordered
72 * but the data from different PMTs are not necessarily time orderd.\n
73 * The fast routing is based on the assumption that the time difference
74 * between consecutive hits in the same frame is limited.\n
75 * The access speed is then determined by this time difference.
76 *
77 * The time slice router class comprises two internal look-up tables:
78 *
79 * - The first table consists of a one dimensional look-up table which is
80 * is used to map the module identifier to the index of the corresponding
81 * data frame in the time slice.
82 *
83 * - The second table consists of a two dimensional array.
84 * In this, the first index of matches with the index of the corresponding data frame in the time slice.
85 * Each first index is mapped to a one dimensional look-up table.
86 * This one dimensional look-up table maps an uncalibrated time <tt>t1</tt>
87 * to a pair of indices <tt>(lpos,rpos)</tt>, where:
88 * -# <tt>lpos</tt> is the index of the first hit in the data frame with time <tt>>= t1</tt>;
89 * -# <tt>rpos</tt> is the index of the last hit in the data frame with time <tt>< t1</tt>;
90 */
92 public JTimesliceRouter_t,
93 public JPointer<const JDAQTimeslice>
94 {
95 /**
96 * Auxiliary structure for indexing hits in a data frame.
97 */
98 struct pair_type {
99 int lpos;
100 int rpos;
101 };
102
105 typedef JDAQTimeslice::const_iterator const_iterator;
107
108
109 /**
110 * Constructor.
111 *
112 * \param numberOfBins number of bins of the hit look-up table
113 */
117
118
119 /**
120 * Constructor.
121 *
122 * \param timeslice timeslice
123 * \param numberOfBins number of bins of the hit look-up table
124 */
126 const int numberOfBins) :
128 {
129 configure(timeslice);
130 }
131
132
133 /**
134 * Configure.
135 *
136 * Note that method reset should be called used after use.
137 *
138 * \param timeslice timeslice
139 */
140 void configure(const JDAQTimeslice& timeslice)
141 {
142 using namespace std;
143 using namespace JPP;
144 using namespace KM3NETDAQ;
145
147 typedef std::vector<JDAQHit> frame_type;
148
149
150 router.clear();
151
152 this->set(&timeslice);
153
154 for (const_iterator i = this->get()->begin(); i != this->get()->end(); ++i) {
155
156 if (router.has(i->getModuleID())) {
157 THROW(JTriggerException, "Multiple data from module " << i->getModuleID());
158 }
159
160 router.put(i->getModuleID(), distance(this->get()->begin(), i));
161 }
162
163
164 // setup grid
165
166 int number_of_elements = 2;
167
168 for (const_iterator i = this->get()->begin(); i != this->get()->end(); ++i) {
169 if (i->size() > number_of_elements) {
170 number_of_elements = i->size();
171 }
172 }
173
174 if (numberOfBins > 1 && numberOfBins + 1 < number_of_elements) {
175 number_of_elements = numberOfBins + 1;
176 }
177
178 double Tmin_ns = getTimeSinceRTS(this->get()->getFrameIndex()) - 0.05 * getFrameTime(); // [ns]
179 double Tmax_ns = getTimeSinceRTS(this->get()->getFrameIndex()) + 1.05 * getFrameTime(); // [ns]
180
181 if (Tmin_ns < TMIN_NS) { Tmin_ns = TMIN_NS; }
182 if (Tmax_ns > TMAX_NS) { Tmax_ns = TMAX_NS; }
183
184 const JGrid<double> bounds(number_of_elements, Tmin_ns, Tmax_ns); // grid of abscissa values for lookup of hit indices based on time
185
186
187 buffer_type limits(bounds.getSize() + 1); // abscissa values of grid with proper data type
188
189 for (int i = 0; i != bounds.getSize(); ++i) {
190 limits[i] = (JDAQHit::JTDC_t) bounds.getX(i);
191 }
192
193 limits[bounds.getSize()] = TMAX_NS; // this will make rpos refer to the next abscissa value in grid
194
195
196 table.resize(this->get()->size()); // lookup table with same indexing as current time slice
197
198 frame_type buffer; // copy of raw data with additional begin and end marker
199
200 vector<grid_type>::iterator grid = table.begin();
201
202 for (const_iterator frame = this->get()->begin(); frame != this->get()->end(); ++frame, ++grid) {
203
204 grid->configure(bounds);
205
206 if (!frame->empty()) {
207
208 buffer.resize(frame->size() + 2); // reserve space for begin and end marker
209
210 copy(frame->begin(), frame->end(), buffer.begin() + 1);
211
212 *buffer. begin() = DAQHIT_MIN; // begin marker
213 *buffer.rbegin() = DAQHIT_MAX; // end markr
214
215 {
216 frame_type ::const_iterator hit = buffer.begin(); ++hit; // skip begin marker
217 buffer_type::const_iterator t1 = limits.begin(); // corresponds to index in grid
218
219 for (grid_type::iterator i = grid->begin(); i != grid->end(); ++i, ++t1) {
220
221 while (hit->getT() < *t1) { ++hit; }
222
223 i->getY().lpos = distance(buffer.cbegin(), hit) - 1; // correct distance for begin marker
224 }
225 }
226
227 {
228 frame_type ::const_reverse_iterator hit = buffer.rbegin(); ++hit; // skip end marker
229 buffer_type::const_reverse_iterator t1 = limits.rbegin(); // corresponds to index in grid plus one
230
231 for (grid_type::reverse_iterator i = grid->rbegin(); i != grid->rend(); ++i, ++t1) {
232
233 while (hit->getT() >= *t1) { ++hit; }
234
235 i->getY().rpos = distance(buffer.cbegin(), hit.base()) - 1; // correct distance for begin marker
236 }
237 }
238 }
239 }
240 }
241
242
243 /**
244 * Get address of module.
245 *
246 * \param module module
247 * \return address
248 */
249 const int getAddress(const JDAQModuleIdentifier& module) const
250 {
251 return router.get(module.getModuleID());
252 }
253
254
255 /**
256 * Check presence of module.
257 *
258 * \param module module
259 * \return true if module present; else false
260 */
261 bool hasSuperFrame(const JDAQModuleIdentifier& module) const
262 {
263 return router.has(module.getModuleID());
264 }
265
266
267 /**
268 * Get super frame.
269 *
270 * \param module module
271 * \return super frame
272 */
274 {
275 return (*(this->get()))[this->getAddress(module)];
276 }
277
278
279 /**
280 * Get subset of frame given module identifier and range of hit times.
281 *
282 * Note that the hit times should have been corrected for the maximal and minimal
283 * time offsets of the PMTs in the corresponding optical module.
284 *
285 * \param module module
286 * \param timeRange time range [ns]
287 * \return subset with begin and end iterators
288 */
289 JDAQFrameSubset getFrameSubset(const JDAQModuleIdentifier& module, const JTimeRange& timeRange) const
290 {
291 const int address = this->getAddress(module);
292
293 const grid_type& grid = table [address];
294 const JDAQSuperFrame& frame = (*(this->get()))[address];
295
296 int first = grid.getIndex(timeRange.getLowerLimit());
297 int second = grid.getIndex(timeRange.getUpperLimit());
298
299 if (first < 0) { first = 0; }
300 if (second >= grid.getSize()) { second = grid.size() - 1; }
301
302 return frame.subset(grid.getY(first).lpos, grid.getY(second).rpos);
303 }
304
305 private:
308 };
309}
310
311#endif
KM3NeT DAQ constants, bit handling, etc.
The elements in a collection are sorted according to their abscissa values and a given distance opera...
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General purpose class for hash map of unique elements.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Template implementation of class that holds pointer to object(s).
Definition JPointer.hh:24
virtual void set(JClass_t *p) override
Set pointer.
Definition JPointer.hh:75
virtual JClass_t * get() const override
Get pointer.
Definition JPointer.hh:64
virtual int getSize() const override
Get number of elements.
const ordinate_type & getY(int index) const
Get ordinate value.
General purpose class for collection of equidistant elements.
int getIndex(typename JClass< abscissa_type >::argument_type x) const
Get index of given abscissa value.
collection_type::reverse_iterator reverse_iterator
collection_type::iterator iterator
bool has(const T &value) const
Test whether given value is present.
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
Subset of data frame.
Definition JDAQFrame.hh:24
JDAQFrameSubset subset(const int i1, const int i2) const
Get subset of data.
Definition JDAQFrame.hh:207
Hit data structure.
Definition JDAQHit.hh:35
unsigned int JTDC_t
leading edge [ns]
Definition JDAQHit.hh:39
int getModuleID() const
Get module identifier.
Data frame of one optical module.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< JHitW0 > buffer_type
hits
Definition JPerth.cc:70
Auxiliary classes and methods for triggering.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
double getTimeSinceRTS(const int frame_index)
Get time in ns since last RTS for a given frame index.
Definition JDAQClock.hh:263
Auxiliary class for TDC constraints.
Definition JTDC_t.hh:39
2D Element.
Definition JPolint.hh:1131
Simple data structure for an abstract collection of equidistant abscissa values.
Definition JGrid.hh:40
virtual int getSize() const override
Get number of elements.
Definition JGrid.hh:75
virtual abscissa_type getX(int index) const override
Get abscissa value.
Definition JGrid.hh:87
General purpose class for hash map of unique keys.
Definition JHashMap.hh:75
virtual mapped_type & get(typename JClass< key_type >::argument_type key) override
Get mapped value.
Definition JHashMap.hh:146
virtual void clear() override
Clear.
Definition JHashMap.hh:107
void put(typename JClass< key_type > ::argument_type key, typename JClass< mapped_type >::argument_type value)
Put pair-wise element (key,value) into collection.
Auxiliary structure for indexing hits in a data frame.
Auxiliary base class for JTimesliceRouter.
JTimesliceRouter_t(const int numberOfBins)
Constructor.
const JDAQHit DAQHIT_MIN
begin hit marker
const JDAQHit::JTDC_t TMIN_NS
minimal TDC value
const JDAQHit::JTDC_t TMAX_NS
maximal TDC value
const JDAQHit DAQHIT_MAX
end hit marker
Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the op...
std::vector< grid_type > table
JTimesliceRouter(const int numberOfBins)
Constructor.
JDAQFrameSubset getFrameSubset(const JDAQModuleIdentifier &module, const JTimeRange &timeRange) const
Get subset of frame given module identifier and range of hit times.
void configure(const JDAQTimeslice &timeslice)
Configure.
JTOOLS::JHashMap< int, int > router_type
JTOOLS::JGridCollection< element_type > grid_type
JTOOLS::JElement2D< double, pair_type > element_type
const JDAQSuperFrame & getSuperFrame(const JDAQModuleIdentifier &module) const
Get super frame.
JTimesliceRouter(const JDAQTimeslice &timeslice, const int numberOfBins)
Constructor.
bool hasSuperFrame(const JDAQModuleIdentifier &module) const
Check presence of module.
JDAQTimeslice::const_iterator const_iterator
const int getAddress(const JDAQModuleIdentifier &module) const
Get address of module.