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