BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
RawFileReader Class Reference

#include <RawFileReader.h>

+ Inheritance diagram for RawFileReader:

Public Types

typedef const VFileNames_t ReaderArgType
 
typedef const VFileNames_t ReaderArgType
 

Public Member Functions

 RawFileReader (const std::string &fname)
 
 RawFileReader (const VFileNames_t &fnames)
 
 RawFileReader (const std::string &fname, const std::string &idxfname)
 
 RawFileReader (const VFileNames_t &fnames, const VFileNames_t &idxfnames)
 
virtual ~RawFileReader ()
 
const uint32_t * nextEvent ()
 
const uint32_t * currentEvent () const
 
const uint32_t * nextEvent (int nIgnore)
 
const uint32_t * findEventById (uint32_t evtId)
 
const uint32_t * roughlyNextEvent (int nIgnore, int evtByte=0)
 
uint32_t runNo ()
 
std::string currentFile ()
 
uint32_t tellg ()
 
uint32_t stat ()
 
 RawFileReader (const std::string &fname)
 
 RawFileReader (const VFileNames_t &fnames)
 
 RawFileReader (const std::string &fname, const std::string &idxfname)
 
 RawFileReader (const VFileNames_t &fnames, const VFileNames_t &idxfnames)
 
virtual ~RawFileReader ()
 
const uint32_t * nextEvent ()
 
const uint32_t * currentEvent () const
 
const uint32_t * nextEvent (int nIgnore)
 
const uint32_t * findEventById (uint32_t evtId)
 
const uint32_t * roughlyNextEvent (int nIgnore, int evtByte=0)
 
uint32_t runNo ()
 
std::string currentFile ()
 
uint32_t tellg ()
 
uint32_t stat ()
 
- Public Member Functions inherited from IRawReader
virtual ~IRawReader ()
 
virtual const uint32_t * nextEvent ()=0
 
virtual const uint32_t * currentEvent () const =0
 
virtual uint32_t runNo ()=0
 
virtual std::string currentFile ()=0
 
virtual uint32_t stat ()=0
 
virtual ~IRawReader ()
 
virtual const uint32_t * nextEvent ()=0
 
virtual const uint32_t * currentEvent () const =0
 
virtual uint32_t runNo ()=0
 
virtual std::string currentFile ()=0
 
virtual uint32_t stat ()=0
 

Static Public Member Functions

static std::vector< int > getEventNumber (const VFileNames_t &idxfnames)
 
static std::vector< int > getEventNumber (const VFileNames_t &idxfnames)
 

Detailed Description

Member Typedef Documentation

◆ ReaderArgType [1/2]

◆ ReaderArgType [2/2]

Constructor & Destructor Documentation

◆ RawFileReader() [1/8]

RawFileReader::RawFileReader ( const std::string &  fname)

Definition at line 38 of file RawFileReader.cxx.

39 : m_bufferSize(DefaultEventBufferSize),
40 m_buffer( new uint32_t[DefaultEventBufferSize] ),
41 m_idxHandler(0)
42{
43 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fname);
44
45 m_rfs = raw_ifstream::instance(newfnames);
46}
std::vector< std::string > VFileNames_t
#define DefaultEventBufferSize
static raw_ifstream * instance(const std::vector< std::string > &fnames)
std::vector< std::string > wildcard_correct(const std::string &fname)
Definition: RawFileTools.cxx:6

Referenced by RawFileReader().

◆ RawFileReader() [2/8]

RawFileReader::RawFileReader ( const VFileNames_t fnames)

Definition at line 48 of file RawFileReader.cxx.

49 : m_bufferSize(DefaultEventBufferSize),
50 m_buffer( new uint32_t[DefaultEventBufferSize] ),
51 m_idxHandler(0)
52{
53 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fnames);
54
55 m_rfs = raw_ifstream::instance(newfnames);
56}

◆ RawFileReader() [3/8]

RawFileReader::RawFileReader ( const std::string &  fname,
const std::string &  idxfname 
)

Definition at line 58 of file RawFileReader.cxx.

59 : m_bufferSize(DefaultEventBufferSize),
60 m_buffer( new uint32_t[DefaultEventBufferSize] )
61{
62 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fname);
63 const VFileNames_t newidxfnames = RawFileTools::wildcard_correct(idxfname);
64
65 if ( newidxfnames.size() != newfnames.size() ) {
66 std::cerr << "[RawFile] Num(IdxFiles) != Num(DataFiles)" << std::endl;
67 exit(1);
68 }
69
70 m_rfs = raw_ifstream::instance(newfnames);
71 m_idxHandler = EvtIdxHandler::instance(newidxfnames);
72}
static EvtIdxHandler * instance(const std::vector< std::string > &fnames)

◆ RawFileReader() [4/8]

RawFileReader::RawFileReader ( const VFileNames_t fnames,
const VFileNames_t idxfnames 
)

Definition at line 74 of file RawFileReader.cxx.

75 : m_bufferSize(DefaultEventBufferSize),
76 m_buffer( new uint32_t[DefaultEventBufferSize] )
77{
78 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fnames);
79 const VFileNames_t newidxfnames = RawFileTools::wildcard_correct(idxfnames);
80
81 if ( newidxfnames.size() != newfnames.size() ) {
82 std::cerr << "[RawFile] Num(IdxFiles) != Num(DataFiles)" << std::endl;
83 exit(1);
84 }
85
86 m_rfs = raw_ifstream::instance(newfnames);
87 m_idxHandler = EvtIdxHandler::instance(newidxfnames);
88}

◆ ~RawFileReader() [1/2]

RawFileReader::~RawFileReader ( )
virtual

Definition at line 90 of file RawFileReader.cxx.

91{
92 delete[] m_buffer;
95}
static void release()
static void release()

◆ RawFileReader() [5/8]

RawFileReader::RawFileReader ( const std::string &  fname)

◆ RawFileReader() [6/8]

RawFileReader::RawFileReader ( const VFileNames_t fnames)

◆ RawFileReader() [7/8]

RawFileReader::RawFileReader ( const std::string &  fname,
const std::string &  idxfname 
)

◆ RawFileReader() [8/8]

RawFileReader::RawFileReader ( const VFileNames_t fnames,
const VFileNames_t idxfnames 
)

◆ ~RawFileReader() [2/2]

virtual RawFileReader::~RawFileReader ( )
virtual

Member Function Documentation

◆ currentEvent() [1/2]

const uint32_t * RawFileReader::currentEvent ( ) const
inlinevirtual

Implements IRawReader.

Definition at line 33 of file Event/RawFile/RawFile-00-00-10/RawFile/RawFileReader.h.

33{ return m_buffer; }

Referenced by MixerAlg::nextEvent().

◆ currentEvent() [2/2]

const uint32_t * RawFileReader::currentEvent ( ) const
inlinevirtual

Implements IRawReader.

Definition at line 33 of file InstallArea/include/RawFile/RawFile/RawFileReader.h.

33{ return m_buffer; }

◆ currentFile() [1/2]

std::string RawFileReader::currentFile ( )
virtual

Implements IRawReader.

Definition at line 229 of file RawFileReader.cxx.

230{
231 return m_rfs->currentFile();
232}

Referenced by MixerAlg::execute(), findEventById(), main(), nextEvent(), and roughlyNextEvent().

◆ currentFile() [2/2]

std::string RawFileReader::currentFile ( )
virtual

Implements IRawReader.

◆ findEventById() [1/2]

const uint32_t * RawFileReader::findEventById ( uint32_t  evtId)

Definition at line 155 of file RawFileReader.cxx.

156{
157 // not thread safe !!!
158 // find an event by ID ( only backward !!! )
159 try {
160 if ( m_idxHandler == 0 ) {
161 while ( true ) {
162 read_one_event();
163 uint32_t curEvtId = m_buffer[ m_buffer[5] + 8 ];
164 if ( curEvtId == evtId ) {
165 break;
166 }
167 }
168 }
169 else {
170 uint32_t pos = m_idxHandler->findPosById( evtId );
171 if ( pos != 0 ) {
172 m_rfs->seekg( pos );
173 read_one_event();
174 }
175 else {
176 throw ReachEndOfFile( currentFile().c_str() );
177 }
178 }
179 }
180 catch (RawFileException& e) {
181 return nextFile(e).findEventById(evtId);
182 }
183
184 return m_buffer;
185}
uint32_t findPosById(uint32_t evtId)
const uint32_t * findEventById(uint32_t evtId)
std::string currentFile()
char * c_str(Index i)
Definition: EvtCyclic3.cc:252

Referenced by findEventById(), and main().

◆ findEventById() [2/2]

const uint32_t * RawFileReader::findEventById ( uint32_t  evtId)

◆ getEventNumber() [1/2]

std::vector< int > RawFileReader::getEventNumber ( const VFileNames_t idxfnames)
static

Definition at line 11 of file RawFileReader.cxx.

12{
13 uint32_t itmp[2];
14 std::vector<int> vNevt;
15
16 const VFileNames_t newfnames = RawFileTools::wildcard_correct(idxfnames);
17 VFileNames_t::const_iterator it = newfnames.begin();
18 while ( it != newfnames.end() ) {
19 if ( access( it->c_str(), F_OK ) < 0 ) {
20 std::cerr << "[RawFile] Invalid IDX file: " << *it << std::endl;
21 exit(1);
22 }
23
24 std::ifstream fs( it->c_str(), std::ios::binary );
25
26 fs.read( (char*)(itmp), sizeof(uint32_t)*2 );
27 if ( itmp[0] != EvtIdxHandler::IdxFileStartMarker() ) {
28 std::cerr << "[RawFile] Wrong IdxFileStartMarker!" << std::endl;
29 exit(1);
30 }
31 vNevt.push_back(itmp[1]);
32 ++it;
33 }
34
35 return vNevt;
36}

Referenced by MixerAlg::execute().

◆ getEventNumber() [2/2]

static std::vector< int > RawFileReader::getEventNumber ( const VFileNames_t idxfnames)
static

◆ nextEvent() [1/4]

const uint32_t * RawFileReader::nextEvent ( )
virtual

Implements IRawReader.

Definition at line 97 of file RawFileReader.cxx.

98{
99 // thread safe
101
102 try {
103 notSafeNextEvent();
104 }
105 catch ( ReachEndOfFileList& e) {
107 throw e;
108 }
109 catch ( RawFileException& e) {
111 e.print();
112 throw e;
113 }
114
116
117 return m_buffer;
118}
virtual void print() const

Referenced by main(), nextEvent(), MixerAlg::nextEvent(), and RawEventReader::readEvent().

◆ nextEvent() [2/4]

const uint32_t * RawFileReader::nextEvent ( )
virtual

Implements IRawReader.

◆ nextEvent() [3/4]

const uint32_t * RawFileReader::nextEvent ( int  nIgnore)

Definition at line 120 of file RawFileReader.cxx.

121{
122 // not thread safe !!!
123 int nnIgnore = nIgnore;
124
125 try {
126 if ( m_idxHandler != 0 ) {
127 int nleft = m_idxHandler->nEvtLeft(nnIgnore);
128 if ( nleft > 0 ) {
129 m_rfs->seekg( m_idxHandler->nextPos( nnIgnore ) );
130 nnIgnore = 0;
131 }
132 else {
133 nnIgnore = -nleft;
134 throw ReachEndOfFile( currentFile().c_str() );
135 }
136 }
137 else {
138 while ( nnIgnore > 0 ) {
139 (*m_rfs) >> m_dataSeparatorRecord;
140 uint32_t size = m_dataSeparatorRecord.getRecord().data_block_size;
141 m_rfs->seekg( size + m_rfs->tellg() );
142 --nnIgnore;
143 }
144 }
145
146 read_one_event();
147 }
148 catch (RawFileException& e) {
149 nextFile(e).nextEvent(nnIgnore);
150 }
151
152 return m_buffer;
153}
const data_separator_record & getRecord() const
uint32_t nextPos(int nIgnore)
const uint32_t * nextEvent()

