BOSS 7.1.1
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
 

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 ()
 
- Public Member Functions inherited from IRawReader
virtual ~IRawReader ()
 

Static Public Member Functions

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

Detailed Description

Definition at line 16 of file RawFileReader.h.

Member Typedef Documentation

◆ ReaderArgType

Definition at line 20 of file RawFileReader.h.

Constructor & Destructor Documentation

◆ RawFileReader() [1/4]

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

Definition at line 39 of file RawFileReader.cxx.

40 : m_bufferSize(DefaultEventBufferSize),
41 m_buffer( new uint32_t[DefaultEventBufferSize] ),
42 m_idxHandler(0)
43{
44 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fname);
45
46 // in case of idx files
47 VFileNames_t datafnames;
48 for ( int i = 0; i < newfnames.size (); ++i ) {
49 int size = newfnames[i].size();
50 if ( size > 4 && newfnames[i].substr(size-4) == ".idx" ) {
51 datafnames.push_back(newfnames[i].substr(0, size-4));
52 }
53 }
54 if ( datafnames.size() == newfnames.size() ) {
55 m_rfs = raw_ifstream::instance(datafnames);
56 m_idxHandler = EvtIdxHandler::instance(newfnames);
57 }
58 else {
59 m_rfs = raw_ifstream::instance(newfnames);
60 }
61}
#define DefaultEventBufferSize
std::vector< std::string > VFileNames_t
static EvtIdxHandler * instance(const std::vector< std::string > &fnames)
static raw_ifstream * instance(const std::vector< std::string > &fnames)
std::vector< std::string > wildcard_correct(const std::string &fname)

Referenced by RawFileReader(), RawFileReader(), RawFileReader(), and RawFileReader().

◆ RawFileReader() [2/4]

RawFileReader::RawFileReader ( const VFileNames_t & fnames)

Definition at line 63 of file RawFileReader.cxx.

64 : m_bufferSize(DefaultEventBufferSize),
65 m_buffer( new uint32_t[DefaultEventBufferSize] ),
66 m_idxHandler(0)
67{
68 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fnames);
69
70 // in case of idx files
71 VFileNames_t datafnames;
72 for ( int i = 0; i < newfnames.size (); ++i ) {
73 int size = newfnames[i].size();
74 if ( size > 4 && newfnames[i].substr(size-4) == ".idx" ) {
75 datafnames.push_back(newfnames[i].substr(0, size-4));
76 }
77 }
78 if ( datafnames.size() == newfnames.size() ) {
79 m_rfs = raw_ifstream::instance(datafnames);
80 m_idxHandler = EvtIdxHandler::instance(newfnames);
81 }
82 else {
83 m_rfs = raw_ifstream::instance(newfnames);
84 }
85}

◆ RawFileReader() [3/4]

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

Definition at line 87 of file RawFileReader.cxx.

88 : m_bufferSize(DefaultEventBufferSize),
89 m_buffer( new uint32_t[DefaultEventBufferSize] )
90{
91 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fname);
92 const VFileNames_t newidxfnames = RawFileTools::wildcard_correct(idxfname);
93
94 if ( newidxfnames.size() != newfnames.size() ) {
95 std::cerr << "[RawFile] Num(IdxFiles) != Num(DataFiles)" << std::endl;
96 exit(1);
97 }
98
99 m_rfs = raw_ifstream::instance(newfnames);
100 m_idxHandler = EvtIdxHandler::instance(newidxfnames);
101}

◆ RawFileReader() [4/4]

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

Definition at line 103 of file RawFileReader.cxx.

104 : m_bufferSize(DefaultEventBufferSize),
105 m_buffer( new uint32_t[DefaultEventBufferSize] )
106{
107 const VFileNames_t newfnames = RawFileTools::wildcard_correct(fnames);
108 const VFileNames_t newidxfnames = RawFileTools::wildcard_correct(idxfnames);
109
110 if ( newidxfnames.size() != newfnames.size() ) {
111 std::cerr << "[RawFile] Num(IdxFiles) != Num(DataFiles)" << std::endl;
112 exit(1);
113 }
114
115 m_rfs = raw_ifstream::instance(newfnames);
116 m_idxHandler = EvtIdxHandler::instance(newidxfnames);
117}

◆ ~RawFileReader()

RawFileReader::~RawFileReader ( )
virtual

Definition at line 119 of file RawFileReader.cxx.

120{
121 delete[] m_buffer;
124}
static void release()
static void release()

Member Function Documentation

◆ currentEvent()

const uint32_t * RawFileReader::currentEvent ( ) const
inlinevirtual

Implements IRawReader.

Definition at line 33 of file RawFileReader.h.

33{ return m_buffer; }

Referenced by MixerAlg::nextEvent().

◆ currentFile()

std::string RawFileReader::currentFile ( )
virtual

Implements IRawReader.

Definition at line 263 of file RawFileReader.cxx.

264{
265 return m_rfs->currentFile();
266}
std::string currentFile() const

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

◆ findEventById()

const uint32_t * RawFileReader::findEventById ( uint32_t evtId)

Definition at line 189 of file RawFileReader.cxx.

190{
191 // not thread safe !!!
192 // find an event by ID ( only backward !!! )
193 try {
194 if ( m_idxHandler == 0 ) {
195 while ( true ) {
196 read_one_event();
197 uint32_t curEvtId = m_buffer[ m_buffer[5] + 8 ];
198 if ( curEvtId == evtId ) {
199 break;
200 }
201 }
202 }
203 else {
204 uint32_t pos = m_idxHandler->findPosById( evtId );
205 if ( pos != 0 ) {
206 m_rfs->seekg( pos );
207 read_one_event();
208 }
209 else {
210 throw ReachEndOfFile( currentFile().c_str() );
211 }
212 }
213 }
214 catch (RawFileException& e) {
215 return nextFile(e).findEventById(evtId);
216 }
217
218 return m_buffer;
219}
uint32_t findPosById(uint32_t evtId)
const uint32_t * findEventById(uint32_t evtId)
std::string currentFile()
char * c_str(Index i)

Referenced by findEventById(), and main().

◆ getEventNumber()

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

Definition at line 12 of file RawFileReader.cxx.

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

Referenced by MixerAlg::execute().

◆ nextEvent() [1/2]

const uint32_t * RawFileReader::nextEvent ( )
virtual

Implements IRawReader.

Definition at line 126 of file RawFileReader.cxx.

127{
128 // thread safe
130
131 try {
132 if ( m_idxHandler == 0 ) {
133 notSafeNextEvent();
134 }
135 else {
136 nextEvent(0);
137 }
138 }
139 catch ( ReachEndOfFileList& e) {
141 throw e;
142 }
143 catch ( RawFileException& e) {
145 e.print();
146 throw e;
147 }
148
150
151 return m_buffer;
152}
virtual void print() const
const uint32_t * nextEvent()
static void unlock()
static void lock()

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

◆ nextEvent() [2/2]

const uint32_t * RawFileReader::nextEvent ( int nIgnore)

Definition at line 154 of file RawFileReader.cxx.

155{
156 // not thread safe !!!
157 int nnIgnore = nIgnore;
158
159 try {
160 if ( m_idxHandler != 0 ) {
161 int nleft = m_idxHandler->nEvtLeft(nnIgnore);
162 if ( nleft > 0 ) {
163 m_rfs->seekg( m_idxHandler->nextPos( nnIgnore ) );
164 nnIgnore = 0;
165 }
166 else {
167 nnIgnore = -nleft;
168 throw ReachEndOfFile( currentFile().c_str() );
169 }
170 }
171 else {
172 while ( nnIgnore > 0 ) {
173 (*m_rfs) >> m_dataSeparatorRecord;
174 uint32_t size = m_dataSeparatorRecord.getRecord().data_block_size;
175 m_rfs->seekg( size + m_rfs->tellg() );
176 --nnIgnore;
177 }
178 }
179
180 read_one_event();
181 }
182 catch (RawFileException& e) {
183 nextFile(e).nextEvent(nnIgnore);
184 }
185
186 return m_buffer;
187}
const data_separator_record & getRecord() const
int nEvtLeft(int nIgnore) const
uint32_t nextPos(int nIgnore)

◆ roughlyNextEvent()

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

Definition at line 221 of file RawFileReader.cxx.

222{
223 // not thread safe !!!
224 if ( evtByte == 0 ) evtByte = EstimatedEventSize;
225
226 assert( (evtByte&3) == 0 );
227
228 uint32_t prePos = m_rfs->tellg();
229 m_rfs->seekg( prePos + nIgnore*evtByte);
230
231 uint32_t halfEvtWord = evtByte / 8;
232 uint32_t halfEvtByte = halfEvtWord * 4;
233
234 while ( m_rfs->read((char*)m_buffer, halfEvtByte).good() ) {
235 uint32_t i = 0;
236 while ( i < halfEvtWord && m_buffer[i] != 0x1234cccc ) {
237 ++i;
238 }
239 if ( i < halfEvtWord ) {
240 uint32_t curPos = m_rfs->tellg();
241 m_rfs->seekg( curPos - (halfEvtWord-i)*4 );
242 read_one_event();
243 return m_buffer;
244 }
245 }
246
247 // reached the end of current data file! m_rfs->eof()
248 m_rfs->clear();
249 m_rfs->seekg( -40, std::ios::end ); //sizeof(FileEndRecord) == 40
250 uint32_t curPos = m_rfs->tellg();
251
252 int nnIgnore = nIgnore - (curPos - prePos) / evtByte;
253 if ( nnIgnore < 0 ) nnIgnore = 0;
254
256 return nextFile(e).roughlyNextEvent(nnIgnore, evtByte);
257}
#define EstimatedEventSize
const uint32_t * roughlyNextEvent(int nIgnore, int evtByte=0)

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

◆ runNo()

uint32_t RawFileReader::runNo ( )
virtual

Implements IRawReader.

Definition at line 258 of file RawFileReader.cxx.

259{
260 return m_rfs->runNo();
261}
uint32_t runNo()

◆ stat()

uint32_t RawFileReader::stat ( )
virtual

Implements IRawReader.

Definition at line 273 of file RawFileReader.cxx.

274{
275 uint32_t stat = 0;
276
277 if ( m_rfs->eof() ) stat |= 1;
278 if ( m_rfs->fail() ) stat |= 2;
279 if ( m_rfs->bad() ) stat |= 4;
280
281 return stat;
282}

Referenced by stat().

◆ tellg()

uint32_t RawFileReader::tellg ( )

Definition at line 268 of file RawFileReader.cxx.

269{
270 return m_rfs->tellg();
271}

Referenced by main().


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