ndmspc  v1.2.0-0.1.rc3
NStorageTree.h
1 #ifndef Ndmspc_NStorageTree_H
2 #define Ndmspc_NStorageTree_H
3 #include <TObject.h>
4 #include <TTree.h>
5 #include <TFile.h>
6 #include "NBinning.h"
7 #include "NBinningPoint.h"
8 #include "NTreeBranch.h"
9 
10 namespace Ndmspc {
11 
22 class NStorageTree : public TObject {
23  public:
28  NStorageTree(NBinning * binning = nullptr);
29 
33  virtual ~NStorageTree();
34 
39  virtual void Print(Option_t * option = "") const;
40 
45  virtual void Clear(Option_t * option = "");
46 
48 
55  bool SetFileTree(TFile * file, TTree * tree);
56 
63  bool InitTree(const std::string & filename = "", const std::string & treename = "ngnt");
64 
69  Long64_t GetEntries() const { return fTree ? fTree->GetEntries() : 0; }
70 
78  Long64_t GetEntry(Long64_t entry, NBinningPoint * point = nullptr, bool checkBinningDef = false);
79 
80  // Int_t Fill(NBinningPoint * point);
81 
91  Int_t Fill(NBinningPoint * point, NStorageTree * hnstIn = nullptr, bool ignoreFilledCheck = false,
92  std::vector<std::vector<int>> ranges = {}, bool useProjection = false);
93 
100  bool Close(bool write = false, std::map<std::string, TList *> outputs = {});
101 
107  TFile * GetFile() const { return fFile; }
108 
114  Long64_t Merge(TCollection * list);
115 
117 
123  std::vector<std::string> GetBrancheNames(bool onlyEnabled = false) const;
124 
129  std::map<std::string, NTreeBranch> GetBranchesMap() const { return fBranchesMap; }
130 
135  void SetBranchesMap(std::map<std::string, NTreeBranch> map) { fBranchesMap = map; }
136 
144  bool AddBranch(const std::string & name, void * address, const std::string & className);
145 
151  NTreeBranch * GetBranch(const std::string & name);
152 
158  TObject * GetBranchObject(const std::string & name);
159 
165  void SetEnabledBranches(std::vector<std::string> branches, int status = 1);
166 
170  void SetBranchAddresses();
171 
176  NBinning * GetBinning() const { return fBinning; }
177 
182  void SetBinning(NBinning * binning) { fBinning = binning; }
183 
188  TTree * GetTree() const { return fTree; }
189 
194  std::string GetFileName() const { return fFileName; }
195 
200  std::string GetPrefix() const { return fPrefix; }
201 
206  std::string GetPostfix() const { return fPostfix; }
207 
212  void SetOutputs(TMap * outputs) { fOutputs = outputs; }
213 
214  protected:
215  std::string fFileName{"ngnt.root"};
216  TFile * fFile{nullptr};
217  TTree * fTree{nullptr};
218  std::string fPrefix{""};
219  std::string fPostfix{""};
220  std::map<std::string, NTreeBranch> fBranchesMap;
221  TMap * fOutputs;
222  NBinning * fBinning{nullptr};
223 
225  ClassDef(NStorageTree, 1);
227 };
228 } // namespace Ndmspc
229 #endif
Represents a single point in multi-dimensional binning.
Definition: NBinningPoint.h:21
NBinning object for managing multi-dimensional binning and axis definitions.
Definition: NBinning.h:45
NDMSPC storage tree object for managing ROOT TTree-based data storage.
Definition: NStorageTree.h:22
std::map< std::string, NTreeBranch > fBranchesMap
Branches map.
Definition: NStorageTree.h:220
void SetBranchAddresses()
Set addresses for all branches.
TFile * GetFile() const
Returns the associated TFile object.
Definition: NStorageTree.h:107
TTree * fTree
! TTree container
Definition: NStorageTree.h:217
Long64_t GetEntries() const
Get number of entries in the tree.
Definition: NStorageTree.h:69
Long64_t Merge(TCollection *list)
Merge storage trees from a collection.
void SetEnabledBranches(std::vector< std::string > branches, int status=1)
Set enabled/disabled status for branches.
virtual void Clear(Option_t *option="")
Clear storage tree data.
bool SetFileTree(TFile *file, TTree *tree)
Tree handling.
std::string GetFileName() const
Get file name.
Definition: NStorageTree.h:194
bool AddBranch(const std::string &name, void *address, const std::string &className)
Add a branch to the tree.
Long64_t GetEntry(Long64_t entry, NBinningPoint *point=nullptr, bool checkBinningDef=false)
Get entry by index and fill NBinningPoint.
std::vector< std::string > GetBrancheNames(bool onlyEnabled=false) const
Branches handling.
std::string fFileName
Current filename.
Definition: NStorageTree.h:215
std::string GetPrefix() const
Get prefix path.
Definition: NStorageTree.h:200
TObject * GetBranchObject(const std::string &name)
Get pointer to branch object by name.
NTreeBranch * GetBranch(const std::string &name)
Get pointer to NTreeBranch by name.
bool InitTree(const std::string &filename="", const std::string &treename="ngnt")
Initialize tree from file and tree name.
std::string GetPostfix() const
Get postfix path.
Definition: NStorageTree.h:206
NBinning * GetBinning() const
Get pointer to binning object.
Definition: NStorageTree.h:176
virtual ~NStorageTree()
Destructor.
bool Close(bool write=false, std::map< std::string, TList * > outputs={})
Close the storage tree, optionally writing outputs.
TFile * fFile
! Current file
Definition: NStorageTree.h:216
NBinning * fBinning
Binning object.
Definition: NStorageTree.h:222
TMap * fOutputs
! Output objects map
Definition: NStorageTree.h:221
void SetBranchesMap(std::map< std::string, NTreeBranch > map)
Set map of branch names to NTreeBranch objects.
Definition: NStorageTree.h:135
TTree * GetTree() const
Get pointer to TTree object.
Definition: NStorageTree.h:188
void SetOutputs(TMap *outputs)
Set outputs map.
Definition: NStorageTree.h:212
NStorageTree(NBinning *binning=nullptr)
Constructor.
virtual void Print(Option_t *option="") const
Print storage tree information.
std::string fPrefix
Prefix path.
Definition: NStorageTree.h:218
std::string fPostfix
Postfix path.
Definition: NStorageTree.h:219
Int_t Fill(NBinningPoint *point, NStorageTree *hnstIn=nullptr, bool ignoreFilledCheck=false, std::vector< std::vector< int >> ranges={}, bool useProjection=false)
Fill tree with NBinningPoint and optional input tree.
void SetBinning(NBinning *binning)
Set binning object pointer.
Definition: NStorageTree.h:182
std::map< std::string, NTreeBranch > GetBranchesMap() const
Get map of branch names to NTreeBranch objects.
Definition: NStorageTree.h:129
NDMSPC tree branch object for managing ROOT TBranch and associated data.
Definition: NTreeBranch.h:18