Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

raw_ofstream Class Reference

#include <raw_ofstream.h>

List of all members.

Public Member Functions

void close ()
void close ()
int write_event (const char *pbuf, int size)
int write_event (const char *pbuf, int size)

Static Public Member Functions

raw_ofstreaminstance (const std::string &fname)
raw_ofstreaminstance (const std::string &fname)
void lock ()
void lock ()
void release ()
void release ()
void unlock ()
void unlock ()

Private Member Functions

void init_fstream ()
void init_fstream ()
 raw_ofstream ()
 raw_ofstream (const std::string &fname)
 raw_ofstream ()
 raw_ofstream (const std::string &fname)
std::string real_fname ()
std::string real_fname ()
virtual ~raw_ofstream ()
virtual ~raw_ofstream ()

Private Attributes

DataSeparatorRecord m_dataSeparatorRecord
FileEndRecord m_fileEndRecord
FileNameStrings m_fileNameStrings
FileStartRecord m_fileStartRecord
std::string m_fname
int m_nevt
int m_nfile
RunParametersRecord m_runParametersRecord

Static Private Attributes

raw_ofstream_instance
raw_ofstream_instance = 0
int _nHandler = 0
pthread_mutex_t _pthread_lock = PTHREAD_MUTEX_INITIALIZER


Constructor & Destructor Documentation

raw_ofstream::raw_ofstream const std::string &  fname  )  [private]
 

00041    : m_nevt(0),
00042      m_nfile(0),
00043      m_fname(fname)
00044 {
00045    init_fstream();
00046 }

raw_ofstream::~raw_ofstream  )  [private, virtual]
 

00049 {
00050    this->close();
00051 }

raw_ofstream::raw_ofstream  )  [private]
 

raw_ofstream::raw_ofstream const std::string &  fname  )  [private]
 

virtual raw_ofstream::~raw_ofstream  )  [private, virtual]
 

raw_ofstream::raw_ofstream  )  [private]
 


Member Function Documentation

void raw_ofstream::close  ) 
 

void raw_ofstream::close  ) 
 

00071 {
00072    if ( is_open() ) {
00073       m_fileEndRecord.setEventsInFile(m_nevt);
00074       m_nevt = 0;
00075 
00076       (*this) << m_fileEndRecord;
00077       std::ofstream::close();
00078 
00079       std::cout << "[RawFile] Finished writing file: " << real_fname() << std::endl;
00080    }
00081 }

void raw_ofstream::init_fstream  )  [private]
 

void raw_ofstream::init_fstream  )  [private]
 

00084 {
00085    ++m_nfile;
00086 
00087    std::string fname = real_fname();
00088 
00089    if ( access( fname.c_str(), F_OK ) == 0 ) {
00090       std::cerr << "[RawFile] Attempt to create an exist file: " << fname << std::endl;
00091       exit(1);
00092    }
00093 
00094    std::cout << "[RawFile] Creating a new file: " << real_fname() << std::endl;
00095    open( fname.c_str(), std::ios::binary );
00096 
00097    (*this) << m_fileStartRecord << m_fileNameStrings << m_runParametersRecord;
00098 }

raw_ofstream* raw_ofstream::instance const std::string &  fname  )  [static]
 

raw_ofstream * raw_ofstream::instance const std::string &  fname  )  [static]
 

00014 {
00015    lock();
00016 
00017    if ( _instance == 0 ) {
00018       _instance = new raw_ofstream(fname);
00019    }
00020 
00021    ++_nHandler;
00022 
00023    unlock();
00024 
00025    return _instance;
00026 }

void raw_ofstream::lock  )  [inline, static]
 

00018                          {
00019          int lstat = pthread_mutex_lock( &_pthread_lock );
00020          assert( lstat == 0 );
00021       };

void raw_ofstream::lock  )  [inline, static]
 

00018                          {
00019          int lstat = pthread_mutex_lock( &_pthread_lock );
00020          assert( lstat == 0 );
00021       };

std::string raw_ofstream::real_fname  )  [private]
 

std::string raw_ofstream::real_fname  )  [private]
 

00101 {
00102    std::string fname = m_fname;
00103 
00104    if ( m_nfile > 1 ) {
00105       fname += ".part" + RawFileTools::itoa( m_nfile );
00106    }
00107 
00108    return fname;
00109 }

void raw_ofstream::release  )  [static]
 

void raw_ofstream::release  )  [static]
 

00029 {
00030    lock();
00031 
00032    if ( _nHandler > 0 && --_nHandler == 0 ) {
00033       delete _instance;
00034       _instance = 0;
00035    }
00036 
00037    unlock();
00038 }

void raw_ofstream::unlock  )  [inline, static]
 

00022                            {
00023          int lstat = pthread_mutex_unlock( &_pthread_lock );
00024          assert( lstat == 0 );
00025       };

void raw_ofstream::unlock  )  [inline, static]
 

00022                            {
00023          int lstat = pthread_mutex_unlock( &_pthread_lock );
00024          assert( lstat == 0 );
00025       };

int raw_ofstream::write_event const char *  pbuf,
int  size
 

int raw_ofstream::write_event const char *  pbuf,
int  size
 

00054 {
00055    uint32_t fsize = tellp();
00056    if ( fsize >= MAX_RAWFILE_SiZE ) {
00057       this->close();
00058       init_fstream();
00059    }
00060 
00061    m_dataSeparatorRecord.setDataBlockNumber(++m_nevt);
00062    m_dataSeparatorRecord.setDataBlockSize(size);
00063 
00064    (*this) << m_dataSeparatorRecord;
00065    std::ofstream::write(pbuf, size);
00066 
00067    return m_nfile;
00068 }


Member Data Documentation

raw_ofstream* raw_ofstream::_instance [static, private]
 

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

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

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

DataSeparatorRecord raw_ofstream::m_dataSeparatorRecord [private]
 

FileEndRecord raw_ofstream::m_fileEndRecord [private]
 

FileNameStrings raw_ofstream::m_fileNameStrings [private]
 

FileStartRecord raw_ofstream::m_fileStartRecord [private]
 

std::string raw_ofstream::m_fname [private]
 

int raw_ofstream::m_nevt [private]
 

int raw_ofstream::m_nfile [private]
 

RunParametersRecord raw_ofstream::m_runParametersRecord [private]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 16:42:03 2011 for BOSS6.5.5 by  doxygen 1.3.9.1