NSCL DDAS  12.1-001
Support for XIA DDAS at FRIB
Public Member Functions | List of all members
DDASReadout::ZeroCopyHit Class Reference

This class extends RawChannel to produce a raw channel that is zero-copied from a reference counted buffer that comes from a buffer arena. This is a key data structure in the zero-copy DDAS readout. More...

#include <ZeroCopyHit.h>

Inheritance diagram for DDASReadout::ZeroCopyHit:
Inheritance graph
[legend]
Collaboration diagram for DDASReadout::ZeroCopyHit:
Collaboration graph
[legend]

Public Member Functions

 ZeroCopyHit ()
 Default constructor. More...
 
 ZeroCopyHit (size_t nWords, void *pHitData, ReferenceCountedBuffer *pBuffer, BufferArena *pArena)
 Construct from parameters. More...
 
 ZeroCopyHit (const ZeroCopyHit &rhs)
 Copy constructor. More...
 
ZeroCopyHitoperator= (const ZeroCopyHit &rhs)
 Assignment operator. More...
 
virtual ~ZeroCopyHit ()
 Destructor. More...
 
void setHit (size_t nWords, void *pHitData, ReferenceCountedBuffer *pBuffer, BufferArena *pArena)
 Sets a new hit. More...
 
void freeHit ()
 Free an existing hit. More...
 
- Public Member Functions inherited from DDASReadout::RawChannel
 RawChannel ()
 Default constructor. More...
 
 RawChannel (size_t nWords)
 Construct a channel for copy-in data. More...
 
 RawChannel (size_t nWords, void *pZcopyData)
 Constructor initialized with zero-copy hit data. More...
 
virtual ~RawChannel ()
 Destructor. More...
 
int SetTime ()
 Set the 48-bit timestamp data from the hit infomration. More...
 
int SetTime (double nsPerTick, bool useExt=false)
 Set time time in ns. More...
 
int SetLength ()
 Set the event length from the data. More...
 
int SetChannel ()
 Set the channel value from the data. More...
 
int Validate (int expecting)
 Determine if a channel has the correct amount of data. More...
 
void setData (size_t nWords, void *pZCopyData)
 Set new data. More...
 
void copyInData (size_t nWords, const void *pData)
 Copy in data. More...
 
 RawChannel (const RawChannel &rhs)
 Copy constructor. More...
 
RawChanneloperator= (const RawChannel &rhs)
 Assignment operator. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from DDASReadout::RawChannel
static uint32_t channelLength (void *pData)
 Extract the number of words in a hit. More...
 
static double moduleCalibration (uint32_t moduleType)
 Returns the multiplier used to convert the module raw timestamp into nanoseconds. More...
 
- Public Attributes inherited from DDASReadout::RawChannel
uint32_t s_moduleType
 Type of module this comes from. More...
 
double s_time
 Extracted time, possibly calibrated. More...
 
int s_chanid
 Channel within module. More...
 
bool s_ownData
 True if we own s_data. More...
 
int s_ownDataSize
 If we own data, how many uint32_t's. More...
 
int s_channelLength
 Number of uint32_t in s_data. More...
 
uint32_t * s_data
 Pointer to the hit data. More...
 

Detailed Description

This class extends RawChannel to produce a raw channel that is zero-copied from a reference counted buffer that comes from a buffer arena. This is a key data structure in the zero-copy DDAS readout.

This acts like a RawChannel, but on destruction, if it is the last reference to the buffer, returns it to the arena from whence it came.

Copy construction and assignment are supported with appropriate semantics to handle proper reference counting.

I'm sure I'm hearing a pile of people ask me why not use std::shared_pointer – The answer is that I don't actually want the buffers to be destroyed as that involves expensive dynamic memory management, I want storage returned to a pre-allocated buffer arena from which it can be quickly re-gotten. Yeah I suppose I could use custom new/delete methods but that seems pretty painful and at least as error prone as this code.

Constructor & Destructor Documentation

◆ ZeroCopyHit() [1/3]

DDASReadout::ZeroCopyHit::ZeroCopyHit ( )

Default constructor.

Creates a hit. The hit must be initialized with setHit before being accessed.

◆ ZeroCopyHit() [2/3]

DDASReadout::ZeroCopyHit::ZeroCopyHit ( size_t  nWords,
void *  pHitData,
ReferenceCountedBuffer pBuffer,
BufferArena pArena 
)

Construct from parameters.

Parameters
nWordsNumber of uint32_t's in the hit.
pHitDataPointer to the hit data.
pBufferUnderlying reference counted buffer.
pArenaBuffer arena to which the buffer is released when no longer referenced.

Stores stuff away and increments the refrence count on the underlying buffer.

◆ ZeroCopyHit() [3/3]

DDASReadout::ZeroCopyHit::ZeroCopyHit ( const ZeroCopyHit rhs)

Copy constructor.

Parameters
rhsReference ot ZeroCopyHit object to copy.

Copy in the new hit and reference.

◆ ~ZeroCopyHit()

DDASReadout::ZeroCopyHit::~ZeroCopyHit ( )
virtual

Destructor.

Dereference.

Member Function Documentation

◆ freeHit()

void DDASReadout::ZeroCopyHit::freeHit ( )

Free an existing hit.

If this hit is associated with data, disassociates.

◆ operator=()

ZeroCopyHit & DDASReadout::ZeroCopyHit::operator= ( const ZeroCopyHit rhs)

Assignment operator.

Parameters
rhsReference to ZeroCopyHit object assigned to lhs.
Returns
Reference to ZeroCopyHit object.

Dereference, copy in, reference.

◆ setHit()

void DDASReadout::ZeroCopyHit::setHit ( size_t  nWords,
void *  pHitData,
ReferenceCountedBuffer pBuffer,
BufferArena pArena 
)

Sets a new hit.

Parameters
nWordsNumber of words in the new hit.
pHitDataPointer to the hit data.
pBufferBuffer from whence the hit data came.
pArenaArena to which the buffer is returned.

If the hit is associated with a zero copy buffer, the reference is released first.


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