#include <DaqBuffer.h>
Inheritance diagram for DybDaq::DaqBuffer:
Public Types | |
typedef std::pair< const char *, unsigned int > | OutputBuffer |
typedef std::vector< OutputBuffer > | OutputBufferList |
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 DaqTraits & | daqTraits () 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 ByteBuffer & | byteBuffer () 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. | |
DaqBuffer & | operator= (const DaqBuffer &rhs) |
Suppress default. | |
Private Attributes | |
const ByteBuffer * | m_byteBuffer |
The ByteBuffer, if the is one, containing this object's buffer. | |
const char * | m_buffer |
The buffer containing this object's data. | |
const DaqTraits * | m_traits |
The DaqTraits instance used to parse this object's buffer. |
Definition at line 23 of file DaqBuffer.h.
typedef std::pair<const char*, unsigned int> DybDaq::DaqBuffer::OutputBuffer |
Definition at line 27 of file DaqBuffer.h.
typedef std::vector<OutputBuffer> DybDaq::DaqBuffer::OutputBufferList |
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.
DaqBuffer::~DaqBuffer | ( | ) | [virtual] |
Destroy this instance of the class.
Definition at line 54 of file DaqBuffer.cc.
00054 { 00055 if (0 == m_byteBuffer) { 00056 delete [] m_buffer; 00057 } else { 00058 m_byteBuffer->release(); 00059 } 00060 }
DaqBuffer::DaqBuffer | ( | const DaqBuffer & | rhs | ) | [protected] |
Creates an instance of this class.
Definition at line 26 of file DaqBuffer.cc.
00026 : 00027 m_byteBuffer(&(buffer.byteBuffer())), 00028 m_buffer(buffer.byteBuffer().grab()), 00029 m_traits(&(buffer.daqTraits())) { 00030 // Currently assumes a ByteBuffer based DaqBuffer is being copied. 00031 }
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.
00035 : 00036 m_byteBuffer(0), 00037 m_buffer(buffer), 00038 m_traits(&traits) { 00039 const unsigned int finished = size * kBytesInInt; 00040 for (unsigned int element = 0; 00041 finished != element; 00042 ++element) { 00043 buffer[element] = 0; 00044 } 00045 }
DaqBuffer::DaqBuffer | ( | const ByteBuffer & | byteBuffer, | |
const DaqTraits & | traits | |||
) | [protected] |
Creates an instance of this class.
Definition at line 47 of file DaqBuffer.cc.
00048 : 00049 m_byteBuffer(&byteBuffer), 00050 m_buffer(byteBuffer.grab()), 00051 m_traits(&traits) { 00052 }
DybDaq::DaqBuffer::DaqBuffer | ( | ) | [private] |
Suppress default.
bool DaqBuffer::hasDaqTraits | ( | ) | const |
Returns true if this object has a DaqTraits associated with it.
Definition at line 62 of file DaqBuffer.cc.
00062 { 00063 return 0 != &daqTraits(); 00064 }
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.
00066 { 00067 return *m_traits; 00068 }
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.
Definition at line 107 of file DaqBuffer.cc.
00107 { 00108 const unsigned int result = bufferSize() * kBytesInInt; 00109 outputBuffers.push_back(OutputBuffer(m_buffer, 00110 result)); 00111 return result; 00112 }
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.
00114 { 00115 const unsigned int component = formatComponent(); 00116 unsigned int cursor = 0; 00117 const unsigned int size = bufferSize(); 00118 if (kUndefinedFormatComponent == component) { 00119 if (0 != size) { 00120 inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + cursor), 00121 0)); 00122 } 00123 } else { 00124 cursor = fillInspectors(inspectors, 00125 component, 00126 cursor); 00127 } 00128 while ((size - cursor) > 1) { 00129 ++cursor; 00130 inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + cursor), 00131 0)); 00132 } 00133 return cursor + 1; 00134 }
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.
00070 { 00071 return m_buffer; 00072 }
bool DaqBuffer::hasByteBuffer | ( | ) | const [protected] |
Returns true if this object has a ByteBuffer associated with it.
Definition at line 74 of file DaqBuffer.cc.
00074 { 00075 return 0 != m_byteBuffer; 00076 }
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.
00078 { 00079 return *m_byteBuffer; 00080 }
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.
00138 { 00139 const DybDaq::DaqTraits::Definitions& definitions = daqTraits().bitsDefinitions(component); 00140 ByteInspector::Bits* bitsInByte = 0; 00141 const DybDaq::DaqTraits::Definitions::const_iterator finished = definitions.end(); 00142 for (DybDaq::DaqTraits::Definitions::const_iterator definition = definitions.begin(); 00143 finished != definition; 00144 ++definition) { 00145 const DybDaq::BitsDefinition& bits = *definition; 00146 if (0 == bitsInByte || (bits.offset() != cursor)) { 00147 if (0 == bitsInByte && (cursor != bits.offset())) { 00148 inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + cursor), 00149 0)); 00150 } 00151 while (((bits.offset() - cursor) > 1)) { 00152 ++cursor; 00153 inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + cursor), 00154 0)); 00155 } 00156 bitsInByte = new ByteInspector::Bits(); 00157 cursor = bits.offset(); 00158 inspectors.push_back(new ByteInspector(*(((unsigned int*)m_buffer) + bits.offset()), 00159 bitsInByte)); 00160 } 00161 DybDaq::BitsInspector* bitInfo = new BitsInspector(readUnsignedInt(bits.field()), 00162 bits); 00163 bitsInByte->push_back(bitInfo); 00164 } 00165 return cursor; 00166 }
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.
00082 { 00083 unsigned int fourBytes = readUnsignedInt(field); 00084 return 0 != fourBytes; 00085 }
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.
00087 { 00088 unsigned int fourBytes = readUnsignedInt(field); 00089 return *(int*)(&fourBytes); 00090 }
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.
00092 { 00093 unsigned int fourBytes = readUnsignedInt(field); 00094 return *(unsigned char*)(&fourBytes); 00095 }
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.
00097 { 00098 const DaqTraits& traits = daqTraits(); 00099 unsigned int index = traits.index(field); 00100 if (index == traits.illegalField()) { 00101 return 0; 00102 } 00103 const unsigned int fourBytes = *(((unsigned int*)m_buffer) + index); 00104 return (fourBytes >> traits.shift(field)) & traits.mask(field); 00105 }
char * DaqBuffer::buffer | ( | ) | [protected] |
Returns the buffer containing the raw file data.
Definition at line 168 of file DaqBuffer.cc.
00168 { 00169 return const_cast<char*>(m_buffer); 00170 }
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.
00173 { 00174 const DaqTraits& traits = daqTraits(); 00175 unsigned int index = traits.index(field); 00176 if (index == traits.illegalField()) { 00177 return; 00178 } 00179 const unsigned int mask = traits.mask(field); 00180 const unsigned int cleared = (*(((unsigned int*)m_buffer) + index)) & (~mask); 00181 if (value) { 00182 *(((unsigned int*)m_buffer) + index) = cleared | mask; 00183 } 00184 }
void DaqBuffer::writeField | ( | const int | value, | |
const unsigned int | field | |||
) | [protected, virtual] |
Write the supplied value into the specified field.
Definition at line 186 of file DaqBuffer.cc.
00187 { 00188 const DaqTraits& traits = daqTraits(); 00189 unsigned int index = traits.index(field); 00190 if (index == traits.illegalField()) { 00191 return; 00192 } 00193 const unsigned int shift = traits.shift(field); 00194 const unsigned int mask = traits.mask(field) << shift; 00195 unsigned int* location = (((unsigned int*)m_buffer) + index); 00196 const unsigned int cleared = (*location) & (~mask); 00197 *location = cleared | ((value << shift) & mask); 00198 }
void DaqBuffer::writeField | ( | const unsigned int | value, | |
const unsigned int | field | |||
) | [protected, virtual] |
Write the supplied value into the specified field.
Definition at line 200 of file DaqBuffer.cc.
00201 { 00202 const DaqTraits& traits = daqTraits(); 00203 unsigned int index = traits.index(field); 00204 if (index == traits.illegalField()) { 00205 return; 00206 } 00207 const unsigned int shift = traits.shift(field); 00208 const unsigned int mask = traits.mask(field) << shift; 00209 unsigned int* location = (((unsigned int*)m_buffer) + index); 00210 const unsigned int cleared = (*location) & (~mask); 00211 *location = cleared | ((value << shift) & mask); 00212 }
unsigned int DaqBuffer::formatComponent | ( | ) | const [protected, virtual] |
Returns the component with the format of this buffer.
Definition at line 214 of file DaqBuffer.cc.
00214 { 00215 return kUndefinedFormatComponent; 00216 }
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.
const ByteBuffer* DybDaq::DaqBuffer::m_byteBuffer [private] |
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] |
const DaqTraits* DybDaq::DaqBuffer::m_traits [private] |
The DaqTraits instance used to parse this object's buffer.
Definition at line 183 of file DaqBuffer.h.