Jpp
Classes | Public Types | Public Member Functions | Protected Attributes | Private Attributes | List of all members
JTRIGGER::JTimesliceRouter Class Reference

Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the optical module identifier and time. More...

#include <JTimesliceRouter.hh>

Inheritance diagram for JTRIGGER::JTimesliceRouter:
JLANG::JPointer< const JDAQTimeslice > JLANG::JAbstractPointer< const JDAQTimeslice > JLANG::JEquals< JAbstractPointer< const JDAQTimeslice > >

Classes

struct  JPair_t
 Auxiliary structure for indexing hits in a data frame. More...
 

Public Types

typedef JTOOLS::JElement2D< double, JPair_telement_type
 
typedef JTOOLS::JGridCollection< element_typegrid_type
 
typedef JTOOLS::JRouter< int > router_type
 
typedef JDAQTimeslice::const_iterator const_iterator
 

Public Member Functions

 JTimesliceRouter (const int numberOfBins)
 Constructor. More...
 
 JTimesliceRouter (const JDAQTimeslice &timeslice, const int numberOfBins)
 Constructor. More...
 
void configure (const JDAQTimeslice &timeslice)
 Configure. More...
 
const int getAddress (const JDAQModuleIdentifier &module) const
 Get address of module. More...
 
bool hasSuperFrame (const JDAQModuleIdentifier &module) const
 Check presence of module. More...
 
const JDAQSuperFramegetSuperFrame (const JDAQModuleIdentifier &module) const
 Get super frame. More...
 
JDAQFrameSubset getFrameSubset (const JDAQModuleIdentifier &module, const JTimeRange &timeRange) const
 Get subset of frame given module identifier and range of hit times. More...
 
virtual const JDAQTimesliceget () const
 Get pointer. More...
 
virtual void set (const JDAQTimeslice *p)
 Set pointer. More...
 
void set (const JPointer< T > &pointer)
 Set pointer. More...
 
virtual void reset ()
 Reset pointer. More...
 
void reset (const JPointer< T > &pointer)
 Reset pointer. More...
 
void reset (const JDAQTimeslice *p)
 Reset pointer. More...
 
const JDAQTimeslice *const & getReference () const
 Get rereference to internal pointer. More...
 
const JDAQTimeslice *& getReference ()
 Get rereference to internal pointer. More...
 
virtual bool equals (const JAbstractPointer &object) const
 Equals. More...
 
bool is_valid () const
 Check validity of pointer. More...
 
const JDAQTimesliceoperator-> () const
 Smart pointer operator. More...
 
 operator const JDAQTimeslice * () const
 Type conversion operator. More...
 

Protected Attributes

const JDAQTimeslice__p
 pointer to object More...
 

Private Attributes

int number_of_bins
 
router_type router
 
std::vector< grid_typetable
 

Detailed Description

Router for fast addressing of hits in KM3NETDAQ::JDAQTimeslice data structure as a function of the optical module identifier and time.

Note that the data in a frame from the same PMT are time ordered but the data from different PMTs are not necessarily time orderd.
The fast routing is based on the assumption that the time difference between consecutive hits in the same frame is limited.
The access speed is then determined by this time difference.

The time slice router class comprises two internal look-up tables:

Definition at line 62 of file JTimesliceRouter.hh.

Member Typedef Documentation

◆ element_type

Definition at line 75 of file JTimesliceRouter.hh.

◆ grid_type

Definition at line 76 of file JTimesliceRouter.hh.

◆ router_type

Definition at line 77 of file JTimesliceRouter.hh.

◆ const_iterator

typedef JDAQTimeslice::const_iterator JTRIGGER::JTimesliceRouter::const_iterator

Definition at line 78 of file JTimesliceRouter.hh.

Constructor & Destructor Documentation

◆ JTimesliceRouter() [1/2]

JTRIGGER::JTimesliceRouter::JTimesliceRouter ( const int  numberOfBins)
inline

Constructor.

Parameters
numberOfBinsnumber of bins of the hit look-up table

Definition at line 86 of file JTimesliceRouter.hh.

86  :
87  number_of_bins(numberOfBins),
88  router(-1)
89  {}

◆ JTimesliceRouter() [2/2]

JTRIGGER::JTimesliceRouter::JTimesliceRouter ( const JDAQTimeslice timeslice,
const int  numberOfBins 
)
inline

Constructor.

Parameters
timeslicetimeslice
numberOfBinsnumber of bins of the hit look-up table

Definition at line 98 of file JTimesliceRouter.hh.

99  :
100  number_of_bins(numberOfBins),
101  router(-1)
102  {
103  configure(timeslice);
104  }

Member Function Documentation

◆ configure()

void JTRIGGER::JTimesliceRouter::configure ( const JDAQTimeslice timeslice)
inline

Configure.

Parameters
timeslicetimeslice

Definition at line 112 of file JTimesliceRouter.hh.

113  {
114  using namespace std;
115  using namespace JPP;
116  using namespace KM3NETDAQ;
117 
118 
119  this->set(&timeslice);
120 
121 
122  for (const_iterator i = this->get()->begin(); i != this->get()->end(); ++i) {
123  router.put(i->getModuleID(), distance(this->get()->begin(), i));
124  }
125 
126 
127  const JDAQHit::JTDC_t TMIN = numeric_limits<JDAQHit::JTDC_t>::min();
128  const JDAQHit::JTDC_t TMAX = numeric_limits<JDAQHit::JTDC_t>::max();
129 
130  double Tmin = getTimeSinceRTS(this->get()->getFrameIndex()) - 0.05 * getFrameTime(); // [ns]
131  double Tmax = getTimeSinceRTS(this->get()->getFrameIndex()) + 1.05 * getFrameTime(); // [ns]
132 
133  if (Tmin < TMIN) { Tmin = TMIN; }
134  if (Tmax > TMAX) { Tmax = TMAX; }
135 
136 
137  int number_of_elements = 2;
138 
139  for (const_iterator i = this->get()->begin(); i != this->get()->end(); ++i) {
140  if (i->size() > number_of_elements) {
141  number_of_elements = i->size();
142  }
143  }
144 
145  if (number_of_bins > 1 && number_of_bins < number_of_elements) {
146  number_of_elements = number_of_bins;
147  }
148 
149 
150  const JGrid<double> bounds(number_of_elements, Tmin, Tmax);
151 
152 
153  typedef vector<JDAQHit::JTDC_t> JBuffer_t; // temporary buffer to store bin edges with proper data type
154 
155  JBuffer_t buffer(bounds.getSize() + 1);
156 
157  for (int i = 0; i != bounds.getSize(); ++i) {
158  buffer[i] = (JDAQHit::JTDC_t) bounds.getX(i);
159  }
160 
161  buffer[bounds.getSize()] = TMAX;
162 
163 
164  table.resize(this->get()->size()); // same indexing as time slice
165 
166  const JDAQHit JDAQHitMin(0, TMIN, 0); // begin marker
167  const JDAQHit JDAQHitMax(0, TMAX, 0); // end marker
168 
169  typedef vector<JDAQHit> JDAQFrame_t;
170 
171  JDAQFrame_t zbuf; // copy of raw data with additional begin and end marker
172 
173  vector<grid_type>::iterator grid = table.begin();
174 
175  for (const_iterator frame = this->get()->begin(); frame != this->get()->end(); ++frame, ++grid) {
176 
177  grid->configure(bounds);
178 
179  if (!frame->empty()) {
180 
181  if (frame-> begin()->getT() < grid->getXmin()) {
182  THROW(JTriggerException, "Hit time out of range " << frame-> begin()->getT() << " < " << grid->getXmin());
183  }
184 
185  if (frame->rbegin()->getT() > grid->getXmax()) {
186  THROW(JTriggerException, "Hit time out of range " << frame->rbegin()->getT() << " > " << grid->getXmax());
187  }
188 
189  zbuf.resize(frame->size() + 2); // reserve space end markers
190 
191  copy(frame->begin(), frame->end(), zbuf.begin() + 1);
192 
193  *zbuf. begin() = JDAQHitMin;
194  *zbuf.rbegin() = JDAQHitMax;
195 
196  {
197  JDAQFrame_t::const_iterator hit = zbuf.begin(); ++hit; // skip begin marker
198  JBuffer_t ::const_iterator t1 = buffer.begin();
199 
200  for (grid_type::iterator i = grid->begin(); i != grid->end(); ++i, ++t1) {
201 
202  while (hit->getT() < *t1) { ++hit; }
203 
204  i->getY().lpos = distance(static_cast<const JDAQFrame_t&>(zbuf).begin(), hit) - 1;
205  }
206  }
207 
208  {
209  JDAQFrame_t::const_reverse_iterator hit = zbuf.rbegin(); ++hit; // skip end marker
210  JBuffer_t ::const_reverse_iterator t1 = buffer.rbegin();
211 
212  for (grid_type::reverse_iterator i = grid->rbegin(); i != grid->rend(); ++i, ++t1) {
213 
214  while (hit->getT() >= *t1) { ++hit; }
215 
216  i->getY().rpos = distance(static_cast<const JDAQFrame_t&>(zbuf).begin(), hit.base()) - 1;
217  }
218  }
219  }
220  }
221  }

◆ getAddress()

const int JTRIGGER::JTimesliceRouter::getAddress ( const JDAQModuleIdentifier module) const
inline

Get address of module.

Parameters
modulemodule
Returns
address

Definition at line 230 of file JTimesliceRouter.hh.

231  {
232  return router.get(module.getModuleID());
233  }

