raw_ifstream Class Reference

#include <raw_ifstream.h>

List of all members.

Public Member Functions

std::string currentFile () const
void next_file ()
uint32_t runNo ()

Static Public Member Functions

static raw_ifstreaminstance (const std::vector< std::string > &fnames)
static void release ()
static void lock ()
static void unlock ()

Private Member Functions

 raw_ifstream (const std::vector< std::string > &fnames)
virtual ~raw_ifstream ()
void init_fstream ()
 raw_ifstream ()

Private Attributes

bool m_isOpen
FileStartRecord m_fileStartRecord
FileNameStrings m_fileNameStrings
RunParametersRecord m_runParametersRecord
std::vector< std::stringm_fnames
std::vector< std::string
>::iterator 
m_curFile

Static Private Attributes

static int _nHandler = 0
static raw_ifstream_instance = 0
static pthread_mutex_t _pthread_lock = PTHREAD_MUTEX_INITIALIZER


Detailed Description

Definition at line 13 of file raw_ifstream.h.


Constructor & Destructor Documentation

raw_ifstream::raw_ifstream ( const std::vector< std::string > &  fnames  )  [private]

Definition at line 42 of file raw_ifstream.cxx.

References init_fstream(), m_curFile, and m_fnames.

00043    : m_isOpen(false), m_fnames(fnames)
00044 {
00045    if ( m_fnames.empty() ) {
00046       throw RawExMessage("[RawFile] Empty input file list!");
00047    }
00048 
00049    m_curFile = m_fnames.begin();
00050    init_fstream();
00051 }

raw_ifstream::~raw_ifstream (  )  [private, virtual]

Definition at line 53 of file raw_ifstream.cxx.

00054 {
00055 }

raw_ifstream::raw_ifstream (  )  [private]

Referenced by instance().


Member Function Documentation

std::string raw_ifstream::currentFile (  )  const [inline]

Definition at line 29 of file raw_ifstream.h.

References m_curFile.

Referenced by RawFileReader::currentFile().

00029 { return *m_curFile; }

void raw_ifstream::init_fstream (  )  [private]

Definition at line 76 of file raw_ifstream.cxx.

References m_curFile, m_fileNameStrings, m_fileStartRecord, m_isOpen, m_runParametersRecord, and RawFileException::print().

Referenced by next_file(), and raw_ifstream().

00077 {
00078    if ( access( m_curFile->c_str(), F_OK ) < 0 ) {
00079       std::cerr << "[RawFile] Invalid file: " << *m_curFile << std::endl;
00080       exit(1);
00081    }
00082 
00083    std::cout << "[RawFile] Prepare for reading: " << *m_curFile << std::endl;
00084 
00085    open( m_curFile->c_str(), std::ios::binary );
00086    m_isOpen = true;
00087 
00088    try {
00089       (*this) >> m_fileStartRecord >> m_fileNameStrings >> m_runParametersRecord;
00090    }
00091    catch (RawFileException& e) {
00092       e.print();
00093       exit(1);
00094    }
00095 }

raw_ifstream * raw_ifstream::instance ( const std::vector< std::string > &  fnames  )  [static]

Definition at line 11 of file raw_ifstream.cxx.

References _instance, _nHandler, lock(), raw_ifstream(), and unlock().

Referenced by RawFileReader::RawFileReader().

00012 {
00013    lock();
00014 
00015    if ( _instance == 0 ) {
00016       _instance = new raw_ifstream(fnames);
00017    }
00018 
00019    ++_nHandler;
00020 
00021    unlock();
00022 
00023    return _instance;
00024 }

static void raw_ifstream::lock (  )  [inline, static]

Definition at line 20 of file raw_ifstream.h.

References _pthread_lock.

Referenced by instance(), RawFileReader::nextEvent(), and release().

00020                          {
00021          int lstat = pthread_mutex_lock( &_pthread_lock );
00022          assert( lstat == 0 );
00023       };

void raw_ifstream::next_file (  ) 

Definition at line 57 of file raw_ifstream.cxx.

References init_fstream(), m_curFile, m_fnames, and m_isOpen.

Referenced by RawFileReader::nextFile().

00058 {
00059    std::cout << "[RawFile] Closing: " << *m_curFile << std::endl;
00060    close();
00061    m_isOpen = false;
00062 
00063    if ( ++m_curFile == m_fnames.end() ) {
00064       --m_curFile;
00065       throw ReachEndOfFileList();
00066    }
00067 
00068    init_fstream();
00069 }

void raw_ifstream::release (  )  [static]

Definition at line 26 of file raw_ifstream.cxx.

References _instance, _nHandler, lock(), m_curFile, m_isOpen, and unlock().

Referenced by RawFileReader::~RawFileReader().

00027 {
00028    lock();
00029 
00030    if ( _nHandler > 0 && --_nHandler == 0 ) {
00031       if ( _instance->m_isOpen ) {
00032          std::cout << "[RawFile] Closing: " << *(_instance->m_curFile) << std::endl;
00033          _instance->close();
00034       }
00035       delete _instance;
00036       _instance = 0;
00037    }
00038 
00039    unlock();
00040 }

uint32_t raw_ifstream::runNo (  ) 

Definition at line 71 of file raw_ifstream.cxx.

References RunParametersRecord::getRecord(), m_runParametersRecord, and run_parameters_record::run_number.

Referenced by RawFileReader::runNo().

00072 {
00073     return m_runParametersRecord.getRecord().run_number;
00074 }

static void raw_ifstream::unlock (  )  [inline, static]

Definition at line 24 of file raw_ifstream.h.

References _pthread_lock.

Referenced by instance(), RawFileReader::nextEvent(), and release().

00024                            {
00025          int lstat = pthread_mutex_unlock( &_pthread_lock );
00026          assert( lstat == 0 );
00027       };


Member Data Documentation

raw_ifstream * raw_ifstream::_instance = 0 [static, private]

Definition at line 58 of file raw_ifstream.h.

Referenced by instance(), and release().

int raw_ifstream::_nHandler = 0 [static, private]

Definition at line 57 of file raw_ifstream.h.

Referenced by instance(), and release().

pthread_mutex_t raw_ifstream::_pthread_lock = PTHREAD_MUTEX_INITIALIZER [static, private]

Definition at line 59 of file raw_ifstream.h.

Referenced by lock(), and unlock().

std::vector<std::string>::iterator raw_ifstream::m_curFile [private]

Definition at line 55 of file raw_ifstream.h.

Referenced by currentFile(), init_fstream(), next_file(), raw_ifstream(), and release().

FileNameStrings raw_ifstream::m_fileNameStrings [private]

Definition at line 51 of file raw_ifstream.h.

Referenced by init_fstream().

FileStartRecord raw_ifstream::m_fileStartRecord [private]

Definition at line 50 of file raw_ifstream.h.

Referenced by init_fstream().

std::vector<std::string> raw_ifstream::m_fnames [private]

Definition at line 54 of file raw_ifstream.h.

Referenced by next_file(), and raw_ifstream().

bool raw_ifstream::m_isOpen [private]

Definition at line 48 of file raw_ifstream.h.

Referenced by init_fstream(), next_file(), and release().

RunParametersRecord raw_ifstream::m_runParametersRecord [private]

Definition at line 52 of file raw_ifstream.h.

Referenced by init_fstream(), and runNo().


Generated on Tue Nov 29 23:20:44 2016 for BOSS_7.0.2 by  doxygen 1.4.7