HighLAND
TreeManager.hxx
1 #ifndef TreeManager_h
2 #define TreeManager_h
3 
4 #include <stdio.h>
5 #include <iostream>
6 #include <map>
7 #include <vector>
8 #include <TROOT.h>
9 #include <TChain.h>
10 #include <TFile.h>
11 
12 /// This class handles several trees, one of which is selected
13 
14 const UInt_t NMAXTREES = 50;
15 
17 public :
18 
19  TreeManager();
20  virtual ~TreeManager();
21 
22  //--------- Tree operations ------------
23 
24  /// Returns the map of trees
25  std::vector< TTree* >& GetTrees(){return _trees_nonull;}
26 
27  /// Returns the a tree with a given index
28  TTree* GetTree(Int_t index){return _trees[index];}
29 
30  /// Returns the a tree with a given name
31  TTree* GetTree(const std::string& name);
32 
33  /// Returns the a tree set as current
34  TTree* GetTree(){return _trees[GetCurrentTree()];}
35 
36  /// Read a tree from a file provided the index
37  void ReadTree(const std::string& file, Int_t index);
38 
39  /// Read a tree from a file provided the name
40  void ReadTree(const std::string& file, const std::string& name);
41 
42  /// Read all trees from a file
43  void ReadFile(const std::string& file);
44 
45  /// Retuns the tree index provided the name
46  Int_t GetTreeIndex(const std::string& tree_name);
47 
48  /// Retuns the tree name provided the index
49  std::string GetTreeName(Int_t index);
50 
51  /// Retuns the current tree index
52  Int_t GetCurrentTree() const {return _current_tree;}
53 
54  /// Retuns the current tree name
55  std::string GetCurrentTreeName();
56 
57  /// Sets the current tree provided the index
58  void SetCurrentTree(Int_t index){_current_tree=index;}
59 
60  /// Sets the current tree provided the name
61  void SetCurrentTree(const std::string& tree_name);
62 
63  /// Check the existence of a tree provided the index
64  bool HasTree(Int_t index);
65 
66  /// Check the existence of a tree provided the name
67  bool HasTree(const std::string& tree_name);
68 
69  protected:
70 
71  /// Root input or output file
72  TFile *_file;
73 
74  /// Vector of trees
75  std::vector< TTree* > _trees;
76 
77  /// Vector of non NULL trees
78  std::vector< TTree* > _trees_nonull;
79 
80  /// Vector of indices for the non NULL TTree in previous vector
81  std::vector< Int_t > _trees_indices;
82 
83  /// The current tree
85 };
86 
87 #endif
88 
89 
std::vector< Int_t > _trees_indices
Vector of indices for the non NULL TTree in previous vector.
Definition: TreeManager.hxx:81
TTree * GetTree(Int_t index)
Returns the a tree with a given index.
Definition: TreeManager.hxx:28
Int_t GetCurrentTree() const
Retuns the current tree index.
Definition: TreeManager.hxx:52
std::string GetTreeName(Int_t index)
Retuns the tree name provided the index.
Definition: TreeManager.cxx:51
std::string GetCurrentTreeName()
Retuns the current tree name.
void ReadFile(const std::string &file)
Read all trees from a file.
void SetCurrentTree(Int_t index)
Sets the current tree provided the index.
Definition: TreeManager.hxx:58
Int_t GetTreeIndex(const std::string &tree_name)
Retuns the tree index provided the name.
Definition: TreeManager.cxx:40
bool HasTree(Int_t index)
Check the existence of a tree provided the index.
Definition: TreeManager.cxx:59
std::vector< TTree *> _trees
Vector of trees.
Definition: TreeManager.hxx:75
void ReadTree(const std::string &file, Int_t index)
Read a tree from a file provided the index.
Definition: TreeManager.cxx:74
TFile * _file
Root input or output file.
Definition: TreeManager.hxx:72
std::vector< TTree *> & GetTrees()
Returns the map of trees.
Definition: TreeManager.hxx:25
std::vector< TTree *> _trees_nonull
Vector of non NULL trees.
Definition: TreeManager.hxx:78
TTree * GetTree()
Returns the a tree set as current.
Definition: TreeManager.hxx:34
Int_t _current_tree
The current tree.
Definition: TreeManager.hxx:84