NSCL DDAS  12.1-001
Support for XIA DDAS at FRIB
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
DDASReadout::RawChannel Struct Reference

A struct containing a pointer to a hit and its properties. More...

#include <RawChannel.h>

Inheritance diagram for DDASReadout::RawChannel:
Inheritance graph
[legend]

Public Member Functions

 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...
 

Static Public Member Functions

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

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

A struct containing a pointer to a hit and its properties.

The struct can be used in either zero copy or copy mode. In zero-copy mode, a channel's data pointer points to some buffer that may have raw data from more than one hit. In copy mode, the data are dynamically allocated to hold the raw hit.

Constructor & Destructor Documentation

◆ RawChannel() [1/4]

DDASReadout::RawChannel::RawChannel ( )

Default constructor.

Constructs a new raw channel that could be used in either zerocopy or copy mode. The size and data are not yet set and the ownData flag is set false since we don't need to delete.

◆ RawChannel() [2/4]

DDASReadout::RawChannel::RawChannel ( size_t  nWords)

Construct a channel for copy-in data.

Parameters
nWordsNumber of data words to pre-allocate.
Exceptions
std::bad_allocIf malloc of pre-allocated storage fails.

Construts a channel for copy in data. Data are pre-allocated as demanded but not initialized. We use malloc rather than new because new will construct (initialize) ints to zero and we don't want to take that time.

Data must eventually be provided by calling copyInData.

Note
after this call, m_ownData is true and m_ownDataSize is set to nWords.

◆ RawChannel() [3/4]

DDASReadout::RawChannel::RawChannel ( size_t  nWords,
void *  pZCopyData 
)

Constructor initialized with zero-copy hit data.

Parameters
nWordsNumber of data words to pre-allocate.
pZCopyDataPointer to the data of the hit.
Note
The data pointed to by pZCopyData must be in scope for the duration of this object's lifetime else probably segfaults or bus errors will happen in the best case.

◆ ~RawChannel()

DDASReadout::RawChannel::~RawChannel ( )
virtual

Destructor.

If we own the data, this will free it.

◆ RawChannel() [4/4]

DDASReadout::RawChannel::RawChannel ( const RawChannel rhs)

Copy constructor.

Parameters
rhsThe object we're copying into this.

This is just assignment to *this once we're appropriately initialized.

Member Function Documentation

◆ channelLength()

uint32_t DDASReadout::RawChannel::channelLength ( void *  pData)
static

Extract the number of words in a hit.

Parameters
pDataPointer to the hit data.
Returns
The length of the hit.

◆ copyInData()

void DDASReadout::RawChannel::copyInData ( size_t  nWords,
const void *  pData 
)

Copy in data.

Parameters
nWordsThe new channel length (32-bit words).
pDataPointer to the data to copy in.
  • If s_ownData is false, then allocate sufficient storage for the hit.
  • If s_ownData is true, and the amount of data we have is too small, allocate new data to hold it.
  • Copy the hit into our owned data.

◆ moduleCalibration()

double DDASReadout::RawChannel::moduleCalibration ( uint32_t  moduleType)
static

Returns the multiplier used to convert the module raw timestamp into nanoseconds.

Parameters
moduleTypeThe module type/speed etc. word that's normally prepended to hit data.
Returns
The timestamp multiplier.

◆ operator=()

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

Assignment operator.

Parameters
rhsThe object we'er assigning to this.
Returns
Pointer to lhs (*this).

Only works if this != &rhs. There are piles of cases to consider:

  • rhs is zero copy: we'll zero copy.
  • rhs is dynamic: we'll be a dynamic deep copy.

These two cases and their subcases are handled by setData and copyInData respectively.

◆ SetChannel()

int DDASReadout::RawChannel::SetChannel ( )

Set the channel value from the data.

Returns
int
Return values
0Success.
1Insufficent data in the hit or the hit has not been set.

◆ setData()

void DDASReadout::RawChannel::setData ( size_t  nWords,
void *  pZCopyData 
)

Set new data.

Parameters
nWordsThe new channel length (32-bit words).
pZCopyDataPointer to the data to set.

Perform at most two tasks:

  • If we own data already, it's freed and the channel length is reset to zero (0).
  • The data and channel length of the data are set from the parameters.

◆ SetLength()

int DDASReadout::RawChannel::SetLength ( )

Set the event length from the data.

Returns
0 Always.

◆ SetTime() [1/2]

int DDASReadout::RawChannel::SetTime ( )

Set the 48-bit timestamp data from the hit infomration.

Returns
int
Return values
0Success.
1If the number of data words is insufficient (< 4).

Assumes that the data are set using the setData() or copyInData() methods of this class. Determine the raw timestamp from the 48-bit timestamp data in the hit and set it in s_time. The timestamp is extracted from data words 1 and 2 of the Pixie-16 list mode event header structure in the hit.

Note
If the data have not yet been set, number of words is 0 so this is well behaved.

◆ SetTime() [2/2]

int DDASReadout::RawChannel::SetTime ( double  nsPerTick,
bool  useExt = false 
)

Set time time in ns.

Parameters
nsPerTickClock calibration in nanoseconds per clock tick.
useExtTrue if using an external timestamp (default=false).
Returns
int
Return values
0Success.
1Failure, which can happen in the following ways:
  • If attempting to use the external timestamp but none is present in the data (header has insufficient words).
  • If not using an external timestamp, but the number of data words are insufficient (< 4).

This function assumes that the data are set using either the setData() or copyInData() methods of this class. Note that setData() is used for zero-copy. Determine the calibrated timestamp from the 48-bit timestamp data in the hit and set it in s_time. The timestamp is extracted from data words 1 and 2 of the Pixie-16 list mode event header structure in the hit. The clock calibration passed to this function is used to convert the time to nanoseconds from clock ticks.

Note
In Pixie systems, the value of nsPerTick is module-dependent.
If the data have not yet been set, number of words is 0 so this is well behaved.

◆ Validate()

int DDASReadout::RawChannel::Validate ( int  expecting)

Determine if a channel has the correct amount of data.

Parameters
expectingThe expected channel length in 32-bit words.
Returns
int
Return values
0Correct length.
1Incorrect channel length. A message is output to std::cerr.

Retains rough compatibility with the old channel class.

Todo:
(ASC 1/23/24): An old and somewhat cryptic comment about "hating the output" but maintaining it for compatibility. Perhaps because we write to stderr and return 1 instead of raising an exception?

Member Data Documentation

◆ s_chanid

int DDASReadout::RawChannel::s_chanid

Channel within module.

◆ s_channelLength

int DDASReadout::RawChannel::s_channelLength

Number of uint32_t in s_data.

◆ s_data

uint32_t* DDASReadout::RawChannel::s_data

Pointer to the hit data.

◆ s_moduleType

uint32_t DDASReadout::RawChannel::s_moduleType

Type of module this comes from.

◆ s_ownData

bool DDASReadout::RawChannel::s_ownData

True if we own s_data.

◆ s_ownDataSize

int DDASReadout::RawChannel::s_ownDataSize

If we own data, how many uint32_t's.

◆ s_time

double DDASReadout::RawChannel::s_time

Extracted time, possibly calibrated.


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