#include <RRawStream.h>
Inheritance diagram for RRawStream:
Public Member Functions | |
RRawStream () | |
RRawStream (const char *filename) | |
virtual | ~RRawStream () |
void | close () |
ifstream-like | |
void | open (const char *filename) |
bool | is_open () const |
bool | good () const |
bool | operator! () const |
Not operator. !stream returns true if in bad/failed state. | |
RRawStream & | read (char *s, int n) |
RRawStream & | ignore (int n=1) |
Private Attributes | |
TFile * | m_file |
TTree * | m_tree |
Int32 | m_buffer [50000] |
Int32 | m_size |
Int32 | m_currentEntry |
Int32 | m_currentPosi |
bool | m_entryEnd |
Definition at line 26 of file RRawStream.h.
RRawStream::RRawStream | ( | ) |
Definition at line 24 of file RRawStream.cc.
00024 : 00025 m_file(0),m_tree(0),m_size(0), 00026 m_currentEntry(-1),m_currentPosi(0),m_entryEnd(true) 00027 { 00028 sanity(); 00029 }
RRawStream::RRawStream | ( | const char * | filename | ) |
Definition at line 31 of file RRawStream.cc.
00031 : 00032 m_file(0),m_tree(0),m_size(0), 00033 m_currentEntry(-1),m_currentPosi(0),m_entryEnd(true) 00034 { 00035 sanity(); 00036 this->open(filename); 00037 }
RRawStream::~RRawStream | ( | ) | [virtual] |
void RRawStream::close | ( | ) | [virtual] |
ifstream-like
Implements IInputStream.
Definition at line 44 of file RRawStream.cc.
00045 { 00046 if(!m_file) return; 00047 00048 m_file->Close(); 00049 delete m_file; 00050 m_file=0; 00051 00052 }
void RRawStream::open | ( | const char * | filename | ) | [virtual] |
Implements IInputStream.
Definition at line 54 of file RRawStream.cc.
00055 { 00056 // open a file 00057 m_file = TFile::Open( filename, "READ" ); 00058 if(!m_file) { 00059 cout<<"RRawStream::Failed to open "<<filename<<endl; 00060 abort(); 00061 } 00062 if( !(m_file->IsOpen()) ) { 00063 cout<<"RRawStream::Failed to open "<<filename<<endl; 00064 abort(); 00065 } 00066 00067 // get the tree 00068 m_tree = (TTree*)m_file->Get("RRawTree"); 00069 if(!m_tree) { 00070 cout<<"RRawStream::Failed to get TTree RRawTree"<<endl; 00071 abort(); 00072 } 00073 00074 // set branch address 00075 m_tree->SetBranchAddress("size",&m_size); 00076 m_tree->SetBranchAddress("buffer",m_buffer); 00077 00078 // reset current entry number to -1 00079 m_currentEntry=-1; 00080 00081 // reset reading status of current entry 00082 m_currentPosi=0; 00083 m_entryEnd=true; 00084 }
bool RRawStream::is_open | ( | ) | const [virtual] |
bool RRawStream::good | ( | ) | const [virtual] |
bool RRawStream::operator! | ( | ) | const [virtual] |
Not operator. !stream returns true if in bad/failed state.
Implements IInputStream.
Definition at line 101 of file RRawStream.cc.
00102 { 00103 if (!this->is_open()) return true; 00104 return !good(); 00105 }
RRawStream & RRawStream::read | ( | char * | s, | |
int | n | |||
) | [virtual] |
Implements IInputStream.
Definition at line 107 of file RRawStream.cc.
00108 { 00109 // Need to handle the case of reaching to the end of one entry 00110 if(m_entryEnd) { 00111 m_currentEntry++; 00112 m_tree->GetEntry(m_currentEntry); 00113 m_entryEnd=false; 00114 m_currentPosi = 0; 00115 00116 /* 00117 cout<<"RRawStream::New Entry "<<m_size<<endl; 00118 for(int i=0;i<m_size;i++) { 00119 cout<<(unsigned int)m_buffer[i]<<" "; 00120 } 00121 cout<<endl; 00122 */ 00123 } 00124 00125 if( m_currentPosi+n <= m_size * 4 ) { 00126 memcpy(s, (char*)(m_buffer) + m_currentPosi, n); 00127 m_currentPosi+=n; 00128 } else { 00129 cout<<"RRawStream::Asking data over one root entry boundary"<<endl; 00130 abort(); 00131 } 00132 00133 // Mark the end 00134 if(m_currentPosi == m_size * 4 ) { 00135 m_entryEnd = true; 00136 } 00137 00138 return *this; 00139 }
RRawStream & RRawStream::ignore | ( | int | n = 1 |
) | [virtual] |
Implements IInputStream.
Definition at line 141 of file RRawStream.cc.
00142 { 00143 // The same as read(...), just without memcpy 00144 00145 // Need to handle the case of reaching to the end of one entry 00146 if(m_entryEnd) { 00147 m_currentEntry++; 00148 m_tree->GetEntry(m_currentEntry); 00149 m_entryEnd=false; 00150 m_currentPosi = 0; 00151 00152 /* 00153 cout<<"RRawStream::New Entry "<<m_size<<endl; 00154 for(int i=0;i<m_size;i++) { 00155 cout<<(unsigned int)m_buffer[i]<<" "; 00156 } 00157 cout<<endl; 00158 */ 00159 } 00160 00161 m_currentPosi+=n; 00162 00163 // Mark the end 00164 if(m_currentPosi == m_size * 4 ) { 00165 m_entryEnd = true; 00166 } 00167 00168 return *this; 00169 }
TFile* RRawStream::m_file [private] |
Definition at line 46 of file RRawStream.h.
TTree* RRawStream::m_tree [private] |
Definition at line 47 of file RRawStream.h.
Int32 RRawStream::m_buffer[50000] [private] |
Definition at line 49 of file RRawStream.h.
Int32 RRawStream::m_size [private] |
Definition at line 50 of file RRawStream.h.
Int32 RRawStream::m_currentEntry [private] |
Definition at line 53 of file RRawStream.h.
Int32 RRawStream::m_currentPosi [private] |
Definition at line 56 of file RRawStream.h.
bool RRawStream::m_entryEnd [private] |
Definition at line 59 of file RRawStream.h.