Jpp  19.1.0
the software that should make you happy
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | List of all members
JDETECTOR::JCLBDefaultSimulatorInterface Class Reference

Default CLB simulation. More...

#include <JCLBDefaultSimulatorInterface.hh>

Inheritance diagram for JDETECTOR::JCLBDefaultSimulatorInterface:
JDETECTOR::JCLBSimulator JDETECTOR::JCLBDefaultSimulator JTRIGGER::JCLBRunByRunSimulator

Classes

struct  compare
 Auxiliary data structure for sorting of hits. More...
 
class  JStateMachine
 Interface to mimic hit ordering effects due to state machine inside CLB. More...
 
class  JTDC
 Interface for TDC. More...
 

Public Types

typedef JDAQHit::JPMT_t JPMT_t
 
typedef JDAQHit::JTDC_t JTDC_t
 
typedef JDAQHit::JTOT_t JTOT_t
 

Public Member Functions

 JCLBDefaultSimulatorInterface (JTDC *TDC, JStateMachine *state_machine)
 Constructor. More...
 
JDAQFrameStatus getDAQFrameStatus (const JModuleIdentifier &id) const
 Get DAQ frame status of given module. More...
 
virtual void processData (const JModuleIdentifier &id, const JCLBInput &input, JDAQSuperFrame &output) const override
 Process data. More...
 
virtual int getUDPNumberOfReceivedPackets (const JModuleIdentifier &id) const
 Get number of received UDP packets. More...
 
virtual int getUDPMaximalSequenceNumber (const JModuleIdentifier &id) const
 Get maximal sequence number of UDP packet. More...
 
virtual bool hasUDPTrailer (const JModuleIdentifier &id) const
 Get UDP trailer status. More...
 
virtual bool getHighRateVeto (const JPMTIdentifier &id) const
 Get high-rate veto of given PMT. More...
 

Static Public Member Functions

static double getMinimalToT ()
 Get minimal pulse length of time-over-threshold measurement. More...
 

Static Public Attributes

static const struct JDETECTOR::JCLBDefaultSimulatorInterface::compare compare
 

Private Attributes

JLANG::JSinglePointer< JTDCTDC
 
JLANG::JSinglePointer< JStateMachinestate_machine
 
std::vector< JDAQHitbuffer
 

Detailed Description

Default CLB simulation.

This class provides for a default implementation of the JCLBSimulator interface which is based on a simulation of the TDC and the state machine inside the CLB. The actual number of hits may change due to the high-rate veto and UDP packet loss (loss of hits) and the dynamic range of the time-over-threshold (gain of hits).

The nested class JStateMachine constitutes a user interface for the simulation of the state machine through method JStateMachine::maybeSwapped(). With the default implementation, the overall time ordering if hits is maintained. For a realistic simulation of the CLB, a pointer to a designated implementation of this interface should be provided.

The implementation of the virtual method JCLBDefaultSimulatorInterface::processData provides for the settings of the status of the data frame.
In this, the high-rate veto is set when:

Definition at line 55 of file JCLBDefaultSimulatorInterface.hh.

Member Typedef Documentation

◆ JPMT_t

Definition at line 60 of file JCLBDefaultSimulatorInterface.hh.

◆ JTDC_t

Definition at line 61 of file JCLBDefaultSimulatorInterface.hh.

◆ JTOT_t

Definition at line 62 of file JCLBDefaultSimulatorInterface.hh.

Constructor & Destructor Documentation

◆ JCLBDefaultSimulatorInterface()

JDETECTOR::JCLBDefaultSimulatorInterface::JCLBDefaultSimulatorInterface ( JTDC TDC,
JStateMachine state_machine 
)
inline

Constructor.

This class owns the objects pointed to.

Parameters
TDCpointer to TDC simulator
state_machinepointer to state machine

Definition at line 128 of file JCLBDefaultSimulatorInterface.hh.

128  :
129  JCLBSimulator(),
130  TDC (TDC),
132  {}
JLANG::JSinglePointer< JStateMachine > state_machine
JCLBSimulator()
Default constructor.

Member Function Documentation

◆ getDAQFrameStatus()

JDAQFrameStatus JDETECTOR::JCLBDefaultSimulatorInterface::getDAQFrameStatus ( const JModuleIdentifier id) const
inline

Get DAQ frame status of given module.

Parameters
idmodule identifier
Returns
DAQ frame status

Definition at line 142 of file JCLBDefaultSimulatorInterface.hh.

