ndmspc v1.2.0-0.1.rc5
Loading...
Searching...
No Matches
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
10namespace Ndmspc {
11
22class 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.
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.
std::map< std::string, NTreeBranch > fBranchesMap
Branches map.
void SetBranchAddresses()
Set addresses for all branches.
TTree * fTree
! TTree container
Long64_t GetEntries() const
Get number of entries in the tree.
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.
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.
std::string GetPrefix() const
Get prefix path.
std::map< std::string, NTreeBranch > GetBranchesMap() const
Get map of branch names to NTreeBranch objects.
TObject * GetBranchObject(const std::string &name)
Get pointer to branch object by name.
NBinning * GetBinning() const
Get pointer to binning object.
NTreeBranch * GetBranch(const std::string &name)
Get pointer to NTreeBranch by name.
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.
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.
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
NBinning * fBinning
Binning object.
TMap * fOutputs
! Output objects map
TFile * GetFile() const
Returns the associated TFile object.
void SetBranchesMap(std::map< std::string, NTreeBranch > map)
Set map of branch names to NTreeBranch objects.
void SetOutputs(TMap *outputs)
Set outputs map.
NStorageTree(NBinning *binning=nullptr)
Constructor.
virtual void Print(Option_t *option="") const
Print storage tree information.
std::string fPrefix
Prefix path.
std::string fPostfix
Postfix path.
TTree * GetTree() const
Get pointer to TTree object.
void SetBinning(NBinning *binning)
Set binning object pointer.
NDMSPC tree branch object for managing ROOT TBranch and associated data.
Definition NTreeBranch.h:18
Global callback function for libwebsockets client events.