/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes
DybDaq::DaqBuffer Class Reference

#include <DaqBuffer.h>

Inheritance diagram for DybDaq::DaqBuffer:
Inheritance graph
[legend]
Collaboration diagram for DybDaq::DaqBuffer:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::pair< const char
*, unsigned int > 
OutputBuffer
typedef std::vector< OutputBufferOutputBufferList
typedef std::vector
< ByteInspector * > 
Bytes
typedef std::vector
< BitsInspector * > 
Bits

Public Member Functions

virtual ~DaqBuffer ()
 Destroy this instance of the class.
bool hasDaqTraits () const
 Returns true if this object has a DaqTraits associated with it.
virtual const DaqTraitsdaqTraits () const
 Returns the DaqTraits instance used to parse this object's buffer.
virtual unsigned int gather (OutputBufferList &outputBuffers) const
 Adds to the supplied list the OutputBuffers that contain the DAQ format of this object's content, returning the total number of bytes in the added buffers.
virtual unsigned int inspect (DaqBuffer::Bytes &inspectors) const
 Adds to the supplied list the DaqBuffer::Bytes that contains inspections of this object's objects.
virtual unsigned int bufferSize () const =0
 Returns the size, in 4-bytes, of this ojbect's contents in the buffer.

Static Public Attributes

static const unsigned int kBytesInInt = 4
static const unsigned int kUndefinedFormatComponent = 0xffffffff

Protected Member Functions

 DaqBuffer (const DaqBuffer &rhs)
 Creates an instance of this class.
 DaqBuffer (char *buffer, const DaqTraits &traits, const unsigned int size=0)
 Creates an instance of this class.
 DaqBuffer (const ByteBuffer &byteBuffer, const DaqTraits &traits)
 Creates an instance of this class.
const char * buffer () const
 Returns the buffer containing the raw file data.
bool hasByteBuffer () const
 Returns true if this object has a ByteBuffer associated with it.
const ByteBufferbyteBuffer () const
 Returns the buffer, if there is one, containing the raw file data.
unsigned int fillInspectors (DaqBuffer::Bytes &inspectors, unsigned int component, unsigned int cursor) const
 Fills the supplied DaqBuffer::Bytes using the specified component.
virtual bool readBool (const unsigned int field) const
 Returns the value in the specified field as a bool.
virtual int readInt (const unsigned int field) const
 Returns the value in the specified field as an signed int.
virtual unsigned char readUnsignedChar (const unsigned int field) const
 Returns the value in the specified field as an unsigned char.
virtual unsigned int readUnsignedInt (const unsigned int field) const
 Returns the value in the specified field as an unsigned int.
char * buffer ()
 Returns the buffer containing the raw file data.
virtual void writeField (const bool value, const unsigned int field)
 Write the supplied value into the specified field.
virtual void writeField (const int value, const unsigned int field)
 Write the supplied value into the specified field.
virtual void writeField (const unsigned int value, const unsigned int field)
 Write the supplied value into the specified field.
virtual unsigned int formatComponent () const
 Returns the component with the format of this buffer.

Private Member Functions

 DaqBuffer ()
 Suppress default.
DaqBufferoperator= (const DaqBuffer &rhs)
 Suppress default.

Private Attributes

const ByteBufferm_byteBuffer
 The ByteBuffer, if the is one, containing this object's buffer.
const char * m_buffer
 The buffer containing this object's data.
const DaqTraitsm_traits
 The DaqTraits instance used to parse this object's buffer.

Detailed Description

Definition at line 23 of file DaqBuffer.h.


Member Typedef Documentation

typedef std::pair<const char*, unsigned int> DybDaq::DaqBuffer::OutputBuffer

Definition at line 27 of file DaqBuffer.h.

Definition at line 28 of file DaqBuffer.h.

typedef std::vector<ByteInspector*> DybDaq::DaqBuffer::Bytes

Definition at line 29 of file DaqBuffer.h.

typedef std::vector<BitsInspector*> DybDaq::DaqBuffer::Bits

Definition at line 30 of file DaqBuffer.h.


Constructor & Destructor Documentation

DaqBuffer::~DaqBuffer ( ) [virtual]

Destroy this instance of the class.

Definition at line 54 of file DaqBuffer.cc.

                      {
    if (0 == m_byteBuffer) {
        delete [] m_buffer;
    } else {
        m_byteBuffer->release();
    }
}
DaqBuffer::DaqBuffer ( const DaqBuffer rhs) [protected]

Creates an instance of this class.

Definition at line 26 of file DaqBuffer.cc.

                                            :
m_byteBuffer(&(buffer.byteBuffer())),
m_buffer(buffer.byteBuffer().grab()),
m_traits(&(buffer.daqTraits())) {
    // Currently assumes a ByteBuffer based DaqBuffer is being copied.
}
DaqBuffer::DaqBuffer ( char *  buffer,
const DaqTraits traits,
const unsigned int  size = 0 
) [protected]

Creates an instance of this class.

Definition at line 33 of file DaqBuffer.cc.

                                              :
m_byteBuffer(0),
m_buffer(buffer),
m_traits(&traits) {
    const unsigned int finished = size * kBytesInInt;
    for (unsigned int element = 0;
         finished != element;
         ++element) {
        buffer[element] = 0;
    }
}
DaqBuffer::DaqBuffer ( const ByteBuffer byteBuffer,
const DaqTraits traits 
) [protected]

Creates an instance of this class.

Definition at line 47 of file DaqBuffer.cc.

                                              :
m_byteBuffer(&byteBuffer),
m_buffer(byteBuffer.grab()),
m_traits(&traits) {
}
DybDaq::DaqBuffer::DaqBuffer ( ) [private]

Suppress default.


Member Function Documentation

bool DaqBuffer::hasDaqTraits ( ) const

Returns true if this object has a DaqTraits associated with it.

Definition at line 62 of file DaqBuffer.cc.

                                   {
    return 0 != &daqTraits();
}
const DaqTraits & DaqBuffer::daqTraits ( ) const [virtual]

Returns the DaqTraits instance used to parse this object's buffer.

Definition at line 66 of file DaqBuffer.cc.

                                            {
    return *m_traits;
}
unsigned int DaqBuffer::gather ( OutputBufferList outputBuffers) const [virtual]

Adds to the supplied list the OutputBuffers that contain the DAQ format of this object's content, returning the total number of bytes in the added buffers.

Reimplemented in DybDaq::DaqContainer.

Definition at line 107 of file DaqBuffer.cc.

                                                                    {
    const unsigned int result = bufferSize() * kBytesInInt;
    outputBuffers.push_back(OutputBuffer(m_buffer,
                                         result));
    return result;
}
unsigned int DaqBuffer::inspect ( DaqBuffer::Bytes inspectors) const [virtual]

Adds to the supplied list the DaqBuffer::Bytes that contains inspections of this object's objects.

Reimplemented in DybDaq::DaqContainer.

Definition at line 114 of file DaqBuffer.cc.

                                                                {
    const unsigned int component = formatComponent();
    unsigned int cursor = 0;
    const unsigned int size = bufferSize();
    if (kUndefinedFormatComponent == component) {
        if (0 != size) {
            inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + cursor),
                                                   0));
        }
    } else {
        cursor = fillInspectors(inspectors,
                                component,
                                cursor);
    }
    while ((size - cursor) > 1) {
        ++cursor;
        inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + cursor),
                                               0));
    }
    return cursor + 1;
}
virtual unsigned int DybDaq::DaqBuffer::bufferSize ( ) const [pure virtual]

Returns the size, in 4-bytes, of this ojbect's contents in the buffer.

const char * DaqBuffer::buffer ( ) const [protected]

Returns the buffer containing the raw file data.

Definition at line 70 of file DaqBuffer.cc.

                                    {
    return m_buffer;
}
bool DaqBuffer::hasByteBuffer ( ) const [protected]

Returns true if this object has a ByteBuffer associated with it.

Definition at line 74 of file DaqBuffer.cc.

                                    {
    return 0 != m_byteBuffer;
}
const ByteBuffer & DaqBuffer::byteBuffer ( ) const [protected]

Returns the buffer, if there is one, containing the raw file data.

Definition at line 78 of file DaqBuffer.cc.

                                              {
    return *m_byteBuffer;
}
unsigned int DaqBuffer::fillInspectors ( DaqBuffer::Bytes inspectors,
unsigned int  component,
unsigned int  cursor 
) const [protected]

Fills the supplied DaqBuffer::Bytes using the specified component.

Definition at line 136 of file DaqBuffer.cc.

                                                                  {
    const DybDaq::DaqTraits::Definitions& definitions = daqTraits().bitsDefinitions(component);
    ByteInspector::Bits* bitsInByte = 0;
    const DybDaq::DaqTraits::Definitions::const_iterator finished = definitions.end();
    for (DybDaq::DaqTraits::Definitions::const_iterator definition = definitions.begin();
         finished != definition;
         ++definition) {
        const DybDaq::BitsDefinition& bits = *definition;
        if (0 == bitsInByte || (bits.offset() != cursor)) {
            if (0 == bitsInByte && (cursor != bits.offset())) {
                inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + cursor),
                                                       0));
            }
            while (((bits.offset() - cursor) > 1)) {
                ++cursor;
                inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + cursor),
                                                       0));
            }
            bitsInByte = new ByteInspector::Bits();
            cursor = bits.offset();
            inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + bits.offset()),
                                                   bitsInByte));
        } 
        DybDaq::BitsInspector* bitInfo = new BitsInspector(readUnsignedInt(bits.field()),
                                                           bits);
        bitsInByte->push_back(bitInfo);
    }
    return cursor;
}
bool DaqBuffer::readBool ( const unsigned int  field) const [protected, virtual]

Returns the value in the specified field as a bool.

Definition at line 82 of file DaqBuffer.cc.

                                                       {
    unsigned int fourBytes = readUnsignedInt(field);
    return 0 != fourBytes;
}
int DaqBuffer::readInt ( const unsigned int  field) const [protected, virtual]

Returns the value in the specified field as an signed int.

Definition at line 87 of file DaqBuffer.cc.

                                                     {
    unsigned int fourBytes = readUnsignedInt(field);
    return *(int*)(&fourBytes);
}
unsigned char DaqBuffer::readUnsignedChar ( const unsigned int  field) const [protected, virtual]

Returns the value in the specified field as an unsigned char.

Definition at line 92 of file DaqBuffer.cc.

                                                                        {
    unsigned int fourBytes = readUnsignedInt(field);
    return *(unsigned char*)(&fourBytes);
}
unsigned int DaqBuffer::readUnsignedInt ( const unsigned int  field) const [protected, virtual]

Returns the value in the specified field as an unsigned int.

Definition at line 97 of file DaqBuffer.cc.

                                                                      {
    const DaqTraits& traits = daqTraits();
    unsigned int index = traits.index(field);
    if (index == traits.illegalField()) {
        return 0;
    }
    const unsigned int fourBytes = *(((unsigned int*)m_buffer) + index);
    return (fourBytes >> traits.shift(field)) & traits.mask(field);
}
char * DaqBuffer::buffer ( ) [protected]

Returns the buffer containing the raw file data.

Definition at line 168 of file DaqBuffer.cc.

                        {
    return const_cast<char*>(m_buffer);
}
void DaqBuffer::writeField ( const bool  value,
const unsigned int  field 
) [protected, virtual]

Write the supplied value into the specified field.

Definition at line 172 of file DaqBuffer.cc.

                                                     {
    const DaqTraits& traits = daqTraits();
    unsigned int index = traits.index(field);
    if (index == traits.illegalField()) {
        return;
    }
    const unsigned int shift = traits.shift(field);
    const unsigned int mask = traits.mask(field) << shift;
    const unsigned int cleared = (*(((unsigned int*)m_buffer) + index)) & (~mask);
    if (value) {
        *(((unsigned int*)m_buffer) + index) = cleared | mask;
    }
}
void DaqBuffer::writeField ( const int  value,
const unsigned int  field 
) [protected, virtual]

Write the supplied value into the specified field.

Definition at line 187 of file DaqBuffer.cc.

                                                     {
    const DaqTraits& traits = daqTraits();
    unsigned int index = traits.index(field);
    if (index == traits.illegalField()) {
        return;
    }
    const unsigned int shift = traits.shift(field);
    const unsigned int mask = traits.mask(field) << shift;
    unsigned int* location = (((unsigned int*)m_buffer) + index);
    const unsigned int cleared = (*location) & (~mask);
    *location = cleared | ((value << shift) & mask);
}
void DaqBuffer::writeField ( const unsigned int  value,
const unsigned int  field 
) [protected, virtual]

Write the supplied value into the specified field.

Definition at line 201 of file DaqBuffer.cc.

                                                     {
    const DaqTraits& traits = daqTraits();
    unsigned int index = traits.index(field);
    if (index == traits.illegalField()) {
        return;
    }
    const unsigned int shift = traits.shift(field);
    const unsigned int mask = traits.mask(field) << shift;
    unsigned int* location = (((unsigned int*)m_buffer) + index);
    const unsigned int cleared = (*location) & (~mask);
    *location = cleared | ((value << shift) & mask);
}
unsigned int DaqBuffer::formatComponent ( ) const [protected, virtual]

Returns the component with the format of this buffer.

Definition at line 215 of file DaqBuffer.cc.

DaqBuffer& DybDaq::DaqBuffer::operator= ( const DaqBuffer rhs) [private]

Suppress default.


Member Data Documentation

const unsigned int DaqBuffer::kBytesInInt = 4 [static]

Definition at line 32 of file DaqBuffer.h.

const unsigned int DaqBuffer::kUndefinedFormatComponent = 0xffffffff [static]

Definition at line 33 of file DaqBuffer.h.

The ByteBuffer, if the is one, containing this object's buffer.

Definition at line 173 of file DaqBuffer.h.

const char* DybDaq::DaqBuffer::m_buffer [private]

The buffer containing this object's data.

Definition at line 178 of file DaqBuffer.h.

The DaqTraits instance used to parse this object's buffer.

Definition at line 183 of file DaqBuffer.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:52:49 for DaqReadoutFormat by doxygen 1.7.4