Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
JDAQFrameStatus getDAQFrameStatus (const JModuleIdentifier &id) const
 Get DAQ frame status of given module.
 
virtual void processData (const JModuleIdentifier &id, const JCLBInput &input, JDAQSuperFrame &output) const override
 Process data.
 
virtual int getUDPNumberOfReceivedPackets (const JModuleIdentifier &id) const
 Get number of received UDP packets.
 
virtual int getUDPMaximalSequenceNumber (const JModuleIdentifier &id) const
 Get maximal sequence number of UDP packet.
 
virtual bool hasUDPTrailer (const JModuleIdentifier &id) const
 Get UDP trailer status.
 
virtual bool setHighRateVeto () const
 Set high-rate veto based on number of hits.
 
virtual bool getHighRateVeto (const JPMTIdentifier &id) const
 Get high-rate veto of given PMT.
 
virtual bool getFIFOStatus (const JPMTIdentifier &id) const
 Get FIFO (almost) full of given PMT.
 
virtual bool hasCLB (const JModuleIdentifier &id) const
 Check if CLB exist.
 

Static Public Member Functions

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

Static Public Attributes

static const struct JDETECTOR::JCLBDefaultSimulatorInterface::compare compare
 

Private Attributes

std::unique_ptr< JTDCTDC
 
std::unique_ptr< JStateMachinestate_machine
 

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 57 of file JCLBDefaultSimulatorInterface.hh.

Member Typedef Documentation

◆ JPMT_t

Definition at line 62 of file JCLBDefaultSimulatorInterface.hh.

◆ JTDC_t

Definition at line 63 of file JCLBDefaultSimulatorInterface.hh.

◆ JTOT_t

Definition at line 64 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 130 of file JCLBDefaultSimulatorInterface.hh.

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 144 of file JCLBDefaultSimulatorInterface.hh.

145 {
146 using namespace KM3NETDAQ;
147
150 int status = DAQ_WHITE_RABBIT.write(1); // TDC status
151 int fifo = DAQ_UDP_TRAILER .write(hasUDPTrailer(id) ? 1 : 0); // FIFO status
152
153 for (size_t pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
154 JBit(pmt).set(status, getHighRateVeto(JPMTIdentifier(id,pmt))); // high-rate veto
155 JBit(pmt).set(fifo, getFIFOStatus (JPMTIdentifier(id,pmt))); // FIFO (almost) full
156 }
157
158 return JDAQFrameStatus(daq, status, fifo);
159 }
virtual bool getFIFOStatus(const JPMTIdentifier &id) const
Get FIFO (almost) full of given PMT.
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.
JWriter & write(JWriter &out) const override final
Write from input.
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
void set(int &mask) const
Set bit in given bit mask.
Definition JDAQ.hh:77

◆ 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 169 of file JCLBDefaultSimulatorInterface.hh.

