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

In This Package:

RecordFromFStream.cc
Go to the documentation of this file.
00001 #include "RawRecordPool/RecordFromFStream.h"
00002 #include "RawRecordPool/RecordBuffer.h"
00003 #include "RawRecordPool/RawRecordPoolUtil.h"
00004 #include <cstdlib>
00005 #include <iostream>
00006 #include <cstring>
00007 
00008 using DybDaq::RecordFromFStream;
00009 using DybDaq::RecordBuffer;
00010 
00011 RecordFromFStream::RecordFromFStream()
00012     : m_block(0),
00013       m_limit(64*1024),
00014       m_preRead(16)  //4*sizeof(uint32_t) = 16 bytes
00015 {
00016     m_block = new char[m_limit];
00017 #ifdef RPC_ERROR_DEBUG
00018     m_debug = RPC_ERROR_DEBUG;
00019 #endif
00020 }
00021 
00022 RecordFromFStream::~RecordFromFStream()
00023 {
00024     if ( m_block !=  0 ) delete [] m_block;
00025     if ( m_fs.is_open() ) m_fs.close();
00026 }
00027 
00028 bool RecordFromFStream::open(const std::string& fname)
00029 {
00030     if ( m_fs.is_open() ) m_fs.close();
00031 
00032     if ( access( fname.c_str(), F_OK ) < 0 ) {
00033         std::cerr << "Invalid file: " << fname << std::endl;
00034         return false;
00035     }
00036     m_fs.clear();
00037     m_fs.open(fname.c_str(), std::ios::binary);
00038 
00039     uint32_t header = 0;
00040     m_fs.read((char*)&header, sizeof(uint32_t));
00041     m_fs.seekg(0, std::ios::beg);
00042     if ( header != DybDaq::RawRecordPoolUtil::FileStartMarker ) {
00043         std::cerr << fname << " is not a DAQ format file!" << std::endl;
00044         return false;
00045     }
00046 
00047     return m_fs.good();
00048 }
00049 
00050 RecordBuffer* RecordFromFStream::next()
00051 {
00052     RecordBuffer* result = 0;
00053 
00054     while ( result == 0 ) {
00055         m_fs.read(m_block, m_preRead);
00056         if ( !m_fs.good() ) break;
00057 
00058         uint32_t marker     = ((uint32_t*)m_block)[0];
00059         uint32_t recordSize = ((uint32_t*)m_block)[1] * sizeof(uint32_t);
00060         bool     isEvent    = marker == DybDaq::RawRecordPoolUtil::DataSeparatorMarker;
00061         if ( isEvent ) {
00062             recordSize += ((int*)m_block)[3];
00063         }
00064 
00065         if ( recordSize > m_limit ) {
00066             do {
00067                 m_limit *= 2;
00068             } while ( recordSize > m_limit );
00069             char* pnew = new char[m_limit];
00070             memcpy(pnew, m_block, m_preRead);
00071             delete [] m_block;
00072             m_block = pnew;
00073         }
00074 
00075         m_fs.read( (m_block+m_preRead), (recordSize-m_preRead) );
00076         if ( m_fs.eof() ) break;
00077 
00078         if ( isEvent && (((uint32_t*)m_block)[11]&1) != 0 ) {
00079 #ifdef RPC_ERROR_DEBUG
00080             if ( m_debug-- > 0 ) {
00081                 std::cout << "Skipping an invalid event..." << std::endl;
00082             }
00083 #endif
00084             continue;
00085         }
00086 
00087         char* data = new char[recordSize];
00088         memcpy(data, m_block, recordSize);
00089 
00090         result = new RecordBuffer(data, recordSize);
00091     }
00092 
00093     return result;
00094 }
| 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