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