◆ hasSuperFrame()

bool JTRIGGER::JTimesliceRouter::hasSuperFrame ( const JDAQModuleIdentifier module) const
inline

Check presence of module.

Parameters
modulemodule
Returns
true if module present; else false

Definition at line 242 of file JTimesliceRouter.hh.

243  {
244  return router.has(module.getModuleID());
245  }

◆ getSuperFrame()

const JDAQSuperFrame& JTRIGGER::JTimesliceRouter::getSuperFrame ( const JDAQModuleIdentifier module) const
inline

Get super frame.

Parameters
modulemodule
Returns
super frame

Definition at line 254 of file JTimesliceRouter.hh.

255  {
256  return (*(this->get()))[this->getAddress(module)];
257  }

◆ getFrameSubset()

JDAQFrameSubset JTRIGGER::JTimesliceRouter::getFrameSubset ( const JDAQModuleIdentifier module,
const JTimeRange &  timeRange 
) const
inline

Get subset of frame given module identifier and range of hit times.

Note that the hit times should have been corrected for the maximal and minimal time offsets of the PMTs in the corresponding optical module.

Parameters
modulemodule
timeRangetime range [ns]
Returns
subset with begin and end iterators

Definition at line 270 of file JTimesliceRouter.hh.

271  {
272  const int address = this->getAddress(module);
273 
274  const grid_type& grid = table [address];
275  const JDAQSuperFrame& frame = (*(this->get()))[address];
276 
277  const int first = grid.getIndex(timeRange.getLowerLimit());
278  const int second = grid.getIndex(timeRange.getUpperLimit());
279 
280  if (first < 0 || second >= grid.getSize()) {
281  THROW(JTriggerException, "Time range [ns] " << timeRange << " bounds " << grid.getXmin() << ' ' << grid.getXmax() << " indices " << first << ' ' << second);
282  }
283 
284  return frame.subset(grid.getY(first).lpos, grid.getY(second).rpos);
285  }

◆ get()

virtual const JDAQTimeslice * JLANG::JPointer< const JDAQTimeslice >::get ( ) const
inlinevirtualinherited

Get pointer.

Returns
pointer to object

Implements JLANG::JAbstractPointer< const JDAQTimeslice >.

Definition at line 64 of file JPointer.hh.

65  {
66  return this->__p;
67  }

◆ set() [1/2]

virtual void JLANG::JPointer< const JDAQTimeslice >::set ( const JDAQTimeslice *  p)
inlinevirtualinherited

Set pointer.

Parameters
ppointer to object

Implements JLANG::JAbstractPointer< const JDAQTimeslice >.

Definition at line 75 of file JPointer.hh.

76  {
77  this->__p = p;
78  }

◆ set() [2/2]

void JLANG::JPointer< const JDAQTimeslice >::set ( const JPointer< T > &  pointer)
inlineinherited

Set pointer.

Parameters
pointerpointer to object

Definition at line 96 of file JPointer.hh.

97  {
98  this->set(pointer.get());
99  }

◆ reset() [1/3]

virtual void JLANG::JPointer< const JDAQTimeslice >::reset ( )
inlinevirtualinherited

Reset pointer.

Implements JLANG::JAbstractPointer< const JDAQTimeslice >.

Definition at line 84 of file JPointer.hh.

85  {
86  this->__p = NULL;
87  }

◆ reset() [2/3]

void JLANG::JPointer< const JDAQTimeslice >::reset ( const JPointer< T > &  pointer)
inlineinherited

Reset pointer.

Parameters
pointerpointer to object

Definition at line 108 of file JPointer.hh.

109  {
110  this->reset(pointer.get());
111  }

◆ reset() [3/3]

