A class to be loaded with arbitrary number of ana_base inherited analysis modules. More...
#include <ana_processor.hh>
Public Types | |
enum | PROCESS_FLAG { INIT, READY, PROCESSING, FINISHED } |
Process flag enum. More... | |
Public Member Functions | |
ana_processor () | |
Default constructor. | |
~ana_processor () | |
Default destructor. | |
virtual void | set_verbosity (MSG::Level level) |
Override a method to set verbosity. | |
void | add_input_file (std::string name) |
Setter for an input DATA file name. | |
void | set_input_rootdir (std::string name) |
Setter for an input ROOT TDirectory name. | |
void | set_output_file (std::string name) |
Setter for an output DATA file name. | |
void | set_ana_output_file (std::string name) |
Setter for an analysis output root file name. | |
void | set_io_mode (storage_manager::MODE mode) |
Setter for I/O mode ... READ or WRITE or BOTH. | |
void | set_data_to_read (DATA::DATA_TYPE type, Bool_t read=true) |
Setter to specify a certain data class to be read from input. | |
Bool_t | get_ana_status (ana_base *ptr) const |
Getter of running analysis status. | |
Bool_t | run (UInt_t start_index=0, UInt_t nevents=0) |
A method to run a batch process. | |
Bool_t | process_event (UInt_t index=0) |
A method to process just one event. | |
Size_t | add_process (ana_base *ana) |
A method to append analysis class instance. Returns index number. | |
ana_base * | get_process (Size_t loc) |
A method to inquir attached analysis class instance. | |
PROCESS_FLAG | get_process_status () |
A method to inquire the process status. | |
MSG::Level | get_verbosity () const |
Getter for the verbosity level. | |
const std::string | class_name () const |
Getter for the class name. | |
void | print (MSG::Level level, std::string where, std::string msg) const |
message print out method | |
void | print (MSG::Level level, std::string msg) const |
message print out method | |
Protected Attributes | |
char | _buf [200] |
char buffer for message manipulation | |
std::vector< bool > | _verbosity |
holder for enabled message levels | |
MSG::Level | _verbosity_level |
holder for specified verbosity level | |
std::string | _name |
class name holder | |
Private Member Functions | |
void | reset () |
A method to reset members. | |
Bool_t | initialize () |
A method to initialize and prepare for running analysis. | |
Bool_t | finalize () |
A method to finalize data processing. | |
Private Attributes | |
std::vector< ana_base * > | _analyzers |
A vector of analysis modules. | |
std::map< ana_base *, Bool_t > | _ana_status |
A map of analysis module status. | |
PROCESS_FLAG | _process |
Processing status flag. | |
UInt_t | _nevents |
Number of events being processed. | |
UInt_t | _index |
Index of currently processing event. | |
std::string | _ofile_name |
Output file name. | |
TFile * | _fout |
Output file pointer. | |
storage_manager * | _storage |
Storage manager pointer. |
A class to be loaded with arbitrary number of ana_base inherited analysis modules.
This class process data by applying loaded analysis modules in consecutive order.
Definition at line 29 of file ana_processor.hh.
Process flag enum.
INIT |
Process is @ the initialization stage. |
READY |
Process is ready to start data processing. |
PROCESSING |
Process is processing data. |
FINISHED |
Process has finished processing allevents. |
Definition at line 34 of file ana_processor.hh.
00034 { 00035 INIT, 00036 READY, 00037 PROCESSING, 00038 FINISHED 00039 };
larlight::ana_processor::ana_processor | ( | ) |
Default constructor.
Definition at line 8 of file ana_processor.cc.
References _fout, larlight::larlight_base::_name, _ofile_name, _storage, larlight::storage_manager::get(), and reset().
00008 { 00009 _name="ana_processor"; 00010 _ofile_name=""; 00011 _storage=storage_manager::get(); 00012 _fout=0; 00013 reset(); 00014 }
larlight::ana_processor::~ana_processor | ( | ) | [inline] |
void larlight::ana_processor::add_input_file | ( | std::string | name | ) | [inline] |
Setter for an input DATA file name.
Definition at line 55 of file ana_processor.hh.
References _storage, and larlight::storage_manager::add_in_filename().
Referenced by main().
00055 {_storage->add_in_filename(name);}
Size_t larlight::ana_processor::add_process | ( | ana_base * | ana | ) | [inline] |
A method to append analysis class instance. Returns index number.
Definition at line 83 of file ana_processor.hh.
References _analyzers.
Referenced by main().
00083 {_analyzers.push_back(ana); return _analyzers.size()-1;}
const std::string larlight::larlight_base::class_name | ( | ) | const [inline, inherited] |
Getter for the class name.
Definition at line 49 of file larlight_base.hh.
References larlight::larlight_base::_name.
00049 {return _name;};
Bool_t larlight::ana_processor::finalize | ( | ) | [private] |
A method to finalize data processing.
Definition at line 196 of file ana_processor.cc.
References _ana_status, _analyzers, _process, larlight::larlight_base::_verbosity, larlight::MSG::DEBUG, larlight::MSG::ERROR, FINISHED, PROCESSING, READY, reset(), and larlight::Message::send().
Referenced by process_event(), and run().
00196 { 00197 00198 if(_verbosity[MSG::DEBUG]) 00199 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"called..."); 00200 00201 if(_process!=PROCESSING && _process!=READY) { 00202 Message::send(MSG::ERROR,__FUNCTION__, 00203 "Logic error: the function should not be called."); 00204 return false; 00205 } 00206 00207 Bool_t status=true; 00208 for(std::vector<ana_base*>::iterator iter(_analyzers.begin()); 00209 iter!=_analyzers.end(); 00210 ++iter) { 00211 00212 _ana_status[(*iter)]=_ana_status[(*iter)] && (*iter)->finalize(); 00213 00214 status = status && _ana_status[(*iter)]; 00215 } 00216 00217 _process=FINISHED; 00218 reset(); 00219 return status; 00220 }
Bool_t larlight::ana_processor::get_ana_status | ( | ana_base * | ptr | ) | const |
Getter of running analysis status.
Definition at line 222 of file ana_processor.cc.
References _ana_status.
00222 { 00223 00224 std::map<ana_base*,Bool_t>::const_iterator iter(_ana_status.find(ptr)); 00225 if(iter==_ana_status.end()) return false; 00226 00227 else return (*iter).second; 00228 00229 }
ana_base* larlight::ana_processor::get_process | ( | Size_t | loc | ) | [inline] |
A method to inquir attached analysis class instance.
Definition at line 86 of file ana_processor.hh.
References _analyzers.
00086 {return (_analyzers.size() > loc) ? _analyzers[loc] : 0;}
PROCESS_FLAG larlight::ana_processor::get_process_status | ( | ) | [inline] |
A method to inquire the process status.
Definition at line 89 of file ana_processor.hh.
References _process.
00089 {return _process;}
MSG::Level larlight::larlight_base::get_verbosity | ( | ) | const [inline, inherited] |
Getter for the verbosity level.
Definition at line 46 of file larlight_base.hh.
References larlight::larlight_base::_verbosity_level.
00046 {return _verbosity_level;};
Bool_t larlight::ana_processor::initialize | ( | ) | [private] |
A method to initialize and prepare for running analysis.
Definition at line 51 of file ana_processor.cc.
References _analyzers, _fout, _index, _nevents, _ofile_name, _process, _storage, larlight::larlight_base::_verbosity, larlight::larlight_base::_verbosity_level, larlight::MSG::DEBUG, larlight::MSG::ERROR, INIT, larlight::storage_manager::open(), READY, larlight::Message::send(), set_verbosity(), and larlight::MSG::WARNING.
Referenced by process_event(), and run().
00051 { 00052 00053 set_verbosity(_verbosity_level); 00054 00055 if(_verbosity[MSG::DEBUG]) 00056 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"called..."); 00057 00058 if(_process!=INIT){ 00059 Message::send(MSG::ERROR,__FUNCTION__, 00060 "Logic error: the function should not be called."); 00061 return false; 00062 } 00063 00064 //_storage->set_io_mode(storage_manager::READ); 00065 if(!_storage->open()) { 00066 00067 Message::send(MSG::ERROR,__FUNCTION__,"File I/O failure..."); 00068 00069 return false; 00070 00071 } 00072 00073 if(_ofile_name.size()==0) 00074 00075 Message::send(MSG::WARNING,__FUNCTION__, 00076 "Analysis output file will not be created for this time..."); 00077 00078 else 00079 00080 _fout=TFile::Open(_ofile_name.c_str(),"RECREATE"); 00081 00082 00083 Bool_t status = true; 00084 00085 for(std::vector<ana_base*>::iterator iter(_analyzers.begin()); 00086 iter!=_analyzers.end(); 00087 ++iter) { 00088 00089 (*iter)->set_output_file(_fout); 00090 00091 if(!((*iter)->initialize())){ 00092 00093 Message::send(MSG::ERROR,__PRETTY_FUNCTION__, 00094 Form("Failed to initialize: %s",(*iter)->class_name().c_str())); 00095 00096 status = false; 00097 } 00098 00099 } 00100 _process=READY; 00101 _index=0; 00102 _nevents=0; 00103 return status; 00104 }
void larlight::larlight_base::print | ( | MSG::Level | level, | |
std::string | msg | |||
) | const [inline, inherited] |
message print out method
Definition at line 56 of file larlight_base.hh.
00057 {if(_verbosity.at(level)) Message::send(level,msg);};
void larlight::larlight_base::print | ( | MSG::Level | level, | |
std::string | where, | |||
std::string | msg | |||
) | const [inline, inherited] |
message print out method
Definition at line 52 of file larlight_base.hh.
References larlight::larlight_base::_verbosity, and larlight::Message::send().
Referenced by larutil::GeometryUtilities::CalculatePitch(), larutil::GeometryUtilities::CalculatePitchPolar(), larlight::storage_manager::create_data_ptr(), larutil::LArProperties::DriftVelocity(), larutil::LArUtilBase::LoadData(), main(), larlight::storage_manager::prepare_tree(), and larlight::storage_manager::read_event().
00053 {if(_verbosity.at(level)) Message::send(level,where,msg);};
Bool_t larlight::ana_processor::process_event | ( | UInt_t | index = 0 |
) |
A method to process just one event.
Definition at line 106 of file ana_processor.cc.
References _ana_status, _analyzers, _index, _nevents, _process, _storage, larlight::MSG::ERROR, finalize(), larlight::storage_manager::go_to(), INIT, initialize(), larlight::storage_manager::next_event(), PROCESSING, READY, and larlight::Message::send().
Referenced by run().
00106 { 00107 00108 if(_process==INIT) { 00109 00110 if(!initialize()) { 00111 Message::send(MSG::ERROR,__FUNCTION__,"Aborting."); 00112 return false; 00113 } 00114 else 00115 _process=PROCESSING; 00116 } 00117 00118 if(_process==READY) 00119 _process=PROCESSING; 00120 00121 Bool_t event_found = index ? _storage->go_to(index) : _storage->next_event(); 00122 00123 if(event_found){ 00124 00125 for(std::vector<ana_base*>::iterator iter(_analyzers.begin()); 00126 iter!=_analyzers.end(); 00127 ++iter) 00128 _ana_status[(*iter)]=(*iter)->analyze(_storage); 00129 00130 _index++; 00131 _nevents++; 00132 00133 return true; 00134 00135 } 00136 else 00137 return finalize(); 00138 }
void larlight::ana_processor::reset | ( | ) | [private] |
A method to reset members.
Definition at line 30 of file ana_processor.cc.
References _ana_status, _analyzers, _fout, _index, _nevents, _process, _storage, larlight::larlight_base::_verbosity, larlight::MSG::DEBUG, INIT, larlight::storage_manager::reset(), and larlight::Message::send().
Referenced by ana_processor(), and finalize().
00030 { 00031 00032 if(_verbosity[MSG::DEBUG]) 00033 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"called..."); 00034 00035 if(_fout){ 00036 _fout->Close(); 00037 _fout=0; 00038 } 00039 00040 if(_storage) 00041 _storage->reset(); 00042 00043 _analyzers.clear(); 00044 _ana_status.clear(); 00045 _nevents=0; 00046 _index=0; 00047 00048 _process=INIT; 00049 }
Bool_t larlight::ana_processor::run | ( | UInt_t | start_index = 0 , |
|
UInt_t | nevents = 0 | |||
) |
A method to run a batch process.
Definition at line 140 of file ana_processor.cc.
References larlight::larlight_base::_buf, _index, _nevents, _process, _storage, larlight::larlight_base::_verbosity, larlight::MSG::DEBUG, larlight::MSG::ERROR, finalize(), larlight::storage_manager::get_entries(), larlight::storage_manager::go_to(), INIT, initialize(), larlight::MSG::NORMAL, process_event(), PROCESSING, and larlight::Message::send().
Referenced by main().
00140 { 00141 00142 if(_verbosity[MSG::DEBUG]) 00143 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"called..."); 00144 00145 Bool_t status=true; 00146 00147 if(_process==INIT) status = initialize(); 00148 00149 if(!status){ 00150 00151 Message::send(MSG::ERROR,__PRETTY_FUNCTION__,"Aborting."); 00152 00153 return false; 00154 } 00155 00156 _index=start_index; 00157 00158 if(start_index) 00159 _storage->go_to(start_index); 00160 00161 if(!nevents) 00162 nevents=_storage->get_entries(); 00163 if(nevents > (_storage->get_entries() - start_index)) 00164 nevents=_storage->get_entries() - start_index; 00165 00166 sprintf(_buf,"Processing %d events from entry %d...",nevents, start_index); 00167 Message::send(MSG::NORMAL,__FUNCTION__,_buf); 00168 00169 int ten_percent_ctr=0; 00170 00171 while(status){ 00172 00173 status=process_event(); 00174 00175 if(nevents && nevents < _nevents){ 00176 Message::send(MSG::NORMAL,__FUNCTION__,Form("Processed %d/%d events! Aborting...",_nevents,nevents)); 00177 finalize(); 00178 break; 00179 } 00180 00181 if(nevents > 10 && (_nevents >= ten_percent_ctr * nevents/10)) { 00182 00183 sprintf(_buf," ... %3d%% done ...",ten_percent_ctr*10); 00184 Message::send(MSG::NORMAL,__FUNCTION__,_buf); 00185 ten_percent_ctr++; 00186 } 00187 00188 if(_process!=PROCESSING) break; 00189 00190 } 00191 00192 return status; 00193 00194 }
void larlight::ana_processor::set_ana_output_file | ( | std::string | name | ) | [inline] |
Setter for an analysis output root file name.
Definition at line 64 of file ana_processor.hh.
References _ofile_name.
Referenced by main().
00064 {_ofile_name=name;}
void larlight::ana_processor::set_data_to_read | ( | DATA::DATA_TYPE | type, | |
Bool_t | read = true | |||
) | [inline] |
Setter to specify a certain data class to be read from input.
Definition at line 70 of file ana_processor.hh.
References _storage, and larlight::storage_manager::set_data_to_read().
00071 {_storage->set_data_to_read(type,read);}
void larlight::ana_processor::set_input_rootdir | ( | std::string | name | ) | [inline] |
Setter for an input ROOT TDirectory name.
Definition at line 58 of file ana_processor.hh.
References _storage, and larlight::storage_manager::set_in_rootdir().
Referenced by main().
00058 {_storage->set_in_rootdir(name);}
void larlight::ana_processor::set_io_mode | ( | storage_manager::MODE | mode | ) | [inline] |
Setter for I/O mode ... READ or WRITE or BOTH.
Definition at line 67 of file ana_processor.hh.
References _storage, and larlight::storage_manager::set_io_mode().
Referenced by main().
00067 {_storage->set_io_mode(mode);}
void larlight::ana_processor::set_output_file | ( | std::string | name | ) | [inline] |
Setter for an output DATA file name.
Definition at line 61 of file ana_processor.hh.
References _storage, and larlight::storage_manager::set_out_filename().
00061 {_storage->set_out_filename(name);}
void larlight::ana_processor::set_verbosity | ( | MSG::Level | level | ) | [virtual] |
Override a method to set verbosity.
It changes the verbosity level of not just this class but also owned other class instances.
Reimplemented from larlight::larlight_base.
Definition at line 16 of file ana_processor.cc.
References _analyzers, _storage, and larlight::larlight_base::set_verbosity().
Referenced by initialize().
00016 { 00017 00018 larlight_base::set_verbosity(level); 00019 if(_storage) 00020 _storage->set_verbosity(level); 00021 00022 for(std::vector<ana_base*>::iterator iter(_analyzers.begin()); 00023 iter!=_analyzers.end(); 00024 ++iter) 00025 00026 (*iter)->set_verbosity(level); 00027 00028 }
std::map<ana_base*,Bool_t> larlight::ana_processor::_ana_status [private] |
A map of analysis module status.
Definition at line 103 of file ana_processor.hh.
Referenced by finalize(), get_ana_status(), process_event(), and reset().
std::vector<ana_base*> larlight::ana_processor::_analyzers [private] |
A vector of analysis modules.
Definition at line 102 of file ana_processor.hh.
Referenced by add_process(), finalize(), get_process(), initialize(), process_event(), reset(), and set_verbosity().
char larlight::larlight_base::_buf[200] [protected, inherited] |
char buffer for message manipulation
Definition at line 57 of file larlight_base.hh.
Referenced by larlight::storage_manager::open(), larlight::storage_manager::prepare_tree(), and run().
TFile* larlight::ana_processor::_fout [private] |
Output file pointer.
Definition at line 109 of file ana_processor.hh.
Referenced by ana_processor(), initialize(), and reset().
UInt_t larlight::ana_processor::_index [private] |
Index of currently processing event.
Definition at line 107 of file ana_processor.hh.
Referenced by initialize(), process_event(), reset(), and run().
std::string larlight::larlight_base::_name [protected, inherited] |
class name holder
Definition at line 64 of file larlight_base.hh.
Referenced by larlight::ana_base::ana_base(), ana_processor(), larlight::larlight_base::class_name(), larutil::DetectorProperties::DetectorProperties(), larutil::Geometry::Geometry(), larutil::GeometryUtilities::GeometryUtilities(), larutil::LArProperties::LArProperties(), larutil::LArUtilBase::LArUtilBase(), larutil::LArUtilBase::LoadData(), and larlight::storage_manager::storage_manager().
UInt_t larlight::ana_processor::_nevents [private] |
Number of events being processed.
Definition at line 106 of file ana_processor.hh.
Referenced by initialize(), process_event(), reset(), and run().
std::string larlight::ana_processor::_ofile_name [private] |
Output file name.
Definition at line 108 of file ana_processor.hh.
Referenced by ana_processor(), initialize(), and set_ana_output_file().
Processing status flag.
Definition at line 105 of file ana_processor.hh.
Referenced by finalize(), get_process_status(), initialize(), process_event(), reset(), and run().
storage_manager* larlight::ana_processor::_storage [private] |
Storage manager pointer.
Definition at line 110 of file ana_processor.hh.
Referenced by add_input_file(), ana_processor(), initialize(), process_event(), reset(), run(), set_data_to_read(), set_input_rootdir(), set_io_mode(), set_output_file(), and set_verbosity().
std::vector<bool> larlight::larlight_base::_verbosity [protected, inherited] |
holder for enabled message levels
Definition at line 62 of file larlight_base.hh.
Referenced by larlight::storage_manager::close(), finalize(), initialize(), larlight::storage_manager::open(), larlight::storage_manager::prepare_tree(), larlight::larlight_base::print(), larlight::storage_manager::reset(), reset(), run(), and larlight::larlight_base::set_verbosity().
MSG::Level larlight::larlight_base::_verbosity_level [protected, inherited] |
holder for specified verbosity level
Definition at line 63 of file larlight_base.hh.
Referenced by larlight::larlight_base::get_verbosity(), initialize(), and larlight::larlight_base::set_verbosity().