19 #include "w32pragma.h"
35 using namespace hippodraw;
80 ifstream test ( name.c_str (), std::ios::in );
81 if ( test.is_open () == false ) {
82 string what (
"RootController: File `" );
84 what +=
"' was not found.";
86 throw std::runtime_error ( what );
88 file =
new TFile ( name.c_str() );
92 file = first -> second;
104 TFile * file = where -> second;
113 const vector < string > &
119 TFile * file =
openFile ( file_name );
122 TList * keys = file -> GetListOfKeys ();
123 Int_t
size = keys -> GetSize ();
125 for ( Int_t
i = 0;
i <
size;
i++ ) {
126 TObject * obj = keys -> At (
i );
127 TKey * key = dynamic_cast < TKey * > ( obj );
128 const string class_name = key -> GetClassName ();
129 if ( class_name ==
"TTree" ||
130 class_name ==
"TNtuple" ||
131 class_name ==
"TNtupleD" ) {
132 const string name = key -> GetName ();
145 const std::string & treename )
147 TFile * file =
openFile ( filename );
148 if ( file == NULL )
return NULL;
150 TObject *
object = file -> Get ( treename.c_str() );
151 TTree * tree = dynamic_cast <
TTree * > ( object );
158 createNTuple (
const std::string & filename,
const std::string & treename )
161 if ( tree == NULL )
return NULL;
165 return initNTuple ( ntuple, filename, treename );
171 const std::string & treename )
173 string ds_name = filename;
177 ntuple -> setTitle ( treename );
178 ntuple -> setName ( ds_name );
180 controller -> registerNTuple ( ds_name, ntuple );
181 controller -> registerDataSourceFile ( ntuple );
184 ntuple -> addObserver (
this );
195 string::size_type pos = name.find_last_of (
':' );
196 if ( pos == string::npos ) {
201 const string filename = name.substr ( 0, pos );
202 string tree_name = name.substr ( pos + 1 );
203 pos = tree_name.find_first_not_of (
' ' );
204 tree_name.erase ( 0, pos );
215 const std::string &
column )
221 int index = rtuple -> indexOf ( column );
222 vector < int >
shape;
223 rtuple -> fillShape ( shape, index );
224 for (
unsigned int i = 1;
i < shape.size();
i++ ) {
225 dims.push_back ( shape [
i] );
261 TupleToFileMap_t::iterator first =
m_tuple_map.find ( tuple );
264 const string & filename = first -> second;
269 const string & name = first -> second;
270 if ( name == filename ) {
Part of an implementation of the Observable-Observer pattern based on the example in the GOF Patterns...
hippodraw::RootController class interface.
TFile * openFile(const std::string &name)
Attempts to open the file name.
const std::string & version() const
Returns the version of ROOT being used.
hippodraw::RootNTuple class interface.
A DataSource class implemented with a ROOT TBranch objects from a ROOT TTree to store the column data...
bool smartExpandRootNTuple(DataSource *source, std::string &column)
Expands the array column.
virtual void willDelete(const Observable *obs)
Closes the file that was used to create the observed RootNTuple.
column
The column indices for 2 dimension data point tuple.
std::map< std::string, TFile * >::iterator FileMapIterator_t
Short cut to iterator type.
std::vector< intptr_t > shape(numeric::array arr)
DataSource * initNTuple(DataSource *source, const std::string &filename, const std::string &treename)
Initialized and registers new DataSource.
DataSource * createNTuple(const std::string &name)
void fillDimSize(std::vector< int > &dims, const DataSource *source, const std::string &column)
Fills the vector dims.
static RootController * s_instance
The singleton instance of the RootController.
intp size(numeric::array arr)
A singleton class that is the interface between GUI and the DataSource objects.
TupleToFileMap_t m_tuple_map
A map to find which ROOT file was used to create RootNTuple.
std::map< std::string, TFile * > m_file_map
The list of opened ROOT files.
static RootController * instance()
Returns the singleton instance of the RootController.
std::string m_version
The version of ROOT being used.
const std::vector< std::string > & getNTupleNames(const std::string &)
Returns the names of the DataSource objects contained in the file name.
virtual void update(const Observable *)
Does nothing, but satisfies the pure virtual function in base.
DataSourceController class interface.
A Controller class for ROOT files.
TTree * getTree(const std::string &file, const std::string &tree)
Returns the named tree from file in the ROOT file.
virtual ~RootController()
The destructor.
void closeFile(const std::string &name)
Closed the named file, if found in list of opened files.
static DataSourceController * instance()
Returns the pointer to the singleton instance.
std::vector< std::string > m_ntuple_names
Temporary list of DataSource names in the file.
Base class for DataSource.