Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_t
element_type
 
typedef
JTOOLS::JGridCollection
< element_type
grid_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

Definition at line 75 of file JTimesliceRouter.hh.

Definition at line 76 of file JTimesliceRouter.hh.

Definition at line 77 of file JTimesliceRouter.hh.

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

Definition at line 78 of file JTimesliceRouter.hh.

Constructor & Destructor Documentation

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  {}
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  }
void configure(const JDAQTimeslice &timeslice)
Configure.

Member Function Documentation

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 KM3NETDAQ;
116  using namespace JTOOLS;
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 = std::numeric_limits<JDAQHit::JTDC_t>::min();
128  const JDAQHit::JTDC_t TMAX = std::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  // temporary buffer to store bin edges with proper data type
154 
155  typedef vector<JDAQHit::JTDC_t> JBuffer_t;
156 
157  JBuffer_t buffer(bounds.getSize() + 1);
158 
159  for (int i = 0; i != bounds.getSize(); ++i) {
160  buffer[i] = (JDAQHit::JTDC_t) bounds.getX(i);
161  }
162 
163  buffer[bounds.getSize()] = TMAX;
164 
165 
166  table.resize(this->get()->size()); // same indexing as time slice
167 
168  const JDAQHit JDAQHitMin(0, TMIN, 0);
169  const JDAQHit JDAQHitMax(0, TMAX, 0);
170 
171  typedef std::vector<JDAQHit> JDAQFrame_t;
172 
173  JDAQFrame_t zbuf; // copy of data with begin and end marker
174 
175  vector<grid_type>::iterator grid = table.begin();
176 
177  for (const_iterator frame = this->get()->begin(); frame != this->get()->end(); ++frame, ++grid) {
178 
179  grid->configure(bounds);
180 
181  if (!frame->empty()) {
182 
183  if (frame-> begin()->getT() < grid->getXmin()) {
184  throw JTriggerException("Hit time out of range (lower limit).");
185  }
186 
187  if (frame->rbegin()->getT() > grid->getXmax()) {
188  throw JTriggerException("Hit time out of range (upper limit).");
189  }
190 
191  zbuf.resize(frame->size() + 2); // reserve space end markers
192 
193  copy(frame->begin(), frame->end(), zbuf.begin() + 1);
194 
195  *zbuf. begin() = JDAQHitMin;
196  *zbuf.rbegin() = JDAQHitMax;
197 
198  {
199  JDAQFrame_t::const_iterator hit = zbuf.begin(); ++hit; // skip begin marker
200  JBuffer_t ::const_iterator t1 = buffer.begin();
201 
202  for (grid_type::iterator i = grid->begin(); i != grid->end(); ++i, ++t1) {
203 
204  while (hit->getT() < *t1) { ++hit; }
205 
206  i->getY().lpos = distance(static_cast<const JDAQFrame_t&>(zbuf).begin(),hit) - 1;
207  }
208  }
209 
210  {
211  JDAQFrame_t::const_reverse_iterator hit = zbuf.rbegin(); ++hit; // skip end marker
212  JBuffer_t ::const_reverse_iterator t1 = buffer.rbegin();
213 
214  for (grid_type::reverse_iterator i = grid->rbegin(); i != grid->rend(); ++i, ++t1) {
215 
216  while (hit->getT() >= *t1) { ++hit; }
217 
218  i->getY().rpos = distance(static_cast<const JDAQFrame_t&>(zbuf).begin(),hit.base()) - 1;
219  }
220  }
221  }
222  }
223  }
std::vector< grid_type > table
JDAQTimeslice::const_iterator const_iterator
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:41
Hit data structure.
Definition: JDAQHit.hh:36
int getFrameIndex(const double t_ns)
Get frame index for a given time in ns.
Definition: JDAQClock.hh:251
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
collection_type::iterator iterator
Simple data structure for an abstract collection of equidistant abscissa values.
Definition: JGrid.hh:32
collection_type::reverse_iterator reverse_iterator
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:40
virtual void set(const JDAQTimeslice *p)
Set pointer.
Definition: JPointer.hh:75
const int JTRIGGER::JTimesliceRouter::getAddress ( const JDAQModuleIdentifier module) const
inline

Get address of module.

Parameters
modulemodule
Returns
address

Definition at line 232 of file JTimesliceRouter.hh.

