Jpp  18.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public 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 struct
JDETECTOR::JCLBDefaultSimulatorInterface::compare 
compare
 

Detailed Description

Default CLB simulation.

This class provides for the implementation of the conversion of a time-over-threshold pulse to a so-called 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 135 of file JCLBDefaultSimulator.hh.

Member Typedef Documentation

Definition at line 60 of file JCLBDefaultSimulatorInterface.hh.

Definition at line 61 of file JCLBDefaultSimulatorInterface.hh.

Definition at line 62 of file JCLBDefaultSimulatorInterface.hh.

Constructor & Destructor Documentation

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

Constructor.

Parameters
Tmaxmaximal time difference for swap [ns]

Definition at line 224 of file JCLBDefaultSimulator.hh.

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

Member Function Documentation

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  }
static const JBits DAQ_UDP_RECEIVED_PACKETS(0, 15)
Mask of UDP received packets.
virtual bool hasUDPTrailer(const JModuleIdentifier &id) const
Get UDP trailer status.
void set(int &mask) const
Set bit in given bit mask.
Definition: JDAQ.hh:77
virtual int getUDPNumberOfReceivedPackets(const JModuleIdentifier &id) const
Get number of received UDP packets.
int write(const int value) const
Write given value as bit mask.
Definition: JDAQ.hh:115
int write(const int value) const
Write given value as bit mask.
Definition: JDAQ.hh:238
static const JBit DAQ_UDP_TRAILER(31)
UDP trailer.
virtual int getUDPMaximalSequenceNumber(const JModuleIdentifier &id) const
Get maximal sequence number of UDP packet.
Auxiliary data structure for single bit.
Definition: JDAQ.hh:36
virtual bool getHighRateVeto(const JPMTIdentifier &id) const
Get high-rate veto of given PMT.
static const JBit DAQ_WHITE_RABBIT(31)
White Rabbit status.
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
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  }
virtual int getUDPNumberOfReceivedPackets(const JModuleIdentifier &id) const
Get number of received UDP packets.
Auxiliary class for TDC constraints.
Definition: JTDC_t.hh:37
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
JLANG::JSinglePointer< JStateMachine > state_machine
virtual int getUDPMaximalSequenceNumber(const JModuleIdentifier &id) const
Get maximal sequence number of UDP packet.
void setHighRateVeto(const int tdc, const bool value)
Set high-rate veto.
void setDAQFrameStatus(const JDAQFrameStatus &status)
Set DAQ frame status.
Template data structure for PMT I/O.
JDAQFrameStatus getDAQFrameStatus(const JModuleIdentifier &id) const
Get DAQ frame status of given module.
std::vector< JElement_t >::const_iterator const_iterator
static struct JDETECTOR::JCLBDefaultSimulatorInterface::compare compare
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
JDAQSuperFrame & add(const JDAQSuperFrame &super_frame)
Add data from same optical module.
static JTOT_t getMaximalToT()
Get maximal time-over-threshold.
Definition: JDAQHit.hh:108
static double getMinimalToT()
Get minimal pulse length of time-over-threshold measurement.
virtual int JDETECTOR::JCLBDefaultSimulatorInterface::getUDPNumberOfReceivedPackets ( const JModuleIdentifier id) const
inlinevirtualinherited

Get number of received UDP packets.

Parameters
idmodule identifier
Returns
2

Definition at line 271 of file JCLBDefaultSimulatorInterface.hh.

272  {
273  return 2;
274  }
virtual int JDETECTOR::JCLBDefaultSimulatorInterface::getUDPMaximalSequenceNumber ( const JModuleIdentifier id) const
inlinevirtualinherited

Get maximal sequence number of UDP packet.

Parameters
idmodule identifier
Returns
1

Definition at line 283 of file JCLBDefaultSimulatorInterface.hh.

284  {
285  return 1;
286  }
virtual bool JDETECTOR::JCLBDefaultSimulatorInterface::hasUDPTrailer ( const JModuleIdentifier id) const
inlinevirtualinherited

Get UDP trailer status.

Parameters
idmodule identifier
Returns
true

Definition at line 295 of file JCLBDefaultSimulatorInterface.hh.

296  {
297  return true;
298  }
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  }
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


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