143  {
144  using namespace KM3NETDAQ;
145 
148  int status = DAQ_WHITE_RABBIT.write(1); // TDC status
149  int fifo = DAQ_UDP_TRAILER .write(hasUDPTrailer(id) ? 1 : 0); // FIFO status
150 
151  for (size_t pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
152  JBit(pmt).set(status, getHighRateVeto(JPMTIdentifier(id,pmt)) ? 1 : 0) ; // high-rate veto
153  }
154 
155  return JDAQFrameStatus(daq, status, fifo);
156  }
virtual bool hasUDPTrailer(const JModuleIdentifier &id) const
Get UDP trailer status.
virtual int getUDPMaximalSequenceNumber(const JModuleIdentifier &id) const
Get maximal sequence number of UDP packet.
virtual int getUDPNumberOfReceivedPackets(const JModuleIdentifier &id) const
Get number of received UDP packets.
virtual bool getHighRateVeto(const JPMTIdentifier &id) const
Get high-rate veto of given PMT.
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
static const JBits DAQ_UDP_RECEIVED_PACKETS(0, 15)
Mask of UDP received packets.
static const JBits DAQ_UDP_SEQUENCE_NUMBER(16, 31)
Mask of UDP sequence number.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
static const JBit DAQ_WHITE_RABBIT(31)
White Rabbit status.
static const JBit DAQ_UDP_TRAILER(31)
UDP trailer.
Auxiliary data structure for single bit.
Definition: JDAQ.hh:36
int write(const int value) const
Write given value as bit mask.
Definition: JDAQ.hh:115
void set(int &mask) const
Set bit in given bit mask.
Definition: JDAQ.hh:77
int write(const int value) const
Write given value as bit mask.
Definition: JDAQ.hh:238

◆ processData()

virtual void JDETECTOR::JCLBDefaultSimulatorInterface::processData ( const JModuleIdentifier id,
const JCLBInput input,
JDAQSuperFrame output 
) const
inlineoverridevirtual

Process data.

Parameters
idmodule identifier
inputPMT data
outputCLB data

Implements JDETECTOR::JCLBSimulator.

Definition at line 166 of file JCLBDefaultSimulatorInterface.hh.

167  {
168  using namespace std;
169  using namespace KM3NETDAQ;
170 
171 
172  const double Tmin = 0.0; // Minimal TDC value [ns]
173  const double Tmax = getFrameTime(); // Maximal TDC value [ns]
174 
176 
177  buffer.clear();
178 
179  size_t ns = 0; // current number of hits in data frame
180 
181  for (size_t pmt = 0; pmt != input.size(); ++pmt) {
182 
183  const JPMTData<JPMTPulse>& in = input[pmt];
184 
185  // TDC
186 
187  for (JPMTData<JPMTPulse>::const_iterator hit = in.begin(); hit != in.end(); ++hit) {
188 
189  if (hit->t_ns >= Tmin && hit->t_ns <= Tmax) {
190 
191  double t1 = hit->t_ns;
192  double tot = hit->tot_ns;
193 
194  // generate multiple hits if time-over-threshold exceeds dynamic range
195 
196  while (tot > JDAQHit::getMaximalToT()) {
197 
198  buffer.push_back(TDC->makeHit((JPMT_t) pmt, t1, (JTOT_t) JDAQHit::getMaximalToT()));
199 
200  t1 += JDAQHit::getMaximalToT();
201  tot -= JDAQHit::getMaximalToT();
202  }
203 
204  if (tot > getMinimalToT()) {
205  buffer.push_back(TDC->makeHit((JPMT_t) pmt, t1, (JTOT_t) (tot + 0.5)));
206  }
207  }
208  }
209 
210  if (buffer.size() > ns + getMaximalNumberOfHits()) {
211 
212  output.setHighRateVeto(pmt, true);
213 
214  buffer.resize(ns + getMaximalNumberOfHits());
215  }
216 
217  inplace_merge(buffer.begin(), buffer.begin() + ns, buffer.end());
218 
219  ns = buffer.size();
220  }
221 
222 
223  // simulate UDP packet loss
224 
225  const int n1 = getUDPNumberOfReceivedPackets(id);
226  const int n2 = getUDPMaximalSequenceNumber (id);
227 
228  if (n1 < n2 + 1) {
229 
230  JTDC_t t0 = (JTDC_t) Tmin;
231  JTDC_t ts = (JTDC_t) ((Tmax - Tmin) / (n2 + 1));
232 
233  for (int i = 0; i != n2 + 1; ++i, t0 += ts) {
234 
235  if (gRandom->Rndm() * (n2 + 1) >= (double) n1) {
236 
237  std::vector<JDAQHit>::iterator p = lower_bound(buffer.begin(), buffer.end(), t0, compare);
238  std::vector<JDAQHit>::iterator q = lower_bound(buffer.begin(), buffer.end(), t0 + ts, compare);
239 
240  buffer.erase(p,q);
241  }
242  }
243  }
244 
245 
246  // process data through state machine
247 
248  if (buffer.size() > 1) {
249 
250  for (std::vector<JDAQHit>::iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
251 
252  if (state_machine->maybeSwapped(*p,*q)) {
253  iter_swap(p,q);
254  }
255  }
256  }
257 
258 
259  // store data
260 
261  output.add(buffer.size(), buffer.data());
262  }
static const struct JDETECTOR::JCLBDefaultSimulatorInterface::compare compare
static double getMinimalToT()
Get minimal pulse length of time-over-threshold measurement.
JDAQFrameStatus getDAQFrameStatus(const JModuleIdentifier &id) const
Get DAQ frame status of given module.
Template data structure for PMT I/O.
std::vector< JElement_t >::const_iterator const_iterator
void setHighRateVeto(const int tdc, const bool value)
Set high-rate veto.
void setDAQFrameStatus(const JDAQFrameStatus &status)
Set DAQ frame status.
static JTOT_t getMaximalToT()
Get maximal time-over-threshold.
Definition: JDAQHit.hh:108
JDAQSuperFrame & add(const JDAQSuperFrame &super_frame)
Add data from same optical module.
std::vector< size_t > ns
void inplace_merge(T __begin, const size_t N, const size_t *delimiter)
Merge multiple sorted ranges.
Definition: JMergeSort.cc:29
size_t getMaximalNumberOfHits()
Get maximal number of hits from one PMT within data frame.
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Definition: JSTDTypes.hh:14
Auxiliary class for TDC constraints.
Definition: JTDC_t.hh:39