◆ nextEvent() [4/4]

const uint32_t * RawFileReader::nextEvent ( int  nIgnore)

◆ roughlyNextEvent() [1/2]

const uint32_t * RawFileReader::roughlyNextEvent ( int  nIgnore,
int  evtByte = 0 
)

Definition at line 187 of file RawFileReader.cxx.

188{
189 // not thread safe !!!
190 if ( evtByte == 0 ) evtByte = EstimatedEventSize;
191
192 assert( (evtByte&3) == 0 );
193
194 uint32_t prePos = m_rfs->tellg();
195 m_rfs->seekg( prePos + nIgnore*evtByte);
196
197 uint32_t halfEvtWord = evtByte / 8;
198 uint32_t halfEvtByte = halfEvtWord * 4;
199
200 while ( m_rfs->read((char*)m_buffer, halfEvtByte).good() ) {
201 uint32_t i = 0;
202 while ( i < halfEvtWord && m_buffer[i] != 0x1234cccc ) {
203 ++i;
204 }
205 if ( i < halfEvtWord ) {
206 uint32_t curPos = m_rfs->tellg();
207 m_rfs->seekg( curPos - (halfEvtWord-i)*4 );
208 read_one_event();
209 return m_buffer;
210 }
211 }
212
213 // reached the end of current data file! m_rfs->eof()
214 m_rfs->clear();
215 m_rfs->seekg( -40, std::ios::end ); //sizeof(FileEndRecord) == 40
216 uint32_t curPos = m_rfs->tellg();
217
218 int nnIgnore = nIgnore - (curPos - prePos) / evtByte;
219 if ( nnIgnore < 0 ) nnIgnore = 0;
220
222 return nextFile(e).roughlyNextEvent(nnIgnore, evtByte);
223}
#define EstimatedEventSize
const uint32_t * roughlyNextEvent(int nIgnore, int evtByte=0)

Referenced by MixerAlg::nextEvent(), and roughlyNextEvent().

◆ roughlyNextEvent() [2/2]

const uint32_t * RawFileReader::roughlyNextEvent ( int  nIgnore,
int  evtByte = 0 
)

◆ runNo() [1/2]

uint32_t RawFileReader::runNo ( )
virtual

Implements IRawReader.

Definition at line 224 of file RawFileReader.cxx.

225{
226 return m_rfs->runNo();
227}
uint32_t runNo()

◆ runNo() [2/2]

uint32_t RawFileReader::runNo ( )
virtual

Implements IRawReader.

◆ stat() [1/2]

uint32_t RawFileReader::stat ( )
virtual

Implements IRawReader.

Definition at line 239 of file RawFileReader.cxx.

240{
241 uint32_t stat = 0;
242
243 if ( m_rfs->eof() ) stat |= 1;
244 if ( m_rfs->fail() ) stat |= 2;
245 if ( m_rfs->bad() ) stat |= 4;
246
247 return stat;
248}
uint32_t stat()

Referenced by stat().

◆ stat() [2/2]

uint32_t RawFileReader::stat ( )
virtual

Implements IRawReader.

◆ tellg() [1/2]

uint32_t RawFileReader::tellg ( )

Definition at line 234 of file RawFileReader.cxx.

235{
236 return m_rfs->tellg();
237}

Referenced by main().

◆ tellg() [2/2]

uint32_t RawFileReader::tellg ( )

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