BOSS 7.0.7
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 ()
 
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)
 

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 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 // in case of idx files
46 VFileNames_t datafnames;
47 for ( int i = 0; i < newfnames.size (); ++i ) {
48 int size = newfnames[i].size();
49 if ( size > 4 && newfnames[i].substr(size-4) == ".idx" ) {
50 datafnames.push_back(newfnames[i].substr(0, size-4));
51 }
52 }
53 if ( datafnames.size() == newfnames.size() ) {
54 m_rfs = raw_ifstream::instance(datafnames);
55 m_idxHandler = EvtIdxHandler::instance(newfnames);
56 }
57 else {
58 m_rfs = raw_ifstream::instance(newfnames);
59 }
60}
#define DefaultEventBufferSize
std::vector< std::string > VFileNames_t
Definition: RawFileReader.h:14
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)
Definition: RawFileTools.cxx:6

Referenced by RawFileReader().

◆ RawFileReader() [2/4]

RawFileReader::RawFileReader ( const VFileNames_t fnames)

Definition at line 62 of file RawFileReader.cxx.

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

◆ RawFileReader() [3/4]

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

Definition at line 86 of file RawFileReader.cxx.

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

◆ RawFileReader() [4/4]

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

Definition at line 102 of file RawFileReader.cxx.

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

◆ ~RawFileReader()

RawFileReader::~RawFileReader ( )
virtual

Definition at line 118 of file RawFileReader.cxx.

119{
120 delete[] m_buffer;
123}
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 262 of file RawFileReader.cxx.

263{
264 return m_rfs->currentFile();
265}
std::string currentFile() const
Definition: raw_ifstream.h:29

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

◆ findEventById()

const uint32_t * RawFileReader::findEventById ( uint32_t  evtId)

Definition at line 188 of file RawFileReader.cxx.

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

◆ getEventNumber()

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}
static uint32_t IdxFileStartMarker()
Definition: EvtIdxHandler.h:13

Referenced by MixerAlg::execute().

◆ nextEvent() [1/2]

const uint32_t * RawFileReader::nextEvent ( )
virtual

Implements IRawReader.

Definition at line 125 of file RawFileReader.cxx.

126{
127 // thread safe
129
130 try {
131 if ( m_idxHandler == 0 ) {
132 notSafeNextEvent();
133 }
134 else {
135 nextEvent(0);
136 }
137 }
138 catch ( ReachEndOfFileList& e) {
140 throw e;
141 }
142 catch ( RawFileException& e) {
144 e.print();
145 throw e;
146 }
147
149
150 return m_buffer;
151}
virtual void print() const
const uint32_t * nextEvent()
static void unlock()
Definition: raw_ifstream.h:24
static void lock()
Definition: raw_ifstream.h:20

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

◆ nextEvent() [2/2]

const uint32_t * RawFileReader::nextEvent ( int  nIgnore)

Definition at line 153 of file RawFileReader.cxx.

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

◆ roughlyNextEvent()

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

Definition at line 220 of file RawFileReader.cxx.

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

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

◆ stat()

uint32_t RawFileReader::stat ( )
virtual

Implements IRawReader.

Definition at line 272 of file RawFileReader.cxx.

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

Referenced by stat().

◆ tellg()

uint32_t RawFileReader::tellg ( )

Definition at line 267 of file RawFileReader.cxx.

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

Referenced by main().


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