/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 Attributes | Private Attributes
DybDaq::RecordFromFStream Class Reference

#include <RecordFromFStream.h>

List of all members.

Public Member Functions

 RecordFromFStream ()
virtual ~RecordFromFStream ()
bool open (const std::string &fname)
RecordBuffernext ()

Protected Attributes

std::ifstream m_fs

Private Attributes

char * m_block
uint32_t m_limit
const int m_preRead

Detailed Description

Definition at line 12 of file RecordFromFStream.h.


Constructor & Destructor Documentation

RecordFromFStream::RecordFromFStream ( )

Definition at line 11 of file RecordFromFStream.cc.

    : m_block(0),
      m_limit(64*1024),
      m_preRead(16)  //4*sizeof(uint32_t) = 16 bytes
{
    m_block = new char[m_limit];
#ifdef RPC_ERROR_DEBUG
    m_debug = RPC_ERROR_DEBUG;
#endif
}
RecordFromFStream::~RecordFromFStream ( ) [virtual]

Definition at line 22 of file RecordFromFStream.cc.

{
    if ( m_block !=  0 ) delete [] m_block;
    if ( m_fs.is_open() ) m_fs.close();
}

Member Function Documentation

bool RecordFromFStream::open ( const std::string &  fname)

Definition at line 28 of file RecordFromFStream.cc.

{
    if ( m_fs.is_open() ) m_fs.close();

    if ( access( fname.c_str(), F_OK ) < 0 ) {
        std::cerr << "Invalid file: " << fname << std::endl;
        return false;
    }
    m_fs.clear();
    m_fs.open(fname.c_str(), std::ios::binary);

    uint32_t header = 0;
    m_fs.read((char*)&header, sizeof(uint32_t));
    m_fs.seekg(0, std::ios::beg);
    if ( header != DybDaq::RawRecordPoolUtil::FileStartMarker ) {
        std::cerr << fname << " is not a DAQ format file!" << std::endl;
        return false;
    }

    return m_fs.good();
}
RecordBuffer * RecordFromFStream::next ( )

Definition at line 50 of file RecordFromFStream.cc.

{
    RecordBuffer* result = 0;

    while ( result == 0 ) {
        m_fs.read(m_block, m_preRead);
        if ( !m_fs.good() ) break;

        uint32_t marker     = ((uint32_t*)m_block)[0];
        uint32_t recordSize = ((uint32_t*)m_block)[1] * sizeof(uint32_t);
        bool     isEvent    = marker == DybDaq::RawRecordPoolUtil::DataSeparatorMarker;
        if ( isEvent ) {
            recordSize += ((int*)m_block)[3];
        }

        if ( recordSize > m_limit ) {
            do {
                m_limit *= 2;
            } while ( recordSize > m_limit );
            char* pnew = new char[m_limit];
            memcpy(pnew, m_block, m_preRead);
            delete [] m_block;
            m_block = pnew;
        }

        m_fs.read( (m_block+m_preRead), (recordSize-m_preRead) );
        if ( m_fs.eof() ) break;

        if ( isEvent && (((uint32_t*)m_block)[11]&1) != 0 ) {
#ifdef RPC_ERROR_DEBUG
            if ( m_debug-- > 0 ) {
                std::cout << "Skipping an invalid event..." << std::endl;
            }
#endif
            continue;
        }

        char* data = new char[recordSize];
        memcpy(data, m_block, recordSize);

        result = new RecordBuffer(data, recordSize);
    }

    return result;
}

Member Data Documentation

std::ifstream DybDaq::RecordFromFStream::m_fs [protected]

Definition at line 24 of file RecordFromFStream.h.

Definition at line 28 of file RecordFromFStream.h.

Definition at line 29 of file RecordFromFStream.h.

Definition at line 30 of file RecordFromFStream.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:46 for RawRecordPool by doxygen 1.7.4