Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

EvtIdxHandler Class Reference

#include <EvtIdxHandler.h>

List of all members.

Public Member Functions

void addPos (uint32_t evtId, uint32_t pos)
void addPos (uint32_t evtId, uint32_t pos)
 EvtIdxHandler ()
 EvtIdxHandler ()
uint32_t findPosById (uint32_t evtId)
uint32_t findPosById (uint32_t evtId)
int nEvtLeft (int nIgnore) const
int nEvtLeft (int nIgnore) const
void next_file ()
void next_file ()
uint32_t nextPos (int nIgnore)
uint32_t nextPos (int nIgnore)
void write (std::string fname)
void write (std::string fname)
virtual ~EvtIdxHandler ()
virtual ~EvtIdxHandler ()

Static Public Member Functions

uint32_t IdxFileStartMarker ()
uint32_t IdxFileStartMarker ()
uint32_t IdxIdBlockMarker ()
uint32_t IdxIdBlockMarker ()
uint32_t IdxPosBlockMarker ()
uint32_t IdxPosBlockMarker ()
EvtIdxHandlerinstance (const std::vector< std::string > &fnames)
EvtIdxHandlerinstance (const std::vector< std::string > &fnames)
void release ()
void release ()

Private Member Functions

void enlarge_block (int min_size)
void enlarge_block (int min_size)
 EvtIdxHandler (const std::vector< std::string > &idxfnames)
 EvtIdxHandler (const std::vector< std::string > &idxfnames)
void init_idx ()
void init_idx ()

Private Attributes

int m_blockSize
std::vector< std::string
>::iterator 
m_curFile
std::vector< std::string
>::iterator 
m_curFile
uint32_t * m_EIdBlock
uint32_t * m_EIdBlock
std::vector< std::string > m_fnames
std::vector< std::string > m_fnames
std::fstream m_fs
int m_idxPos
uint32_t * m_PosBlock
uint32_t * m_PosBlock
int m_totEvt

Static Private Attributes

EvtIdxHandler_instance
EvtIdxHandler_instance = 0
int _nHandler = 0


Constructor & Destructor Documentation

EvtIdxHandler::EvtIdxHandler  ) 
 

00042    : m_totEvt(0),
00043      m_idxPos(-1),
00044      m_blockSize(DefaultIdxBlockSize)
00045 {
00046    m_EIdBlock = new uint32_t[m_blockSize];
00047    m_PosBlock = new uint32_t[m_blockSize];
00048 }

EvtIdxHandler::~EvtIdxHandler  )  [virtual]
 

00051 {
00052    delete[] m_EIdBlock;
00053    delete[] m_PosBlock;
00054 }

EvtIdxHandler::EvtIdxHandler const std::vector< std::string > &  idxfnames  )  [private]
 

00030    : m_idxPos(0),
00031      m_blockSize(DefaultIdxBlockSize),
00032      m_fnames(idxfnames)
00033 {
00034    m_EIdBlock = new uint32_t[m_blockSize];
00035    m_PosBlock = new uint32_t[m_blockSize];
00036 
00037    m_curFile = m_fnames.begin();
00038    init_idx();
00039 }

EvtIdxHandler::EvtIdxHandler  ) 
 

virtual EvtIdxHandler::~EvtIdxHandler  )  [virtual]
 

EvtIdxHandler::EvtIdxHandler const std::vector< std::string > &  idxfnames  )  [private]
 


Member Function Documentation

void EvtIdxHandler::addPos uint32_t  evtId,
uint32_t  pos
 

void EvtIdxHandler::addPos uint32_t  evtId,
uint32_t  pos
 

00082 {
00083    ++m_totEvt;
00084 
00085    if ( m_totEvt > m_blockSize ) enlarge_block( m_totEvt );
00086 
00087    m_EIdBlock[m_totEvt-1] = evtId;
00088    m_PosBlock[m_totEvt-1] = pos;
00089 }

void EvtIdxHandler::enlarge_block int  min_size  )  [private]
 

void EvtIdxHandler::enlarge_block int  min_size  )  [private]
 

00172 {
00173    while ( min_size > m_blockSize ) {
00174       m_blockSize *= 2;
00175    }
00176 
00177    delete[] m_EIdBlock;
00178    delete[] m_PosBlock;
00179 
00180    m_EIdBlock = new uint32_t[m_blockSize];
00181    m_PosBlock = new uint32_t[m_blockSize];
00182 }

uint32_t EvtIdxHandler::findPosById uint32_t  evtId  ) 
 

uint32_t EvtIdxHandler::findPosById uint32_t  evtId  ) 
 

00071 {
00072    while ( m_totEvt > m_idxPos ) {
00073       if ( m_EIdBlock[m_idxPos] == evtId ) {
00074          return m_PosBlock[m_idxPos++];
00075       }
00076       ++m_idxPos;
00077    }
00078    return 0;
00079 }

uint32_t EvtIdxHandler::IdxFileStartMarker  )  [inline, static]
 

00012 { return 0xFFFFAAAA; }

uint32_t EvtIdxHandler::IdxFileStartMarker  )  [inline, static]
 

00012 { return 0xFFFFAAAA; }

uint32_t EvtIdxHandler::IdxIdBlockMarker  )  [inline, static]
 

00013 { return 0xFFFFBBBB; }

uint32_t EvtIdxHandler::IdxIdBlockMarker  )  [inline, static]
 

00013 { return 0xFFFFBBBB; }

uint32_t EvtIdxHandler::IdxPosBlockMarker  )  [inline, static]
 

00014 { return 0xFFFFCCCC; }

uint32_t EvtIdxHandler::IdxPosBlockMarker  )  [inline, static]
 

00014 { return 0xFFFFCCCC; }

void EvtIdxHandler::init_idx  )  [private]
 

void EvtIdxHandler::init_idx  )  [private]
 

00125 {
00126    if ( access( m_curFile->c_str(), F_OK ) < 0 ) {
00127       std::cerr << "[RawFile] Invalid IDX file: " << *m_curFile << std::endl;
00128       exit(1);
00129    }
00130 
00131    std::cout << "[RawFile] Initialize IDX with file: " << *m_curFile << std::endl;
00132 
00133    m_fs.open( m_curFile->c_str(), std::ios::in | std::ios::binary );
00134 
00135    uint32_t marker;
00136 
00137    m_fs.read( (char*)&marker, sizeof(marker) );
00138    if ( marker != EvtIdxHandler::IdxFileStartMarker() ) {
00139       std::cerr << "[RawFile] Wrong IdxFileStartMarker!" << std::endl;
00140       exit(1);
00141    }
00142 
00143    m_fs.read( (char*)&m_totEvt, sizeof(m_totEvt) );
00144 
00145    if ( m_totEvt > m_blockSize ) enlarge_block( m_totEvt );
00146 
00147    m_fs.read( (char*)&marker, sizeof(marker) );
00148    if ( marker != EvtIdxHandler::IdxIdBlockMarker() ) {
00149       std::cerr << "[RawFile] Wrong IdxIdBlockMarker!" << std::endl;
00150       exit(1);
00151    }
00152 
00153    m_fs.read( (char*)m_EIdBlock, m_totEvt*sizeof(uint32_t) );
00154 
00155    m_fs.read( (char*)&marker, sizeof(marker) );
00156    if ( marker != EvtIdxHandler::IdxPosBlockMarker() ) {
00157       std::cerr << "[RawFile] Wrong IdxPosBlockMarker!" << std::endl;
00158       exit(1);
00159    }
00160 
00161    m_fs.read( (char*)m_PosBlock, m_totEvt*sizeof(uint32_t) );
00162 
00163    if ( ! m_fs.good() ) {
00164       std::cerr << "[RawFile] Error occured while initialize the IDX file!" << std::endl;
00165       exit(1);
00166    }
00167 
00168    m_fs.close();
00169 }

EvtIdxHandler* EvtIdxHandler::instance const std::vector< std::string > &  fnames  )  [static]
 

EvtIdxHandler * EvtIdxHandler::instance const std::vector< std::string > &  fnames  )  [static]
 