◆ getUDPNumberOfReceivedPackets()

virtual int JDETECTOR::JCLBDefaultSimulatorInterface::getUDPNumberOfReceivedPackets ( const JModuleIdentifier id) const
inlinevirtual

Get number of received UDP packets.

Parameters
idmodule identifier
Returns
2

Reimplemented in JTRIGGER::JCLBRunByRunSimulator.

Definition at line 271 of file JCLBDefaultSimulatorInterface.hh.

272  {
273  return 2;
274  }

◆ getUDPMaximalSequenceNumber()

virtual int JDETECTOR::JCLBDefaultSimulatorInterface::getUDPMaximalSequenceNumber ( const JModuleIdentifier id) const
inlinevirtual

Get maximal sequence number of UDP packet.

Parameters
idmodule identifier
Returns
1

Reimplemented in JTRIGGER::JCLBRunByRunSimulator.

Definition at line 283 of file JCLBDefaultSimulatorInterface.hh.

284  {
285  return 1;
286  }

◆ hasUDPTrailer()

virtual bool JDETECTOR::JCLBDefaultSimulatorInterface::hasUDPTrailer ( const JModuleIdentifier id) const
inlinevirtual

Get UDP trailer status.

Parameters
idmodule identifier
Returns
true

Reimplemented in JTRIGGER::JCLBRunByRunSimulator.

Definition at line 295 of file JCLBDefaultSimulatorInterface.hh.

296  {
297  return true;
298  }

◆ getHighRateVeto()

virtual bool JDETECTOR::JCLBDefaultSimulatorInterface::getHighRateVeto ( const JPMTIdentifier id) const
inlinevirtual

Get high-rate veto of given PMT.

Parameters
idPMT identifier
Returns
false

Reimplemented in JTRIGGER::JCLBRunByRunSimulator.

Definition at line 307 of file JCLBDefaultSimulatorInterface.hh.

308  {
309  return false;
310  }

◆ getMinimalToT()

static double JDETECTOR::JCLBDefaultSimulatorInterface::getMinimalToT ( )
inlinestatic

Get minimal pulse length of time-over-threshold measurement.

Returns
TDC value [ns]

Definition at line 318 of file JCLBDefaultSimulatorInterface.hh.

319  {
320  return 0.5;
321  }

Member Data Documentation

◆ compare

◆ TDC

JLANG::JSinglePointer<JTDC> JDETECTOR::JCLBDefaultSimulatorInterface::TDC
private

Definition at line 356 of file JCLBDefaultSimulatorInterface.hh.

◆ state_machine

JLANG::JSinglePointer<JStateMachine> JDETECTOR::JCLBDefaultSimulatorInterface::state_machine
private

Definition at line 357 of file JCLBDefaultSimulatorInterface.hh.

◆ buffer

std::vector<JDAQHit> JDETECTOR::JCLBDefaultSimulatorInterface::buffer
mutableprivate

Definition at line 358 of file JCLBDefaultSimulatorInterface.hh.


The documentation for this class was generated from the following file: