Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
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 getHighRateVeto (const JPMTIdentifier &id) const
 Get high-rate veto of given PMT.
 

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

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

Member Typedef Documentation

◆ JPMT_t

◆ JTDC_t

◆ JTOT_t

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

129 :
131 TDC (TDC),
133 {}
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 143 of file JCLBDefaultSimulatorInterface.hh.

144 {
145 using namespace KM3NETDAQ;
146
149 int status = DAQ_WHITE_RABBIT.write(1); // TDC status
150 int fifo = DAQ_UDP_TRAILER .write(hasUDPTrailer(id) ? 1 : 0); // FIFO status
151
152 for (size_t pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
153 JBit(pmt).set(status, getHighRateVeto(JPMTIdentifier(id,pmt)) ? 1 : 0) ; // high-rate veto
154 }
155
156 return JDAQFrameStatus(daq, status, fifo);
157 }
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.
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
Definition io_ascii.hh:155
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 167 of file JCLBDefaultSimulatorInterface.hh.

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

276 {
277 return 2;
278 }

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

288 {
289 return 1;
290 }

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

300 {
301 return true;
302 }

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

312 {
313 return false;
314 }

◆ getMinimalToT()

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

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

Returns
TDC value [ns]

Definition at line 322 of file JCLBDefaultSimulatorInterface.hh.

323 {
324 return 0.5;
325 }

Member Data Documentation

◆ compare

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

◆ TDC

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

Definition at line 360 of file JCLBDefaultSimulatorInterface.hh.

◆ state_machine

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

Definition at line 361 of file JCLBDefaultSimulatorInterface.hh.

◆ buffer

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

Definition at line 362 of file JCLBDefaultSimulatorInterface.hh.


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