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

In This Package:

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DybDaq::DaqFromFStream Class Reference

#include <DaqFromFStream.h>

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

List of all members.

Public Member Functions

 DaqFromFStream ()
 Creates an instance of this class.
virtual ~DaqFromFStream ()
 Destroys this instance.
const bool openFile (const char *const fileName)
 Opens the specified file for reading.
bool close ()
 Closes the current Stream being read.
const FileBuffernextRecord ()
 Returns the next record in the file of NULL is the end of the file has been reached.

Protected Member Functions

virtual void closeStream (std::istream &stream)
 Used to close the istream that is backing this class.
virtual std::istream * openStream ()
 Used to open a new stream that is used as the backing of this class.
bool hasIStream () const
 Returns true when this object has a valid ostream.
bool open ()
 Opens this object for reading.

Private Member Functions

 DaqFromFStream (DaqFromFStream &rhs)
 Suppress default.
DaqFromFStreamoperator= (DaqFromFStream &rhs)
 Suppress default.

Private Attributes

std::string * m_fileName
 The name of the file to open.
std::ifstream * m_ifstream
 The file being read.

Detailed Description

Definition at line 18 of file DaqFromFStream.h.


Constructor & Destructor Documentation

DaqFromFStream::DaqFromFStream ( )

Creates an instance of this class.

Definition at line 20 of file DaqFromFStream.cc.

                               :
  m_fileName(0),
  m_ifstream(0) {
}
DaqFromFStream::~DaqFromFStream ( ) [virtual]

Destroys this instance.

Definition at line 25 of file DaqFromFStream.cc.

                                {
    if (0 != m_fileName) {
        delete m_fileName;
    }
    if (hasIStream()) {
        if (m_ifstream->is_open()) {
            m_ifstream->close();
        }
    }
}
DybDaq::DaqFromFStream::DaqFromFStream ( DaqFromFStream rhs) [private]

Suppress default.


Member Function Documentation

const bool DaqFromFStream::openFile ( const char *const  fileName)

Opens the specified file for reading.

Definition at line 48 of file DaqFromFStream.cc.

                                                              {
    if (0 != m_fileName) {
        delete m_fileName;
    }
    m_fileName = new string(fileName);
    return open();
}
void DaqFromFStream::closeStream ( std::istream &  stream) [protected, virtual]

Used to close the istream that is backing this class.

Implements DybDaq::DaqFromIStream.

Definition at line 42 of file DaqFromFStream.cc.

                                                   {
    ifstream& fileStream = dynamic_cast<ifstream&> (stream);
    fileStream.close();
    m_ifstream = 0;
}
std::istream * DaqFromFStream::openStream ( ) [protected, virtual]

Used to open a new stream that is used as the backing of this class.

Implements DybDaq::DaqFromIStream.

Definition at line 36 of file DaqFromFStream.cc.

                                       {
    m_ifstream = new ifstream(m_fileName->c_str(),
                              istream::in | istream::binary);
    return m_ifstream;
}
DaqFromFStream& DybDaq::DaqFromFStream::operator= ( DaqFromFStream rhs) [private]

Suppress default.

bool DaqFromIStream::close ( ) [inherited]

Closes the current Stream being read.

Definition at line 40 of file DaqFromIStream.cc.

                           {
    if (0 != m_istream) {
        closeStream(*m_istream);
        delete m_istream;
        m_istream = 0;
    }
    return true;
}
const FileBuffer * DaqFromIStream::nextRecord ( ) [virtual, inherited]

Returns the next record in the file of NULL is the end of the file has been reached.

Implements DybDaq::DaqFromStream.

Definition at line 58 of file DaqFromIStream.cc.

                                             {
        ByteBuffer* buffer = new ByteBuffer(new char[DEFAULT_BUFFER_SIZE],
                                        DEFAULT_BUFFER_SIZE);
        m_istream->read(buffer->cursor(),
                   2 * ByteBuffer::BYTES_IN_INT);
        if (m_istream->eof()) {
                return 0;
        }
        
        unsigned int size = buffer->readUnsignedInt(4);
        unsigned int lengthInBytes = size * ByteBuffer::BYTES_IN_INT;
        const FileBuffer* result = 0;
    unsigned int begin = 0;
        while (0 == result && buffer->capacity() != lengthInBytes) {
                if (lengthInBytes > buffer->capacity()) {
                        ByteBuffer* previousBuffer = buffer;
                        buffer = new ByteBuffer(new char[lengthInBytes],
                                                                        lengthInBytes);
                        unsigned int bytesRead = previousBuffer->limit();
            previousBuffer->position(begin);
                        memcpy(buffer->cursor(),
                                   previousBuffer->cursor(),
                                   bytesRead);
                        buffer->limit(bytesRead);
            previousBuffer->release();
                }
                unsigned int bytesRead = buffer->limit();
                m_istream->read(buffer->cursor() + bytesRead,
                       buffer->capacity() - bytesRead);
                buffer->limit(buffer->capacity());
        begin = buffer->position();
                result = m_daqFromBytes->createFileBuffer(buffer);
                if (0 == result) {
                        lengthInBytes = m_daqFromBytes->additionalCapacity() + buffer->capacity();
                }
        }
        return result;
}
bool DaqFromIStream::hasIStream ( ) const [protected, inherited]

Returns true when this object has a valid ostream.

Definition at line 49 of file DaqFromIStream.cc.

                                      {
    return 0 != m_istream;
}
bool DaqFromIStream::open ( ) [protected, inherited]

Opens this object for reading.

Definition at line 53 of file DaqFromIStream.cc.

                          {
    m_istream = openStream();
    return hasIStream();
}

Member Data Documentation

std::string* DybDaq::DaqFromFStream::m_fileName [private]

The name of the file to open.

Definition at line 64 of file DaqFromFStream.h.

std::ifstream* DybDaq::DaqFromFStream::m_ifstream [private]

The file being read.

Definition at line 69 of file DaqFromFStream.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:53:22 for FileReadoutFormat by doxygen 1.7.4