| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybDaq::MetadataStrings Class Reference

#include <MetadataStrings.h>

Inheritance diagram for DybDaq::MetadataStrings:

[legend]
Collaboration diagram for DybDaq::MetadataStrings:
[legend]
List of all members.

Public Types

typedef std::pair< std::string,
std::string > 
MetadataString
typedef std::vector< const
MetadataString * > 
MetadataStringPtrList
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

 MetadataStrings (const MetadataStringPtrList &metadataStrings, const FileTraits &traits)
 Create an instance of this class.
 MetadataStrings (const DybDaq::ByteBuffer &byteBuffer, const FileTraits &traits)
 Create an instance of this class.
virtual ~MetadataStrings ()
 Destroy this instance of the class.
virtual bool isMarked (unsigned int marker) const
 Returns true if this object contains the specified marker.
const MetadataStringPtrListmetadataStrings () const
 Returns the list of pointers to metadata strings.
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.
const FileTraitsfileTraits () const
 Returns the FileTraits instance used to parse this object's buffer.
unsigned int marker () const
 Returns the marker for this FileBuffer.
unsigned int size () const
 Returns the length of this record in 4-byte words.
virtual unsigned int bufferSize () const
 Returns the size, in 4-bytes,, of this object's contents in the buffer.
bool hasDaqTraits () const
virtual const DaqTraitsdaqTraits () const
virtual unsigned int gather (OutputBufferList &outputBuffers) const
virtual unsigned int inspect (DaqBuffer::Bytes &inspectors) const

Static Public Attributes

static const unsigned int kBytesInInt
static const unsigned int kUndefinedFormatComponent

Protected Member Functions

virtual unsigned int formatComponent () const
 Returns the component with the format of this buffer.
void setMarker (const unsigned int marker)
 Sets the marker for this FileBuffer.
void setSize (const unsigned int size)
 Sets the size, in 4-bytes,, of this object's contents in the buffer.
const char * buffer () const
char * buffer ()
bool hasByteBuffer () const
const ByteBufferbyteBuffer () const
unsigned int fillInspectors (DaqBuffer::Bytes &inspectors, unsigned int component, unsigned int cursor) const
virtual bool readBool (const unsigned int field) const
virtual int readInt (const unsigned int field) const
virtual unsigned char readUnsignedChar (const unsigned int field) const
virtual unsigned int readUnsignedInt (const unsigned int field) const
virtual void writeField (const bool value, const unsigned int field)
virtual void writeField (const int value, const unsigned int field)
virtual void writeField (const unsigned int value, const unsigned int field)

Private Member Functions

 MetadataStrings ()
 Suppress default.
 MetadataStrings (MetadataStrings &rhs)
 Suppress default.
MetadataStringsoperator= (MetadataStrings &rhs)
 Suppress default.
void setMetadataStrings (const MetadataStringPtrList &metadataStrings)
 Sets the list of pointers to metadata strings.

Static Private Member Functions

static std::string readString (const char *buffer)
 Reads string from binary representation.
static unsigned int calculateStringsLength (const MetadataStringPtrList &metadataStrings)
 Calculates, in bytes, the length os the totoal binary representation.
static unsigned int writeString (const std::string &value, char *buffer)
 Reads string into binary representation.

Private Attributes

MetadataStringPtrListm_strings
 The tag/value pairs of the metadata strings.
char * m_stringBuffer
 The buffer used to hold binary bytes of the metadata strings.

Detailed Description

Definition at line 19 of file MetadataStrings.h.


Member Typedef Documentation

typedef std::pair<std::string, std::string> DybDaq::MetadataStrings::MetadataString

Definition at line 23 of file MetadataStrings.h.

typedef std::vector<const MetadataString* > DybDaq::MetadataStrings::MetadataStringPtrList

Definition at line 24 of file MetadataStrings.h.


Constructor & Destructor Documentation

MetadataStrings::MetadataStrings ( const MetadataStringPtrList metadataStrings,
const FileTraits traits 
)

Create an instance of this class.

Definition at line 21 of file MetadataStrings.cc.

00022                                                                                            :
00023 FileBuffer(new char[traits.recordSize(FileTraits::kMetadataStrings) * kBytesInInt],
00024            traits,
00025            FileTraits::kMetadataStrings),
00026 m_strings(0),
00027 m_stringBuffer(0) {
00028     setMetadataStrings(metadataStrings);
00029 }

MetadataStrings::MetadataStrings ( const DybDaq::ByteBuffer byteBuffer,
const FileTraits traits 
)

Create an instance of this class.

Definition at line 31 of file MetadataStrings.cc.

00032                                                                                            :
00033 FileBuffer(byteBuffer,
00034                    traits),
00035 m_strings(0),
00036 m_stringBuffer(0) {
00037 }

MetadataStrings::~MetadataStrings (  )  [virtual]

Destroy this instance of the class.

Definition at line 39 of file MetadataStrings.cc.

00039                                   {
00040     if (0 != m_stringBuffer) {
00041         delete m_stringBuffer;
00042     }
00043         if (0 != m_strings) {
00044                 MetadataStringPtrList::const_iterator entry;
00045                 for (entry = m_strings->begin();
00046                          entry != m_strings->end();
00047                          ++entry) {
00048                         delete const_cast<MetadataString*>(*entry);
00049                 }
00050                 delete m_strings;
00051         }
00052 }

DybDaq::MetadataStrings::MetadataStrings (  )  [private]

Suppress default.

DybDaq::MetadataStrings::MetadataStrings ( MetadataStrings rhs  )  [private]

Suppress default.


Member Function Documentation

bool MetadataStrings::isMarked ( unsigned int  marker  )  const [virtual]

Returns true if this object contains the specified marker.

Implements DybDaq::FileBuffer.

Definition at line 54 of file MetadataStrings.cc.

00054                                                         {
00055     return FileTraits::kMetadataStrings == marker;
00056 }

const MetadataStrings::MetadataStringPtrList & MetadataStrings::metadataStrings (  )  const

Returns the list of pointers to metadata strings.

Definition at line 58 of file MetadataStrings.cc.

00058                                                                                    {
00059     if (0 == m_strings) {
00060         m_strings = new MetadataStringPtrList();
00061         const unsigned int finished = readUnsignedInt(FileTraits::kMetadataCount);
00062         const char* start;
00063         if (hasByteBuffer()) {
00064             start = buffer() + (fileTraits().firstMetadataLengthOffset() * kBytesInInt);
00065         } else {
00066             start = m_stringBuffer;
00067         }
00068         for (unsigned int metadata = 0;
00069              metadata != finished ;
00070              ++metadata) {
00071             string entry = readString(start);
00072             const unsigned int length = entry.size();
00073             const unsigned int paddedLength = length + (kBytesInInt - 1) - ((length - 1) % kBytesInInt );
00074             start += paddedLength + kBytesInInt;
00075             size_t found = entry.find('=');
00076             if (found != string::npos) {
00077                 string first = entry.substr(0,
00078                                             found);
00079                 string second = entry.substr(found + 1, length - (found + 1));
00080                 m_strings->push_back(new MetadataString(first,
00081                                                         second));
00082             }
00083         }
00084     }
00085         return *m_strings;
00086 }

unsigned int MetadataStrings::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 88 of file MetadataStrings.cc.

00088                                                                           {
00089     if (hasByteBuffer()) {
00090         return FileBuffer::gather(outputBuffers);
00091     }
00092     const unsigned int fixedLength = fileTraits().recordSize(FileTraits::kMetadataStrings) * kBytesInInt;
00093     outputBuffers.push_back(OutputBuffer(buffer(),
00094                                          fixedLength));
00095     unsigned int stringsLength = (size() * kBytesInInt) - fixedLength;
00096     outputBuffers.push_back(OutputBuffer(m_stringBuffer,
00097                                          stringsLength));
00098     return fixedLength + stringsLength;
00099 }

unsigned int MetadataStrings::formatComponent (  )  const [protected, virtual]

Returns the component with the format of this buffer.

Reimplemented from DybDaq::DaqBuffer.

Definition at line 101 of file MetadataStrings.cc.

00101                                                     {
00102     return FileTraits::kMetadataStrings;
00103 }

MetadataStrings& DybDaq::MetadataStrings::operator= ( MetadataStrings rhs  )  [private]

Suppress default.

void MetadataStrings::setMetadataStrings ( const MetadataStringPtrList metadataStrings  )  [private]

Sets the list of pointers to metadata strings.

Definition at line 105 of file MetadataStrings.cc.

00105                                                                                      {
00106     if (0 != m_stringBuffer) {
00107         delete m_stringBuffer;
00108     }
00109     unsigned int stringsLength = calculateStringsLength(metadataStrings);
00110     setSize(fileTraits().recordSize(FileTraits::kMetadataStrings) + (stringsLength / kBytesInInt));
00111     m_stringBuffer = new char[stringsLength];
00112     char* start = m_stringBuffer;
00113     MetadataStrings::MetadataStringPtrList::const_iterator metadata;
00114     for (metadata = metadataStrings.begin();
00115          metadata != metadataStrings.end();
00116          ++metadata) {
00117         const string entry = (*metadata)->first + "=" + (*metadata)->second;
00118         start += writeString(entry,
00119                              start);
00120     }
00121     writeField((unsigned int)(metadataStrings.size()),
00122                FileTraits::kMetadataCount);
00123     if (0 != m_strings) {
00124         delete m_strings;
00125         m_strings = 0;
00126     }
00127 }

string MetadataStrings::readString ( const char *  buffer  )  [static, private]

Reads string from binary representation.

Definition at line 129 of file MetadataStrings.cc.

00129                                                      {
00130     unsigned int length = *((unsigned int*)(buffer));
00131     char* base = new char[length + 1];
00132     memcpy(base,
00133            buffer + kBytesInInt,
00134            length);
00135     base[length] = 0;
00136     string result(base);
00137     delete base;
00138     return result;
00139 }

unsigned int MetadataStrings::calculateStringsLength ( const MetadataStringPtrList metadataStrings  )  [static, private]

Calculates, in bytes, the length os the totoal binary representation.

Definition at line 141 of file MetadataStrings.cc.

00141                                                                                                  {
00142     unsigned int result = 0;
00143     MetadataStrings::MetadataStringPtrList::const_iterator metadata;
00144     for (metadata = metadataStrings.begin();
00145          metadata != metadataStrings.end();
00146          ++metadata) {
00147         const string entry = (*metadata)->first + "=" + (*metadata)->second;
00148         const unsigned int length = entry.size();
00149         const unsigned int paddedLength = length + (kBytesInInt - 1) - ((length - 1) % kBytesInInt );
00150         result += paddedLength + kBytesInInt;        
00151     }
00152     return result;
00153 }

static unsigned int DybDaq::MetadataStrings::writeString ( const std::string &  value,
char *  buffer 
) [static, private]

Reads string into binary representation.

const FileTraits & FileBuffer::fileTraits (  )  const [inherited]

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

Definition at line 40 of file FileBuffer.cc.

00040                                                {
00041     return dynamic_cast<const FileTraits&>(daqTraits());
00042 }

unsigned int FileBuffer::marker (  )  const [inherited]

Returns the marker for this FileBuffer.

Definition at line 44 of file FileBuffer.cc.

00044                                       {
00045     return readUnsignedInt(FileTraits::kMarker);
00046 }

unsigned int FileBuffer::size (  )  const [inherited]

Returns the length of this record in 4-byte words.

Definition at line 48 of file FileBuffer.cc.

00048                                     {
00049     return readUnsignedInt(FileTraits::kRecordSize);
00050 }

unsigned int FileBuffer::bufferSize (  )  const [virtual, inherited]

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

Implements DybDaq::DaqBuffer.

Definition at line 52 of file FileBuffer.cc.

00052                                           {
00053     return size();
00054 }

void FileBuffer::setMarker ( const unsigned int  marker  )  [protected, inherited]

Sets the marker for this FileBuffer.

Definition at line 56 of file FileBuffer.cc.

00056                                                     {
00057     writeField(marker,
00058                FileTraits::kMarker);
00059 }

void FileBuffer::setSize ( const unsigned int  size  )  [protected, inherited]

Sets the size, in 4-bytes,, of this object's contents in the buffer.

Definition at line 61 of file FileBuffer.cc.

00061                                                 {
00062     writeField(size,
00063                FileTraits::kRecordSize);
00064 }


Member Data Documentation

MetadataStringPtrList* DybDaq::MetadataStrings::m_strings [mutable, private]

The tag/value pairs of the metadata strings.

Definition at line 107 of file MetadataStrings.h.

char* DybDaq::MetadataStrings::m_stringBuffer [private]

The buffer used to hold binary bytes of the metadata strings.

Definition at line 112 of file MetadataStrings.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 Mon Apr 11 20:08:36 2011 for FileReadoutFormat by doxygen 1.4.7