Jpp  master_rocky-37-gf0c5bc59d
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::JCLBDefaultSimulator Class Reference

Default CLB simulation. More...

#include <JCLBDefaultSimulator.hh>

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

Classes

class  JStateMachine
 Auxiliary class to mimic hit ordering effects due to state machine inside CLB. More...
 
class  JTDC
 Implementation of non-linearity of 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

 JCLBDefaultSimulator (const JDAQHit::JTDC_t Tmax=0)
 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 the implementation of the conversion of a time-over-threshold pulse to a hit.
A hit consists of:

The time stamping and pulse length determination is done by a TDC which is integrated inside the FPGA. The observed non-linearity of the TDC is implemented in this class.

Although the hits from the same PMT are striclty time sorted, hits from different PMTs could be reordered due to the occupancy of the buffers inside the FPGA. This reordering is also implemented in the this class.

Definition at line 134 of file JCLBDefaultSimulator.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

◆ JCLBDefaultSimulator()

JDETECTOR::JCLBDefaultSimulator::JCLBDefaultSimulator ( const JDAQHit::JTDC_t  Tmax = 0)
inline

Constructor.

Parameters
Tmaxmaximal time difference for swap [ns]

Definition at line 223 of file JCLBDefaultSimulator.hh.

223  :
224  JCLBDefaultSimulatorInterface(new JTDC(),
225  new JStateMachine(Tmax))
226  {}
JCLBDefaultSimulatorInterface(JTDC *TDC, JStateMachine *state_machine)
Constructor.

Member Function Documentation

◆ getDAQFrameStatus()

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

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
inlineoverridevirtualinherited

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
JLANG::JSinglePointer< JStateMachine > state_machine
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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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 ( )
inlinestaticinherited

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
privateinherited

Definition at line 356 of file JCLBDefaultSimulatorInterface.hh.

◆ state_machine

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

Definition at line 357 of file JCLBDefaultSimulatorInterface.hh.

◆ buffer

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

Definition at line 358 of file JCLBDefaultSimulatorInterface.hh.


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