00011 {
00012    if ( _instance == 0 ) {
00013       _instance = new EvtIdxHandler(idxfnames);
00014    }
00015 
00016    ++_nHandler;
00017 
00018    return _instance;
00019 }

int EvtIdxHandler::nEvtLeft int  nIgnore  )  const [inline]
 

00028                                       {
00029          return ( m_totEvt - (m_idxPos+nIgnore) );
00030       }

int EvtIdxHandler::nEvtLeft int  nIgnore  )  const [inline]
 

00028                                       {
00029          return ( m_totEvt - (m_idxPos+nIgnore) );
00030       }

void EvtIdxHandler::next_file  ) 
 

void EvtIdxHandler::next_file  ) 
 

00057 {
00058    ++m_curFile;
00059 
00060    m_idxPos = 0;
00061    init_idx();
00062 }

uint32_t EvtIdxHandler::nextPos int  nIgnore  ) 
 

uint32_t EvtIdxHandler::nextPos int  nIgnore  ) 
 

00065 {
00066    m_idxPos += nIgnore;
00067    return m_PosBlock[m_idxPos++];
00068 }

void EvtIdxHandler::release  )  [static]
 

void EvtIdxHandler::release  )  [static]
 

00022 {
00023    if ( _nHandler > 0 && --_nHandler == 0 ) {
00024       delete _instance;
00025       _instance = 0;
00026    }
00027 }

void EvtIdxHandler::write std::string  fname  ) 
 

void EvtIdxHandler::write std::string  fname  ) 
 

00092 {
00093    if ( m_idxPos >= 0 ) {
00094       std::cerr << "[RawFile] Writing an EvtIdxHandler for reading !!!" << std::endl;
00095       exit(1);
00096    }
00097 
00098    m_fs.open( fname.c_str(), std::ios::out | std::ios::binary );
00099 
00100    uint32_t marker = EvtIdxHandler::IdxFileStartMarker();
00101    m_fs.write( (char*)&marker, sizeof(marker) );
00102    m_fs.write( (char*)&m_totEvt, sizeof(m_totEvt) );
00103 
00104    marker = EvtIdxHandler::IdxIdBlockMarker();
00105    m_fs.write( (char*)&marker, sizeof(marker) );
00106    m_fs.write( (char*)m_EIdBlock, m_totEvt*sizeof(uint32_t) );
00107 
00108    marker = EvtIdxHandler::IdxPosBlockMarker();
00109    m_fs.write( (char*)&marker, sizeof(marker) );
00110    m_fs.write( (char*)m_PosBlock, m_totEvt*sizeof(uint32_t) );
00111 
00112    if ( ! m_fs.good() ) {
00113       std::cerr << "[RawFile] Error writing IDX file: " << fname << std::endl;
00114       exit(1);
00115    }
00116 
00117    m_fs.close();
00118 
00119    std::cout << "[RawFile] Written IDX file: " << fname << std::endl;
00120 
00121    m_totEvt = 0;
00122 }


Member Data Documentation

EvtIdxHandler* EvtIdxHandler::_instance [static, private]
 

EvtIdxHandler * EvtIdxHandler::_instance = 0 [static, private]
 

int EvtIdxHandler::_nHandler = 0 [static, private]
 

int EvtIdxHandler::m_blockSize [private]
 

std::vector<std::string>::iterator EvtIdxHandler::m_curFile [private]
 

std::vector<std::string>::iterator EvtIdxHandler::m_curFile [private]
 

uint32_t* EvtIdxHandler::m_EIdBlock [private]
 

uint32_t* EvtIdxHandler::m_EIdBlock [private]
 

std::vector<std::string> EvtIdxHandler::m_fnames [private]
 

std::vector<std::string> EvtIdxHandler::m_fnames [private]
 

std::fstream EvtIdxHandler::m_fs [private]
 

int EvtIdxHandler::m_idxPos [private]
 

uint32_t* EvtIdxHandler::m_PosBlock [private]
 

uint32_t* EvtIdxHandler::m_PosBlock [private]
 

int EvtIdxHandler::m_totEvt [private]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 16:06:02 2011 for BOSS6.5.5 by  doxygen 1.3.9.1