QCrateReceiverBuffer Class Reference

List of all members.


Detailed Description

class for shared memory handling

Author:
sergio.didomizio@ge.infn.it One object of this kind will handle a shared memory structure for a single DAQ channel.
Shared memory structure contains some useful variables and a data buffer containing one long word for each acquired sample.
See QBufferStructure_t documentation below for further details about content of shared memory structure.
Follows a description of the format of a single word in data buffer.


Public Member Functions

 QCrateReceiverBuffer (unsigned long ch, bool attach, bool OpenFiles, int RunNumber=0, bool offset_shm=false)
 constructor
virtual ~QCrateReceiverBuffer ()
 destructor
unsigned long Size () const
 returns the number of samples that can be contained in the data buffer
char * Start () const
 get pointer to first valid word
unsigned long GetNumberOfWords () const
 get number of valid words in buffer
bool EnableTriggerPointer ()
 book trigger pointer
void ReleaseTriggerPointer ()
 release trigger pointer (do nothing if it wasn't booked)
bool EnableBuilderPointer ()
 book builder pointer
void ReleaseBuilderPointer ()
 release builder pointer (do nothing if it wasn't booked)
bool EnableReadPointer ()
 book read pointer
void ReleaseReadPointer ()
 release read pointer (do nothing if it wasn't booked)
void Release (unsigned int n)
 remove data from circular buffer
void Add (int n, const long *data)
 add data to circular buffer
void AddFromNetwork (QConnectedSocket *cs)
 get data from network and add to buffer
unsigned long GetLg () const
 get logical channel associated to this object
unsigned long GetRunNumber () const
 get run number associated to this object
int ReadToEnd () const
 distance of read pointer to end of buffer
void SetProcessed (unsigned int n)
 flag n words as processed by trigger
void SetBuilt (unsigned int n)
 flag n words as processed by builder
unsigned long GetToBeProcessed () const
 get number of valid words still to be processed by trigger
unsigned long GetToBeBuilt () const
 get number of valid words still to be processed by builder
unsigned long GetToBeRead () const
 get number of valid words still to be read
unsigned long long GetProcessed () const
 get id of the first word still to be processed by trigger
unsigned long long GetBuilt () const
 get id of the first word to be processed by builder
unsigned long long GetRead () const
 get id of the first word to be read
unsigned long long GetWritten () const
 get id of the first free word in buffer
long GetData (unsigned long long index) const
 get data at a given index
long GetSample (unsigned long long index) const
 get sample
int GetTriggerFlags (unsigned long long index, unsigned long mask=0x0000000F) const
 get trigger flags for given sample
void FlagTrigger (unsigned long long index, int tag)
 flag word with trigger tag
void SetTriggerEnabled (bool enabled)
 set trigger enable/disable flag
void SetSamplingRate (unsigned long rateHz)
 set sampling rate in Hz
unsigned long GetSamplingRate () const
 get sampling rate in Hz
long long GetTimeOfSample (unsigned long long index) const
 get time associated to a given sample index
unsigned long long GetSampleOfTime (long long timeNs) const
 get sample index associated to a given time
void Dump ()
void SetScanned (unsigned long long i)
void SetAnalyzed (unsigned long long i)
void SetCounter (unsigned long long i, unsigned int counter)

Private Member Functions

void Release ()
 throw away all useless words from circular buffer
void SetProcessed ()
 method used to update trigger pointer when it is not booked
void SetBuilt ()
 method used to update builder pointer when it is not booked
unsigned long GetToBeWritten () const
 get number of words still to be written on gzipped file
void WriteFile ()
 write data in gzipped file
void OpenFile ()
 open new gzipped file
void CloseFile (bool last)
 close current gzipped file

Private Attributes

int fHandle
int fShmid
bool fOwn
QBufferStructure_tp_buffer
gzFile zFile
std::string fGzFileName
unsigned int fPartialFile
bool fReadPtrBooked
bool fBuilderPtrBooked
bool fTrgPtrBooked

Constructor & Destructor Documentation

QCrateReceiverBuffer::QCrateReceiverBuffer ( unsigned long  ch,
bool  attach,
bool  OpenFiles,
int  RunNumber = 0,
bool  offset_shm = false 
)

constructor

Parameters:
ch logical channel this shared memory will be associated to
attach if true this object will be the shared memory owner; if false the constructor will attach to an already existing shared memory
OpenFiles if true, the data stream associated to this object will be dumped into a compressed data stream
RunNumber this parameter is stored in the shared memory in case this object is the owner of the shared memory.
off_shm if true, an offset of 20000 will be added to the id associated to the shared memory handled by this object
A QError is thrown in case of any error when creating or attaching to a shared memory

References fBuilderPtrBooked, QBufferStructure_t::fCurrentRun, fGzFileName, QBufferStructure_t::fId, QBufferStructure_t::fNotBuilt, QBufferStructure_t::fNotBuiltIsActive, QBufferStructure_t::fNotProcessed, QBufferStructure_t::fNotProcessedIsActive, QBufferStructure_t::fNum, fOwn, fPartialFile, QBufferStructure_t::fRead, QBufferStructure_t::fReadFile, fReadPtrBooked, QBufferStructure_t::fReadPtrIsActive, QBufferStructure_t::fSamplingRateHz, QBufferStructure_t::fSaveFile, fShmid, fTrgPtrBooked, QBufferStructure_t::fWrite, p_buffer, and zFile.

QCrateReceiverBuffer::~QCrateReceiverBuffer (  )  [virtual]

destructor

All the data buffer pointers are released and the shared memory is released.

References CloseFile(), QBufferStructure_t::fId, fOwn, p_buffer, ReleaseBuilderPointer(), ReleaseReadPointer(), ReleaseTriggerPointer(), and zFile.


Member Function Documentation

bool QCrateReceiverBuffer::EnableTriggerPointer (  ) 

book trigger pointer

Returns:
true if booking succeeded, false otherwise
For each shared memory, only one instance of QCrateReceiverBuffer can take control of trigger pointer

References QBufferStructure_t::fId, QBufferStructure_t::fNotProcessedIsActive, fTrgPtrBooked, and p_buffer.

bool QCrateReceiverBuffer::EnableBuilderPointer (  ) 

book builder pointer

Returns:
true if booking succeeded, false otherwise
For each shared memory, only one instance of QCrateReceiverBuffer can take control of builder pointer

References fBuilderPtrBooked, QBufferStructure_t::fId, QBufferStructure_t::fNotBuiltIsActive, and p_buffer.

bool QCrateReceiverBuffer::EnableReadPointer (  ) 

book read pointer

Returns:
true if booking succeeded, false otherwise
For each shared memory, only one instance of QCrateReceiverBuffer can take control of read pointer

References QBufferStructure_t::fId, fReadPtrBooked, QBufferStructure_t::fReadPtrIsActive, and p_buffer.

void QCrateReceiverBuffer::Release ( unsigned int  n  ) 

remove data from circular buffer

Parameters:
n number of samples to be removed

References QBufferStructure_t::fId, QBufferStructure_t::fNum, QBufferStructure_t::fRead, fReadPtrBooked, GetToBeRead(), and p_buffer.

void QCrateReceiverBuffer::Add ( int  n,
const long *  data 
)

int QCrateReceiverBuffer::ReadToEnd (  )  const [inline]

distance of read pointer to end of buffer

SDD FIXME this method should be removed or at least made private: the distance of the pointer from the physical end of the buffer should an implementation detail

References DEFAULT_BUFFER_SIZE, QBufferStructure_t::fRead, and p_buffer.

long QCrateReceiverBuffer::GetData ( unsigned long long  index  )  const

get data at a given index

Parameters:
index index of data to be returned
Returns:
the complete content of the long word identified by index

References DEFAULT_BUFFER_SIZE, QBufferStructure_t::fData, QBufferStructure_t::fWrite, p_buffer, and QError::SetDescription().

Referenced by GetSample(), GetTriggerFlags(), and WriteFile().

long QCrateReceiverBuffer::GetSample ( unsigned long long  index  )  const

get sample

Parameters:
index index of sample to be returned
return the value sampled by ADC identified by index. It is not the whole content of the long word contained in the buffer, but a subpart of it. See the top of this file for detailed description of data sctructure.

References GetData().

Referenced by QSmartScopeChannel::GetData().

int QCrateReceiverBuffer::GetTriggerFlags ( unsigned long long  index,
unsigned long  mask = 0x0000000F 
) const [inline]

get trigger flags for given sample

Parameters:
index index of sample for which trigger flags are returned
mask bit mask that can be used to return only a subset of the trigger flags. Defaults to all (0xF).
Returns:
int containing the 4 trigger flags in the 4 LSB bits.

References GetData().

void QCrateReceiverBuffer::FlagTrigger ( unsigned long long  index,
int  tag 
)

flag word with trigger tag

Parameters:
index buffer index
tag id of the trigger to be flagged. valid values: 1..4

References DEFAULT_BUFFER_SIZE, QBufferStructure_t::fData, QBufferStructure_t::fWrite, p_buffer, and QError::SetDescription().

void QCrateReceiverBuffer::SetTriggerEnabled ( bool  enabled  ) 

set trigger enable/disable flag

Parameters:
enabled if true, bit 26 is flagged. If false, bit 25 is flagged
When this method is called, a flag is set in last sample written by Daq.

References DEFAULT_BUFFER_SIZE, QBufferStructure_t::fData, QBufferStructure_t::fWrite, and p_buffer.

long long QCrateReceiverBuffer::GetTimeOfSample ( unsigned long long  index  )  const

get time associated to a given sample index

Parameters:
index sample index for which time is requested
Returns:
time associated to the requested index in ns; if index does not fall between the first and the last valid index (i.e. that sample is not available) the returned time is multiplied by -1

References QBufferStructure_t::fSamplingRateHz, QBufferStructure_t::fWrite, and p_buffer.

Referenced by QLCTriggerFinder::CheckExtraBits(), and QSmartScopeChannel::SetSampleZero().

unsigned long long QCrateReceiverBuffer::GetSampleOfTime ( long long  timeNs  )  const

get sample index associated to a given time

Returns:
sample index, obtained by truncating the product of the requested time and the sampling frequency.

References QBufferStructure_t::fSamplingRateHz, and p_buffer.

Referenced by QSmartScopeChannel::SetSampleZero().


Member Data Documentation

shared memory id

Referenced by QCrateReceiverBuffer().

true if shared memory is owned by this instance of QCrateReceiverBuffer

Referenced by QCrateReceiverBuffer(), and ~QCrateReceiverBuffer().

gzFile QCrateReceiverBuffer::zFile [private]

pointer to single channel data file

Referenced by CloseFile(), OpenFile(), QCrateReceiverBuffer(), WriteFile(), and ~QCrateReceiverBuffer().

std::string QCrateReceiverBuffer::fGzFileName [private]

single channel data file name

Referenced by CloseFile(), OpenFile(), QCrateReceiverBuffer(), and WriteFile().

unsigned int QCrateReceiverBuffer::fPartialFile [private]

partial file number

Referenced by CloseFile(), OpenFile(), and QCrateReceiverBuffer().

true if this instance of QCrateReceiver has control on read ptr

Referenced by EnableReadPointer(), QCrateReceiverBuffer(), Release(), and ReleaseReadPointer().

true if this instance of QCrateReceiverBuffer has control on builder pointer

Referenced by EnableBuilderPointer(), QCrateReceiverBuffer(), ReleaseBuilderPointer(), and SetBuilt().

true if this instance of QCrateReceiverBuffer has control on trigger pointer

Referenced by EnableTriggerPointer(), QCrateReceiverBuffer(), ReleaseTriggerPointer(), and SetProcessed().


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

Generated on Tue Nov 16 10:50:05 2010 for CUORE Software by  doxygen 1.5.6