170 {
171 using namespace std;
172 using namespace JPP;
173 using namespace KM3NETDAQ;
174
175
176 const double Tmin = 0.0; // Minimal TDC value [ns]
177 const double Tmax = getFrameTime(); // Maximal TDC value [ns]
178
180
181 vector<JDAQHit> buffer;
182
183 size_t ns = 0; // current number of hits in data frame
184
185 for (size_t pmt = 0; pmt != input.size(); ++pmt) {
186
187 const JPMTData<JPMTPulse>& in = input[pmt];
188
189 // TDC
190
191 for (JPMTData<JPMTPulse>::const_iterator hit = in.begin(); hit != in.end(); ++hit) {
192
193 if (hit->t_ns >= Tmin && hit->t_ns <= Tmax) {
194
195 double t1 = hit->t_ns;
196 double tot = hit->tot_ns;
197
198 // generate multiple hits if time-over-threshold exceeds dynamic range
199
200 while (tot > JDAQHit::getMaximalToT()) {
201
202 buffer.push_back(TDC->makeHit((JPMT_t) pmt, t1, (JTOT_t) JDAQHit::getMaximalToT()));
203
205 tot -= JDAQHit::getMaximalToT();
206 }
207
208 if (tot > getMinimalToT()) {
209 buffer.push_back(TDC->makeHit((JPMT_t) pmt, t1, (JTOT_t) (tot + 0.5)));
210 }
211 }
212 }
213
214 if (buffer.size() > ns + getMaximalNumberOfHits()) {
215
216 if (setHighRateVeto()) {
217 output.setHighRateVeto(pmt, true);
218 }
219
220 if (output.testHighRateVeto(pmt)) {
221 buffer.resize(ns + getMaximalNumberOfHits());
222 }
223 }
224
225 inplace_merge(buffer.begin(), buffer.begin() + ns, buffer.end());
226
227 ns = buffer.size();
228 }
229
230
231 // simulate UDP packet loss
232
233 const int n1 = getUDPNumberOfReceivedPackets(id);
234 const int n2 = getUDPMaximalSequenceNumber (id);
235
236 if (n1 < n2 + 1) {
237
238 const int ns = getBayesianMedian(n2, n1, 0);
239
240 JTDC_t t0 = (JTDC_t) Tmin;
241 JTDC_t ts = (JTDC_t) ((Tmax - Tmin) / ns);
242
243 for (int i = 0; i != ns; ++i, t0 += ts) {
244
245 if (gRandom->Rndm() * ns >= (double) n1) {
246
247 std::vector<JDAQHit>::iterator p = lower_bound(buffer.begin(), buffer.end(), t0, compare);
248 std::vector<JDAQHit>::iterator q = lower_bound(buffer.begin(), buffer.end(), t0 + ts, compare);
249
250 buffer.erase(p,q);
251 }
252 }
253 }
254
255
256 // process data through state machine
257
258 if (buffer.size() > 1) {
259
260 for (std::vector<JDAQHit>::iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
261
262 if (state_machine->maybeSwapped(*p,*q)) {
263 iter_swap(p,q);
264 }
265 }
266 }
267
268
269 // store data
270
271 output.add(buffer.size(), buffer.data());
272 }
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.
virtual bool setHighRateVeto() const
Set high-rate veto based on number of hits.
std::vector< JElement_t >::const_iterator const_iterator
Template definition of a multi-dimensional oscillation probability interpolation table.
void setHighRateVeto(const int tdc, const bool value)
Set high-rate veto.
bool testHighRateVeto() const
Test high-rate veto status.
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.
size_t getBayesianMedian(const size_t m, const size_t k)
Get estimate of maximum number.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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
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 281 of file JCLBDefaultSimulatorInterface.hh.

282 {
283 return 2;
284 }

◆ 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 293 of file JCLBDefaultSimulatorInterface.hh.

294 {
295 return 1;
296 }

◆ 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 305 of file JCLBDefaultSimulatorInterface.hh.

306 {
307 return true;
308 }

◆ setHighRateVeto()

virtual bool JDETECTOR::JCLBDefaultSimulatorInterface::setHighRateVeto ( ) const
inlinevirtual

Set high-rate veto based on number of hits.

Returns
true

Reimplemented in JTRIGGER::JCLBRunByRunSimulator.

Definition at line 316 of file JCLBDefaultSimulatorInterface.hh.

317 {
318 return true;
319 }

◆ 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 328 of file JCLBDefaultSimulatorInterface.hh.

329 {
330 return false;
331 }

◆ getFIFOStatus()

virtual bool JDETECTOR::JCLBDefaultSimulatorInterface::getFIFOStatus ( const JPMTIdentifier & id) const
inlinevirtual

Get FIFO (almost) full of given PMT.

Parameters
idPMT identifier
Returns
false

Reimplemented in JTRIGGER::JCLBRunByRunSimulator.

Definition at line 340 of file JCLBDefaultSimulatorInterface.hh.

341 {
342 return false;
343 }

◆ getMinimalToT()

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

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

Returns
TDC value [ns]

Definition at line 351 of file JCLBDefaultSimulatorInterface.hh.

352 {
353 return 0.5;
354 }

◆ hasCLB()

virtual bool JDETECTOR::JCLBSimulator::hasCLB ( const JModuleIdentifier & id) const
inlinevirtualinherited

Check if CLB exist.

Parameters
idmodule identifier
Returns
true

Reimplemented in JTRIGGER::JCLBRunByRunSimulator.

Definition at line 67 of file JCLBSimulator.hh.

68 {
69 return true;
70 }

Member Data Documentation

◆ compare

const struct JDETECTOR::JCLBDefaultSimulatorInterface::compare JDETECTOR::JCLBDefaultSimulatorInterface::compare
static

◆ TDC

std::unique_ptr<JTDC> JDETECTOR::JCLBDefaultSimulatorInterface::TDC
private

Definition at line 389 of file JCLBDefaultSimulatorInterface.hh.

◆ state_machine

std::unique_ptr<JStateMachine> JDETECTOR::JCLBDefaultSimulatorInterface::state_machine
private

Definition at line 390 of file JCLBDefaultSimulatorInterface.hh.


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