233  {
234  return router.get(module.getModuleID());
235  }
int getModuleID() const
Get module identifier.
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 244 of file JTimesliceRouter.hh.

245  {
246  return router.has(module.getModuleID());
247  }
int getModuleID() const
Get module identifier.
const JDAQSuperFrame& JTRIGGER::JTimesliceRouter::getSuperFrame ( const JDAQModuleIdentifier module) const
inline

Get super frame.

Parameters
modulemodule
Returns
super frame

Definition at line 256 of file JTimesliceRouter.hh.

257  {
258  return (*(this->get()))[getAddress(module)];
259  }
const int getAddress(const JDAQModuleIdentifier &module) const
Get address of module.
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 272 of file JTimesliceRouter.hh.

273  {
274  const int address = getAddress(module);
275 
276  const grid_type& grid = table [address];
277  const JDAQSuperFrame& frame = (*(this->get()))[address];
278 
279  const int first = grid.getIndex(timeRange.getLowerLimit());
280  const int second = grid.getIndex(timeRange.getUpperLimit());
281 
282  return frame.subset(grid.getY(first).lpos, grid.getY(second).rpos);
283  }
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:180
std::vector< grid_type > table
JTOOLS::JGridCollection< element_type > grid_type
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:191
const int getAddress(const JDAQModuleIdentifier &module) const
Get address of module.
Data frame of one optical module.
JDAQFrameSubset subset(const int i1, const int i2) const
Get subset of data.
Definition: JDAQFrame.hh:181
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  }
const JDAQTimeslice * __p
pointer to object
Definition: JPointer.hh:136
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  }
const JDAQTimeslice * __p
pointer to object
Definition: JPointer.hh:136
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  }
virtual JClass_t * get() const
Get pointer.
Definition: JPointer.hh:64
virtual void set(const JDAQTimeslice *p)
Set pointer.
Definition: JPointer.hh:75
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  }
const JDAQTimeslice * __p
pointer to object
Definition: JPointer.hh:136
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  }
virtual void reset()
Reset pointer.
Definition: JPointer.hh:84
virtual JClass_t * get() const
Get pointer.
Definition: JPointer.hh:64
void JLANG::JAbstractPointer< const JDAQTimeslice >::reset ( const JDAQTimeslice *  p)
inlineinherited

Reset pointer.

Parameters
ppointer to object

Definition at line 92 of file JAbstractPointer.hh.

93  {
94  if (this->get() != p) {
95 
96  this->reset();
97 
98  if (p != NULL) {
99  this->set(p);
100  }
101  }
102  }
virtual void reset()=0
Reset pointer.
virtual void set(const JDAQTimeslice *p)=0
Set pointer.
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  }
const JDAQTimeslice * __p
pointer to object
Definition: JPointer.hh:136
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  }
const JDAQTimeslice * __p
pointer to object
Definition: JPointer.hh:136
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 48 of file JAbstractPointer.hh.

49  {
50  return this->get() == object.get();
51  }
bool JLANG::JAbstractPointer< const JDAQTimeslice >::is_valid ( ) const
inlineinherited

Check validity of pointer.

Returns
true if pointer not null; else false

Definition at line 81 of file JAbstractPointer.hh.

82  {
83  return this->get() != NULL;
84  }
const JDAQTimeslice * JLANG::JAbstractPointer< const JDAQTimeslice >::operator-> ( ) const
inlineinherited

Smart pointer operator.

Returns
pointer to object

Definition at line 110 of file JAbstractPointer.hh.

111  {
112  if (!is_valid())
113  throw JNullPointerException("JAbstractPointer::operator->()");
114  else
115  return this->get();
116  }
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:198
JLANG::JAbstractPointer< const JDAQTimeslice >::operator const JDAQTimeslice * ( ) const
inlineinherited

Type conversion operator.

Returns
pointer to object

Definition at line 124 of file JAbstractPointer.hh.

125  {
126  return this->get();
127  }

Member Data Documentation

int JTRIGGER::JTimesliceRouter::number_of_bins
private

Definition at line 286 of file JTimesliceRouter.hh.

router_type JTRIGGER::JTimesliceRouter::router
private

Definition at line 287 of file JTimesliceRouter.hh.

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

Definition at line 288 of file JTimesliceRouter.hh.

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: