BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
raw_ifstream.cxx
Go to the documentation of this file.
3#include <cstdlib>
4
5//static data members
6int raw_ifstream::_nHandler = 0;
7raw_ifstream* raw_ifstream::_instance = 0;
8pthread_mutex_t raw_ifstream::_pthread_lock = PTHREAD_MUTEX_INITIALIZER;
9
10
11raw_ifstream* raw_ifstream::instance(const std::vector<std::string>& fnames)
12{
13 lock();
14
15 if ( _instance == 0 ) {
16 _instance = new raw_ifstream(fnames);
17 }
18
19 ++_nHandler;
20
21 unlock();
22
23 return _instance;
24}
25
27{
28 lock();
29
30 if ( _nHandler > 0 && --_nHandler == 0 ) {
31 if ( _instance->m_isOpen ) {
32 std::cout << "[RawFile] Closing: " << *(_instance->m_curFile) << std::endl;
33 _instance->close();
34 }
35 delete _instance;
36 _instance = 0;
37 }
38
39 unlock();
40}
41
42raw_ifstream::raw_ifstream(const std::vector<std::string>& fnames)
43 : m_isOpen(false), m_fnames(fnames)
44{
45 if ( m_fnames.empty() ) {
46 throw RawExMessage("[RawFile] Empty input file list!");
47 }
48
49 m_curFile = m_fnames.begin();
50 init_fstream();
51}
52
54{
55}
56
58{
59 std::cout << "[RawFile] Closing: " << *m_curFile << std::endl;
60 close();
61 m_isOpen = false;
62
63 if ( ++m_curFile == m_fnames.end() ) {
64 --m_curFile;
65 throw ReachEndOfFileList();
66 }
67
68 init_fstream();
69}
70
72{
73 return m_runParametersRecord.getRecord().run_number;
74}
75
76void raw_ifstream::init_fstream()
77{
78 if ( access( m_curFile->c_str(), F_OK ) < 0 ) {
79 std::cerr << "[RawFile] Invalid file: " << *m_curFile << std::endl;
80 exit(1);
81 }
82
83 std::cout << "[RawFile] Prepare for reading: " << *m_curFile << std::endl;
84
85 open( m_curFile->c_str(), std::ios::binary );
86 m_isOpen = true;
87
88 try {
89 (*this) >> m_fileStartRecord >> m_fileNameStrings >> m_runParametersRecord;
90 }
91 catch (RawFileException& e) {
92 e.print();
93 exit(1);
94 }
95}
virtual void print() const
const run_parameters_record & getRecord() const
Definition: RawFileUtil.h:106
raw_ifstream(const std::vector< std::string > &fnames)
void next_file()
static void unlock()
Definition: raw_ifstream.h:24
static void lock()
Definition: raw_ifstream.h:20
static void release()
static raw_ifstream * instance(const std::vector< std::string > &fnames)
virtual ~raw_ifstream()
uint32_t runNo()
file close()