BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtIdxHandler Class Reference

#include <EvtIdxHandler.h>

Public Member Functions

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

Static Public Member Functions

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

Detailed Description

Definition at line 9 of file EvtIdxHandler.h.

Constructor & Destructor Documentation

◆ EvtIdxHandler()

EvtIdxHandler::EvtIdxHandler ( )

Definition at line 46 of file EvtIdxHandler.cxx.

47 : m_totEvt(0),
48 m_idxPos(-1),
49 m_blockSize(DefaultIdxBlockSize)
50{
51 m_EIdBlock = new uint32_t[m_blockSize];
52 m_PosBlock = new uint32_t[m_blockSize];
53}
#define DefaultIdxBlockSize

Referenced by instance().

◆ ~EvtIdxHandler()

EvtIdxHandler::~EvtIdxHandler ( )
virtual

Definition at line 55 of file EvtIdxHandler.cxx.

56{
57 delete[] m_EIdBlock;
58 delete[] m_PosBlock;
59}

Member Function Documentation

◆ addPos()

void EvtIdxHandler::addPos ( uint32_t  evtId,
uint32_t  pos 
)

Definition at line 86 of file EvtIdxHandler.cxx.

87{
88 ++m_totEvt;
89
90 if ( m_totEvt > m_blockSize ) enlarge_block( m_totEvt );
91
92 m_EIdBlock[m_totEvt-1] = evtId;
93 m_PosBlock[m_totEvt-1] = pos;
94}

Referenced by GenRdmTrgIdxAlg::execute(), and main().

◆ findPosById()

uint32_t EvtIdxHandler::findPosById ( uint32_t  evtId)

Definition at line 75 of file EvtIdxHandler.cxx.

76{
77 while ( m_totEvt > m_idxPos ) {
78 if ( m_EIdBlock[m_idxPos] == evtId ) {
79 return m_PosBlock[m_idxPos++];
80 }
81 ++m_idxPos;
82 }
83 return 0;
84}

Referenced by RawFileReader::findEventById().

◆ IdxFileStartMarker()

static uint32_t EvtIdxHandler::IdxFileStartMarker ( )
inlinestatic

Definition at line 13 of file EvtIdxHandler.h.

13{ return 0xFFFFAAAA; }

Referenced by RawFileReader::getEventNumber(), and write().

◆ IdxIdBlockMarker()

static uint32_t EvtIdxHandler::IdxIdBlockMarker ( )
inlinestatic

Definition at line 14 of file EvtIdxHandler.h.

14{ return 0xFFFFBBBB; }

Referenced by write().

◆ IdxPosBlockMarker()

static uint32_t EvtIdxHandler::IdxPosBlockMarker ( )
inlinestatic

Definition at line 15 of file EvtIdxHandler.h.

15{ return 0xFFFFCCCC; }

Referenced by write().

◆ instance()

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

Definition at line 15 of file EvtIdxHandler.cxx.

16{
17 if ( _instance == 0 ) {
18 _instance = new EvtIdxHandler(idxfnames);
19 }
20
21 ++_nHandler;
22
23 return _instance;
24}

Referenced by RawFileReader::RawFileReader().

◆ nEvtLeft()

int EvtIdxHandler::nEvtLeft ( int  nIgnore) const
inline

Definition at line 29 of file EvtIdxHandler.h.

29 {
30 return ( m_totEvt - (m_idxPos+nIgnore) );
31 }

Referenced by RawFileReader::nextEvent().

◆ next_file()

void EvtIdxHandler::next_file ( )

Definition at line 61 of file EvtIdxHandler.cxx.

62{
63 ++m_curFile;
64
65 m_idxPos = 0;
66 init_idx();
67}

◆ nextPos()

uint32_t EvtIdxHandler::nextPos ( int  nIgnore)

Definition at line 69 of file EvtIdxHandler.cxx.

70{
71 m_idxPos += nIgnore;
72 return m_PosBlock[m_idxPos++];
73}

Referenced by RawFileReader::nextEvent().

◆ release()

void EvtIdxHandler::release ( )
static

Definition at line 26 of file EvtIdxHandler.cxx.

27{
28 if ( _nHandler > 0 && --_nHandler == 0 ) {
29 delete _instance;
30 _instance = 0;
31 }
32}

Referenced by RawFileReader::~RawFileReader().

◆ write()

void EvtIdxHandler::write ( std::string  fname)

Definition at line 96 of file EvtIdxHandler.cxx.

97{
98 if ( m_idxPos >= 0 ) {
99 std::cerr << "[RawFile] Writing an EvtIdxHandler for reading !!!" << std::endl;
100 exit(1);
101 }
102
103 m_fs.open( fname.c_str(), std::ios::out | std::ios::binary );
104
105 uint32_t marker = EvtIdxHandler::IdxFileStartMarker();
106 m_fs.write( (char*)&marker, sizeof(marker) );
107 m_fs.write( (char*)&m_totEvt, sizeof(m_totEvt) );
108
110 m_fs.write( (char*)&marker, sizeof(marker) );
111 m_fs.write( (char*)m_EIdBlock, m_totEvt*sizeof(uint32_t) );
112
114 m_fs.write( (char*)&marker, sizeof(marker) );
115 m_fs.write( (char*)m_PosBlock, m_totEvt*sizeof(uint32_t) );
116
117 if ( ! m_fs.good() ) {
118 std::cerr << "[RawFile] Error writing IDX file: " << fname << std::endl;
119 exit(1);
120 }
121
122 m_fs.close();
123
124 std::cout << "[RawFile] Written IDX file: " << fname << std::endl;
125
126 m_totEvt = 0;
127}
static uint32_t IdxPosBlockMarker()
Definition: EvtIdxHandler.h:15
static uint32_t IdxFileStartMarker()
Definition: EvtIdxHandler.h:13
static uint32_t IdxIdBlockMarker()
Definition: EvtIdxHandler.h:14

Referenced by GenRdmTrgIdxAlg::execute(), GenRdmTrgIdxAlg::finalize(), and main().


The documentation for this class was generated from the following files: