BOSS 7.0.9
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 42 of file EvtIdxHandler.cxx.

43 : m_totEvt(0),
44 m_idxPos(-1),
45 m_blockSize(DefaultIdxBlockSize)
46{
47 m_EIdBlock = new uint32_t[m_blockSize];
48 m_PosBlock = new uint32_t[m_blockSize];
49}
#define DefaultIdxBlockSize

Referenced by instance().

◆ ~EvtIdxHandler()

EvtIdxHandler::~EvtIdxHandler ( )
virtual

Definition at line 51 of file EvtIdxHandler.cxx.

52{
53 delete[] m_EIdBlock;
54 delete[] m_PosBlock;
55}

Member Function Documentation

◆ addPos()

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

Definition at line 82 of file EvtIdxHandler.cxx.

83{
84 ++m_totEvt;
85
86 if ( m_totEvt > m_blockSize ) enlarge_block( m_totEvt );
87
88 m_EIdBlock[m_totEvt-1] = evtId;
89 m_PosBlock[m_totEvt-1] = pos;
90}

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

◆ findPosById()

uint32_t EvtIdxHandler::findPosById ( uint32_t  evtId)

Definition at line 71 of file EvtIdxHandler.cxx.

72{
73 while ( m_totEvt > m_idxPos ) {
74 if ( m_EIdBlock[m_idxPos] == evtId ) {
75 return m_PosBlock[m_idxPos++];
76 }
77 ++m_idxPos;
78 }
79 return 0;
80}

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 11 of file EvtIdxHandler.cxx.

12{
13 if ( _instance == 0 ) {
14 _instance = new EvtIdxHandler(idxfnames);
15 }
16
17 ++_nHandler;
18
19 return _instance;
20}

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 57 of file EvtIdxHandler.cxx.

58{
59 ++m_curFile;
60
61 m_idxPos = 0;
62 init_idx();
63}

◆ nextPos()

uint32_t EvtIdxHandler::nextPos ( int  nIgnore)

Definition at line 65 of file EvtIdxHandler.cxx.

66{
67 m_idxPos += nIgnore;
68 return m_PosBlock[m_idxPos++];
69}

Referenced by RawFileReader::nextEvent().

◆ release()

void EvtIdxHandler::release ( )
static

Definition at line 22 of file EvtIdxHandler.cxx.

23{
24 if ( _nHandler > 0 && --_nHandler == 0 ) {
25 delete _instance;
26 _instance = 0;
27 }
28}

Referenced by RawFileReader::~RawFileReader().

◆ write()

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

Definition at line 92 of file EvtIdxHandler.cxx.

93{
94 if ( m_idxPos >= 0 ) {
95 std::cerr << "[RawFile] Writing an EvtIdxHandler for reading !!!" << std::endl;
96 exit(1);
97 }
98
99 m_fs.open( fname.c_str(), std::ios::out | std::ios::binary );
100
101 uint32_t marker = EvtIdxHandler::IdxFileStartMarker();
102 m_fs.write( (char*)&marker, sizeof(marker) );
103 m_fs.write( (char*)&m_totEvt, sizeof(m_totEvt) );
104
106 m_fs.write( (char*)&marker, sizeof(marker) );
107 m_fs.write( (char*)m_EIdBlock, m_totEvt*sizeof(uint32_t) );
108
110 m_fs.write( (char*)&marker, sizeof(marker) );
111 m_fs.write( (char*)m_PosBlock, m_totEvt*sizeof(uint32_t) );
112
113 if ( ! m_fs.good() ) {
114 std::cerr << "[RawFile] Error writing IDX file: " << fname << std::endl;
115 exit(1);
116 }
117
118 m_fs.close();
119
120 std::cout << "[RawFile] Written IDX file: " << fname << std::endl;
121
122 m_totEvt = 0;
123}
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: