BOSS 6.6.4.p01
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
53raw_ifstream::~raw_ifstream()
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
71void raw_ifstream::init_fstream()
72{
73 if ( access( m_curFile->c_str(), F_OK ) < 0 ) {
74 std::cerr << "[RawFile] Invalid file: " << *m_curFile << std::endl;
75 exit(1);
76 }
77
78 std::cout << "[RawFile] Prepare for reading: " << *m_curFile << std::endl;
79
80 open( m_curFile->c_str(), std::ios::binary );
81 m_isOpen = true;
82
83 try {
84 (*this) >> m_fileStartRecord >> m_fileNameStrings >> m_runParametersRecord;
85 }
86 catch (RawFileException& e) {
87 e.print();
88 exit(1);
89 }
90}
m_outputFile open("YYYY/m_txt_dir/LumTau_XXXX.txt", ios_base::app)
virtual void print() const
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)