A higher level manager class to handle event-wise data and output file. More...
#include <storage_manager.hh>
Public Types | |
enum | MODE { READ, WRITE, BOTH, UNDEFINED } |
Defines I/O mode ... currently only read OR write. More... | |
enum | STATUS { INIT, OPENED, READY_IO, OPERATING, CLOSED } |
Defines I/O process status flags. More... | |
Public Member Functions | |
storage_manager (MODE mode=UNDEFINED) | |
Default constructor. Allow user to specify the I/O mode here. | |
virtual | ~storage_manager () |
Default destructor. | |
void | set_data_to_read (DATA::DATA_TYPE type, bool read=true) |
Setter to specify a certain data class to be read from input. | |
void | set_io_mode (MODE mode) |
Setter for I/O mode. | |
void | add_in_filename (std::string name) |
Setter for input filename. | |
void | set_in_rootdir (std::string name) |
Setter for input file's TDirectory name. | |
void | set_out_filename (std::string name) |
Setter for output filename. | |
void | enable_event_alignment (bool doit=true) |
Setter to disable event alignment check. | |
MODE | io_mode () const |
Getter for I/O mode. | |
std::vector< std::string > | input_filename () const |
Getter for an array of input files set by the user. | |
std::string | output_filename () const |
Getter for I/O file name. | |
STATUS | status () const |
Getter for process status stamp. See storage_manager::STATUS. | |
void | reset () |
Reset variables and I/O process to prepare for a new I/O. | |
bool | open () |
Open I/O file. Return true upon success. | |
bool | is_open () |
Utility boolean to check if file is opened. | |
bool | is_ready_io () |
Utility boolean to check if file is opened and ready for I/O. | |
bool | next_event () |
Stores an event to the output in WRITE mode, and loads an event to local memory in READ mode. | |
bool | go_to (UInt_t index) |
Move to the TTree entry with the provided index number. | |
bool | close () |
Close I/O file. | |
event_base * | get_data (DATA::DATA_TYPE type) |
Universal data pointer getter to return data_base* pointer for specified data type. | |
std::vector < larlight::DATA::DATA_TYPE > | list_data_types () |
What data is available? | |
UInt_t | get_entries () const |
Getter for a number of events in the file. | |
UInt_t | get_index () const |
Getter for a TTree index. | |
UInt_t | get_entries_read () const |
Getter for a counter of read-out events. | |
UInt_t | get_entires_written () const |
Getter for a counter of written-out events. | |
virtual void | set_verbosity (MSG::Level level) |
Setter for the verbosity level. | |
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 | |
Static Public Member Functions | |
static storage_manager * | get () |
Getter for a shared object instance pointer. Not limited to be a singleton. | |
static void | kill () |
killer for a shared object instance. | |
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 | create_data_ptr (DATA::DATA_TYPE type) |
void | delete_data_ptr (DATA::DATA_TYPE type) |
bool | read_event () |
Load next event from imput. | |
bool | write_event () |
Write the current event into output. | |
bool | prepare_tree () |
Called upon opening a file to prepare read/write events in TTree. | |
Private Attributes | |
UInt_t | _index |
tree index marker | |
UInt_t | _nevents |
number of events read/written | |
UInt_t | _nevents_read |
UInt_t | _nevents_written |
STATUS | _status |
status control stamp | |
MODE | _mode |
I/O mode. | |
bool | _read_data_array [DATA::DATA_TYPE_MAX] |
Boolean to record what data to be read out from a file. | |
bool | _write_data_array [DATA::DATA_TYPE_MAX] |
Boolean to record what data to be written out from a file. | |
bool | _check_alignment |
Boolean to enable event alignment check. | |
event_base * | _ptr_data_array [DATA::DATA_TYPE_MAX] |
Data pointer array for reading. | |
std::string | _out_fname |
I/O filename. | |
std::vector< std::string > | _in_fnames |
std::string | _name_tdirectory |
const std::string | _treename |
TTree name. | |
TFile * | _fout |
ROOT file instance. | |
TChain * | _in_ch [DATA::DATA_TYPE_MAX] |
TTree instance. | |
TTree * | _out_ch [DATA::DATA_TYPE_MAX] |
Static Private Attributes | |
static storage_manager * | me = 0 |
shared object instance pointer |
A higher level manager class to handle event-wise data and output file.
Definition at line 44 of file storage_manager.hh.
Defines I/O process status flags.
Definition at line 57 of file storage_manager.hh.
larlight::storage_manager::storage_manager | ( | storage_manager::MODE | mode = UNDEFINED |
) |
Default constructor. Allow user to specify the I/O mode here.
Definition at line 9 of file storage_manager.cc.
References _check_alignment, _fout, _mode, larlight::larlight_base::_name, _name_tdirectory, _out_fname, _status, INIT, and reset().
Referenced by get().
00010 : larlight_base(), _treename("pmt_data") 00011 { 00012 _name="storage_manager"; 00013 //_event_wf=0; 00014 _fout=0; 00015 _out_fname=""; 00016 _name_tdirectory=""; 00017 _status=INIT; 00018 _check_alignment=true; 00019 00020 reset(); 00021 _mode=mode; 00022 00023 };
virtual larlight::storage_manager::~storage_manager | ( | ) | [inline, virtual] |
void larlight::storage_manager::add_in_filename | ( | std::string | name | ) | [inline] |
Setter for input filename.
Definition at line 80 of file storage_manager.hh.
References _in_fnames.
Referenced by larlight::ana_processor::add_input_file(), and main().
00080 {_in_fnames.push_back(name);}
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 larlight::storage_manager::close | ( | ) |
Close I/O file.
Definition at line 437 of file storage_manager.cc.
References _fout, _in_ch, _mode, _out_ch, _out_fname, _ptr_data_array, _status, larlight::larlight_base::_verbosity, CLOSED, larlight::DATA::DATA_TREE_NAME, larlight::DATA::DATA_TYPE_MAX, larlight::MSG::DEBUG, delete_data_ptr(), larlight::MSG::ERROR, larlight::MSG::INFO, INIT, larlight::MSG::NORMAL, OPENED, OPERATING, READ, READY_IO, larlight::Message::send(), status(), and larlight::MSG::WARNING.
Referenced by main(), prepare_tree(), and reset().
00437 { 00438 00439 if(_verbosity[MSG::DEBUG]) 00440 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"called ..."); 00441 00442 bool status=true; 00443 switch(_status){ 00444 case INIT: 00445 case CLOSED: 00446 Message::send(MSG::ERROR,__FUNCTION__,"Attempt to close file while not operating I/O!"); 00447 status=false; 00448 break; 00449 case OPENED: 00450 case READY_IO: 00451 Message::send(MSG::WARNING,__FUNCTION__,"Closing a file without any I/O operation done!"); 00452 break; 00453 case OPERATING: 00454 if(_mode!=READ){ 00455 00456 //_fout->cd(); 00457 00458 for(size_t i=0; i<DATA::DATA_TYPE_MAX; i++) { 00459 00460 if(!_out_ch[i]) { 00461 00462 if(_verbosity[MSG::DEBUG]) 00463 00464 Message::send(MSG::DEBUG,__FUNCTION__, 00465 Form("Skipping to write a Tree %s_tree...", 00466 DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str())); 00467 00468 continue; 00469 } 00470 00471 if(_verbosity[MSG::INFO]) 00472 00473 Message::send(MSG::INFO,__FUNCTION__,Form("Writing TTree: %s",_out_ch[i]->GetName())); 00474 00475 _fout = _out_ch[i]->GetCurrentFile(); 00476 _fout->cd(); 00477 _out_ch[i]->Write(); 00478 00479 Message::send(MSG::NORMAL,__FUNCTION__, 00480 Form("TTree \"%s\" written with %lld events...", 00481 _out_ch[i]->GetName(), 00482 _out_ch[i]->GetEntries())); 00483 } 00484 } 00485 break; 00486 } 00487 00488 if(status) { 00489 00490 if(_fout) { 00491 00492 Message::send(MSG::NORMAL,__FUNCTION__,Form("Closing the output: %s",_out_fname.c_str())); 00493 _fout->Close(); 00494 00495 } 00496 _fout=0; 00497 00498 for(size_t i=0; i<DATA::DATA_TYPE_MAX; ++i) { 00499 00500 if(_in_ch[i]) { delete _in_ch[i]; _in_ch[i]=0; } 00501 if(_out_ch[i]) { _out_ch[i]=0; } 00502 if(_ptr_data_array[i]) delete_data_ptr((DATA::DATA_TYPE)i); 00503 00504 } 00505 00506 } 00507 00508 if(_verbosity[MSG::DEBUG]) 00509 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"ends ..."); 00510 00511 _status=CLOSED; 00512 return status; 00513 }
void larlight::storage_manager::create_data_ptr | ( | DATA::DATA_TYPE | type | ) | [private] |
Definition at line 327 of file storage_manager.cc.
References _ptr_data_array, larlight::DATA::APAHit, larlight::DATA::Bezier, larlight::DATA::Calorimetry, larlight::DATA::Cluster, larlight::DATA::CrawlerCluster, larlight::DATA::CrawlerHit, larlight::DATA::DATA_TYPE_MAX, larlight::DATA::DBCluster, larlight::DATA::EndPoint2D, larlight::MSG::ERROR, larlight::DATA::Event, larlight::DATA::FeatureEndPoint2D, larlight::DATA::FeatureVertex, larlight::DATA::FFTHit, larlight::DATA::FIFO, larlight::DATA::FuzzyCluster, larlight::DATA::GausHit, larlight::DATA::HarrisEndPoint2D, larlight::DATA::HarrisVertex, larlight::DATA::Hit, larlight::DATA::HoughCluster, larlight::DATA::Kalman3DHit, larlight::DATA::Kalman3DSPS, larlight::DATA::MCNeutrino, larlight::DATA::MCParticle, larlight::DATA::MCShower, larlight::DATA::MCTrajectory, larlight::DATA::MCTruth, larlight::DATA::PMTFIFO, larlight::DATA::PMTPulse_FixedWin, larlight::DATA::PMTPulse_ThresWin, larlight::larlight_base::print(), larlight::DATA::Pulse, larlight::DATA::RFFHit, larlight::DATA::Seed, larlight::DATA::Shower, larlight::DATA::ShowerAngleCluster, larlight::DATA::SimChannel, larlight::DATA::SpacePoint, larlight::DATA::TPCFIFO, larlight::DATA::TPCPulse_FixedWin, larlight::DATA::TPCPulse_ThresWin, larlight::DATA::Track, larlight::DATA::Trigger, larlight::DATA::UserInfo, larlight::DATA::Vertex, and larlight::DATA::Wire.
Referenced by get_data(), and prepare_tree().
00327 { 00328 00329 if(_ptr_data_array[type]) return; 00330 00331 switch(type){ 00332 case DATA::SimChannel: 00333 _ptr_data_array[type]=(event_base*)(new event_simch(type)); 00334 break; 00335 case DATA::MCShower: 00336 _ptr_data_array[type]=(event_base*)(new event_mcshower(type)); 00337 break; 00338 case DATA::Track: 00339 case DATA::Bezier: 00340 case DATA::Kalman3DHit: 00341 case DATA::Kalman3DSPS: 00342 _ptr_data_array[type]=(event_base*)(new event_track(type)); 00343 break; 00344 case DATA::MCTruth: 00345 _ptr_data_array[type]=(event_base*)(new event_mctruth(type)); 00346 break; 00347 case DATA::MCParticle: 00348 _ptr_data_array[type]=(event_base*)(new event_mcpart(type)); 00349 break; 00350 case DATA::SpacePoint: 00351 _ptr_data_array[type]=(event_base*)(new event_sps(type)); 00352 break; 00353 case DATA::UserInfo: 00354 _ptr_data_array[type]=(event_base*)(new event_user(type)); 00355 break; 00356 case DATA::FIFO: 00357 _ptr_data_array[type]=(event_base*)(new event_fifo(type)); 00358 break; 00359 case DATA::PMTFIFO: 00360 _ptr_data_array[type]=(event_base*)(new event_pmtfifo(type)); 00361 break; 00362 case DATA::TPCFIFO: 00363 _ptr_data_array[type]=(event_base*)(new event_tpcfifo(type)); 00364 break; 00365 case DATA::Pulse: 00366 case DATA::PMTPulse_ThresWin: 00367 case DATA::TPCPulse_ThresWin: 00368 case DATA::PMTPulse_FixedWin: 00369 case DATA::TPCPulse_FixedWin: 00370 _ptr_data_array[type]=(event_base*)(new event_pulse(type)); 00371 break; 00372 case DATA::Trigger: 00373 _ptr_data_array[type]=(event_base*)(new trigger(type)); 00374 break; 00375 case DATA::Wire: 00376 _ptr_data_array[type]=(event_base*)(new event_wire(type)); 00377 break; 00378 case DATA::Hit: 00379 case DATA::CrawlerHit: 00380 case DATA::GausHit: 00381 case DATA::APAHit: 00382 case DATA::FFTHit: 00383 case DATA::RFFHit: 00384 _ptr_data_array[type]=(event_base*)(new event_hit(type)); 00385 break; 00386 case DATA::Cluster: 00387 case DATA::CrawlerCluster: 00388 case DATA::DBCluster: 00389 case DATA::FuzzyCluster: 00390 case DATA::HoughCluster: 00391 case DATA::ShowerAngleCluster: 00392 _ptr_data_array[type]=(event_base*)(new event_cluster(type)); 00393 break; 00394 case DATA::Shower: 00395 _ptr_data_array[type]=(event_base*)(new event_shower(type)); 00396 break; 00397 case DATA::Vertex: 00398 case DATA::FeatureVertex: 00399 case DATA::HarrisVertex: 00400 _ptr_data_array[type]=(event_base*)(new event_vertex(type)); 00401 break; 00402 case DATA::EndPoint2D: 00403 case DATA::FeatureEndPoint2D: 00404 case DATA::HarrisEndPoint2D: 00405 _ptr_data_array[type]=(event_base*)(new event_endpoint2d(type)); 00406 break; 00407 case DATA::Calorimetry: 00408 _ptr_data_array[type]=(event_base*)(new event_calorimetry(type)); 00409 break; 00410 case DATA::MCNeutrino: 00411 print(MSG::ERROR,__FUNCTION__,Form("MCNeutrino is stored within MCTruth! Retrieve MCTruth instead.")); 00412 break; 00413 case DATA::MCTrajectory: 00414 print(MSG::ERROR,__FUNCTION__,Form("MCTrajectory is stored within MCParticle! Retrieve MCParticle instead.")); 00415 break; 00416 case DATA::Seed: 00417 case DATA::Event: 00418 case DATA::DATA_TYPE_MAX: 00419 print(MSG::ERROR,__FUNCTION__,Form("Data identifier not supported: %d",(int)type)); 00420 break; 00421 } 00422 00423 return; 00424 }
void larlight::storage_manager::delete_data_ptr | ( | DATA::DATA_TYPE | type | ) | [private] |
Definition at line 426 of file storage_manager.cc.
References _ptr_data_array.
Referenced by close().
00426 { 00427 00428 if(!_ptr_data_array[type]) return; 00429 00430 delete _ptr_data_array[type]; 00431 00432 _ptr_data_array[type]=0; 00433 00434 return; 00435 }
void larlight::storage_manager::enable_event_alignment | ( | bool | doit = true |
) | [inline] |
Setter to disable event alignment check.
Definition at line 89 of file storage_manager.hh.
References _check_alignment.
00089 {_check_alignment=doit;}
static storage_manager* larlight::storage_manager::get | ( | ) | [inline, static] |
Getter for a shared object instance pointer. Not limited to be a singleton.
Definition at line 133 of file storage_manager.hh.
References me, and storage_manager().
Referenced by larlight::ana_processor::ana_processor().
00134 { if(!me) me= new storage_manager(); return me; }
event_base * larlight::storage_manager::get_data | ( | DATA::DATA_TYPE | type | ) |
Universal data pointer getter to return data_base* pointer for specified data type.
A user then cast the pointer type to whatever the relevant data class pointer type to access members.
Definition at line 25 of file storage_manager.cc.
References _fout, _mode, _out_ch, _ptr_data_array, _write_data_array, create_data_ptr(), larlight::DATA::DATA_TREE_NAME, READ, larlight::Message::send(), and larlight::MSG::WARNING.
Referenced by main().
00025 { 00026 00027 // If data class object does not exist, and if it's either WRITE or BOTH mode, create it. 00028 if(!_ptr_data_array[type] && _mode != READ){ 00029 00030 create_data_ptr(type); 00031 00032 if(_ptr_data_array[(size_t)type]) { 00033 00034 _fout->cd(); 00035 00036 _out_ch[(size_t)type]=new TTree(Form("%s_tree",DATA::DATA_TREE_NAME[type].c_str()), 00037 Form("%s Tree",DATA::DATA_TREE_NAME[type].c_str())); 00038 _out_ch[(size_t)type]->SetMaxTreeSize (1024*1024*1024); 00039 _out_ch[(size_t)type]->SetMaxVirtualSize (1024*1024*1024); 00040 00041 _out_ch[(size_t)type]->Branch(Form("%s_branch",DATA::DATA_TREE_NAME[type].c_str()), 00042 _ptr_data_array[(size_t)type]->GetName(), 00043 &(_ptr_data_array[(size_t)type])); 00044 00045 Message::send(MSG::WARNING,__FUNCTION__, 00046 Form("Requested tree %s which does not exists yet. Created a new one.", 00047 _out_ch[(size_t)type]->GetName()) 00048 ); 00049 00050 _write_data_array[(size_t)type]=true; 00051 } 00052 } 00053 00054 return (event_base*)(_ptr_data_array[type]); 00055 00056 }
UInt_t larlight::storage_manager::get_entires_written | ( | ) | const [inline] |
Getter for a counter of written-out events.
Definition at line 150 of file storage_manager.hh.
References _nevents_written.
00150 {return _nevents_written;}
UInt_t larlight::storage_manager::get_entries | ( | ) | const [inline] |
Getter for a number of events in the file.
Definition at line 141 of file storage_manager.hh.
References _nevents.
Referenced by larlight::ana_processor::run().
00141 {return _nevents;}
UInt_t larlight::storage_manager::get_entries_read | ( | ) | const [inline] |
Getter for a counter of read-out events.
Definition at line 147 of file storage_manager.hh.
References _nevents_read.
00147 {return _nevents_read;}
UInt_t larlight::storage_manager::get_index | ( | ) | const [inline] |
Getter for a TTree index.
Definition at line 144 of file storage_manager.hh.
References _index.
00144 {return _index;}
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 larlight::storage_manager::go_to | ( | UInt_t | index | ) |
Move to the TTree entry with the provided index number.
Referenced by larlight::ana_processor::process_event(), and larlight::ana_processor::run().
std::vector<std::string> larlight::storage_manager::input_filename | ( | ) | const [inline] |
Getter for an array of input files set by the user.
Definition at line 95 of file storage_manager.hh.
References _in_fnames.
00095 {return _in_fnames;}
MODE larlight::storage_manager::io_mode | ( | ) | const [inline] |
Getter for I/O mode.
Definition at line 92 of file storage_manager.hh.
References _mode.
00092 {return _mode;}
bool larlight::storage_manager::is_open | ( | ) |
bool larlight::storage_manager::is_ready_io | ( | ) |
static void larlight::storage_manager::kill | ( | ) | [inline, static] |
killer for a shared object instance.
Definition at line 137 of file storage_manager.hh.
References me.
std::vector< larlight::DATA::DATA_TYPE > larlight::storage_manager::list_data_types | ( | ) |
What data is available?
Definition at line 58 of file storage_manager.cc.
References _ptr_data_array, and larlight::DATA::DATA_TYPE_MAX.
00058 { 00059 std::vector<larlight::DATA::DATA_TYPE> list; 00060 for(int i=0;i<larlight::DATA::DATA_TYPE_MAX;i++) { 00061 if( _ptr_data_array[i]) { list.push_back((larlight::DATA::DATA_TYPE)(i)); } 00062 } 00063 return list; 00064 }
bool larlight::storage_manager::next_event | ( | ) |
Stores an event to the output in WRITE mode, and loads an event to local memory in READ mode.
Definition at line 536 of file storage_manager.cc.
References _mode, _nevents_read, _status, BOTH, CLOSED, larlight::MSG::ERROR, INIT, OPENED, OPERATING, READ, read_event(), READY_IO, larlight::Message::send(), UNDEFINED, WRITE, and write_event().
Referenced by main(), and larlight::ana_processor::process_event().
00536 { 00537 00538 bool status=true; 00539 00540 switch(_status){ 00541 case READY_IO: 00542 // first event 00543 _status=OPERATING; 00544 case OPERATING: 00545 switch(_mode) { 00546 case READ: 00547 status=read_event(); 00548 break; 00549 case WRITE: 00550 status=write_event(); 00551 break; 00552 case BOTH: 00553 if(_nevents_read) 00554 status = write_event(); 00555 if(status) status = read_event(); 00556 break; 00557 case UNDEFINED: 00558 break; 00559 } 00560 break; 00561 case INIT: 00562 case OPENED: 00563 case CLOSED: 00564 Message::send(MSG::ERROR,__FUNCTION__,"Cannot perform I/O on a closed file!"); 00565 status=false; 00566 break; 00567 } 00568 00569 return status; 00570 }
bool larlight::storage_manager::open | ( | ) |
Open I/O file. Return true upon success.
Definition at line 133 of file storage_manager.cc.
References larlight::larlight_base::_buf, _fout, _in_fnames, _mode, _out_fname, _status, larlight::larlight_base::_verbosity, BOTH, larlight::MSG::DEBUG, larlight::MSG::ERROR, larlight::MSG::NORMAL, OPENED, prepare_tree(), READ, larlight::Message::send(), status(), UNDEFINED, and WRITE.
Referenced by larlight::ana_processor::initialize(), and main().
00134 { 00135 bool status=true; 00136 00137 if(_verbosity[MSG::DEBUG]) 00138 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"called ..."); 00139 00140 if((_mode==READ || _mode==BOTH) && _in_fnames.size()==0){ 00141 Message::send(MSG::ERROR, 00142 __FUNCTION__, 00143 "Open attempt w/o specifing a file name!"); 00144 return false; 00145 } 00146 00147 if((_mode==WRITE || _mode==BOTH) && _out_fname.size()==0){ 00148 Message::send(MSG::ERROR, 00149 __FUNCTION__, 00150 "Open attempt w/o specifing a file name!"); 00151 return false; 00152 } 00153 00154 switch(_mode){ 00155 00156 case BOTH: 00157 case READ: 00158 00159 for(std::vector<std::string>::const_iterator iter(_in_fnames.begin()); 00160 iter!=_in_fnames.end(); 00161 ++iter) { 00162 00163 TFile *fin = TFile::Open((*iter).c_str(),"READ"); 00164 if(!fin) { 00165 sprintf(_buf,"Open attempt failed for a file: %s", (*iter).c_str()); 00166 Message::send(MSG::ERROR,__FUNCTION__,_buf); 00167 status=false; 00168 }else{ 00169 sprintf(_buf,"Opening a file in READ mode: %s", (*iter).c_str()); 00170 Message::send(MSG::NORMAL,__FUNCTION__,_buf); 00171 fin->Close(); 00172 } 00173 00174 } 00175 00176 if(_mode==READ) break; 00177 case WRITE: 00178 sprintf(_buf,"Opening a file in WRITE mode: %s",_out_fname.c_str()); 00179 Message::send(MSG::NORMAL,__FUNCTION__,_buf); 00180 _fout=TFile::Open(_out_fname.c_str(),"RECREATE"); 00181 if(!_fout) { 00182 sprintf(_buf,"Open attempt failed for a file: %s", _out_fname.c_str()); 00183 Message::send(MSG::ERROR,__FUNCTION__,_buf); 00184 status=false; 00185 } 00186 break; 00187 00188 case UNDEFINED: 00189 Message::send(MSG::ERROR, 00190 __FUNCTION__, 00191 "Open attempt w/o specifing I/O mode!"); 00192 status=false; 00193 break; 00194 } 00195 00196 if(!status) return status; 00197 00198 if(_verbosity[MSG::DEBUG]) 00199 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"ends ..."); 00200 00201 _status=OPENED; 00202 return prepare_tree(); 00203 };
std::string larlight::storage_manager::output_filename | ( | ) | const [inline] |
Getter for I/O file name.
Definition at line 98 of file storage_manager.hh.
References _out_fname.
00098 {return _out_fname;}
bool larlight::storage_manager::prepare_tree | ( | ) | [private] |
Called upon opening a file to prepare read/write events in TTree.
Definition at line 205 of file storage_manager.cc.
References larlight::larlight_base::_buf, _fout, _in_ch, _in_fnames, _index, _mode, _name_tdirectory, _nevents, _nevents_read, _nevents_written, _out_ch, _ptr_data_array, _read_data_array, _status, larlight::larlight_base::_verbosity, _write_data_array, BOTH, close(), create_data_ptr(), larlight::DATA::DATA_TREE_NAME, larlight::DATA::DATA_TYPE_MAX, larlight::MSG::DEBUG, larlight::MSG::ERROR, OPENED, larlight::larlight_base::print(), READ, READY_IO, larlight::Message::send(), status(), larlight::MSG::WARNING, and WRITE.
Referenced by open().
00205 { 00206 00207 bool status=true; 00208 00209 std::vector<size_t> nevents_array(DATA::DATA_TYPE_MAX,0); 00210 00211 if(_verbosity[MSG::DEBUG]) 00212 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"called ..."); 00213 00214 if(_status!=OPENED) { 00215 sprintf(_buf,"Unexpected function call @ _status=%d!",_status); 00216 Message::send(MSG::ERROR,__FUNCTION__,_buf); 00217 status=false; 00218 } 00219 00220 for(size_t i=0; i<DATA::DATA_TYPE_MAX; ++i){ 00221 00222 if(!_status) break; 00223 00224 if(_mode!=WRITE && _read_data_array[i]) { 00225 00226 std::string tree_name(Form("%s_tree",DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str())); 00227 00228 if(_name_tdirectory.size()>0) 00229 _in_ch[i]=new TChain(Form("%s/%s",_name_tdirectory.c_str(),tree_name.c_str()), 00230 Form("%s Tree",DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str())); 00231 else 00232 _in_ch[i]=new TChain(tree_name.c_str(), 00233 Form("%s Tree",DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str())); 00234 00235 for(size_t j=0; j<_in_fnames.size(); ++j) 00236 00237 _in_ch[i]->AddFile(_in_fnames[j].c_str()); 00238 00239 // Ignore ROOT error message due to not finding a TTree 00240 gErrorIgnoreLevel = kBreak; 00241 nevents_array[i]=_in_ch[i]->GetEntries(); 00242 gErrorIgnoreLevel = kWarning; 00243 00244 if(nevents_array[i]) { 00245 00246 print(MSG::DEBUG,__FUNCTION__, 00247 Form("Found %zu events found in TTree %s ...",nevents_array[i],tree_name.c_str())); 00248 00249 create_data_ptr((DATA::DATA_TYPE)i); 00250 00251 _in_ch[i]->SetBranchAddress(Form("%s_branch",DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str()),&(_ptr_data_array[i])); 00252 00253 if(!_nevents) _nevents = nevents_array[i]; 00254 00255 if(_mode==BOTH) _write_data_array[i]=true; 00256 00257 }else{ 00258 delete _in_ch[i]; 00259 _in_ch[i]=0; 00260 if(_mode==BOTH) _write_data_array[i]=false; 00261 } 00262 } 00263 00264 if(_mode!=READ && _write_data_array[i] ) { 00265 00266 _fout->cd(); 00267 00268 _out_ch[i]=new TTree(Form("%s_tree",DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str()), 00269 Form("%s Tree",DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str())); 00270 _out_ch[i]->SetMaxTreeSize (1024*1024*1024); 00271 _out_ch[i]->SetMaxVirtualSize (1024*1024*1024); 00272 00273 create_data_ptr((DATA::DATA_TYPE)i); 00274 00275 _out_ch[i]->Branch(Form("%s_branch",DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str()), 00276 _ptr_data_array[i]->GetName(), 00277 &(_ptr_data_array[i])); 00278 00279 } 00280 00281 _nevents_written=0; 00282 _nevents_read=0; 00283 _index=0; 00284 00285 } 00286 00287 if( _mode!=WRITE && _nevents==0) { 00288 Message::send(MSG::ERROR,__FUNCTION__,"Did not find any relevant data tree!"); 00289 status=false; 00290 } 00291 00292 size_t min_nevents=_nevents; 00293 00294 for(size_t i=0; i<DATA::DATA_TYPE_MAX; ++i) { 00295 00296 if(nevents_array[i] && _nevents!=nevents_array[i]) { 00297 00298 Message::send(MSG::WARNING,__FUNCTION__, 00299 Form("Different number of entries found on tree: %s (found %ud while previous found %zu)", 00300 DATA::DATA_TREE_NAME[(DATA::DATA_TYPE)i].c_str(),_nevents, nevents_array[i])); 00301 if( nevents_array[i] < min_nevents) 00302 00303 min_nevents = nevents_array[i]; 00304 } 00305 00306 } 00307 00308 if(_nevents!=min_nevents) { 00309 00310 Message::send(MSG::WARNING,__FUNCTION__, 00311 Form("Running the event loop with the smallest TTree's entries (=%zu)",min_nevents)); 00312 00313 _nevents = min_nevents; 00314 00315 } 00316 00317 if(status) _status=READY_IO; 00318 00319 else close(); 00320 00321 if(_verbosity[MSG::DEBUG]) 00322 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"ends ..."); 00323 00324 return status; 00325 }
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(), create_data_ptr(), larutil::LArProperties::DriftVelocity(), larutil::LArUtilBase::LoadData(), main(), prepare_tree(), and read_event().
00053 {if(_verbosity.at(level)) Message::send(level,where,msg);};
bool larlight::storage_manager::read_event | ( | ) | [private] |
Load next event from imput.
Definition at line 572 of file storage_manager.cc.
References _check_alignment, _in_ch, _index, _mode, _nevents, _nevents_read, _ptr_data_array, _read_data_array, larlight::DATA::DATA_TYPE_MAX, larlight::MSG::ERROR, larlight::event_base::event_id(), larlight::DATA::INVALID_UINT, larlight::larlight_base::print(), and WRITE.
Referenced by next_event().
00572 { 00573 00574 if(_index>=_nevents) 00575 return false; 00576 00577 UInt_t event_id = DATA::INVALID_UINT; 00578 00579 for(size_t i=0; i<DATA::DATA_TYPE_MAX; ++i) { 00580 00581 if(_in_ch[i]) { 00582 00583 _in_ch[i]->GetEntry(_index); 00584 00585 if(_mode != WRITE && _read_data_array[i] && _check_alignment) { 00586 00587 if(event_id == DATA::INVALID_UINT) event_id = _ptr_data_array[i]->event_id(); 00588 00589 else if(event_id != _ptr_data_array[i]->event_id()) { 00590 00591 print(MSG::ERROR,__FUNCTION__, 00592 Form("Detected event-alignment mismatch! (%d != %d)",event_id,_ptr_data_array[i]->event_id())); 00593 00594 return false; 00595 00596 } 00597 } // end check event alignment 00598 } // end read-in data @ _index 00599 } // end looping over data types 00600 00601 _index++; 00602 _nevents_read++; 00603 return true; 00604 }
void larlight::storage_manager::reset | ( | ) |
Reset variables and I/O process to prepare for a new I/O.
Definition at line 66 of file storage_manager.cc.
References _in_ch, _in_fnames, _index, _mode, _nevents, _nevents_read, _nevents_written, _out_ch, _ptr_data_array, _read_data_array, _status, larlight::larlight_base::_verbosity, _write_data_array, close(), CLOSED, larlight::DATA::DATA_TYPE_MAX, larlight::MSG::DEBUG, INIT, OPENED, OPERATING, READY_IO, larlight::Message::send(), and UNDEFINED.
Referenced by main(), larlight::ana_processor::reset(), and storage_manager().
00067 { 00068 if(_verbosity[MSG::DEBUG]) 00069 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"called ..."); 00070 00071 switch(_status){ 00072 case READY_IO: 00073 case OPENED: 00074 case OPERATING: 00075 close(); 00076 break; 00077 case INIT: 00078 case CLOSED: 00079 break; 00080 } 00081 00082 _index=0; 00083 _nevents=0; 00084 _nevents_written=0; 00085 _nevents_read=0; 00086 _mode=UNDEFINED; 00087 _status=INIT; 00088 _in_fnames.clear(); 00089 00090 for(size_t i=0; i<DATA::DATA_TYPE_MAX; ++i) { 00091 _read_data_array[i]=true; // Attempt to read in all data by default 00092 _write_data_array[i]=false; // Attemp to write no data by default 00093 _in_ch[i]=0; 00094 _out_ch[i]=0; 00095 _ptr_data_array[i]=0; 00096 } 00097 00098 if(_verbosity[MSG::DEBUG]) 00099 Message::send(MSG::DEBUG,__PRETTY_FUNCTION__,"ends ..."); 00100 };
void larlight::storage_manager::set_data_to_read | ( | DATA::DATA_TYPE | type, | |
bool | read = true | |||
) | [inline] |
Setter to specify a certain data class to be read from input.
Definition at line 72 of file storage_manager.hh.
References _read_data_array.
Referenced by main(), and larlight::ana_processor::set_data_to_read().
00073 {_read_data_array[type]=read;}
void larlight::storage_manager::set_in_rootdir | ( | std::string | name | ) | [inline] |
Setter for input file's TDirectory name.
Definition at line 83 of file storage_manager.hh.
References _name_tdirectory.
Referenced by larlight::ana_processor::set_input_rootdir().
00083 {_name_tdirectory=name;}
void larlight::storage_manager::set_io_mode | ( | MODE | mode | ) | [inline] |
Setter for I/O mode.
Definition at line 76 of file storage_manager.hh.
References _mode.
Referenced by main(), and larlight::ana_processor::set_io_mode().
00076 {_mode=mode;}
void larlight::storage_manager::set_out_filename | ( | std::string | name | ) | [inline] |
Setter for output filename.
Definition at line 86 of file storage_manager.hh.
References _out_fname.
Referenced by main(), and larlight::ana_processor::set_output_file().
00086 {_out_fname=name;}
void larlight::larlight_base::set_verbosity | ( | MSG::Level | level | ) | [virtual, inherited] |
Setter for the verbosity level.
Reimplemented in larlight::ana_processor.
Definition at line 8 of file larlight_base.cc.
References larlight::larlight_base::_verbosity, larlight::larlight_base::_verbosity_level, larlight::MSG::DEBUG, larlight::MSG::ERROR, larlight::MSG::INFO, larlight::MSG::MSG_TYPE_MAX, larlight::MSG::NORMAL, and larlight::MSG::WARNING.
Referenced by larlight::larlight_base::larlight_base(), main(), and larlight::ana_processor::set_verbosity().
00010 { 00011 00012 _verbosity_level=level; 00013 00014 for(size_t i=(size_t)(MSG::DEBUG); i<(size_t)(MSG::MSG_TYPE_MAX); ++i) 00015 _verbosity[i]=false; 00016 00017 switch(level){ 00018 case MSG::DEBUG: 00019 _verbosity[MSG::DEBUG]=true; 00020 case MSG::INFO: 00021 _verbosity[MSG::INFO]=true; 00022 case MSG::NORMAL: 00023 _verbosity[MSG::NORMAL]=true; 00024 case MSG::WARNING: 00025 _verbosity[MSG::WARNING]=true; 00026 case MSG::ERROR: 00027 _verbosity[MSG::ERROR]=true; 00028 case MSG::MSG_TYPE_MAX: 00029 break; 00030 } 00031 00032 }
STATUS larlight::storage_manager::status | ( | ) | const [inline] |
Getter for process status stamp. See storage_manager::STATUS.
Definition at line 101 of file storage_manager.hh.
References _status.
Referenced by close(), is_open(), is_ready_io(), open(), and prepare_tree().
00101 {return _status;}
bool larlight::storage_manager::write_event | ( | ) | [private] |
Write the current event into output.
Definition at line 606 of file storage_manager.cc.
References _index, _mode, _nevents_written, _out_ch, _ptr_data_array, larlight::event_base::clear_data(), larlight::DATA::DATA_TYPE_MAX, and WRITE.
Referenced by next_event().
00606 { 00607 00608 for(size_t i=0; i<DATA::DATA_TYPE_MAX; ++i) { 00609 00610 if(!_out_ch[i]) continue; 00611 00612 _out_ch[i]->Fill(); 00613 _ptr_data_array[i]->clear_data(); 00614 00615 } 00616 00617 if(_mode==WRITE) 00618 _index++; 00619 _nevents_written++; 00620 //_event_wf->clear_data(); 00621 return true; 00622 }
char larlight::larlight_base::_buf[200] [protected, inherited] |
char buffer for message manipulation
Definition at line 57 of file larlight_base.hh.
Referenced by open(), prepare_tree(), and larlight::ana_processor::run().
bool larlight::storage_manager::_check_alignment [private] |
Boolean to enable event alignment check.
Definition at line 189 of file storage_manager.hh.
Referenced by enable_event_alignment(), read_event(), and storage_manager().
TFile* larlight::storage_manager::_fout [private] |
ROOT file instance.
Definition at line 204 of file storage_manager.hh.
Referenced by close(), get_data(), open(), prepare_tree(), and storage_manager().
TChain* larlight::storage_manager::_in_ch[DATA::DATA_TYPE_MAX] [private] |
TTree instance.
Definition at line 208 of file storage_manager.hh.
Referenced by close(), prepare_tree(), read_event(), and reset().
std::vector<std::string> larlight::storage_manager::_in_fnames [private] |
Definition at line 196 of file storage_manager.hh.
Referenced by add_in_filename(), input_filename(), open(), prepare_tree(), and reset().
UInt_t larlight::storage_manager::_index [private] |
tree index marker
Definition at line 171 of file storage_manager.hh.
Referenced by get_index(), prepare_tree(), read_event(), reset(), and write_event().
MODE larlight::storage_manager::_mode [private] |
I/O mode.
Definition at line 180 of file storage_manager.hh.
Referenced by close(), get_data(), io_mode(), next_event(), open(), prepare_tree(), read_event(), reset(), set_io_mode(), storage_manager(), and write_event().
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(), larlight::ana_processor::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 storage_manager().
std::string larlight::storage_manager::_name_tdirectory [private] |
Definition at line 197 of file storage_manager.hh.
Referenced by prepare_tree(), set_in_rootdir(), and storage_manager().
UInt_t larlight::storage_manager::_nevents [private] |
number of events read/written
Definition at line 174 of file storage_manager.hh.
Referenced by get_entries(), prepare_tree(), read_event(), and reset().
UInt_t larlight::storage_manager::_nevents_read [private] |
Definition at line 174 of file storage_manager.hh.
Referenced by get_entries_read(), next_event(), prepare_tree(), read_event(), and reset().
UInt_t larlight::storage_manager::_nevents_written [private] |
Definition at line 174 of file storage_manager.hh.
Referenced by get_entires_written(), prepare_tree(), reset(), and write_event().
TTree* larlight::storage_manager::_out_ch[DATA::DATA_TYPE_MAX] [private] |
Definition at line 209 of file storage_manager.hh.
Referenced by close(), get_data(), prepare_tree(), reset(), and write_event().
std::string larlight::storage_manager::_out_fname [private] |
I/O filename.
Definition at line 195 of file storage_manager.hh.
Referenced by close(), open(), output_filename(), set_out_filename(), and storage_manager().
event_base* larlight::storage_manager::_ptr_data_array[DATA::DATA_TYPE_MAX] [private] |
Data pointer array for reading.
Definition at line 192 of file storage_manager.hh.
Referenced by close(), create_data_ptr(), delete_data_ptr(), get_data(), list_data_types(), prepare_tree(), read_event(), reset(), and write_event().
bool larlight::storage_manager::_read_data_array[DATA::DATA_TYPE_MAX] [private] |
Boolean to record what data to be read out from a file.
Definition at line 183 of file storage_manager.hh.
Referenced by prepare_tree(), read_event(), reset(), and set_data_to_read().
STATUS larlight::storage_manager::_status [private] |
status control stamp
Definition at line 177 of file storage_manager.hh.
Referenced by close(), is_open(), is_ready_io(), next_event(), open(), prepare_tree(), reset(), status(), and storage_manager().
const std::string larlight::storage_manager::_treename [private] |
TTree name.
Definition at line 200 of file storage_manager.hh.
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 close(), larlight::ana_processor::finalize(), larlight::ana_processor::initialize(), open(), prepare_tree(), larlight::larlight_base::print(), reset(), larlight::ana_processor::reset(), larlight::ana_processor::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(), larlight::ana_processor::initialize(), and larlight::larlight_base::set_verbosity().
bool larlight::storage_manager::_write_data_array[DATA::DATA_TYPE_MAX] [private] |
Boolean to record what data to be written out from a file.
Definition at line 186 of file storage_manager.hh.
Referenced by get_data(), prepare_tree(), and reset().
storage_manager * larlight::storage_manager::me = 0 [static, private] |
shared object instance pointer
Definition at line 154 of file storage_manager.hh.