00001
00014 #ifndef STORAGE_MANAGER_HH
00015 #define STORAGE_MANAGER_HH
00016
00017 #include <TFile.h>
00018 #include <TChain.h>
00019 #include "data_base.hh"
00020 #include "larlight_base.hh"
00021 #include "track.hh"
00022 #include "mctruth.hh"
00023 #include "user_info.hh"
00024 #include "spacepoint.hh"
00025 #include "pmtfifo.hh"
00026 #include "tpcfifo.hh"
00027 #include "trigger.hh"
00028 #include "wire.hh"
00029 #include "hit.hh"
00030 #include "cluster.hh"
00031 #include "shower.hh"
00032 #include "mcshower.hh"
00033 #include "simch.hh"
00034 #include "calorimetry.hh"
00035 #include "pulse.hh"
00036 #include "vertex.hh"
00037 #include "endpoint2d.hh"
00038
00039 namespace larlight {
00044 class storage_manager : public larlight_base {
00045
00046 public:
00047
00049 enum MODE{
00050 READ,
00051 WRITE,
00052 BOTH,
00053 UNDEFINED
00054 };
00055
00057 enum STATUS{
00058 INIT,
00059 OPENED,
00060 READY_IO,
00061 OPERATING,
00062 CLOSED
00063 };
00064
00066 storage_manager(MODE mode=UNDEFINED);
00067
00069 virtual ~storage_manager(){}
00070
00072 void set_data_to_read(DATA::DATA_TYPE type,bool read=true)
00073 {_read_data_array[type]=read;}
00074
00076 void set_io_mode(MODE mode) {_mode=mode;}
00077
00079
00080 void add_in_filename(std::string name) {_in_fnames.push_back(name);}
00081
00083 void set_in_rootdir(std::string name){_name_tdirectory=name;}
00084
00086 void set_out_filename(std::string name) {_out_fname=name;}
00087
00089 void enable_event_alignment(bool doit=true) {_check_alignment=doit;}
00090
00092 MODE io_mode() const {return _mode;}
00093
00095 std::vector<std::string> input_filename() const {return _in_fnames;}
00096
00098 std::string output_filename() const {return _out_fname;}
00099
00101 STATUS status() const {return _status;}
00102
00104 void reset();
00105
00107 bool open();
00108
00110 bool is_open();
00111
00113 bool is_ready_io();
00114
00116 bool next_event();
00117
00119 bool go_to(UInt_t index);
00120
00122 bool close();
00123
00127 event_base* get_data(DATA::DATA_TYPE type);
00128
00130 std::vector<larlight::DATA::DATA_TYPE> list_data_types();
00131
00133 static storage_manager* get()
00134 { if(!me) me= new storage_manager(); return me; }
00135
00137 static void kill()
00138 { if(me) delete me;}
00139
00141 inline UInt_t get_entries() const {return _nevents;}
00142
00144 inline UInt_t get_index() const {return _index;}
00145
00147 inline UInt_t get_entries_read() const {return _nevents_read;}
00148
00150 inline UInt_t get_entires_written() const {return _nevents_written;}
00151
00152 private:
00153
00154 static storage_manager* me;
00155
00157 void create_data_ptr(DATA::DATA_TYPE type);
00158
00159 void delete_data_ptr(DATA::DATA_TYPE type);
00160
00162 bool read_event();
00163
00165 bool write_event();
00166
00168 bool prepare_tree();
00169
00171 UInt_t _index;
00172
00174 UInt_t _nevents, _nevents_read, _nevents_written;
00175
00177 STATUS _status;
00178
00180 MODE _mode;
00181
00183 bool _read_data_array[DATA::DATA_TYPE_MAX];
00184
00186 bool _write_data_array[DATA::DATA_TYPE_MAX];
00187
00189 bool _check_alignment;
00190
00192 event_base *_ptr_data_array[DATA::DATA_TYPE_MAX];
00193
00195 std::string _out_fname;
00196 std::vector<std::string> _in_fnames;
00197 std::string _name_tdirectory;
00198
00200 const std::string _treename;
00201
00203
00204 TFile *_fout;
00205
00207
00208 TChain *_in_ch[DATA::DATA_TYPE_MAX];
00209 TTree *_out_ch[DATA::DATA_TYPE_MAX];
00210
00211 };
00212 }
00213 #endif
00214