void JLANG::JAbstractPointer< const JDAQTimeslice >::reset ( const JDAQTimeslice *  p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 94 of file JAbstractPointer.hh.

95  {
96  if (this->get() != p) {
97 
98  this->reset();
99 
100  if (p != NULL) {
101  this->set(p);
102  }
103  }
104  }

◆ getReference() [1/2]

const JDAQTimeslice * const& JLANG::JPointer< const JDAQTimeslice >::getReference ( ) const
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 119 of file JPointer.hh.

120  {
121  return __p;
122  }

◆ getReference() [2/2]

const JDAQTimeslice * & JLANG::JPointer< const JDAQTimeslice >::getReference ( )
inlineinherited

Get rereference to internal pointer.

Returns
reference to internal pointer

Definition at line 130 of file JPointer.hh.

131  {
132  return __p;
133  }

◆ equals()

virtual bool JLANG::JAbstractPointer< const JDAQTimeslice >::equals ( const JAbstractPointer< const JDAQTimeslice > &  object) const
inlinevirtualinherited

Equals.

The equality is evaluated by comparison of the internal pointers.

Parameters
objectabstract pointer
Returns
true if equals; else false

Definition at line 50 of file JAbstractPointer.hh.

51  {
52  return this->get() == object.get();
53  }

◆ is_valid()

bool JLANG::JAbstractPointer< const JDAQTimeslice >::is_valid ( ) const
inlineinherited

Check validity of pointer.

Returns
true if pointer not null; else false

Definition at line 83 of file JAbstractPointer.hh.

84  {
85  return this->get() != NULL;
86  }

◆ operator->()

const JDAQTimeslice * JLANG::JAbstractPointer< const JDAQTimeslice >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 112 of file JAbstractPointer.hh.

113  {
114  if (!is_valid())
115  throw JNullPointerException("JAbstractPointer::operator->()");
116  else
117  return this->get();
118  }

◆ operator const JDAQTimeslice *()

JLANG::JAbstractPointer< const JDAQTimeslice >::operator const JDAQTimeslice * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 126 of file JAbstractPointer.hh.

127  {
128  return this->get();
129  }

Member Data Documentation

◆ number_of_bins

int JTRIGGER::JTimesliceRouter::number_of_bins
private

Definition at line 288 of file JTimesliceRouter.hh.

◆ router

router_type JTRIGGER::JTimesliceRouter::router
private

Definition at line 289 of file JTimesliceRouter.hh.

◆ table

std::vector<grid_type> JTRIGGER::JTimesliceRouter::table
private

Definition at line 290 of file JTimesliceRouter.hh.

◆ __p

const JDAQTimeslice * JLANG::JPointer< const JDAQTimeslice >::__p
protectedinherited

pointer to object

Definition at line 136 of file JPointer.hh.


The documentation for this class was generated from the following file:
JLANG::JPointer< const JDAQTimeslice >::set
virtual void set(const JDAQTimeslice *p)
Set pointer.
Definition: JPointer.hh:75
JTOOLS::JGridCollection::iterator
collection_type::iterator iterator
Definition: JGridCollection.hh:43
JTRIGGER::JTimesliceRouter::router
router_type router
Definition: JTimesliceRouter.hh:289
JTRIGGER::JTimesliceRouter::grid_type
JTOOLS::JGridCollection< element_type > grid_type
Definition: JTimesliceRouter.hh:76
JLANG::JPointer< const JDAQTimeslice >::get
virtual const JDAQTimeslice * get() const
Get pointer.
Definition: JPointer.hh:64
JLANG::JPointer< const JDAQTimeslice >::__p
const JDAQTimeslice * __p
pointer to object
Definition: JPointer.hh:136
JTRIGGER::JTimesliceRouter::number_of_bins
int number_of_bins
Definition: JTimesliceRouter.hh:288
std::vector< JDAQHit::JTDC_t >
JLANG::JNullPointerException
Exception for null pointer operation.
Definition: JException.hh:216
JLANG::JAbstractPointer< const JDAQTimeslice >::reset
virtual void reset()=0
Reset pointer.
KM3NETDAQ::JDAQModuleIdentifier::getModuleID
int getModuleID() const
Get module identifier.
Definition: JDAQModuleIdentifier.hh:72
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
JAANET::copy
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:152
JTOOLS::JGridCollection::reverse_iterator
collection_type::reverse_iterator reverse_iterator
Definition: JGridCollection.hh:44
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
JTRIGGER::JTriggerException
General exception.
Definition: JTriggerException.hh:23
JLANG::JPointer< const JDAQTimeslice >::reset
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:669
KM3NETDAQ::JDAQFrame::subset
JDAQFrameSubset subset(const int i1, const int i2) const
Get subset of data.
Definition: JDAQFrame.hh:181
JTRIGGER::JTimesliceRouter::table
std::vector< grid_type > table
Definition: JTimesliceRouter.hh:290
JTRIGGER::JTimesliceRouter::configure
void configure(const JDAQTimeslice &timeslice)
Configure.
Definition: JTimesliceRouter.hh:112
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::JTimesliceRouter::getAddress
const int getAddress(const JDAQModuleIdentifier &module) const
Get address of module.
Definition: JTimesliceRouter.hh:230
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
KM3NETDAQ::JDAQSuperFrame
Data frame of one optical module.
Definition: JDAQSuperFrame.hh:27
KM3NETDAQ::JDAQHit
Hit data structure.
Definition: JDAQHit.hh:40
JTRIGGER::JTimesliceRouter::const_iterator
JDAQTimeslice::const_iterator const_iterator
Definition: JTimesliceRouter.hh:78
JLANG::JAbstractPointer< const JDAQTimeslice >::is_valid
bool is_valid() const
Check validity of pointer.
Definition: JAbstractPointer.hh:83
KM3NETDAQ::getFrameIndex
int getFrameIndex(const double t_ns)
Get frame index for a given time in ns.
Definition: JDAQClock.hh:251