ndmspc  v1.1.1-1
NGnTree.h
1 #ifndef Ndmspc_NGnTree_H
2 #define Ndmspc_NGnTree_H
3 #include <TObject.h>
4 #include <THnSparse.h>
5 #include <TH1.h>
6 #include <TH2.h>
7 #include <TH3.h>
8 #include <TObject.h>
9 #include <vector>
10 #include "NBinning.h"
11 #include "NParameters.h"
12 #include "NStorageTree.h"
13 #include "NWsClient.h"
14 // #include "NBinningPoint.h"
15 
16 namespace Ndmspc {
17 
28 using NHnSparseProcessFuncPtr = void (*)(Ndmspc::NBinningPoint *, TList *, TList *, int);
29 
41 using NGnProcessFuncPtr = void (*)(Ndmspc::NBinningPoint *, TList *, TList *, int);
42 
53 using NGnBeginFuncPtr = void (*)(Ndmspc::NBinningPoint *, int);
54 
63 using NGnEndFuncPtr = void (*)(Ndmspc::NBinningPoint *, int);
64 
75 class NGnNavigator;
76 class NGnTree : public TObject {
77  public:
81  NGnTree();
82 
89  NGnTree(std::vector<TAxis *> axes, std::string filename = "", std::string treename = "ngnt");
90 
97  NGnTree(TObjArray * axes, std::string filename = "", std::string treename = "ngnt");
98 
105  NGnTree(NGnTree * ngnt, std::string filename = "", std::string treename = "ngnt");
106 
112  NGnTree(NBinning * binning, NStorageTree * treeStorage);
113 
122  NGnTree(THnSparse * hns, std::string parameterAxis, const std::string & outFileName = "/tmp/ngnt_imported.root",
123  json cfg = json::object());
124 
128  virtual ~NGnTree();
129 
134  virtual void Print(Option_t * option = "") const override;
135 
144  virtual void Draw(Option_t * option = "") override;
145 
155  void Play(int timeout = 0, std::string binning = "", std::vector<int> outputPointIds = {0},
156  std::vector<std::vector<int>> ranges = {}, Option_t * option = "", std::string ws = "");
157 
162  NBinning * GetBinning() const { return fBinning; }
163 
168  void SetBinning(NBinning * binning) { fBinning = binning; }
169 
175 
180  std::map<std::string, TList *> GetOutputs() const { return fOutputs; }
181 
187  TList * GetOutput(std::string name = "");
188 
193  void SetOutputs(std::map<std::string, TList *> outputs) { fOutputs = outputs; }
194 
199  NGnTree * GetInput() const { return fInput; }
200 
205  void SetInput(NGnTree * input) { fInput = input; }
206 
211  NGnNavigator * GetNavigator() const { return fNavigator; }
212 
217  void SetNavigator(NGnNavigator * navigator);
218 
224  bool IsPureCopy() const { return fIsPureCopy; }
225 
231  void SetIsPureCopy(bool val) { fIsPureCopy = val; }
232 
237  Long64_t GetEntries() const { return fTreeStorage ? fTreeStorage->GetEntries() : 0; }
238 
245  Int_t GetEntry(Long64_t entry, bool checkBinningDef = true);
246 
254  Int_t GetEntry(std::vector<std::vector<int>> range, bool checkBinningDef = true);
255 
261  bool Close(bool write = false);
262 
270  bool Process(NGnProcessFuncPtr func, const json & cfg = json::object(), std::string binningName = "",
271  NGnBeginFuncPtr beginFunc = nullptr, NGnEndFuncPtr endFunc = nullptr);
272 
281  bool Process(NGnProcessFuncPtr func, const std::vector<std::string> & defNames, const json & cfg = json::object(),
282  NBinning * binningIn = nullptr, NGnBeginFuncPtr beginFunc = nullptr, NGnEndFuncPtr endFunc = nullptr);
283 
290  TList * Projection(const json & cfg, std::string binningName = "");
300  NGnNavigator * Reshape(std::string binningName, std::vector<std::vector<int>> levels, int level = 0,
301  std::map<int, std::vector<int>> ranges = {}, std::map<int, std::vector<int>> rangesBase = {});
312  NGnNavigator * GetResourceStatisticsNavigator(std::string binningName, std::vector<std::vector<int>> levels,
313  int level = 0, std::map<int, std::vector<int>> ranges = {},
314  std::map<int, std::vector<int>> rangesBase = {});
319  NParameters * GetParameters() const { return fParameters; }
320 
325  NWsClient * GetWsClient() const { return fWsClient; }
326 
331  void SetWsClient(NWsClient * client) { fWsClient = client; }
332 
341  bool InitParameters(const std::vector<std::string> & paramNames);
342 
350  static NGnTree * Open(const std::string & filename, const std::string & branches = "",
351  const std::string & treename = "ngnt");
352 
360  static NGnTree * Open(TTree * tree, const std::string & branches = "", TFile * file = nullptr);
361 
374  static NGnTree * Import(const std::string & findPath, const std::string & fileName,
375  const std::vector<std::string> & headers,
376  const std::string & outFileName = "/tmp/ngnt_imported.root",bool close=true);
377 
385  static std::string BuildObjectPath(const json & cfg, const json & objCfg, const NBinningPoint * point);
386 
387  protected:
388  NBinning * fBinning{nullptr};
390  std::map<std::string, TList *> fOutputs;
391  NGnTree * fInput{nullptr};
394  NWsClient * fWsClient{nullptr};
395  bool fIsPureCopy{false};
396 
398  ClassDefOverride(NGnTree, 1);
400 };
401 } // namespace Ndmspc
402 #endif
Represents a single point in multi-dimensional binning.
Definition: NBinningPoint.h:23
NBinning object for managing multi-dimensional binning and axis definitions.
Definition: NBinning.h:45
Navigator object for managing hierarchical data structures and projections.
Definition: NGnNavigator.h:22
NDMSPC tree object for managing multi-dimensional data storage and processing.
Definition: NGnTree.h:76
NBinning * GetBinning() const
Get pointer to binning object.
Definition: NGnTree.h:162
std::map< std::string, TList * > GetOutputs() const
Get outputs map.
Definition: NGnTree.h:180
virtual void Draw(Option_t *option="") override
Draws the tree object.
Definition: NGnTree.cxx:487
NGnNavigator * GetNavigator() const
Returns the navigator associated with this tree.
Definition: NGnTree.h:211
void SetIsPureCopy(bool val)
Sets the pure copy status of the tree.
Definition: NGnTree.h:231
bool Close(bool write=false)
Close the tree, optionally writing data.
Definition: NGnTree.cxx:916
void SetBinning(NBinning *binning)
Set binning object pointer.
Definition: NGnTree.h:168
bool IsPureCopy() const
Checks if the tree is a pure copy.
Definition: NGnTree.h:224
virtual ~NGnTree()
Destructor.
Definition: NGnTree.cxx:451
Int_t GetEntry(Long64_t entry, bool checkBinningDef=true)
Get entry by index.
Definition: NGnTree.cxx:930
virtual void Print(Option_t *option="") const override
Print tree information.
Definition: NGnTree.cxx:463
void SetInput(NGnTree *input)
Set input NGnTree pointer.
Definition: NGnTree.h:205
NGnTree()
Default constructor.
Definition: NGnTree.cxx:156
static NGnTree * Import(const std::string &findPath, const std::string &fileName, const std::vector< std::string > &headers, const std::string &outFileName="/tmp/ngnt_imported.root", bool close=true)
Imports an NGnTree from a specified file.
Definition: NGnTree.cxx:1307
NGnNavigator * Reshape(std::string binningName, std::vector< std::vector< int >> levels, int level=0, std::map< int, std::vector< int >> ranges={}, std::map< int, std::vector< int >> rangesBase={})
Reshape navigator using binning name and levels.
Definition: NGnTree.cxx:1237
NBinning * fBinning
Binning object.
Definition: NGnTree.h:388
NWsClient * fWsClient
! WebSocket client for communication
Definition: NGnTree.h:394
TList * GetOutput(std::string name="")
Get output list by name.
Definition: NGnTree.cxx:796
NParameters * GetParameters() const
Returns the parameters associated with this tree.
Definition: NGnTree.h:319
NGnTree * fInput
Input NGnTree for processing.
Definition: NGnTree.h:391
void SetWsClient(NWsClient *client)
Sets the NWsClient instance for this object.
Definition: NGnTree.h:331
NStorageTree * GetStorageTree() const
Get pointer to storage tree object.
Definition: NGnTree.h:174
NGnTree * GetInput() const
Get pointer to input NGnTree.
Definition: NGnTree.h:199
void SetOutputs(std::map< std::string, TList * > outputs)
Set outputs map.
Definition: NGnTree.h:193
bool InitParameters(const std::vector< std::string > &paramNames)
Initializes the parameters for the tree using the provided parameter names.
Definition: NGnTree.cxx:1286
std::map< std::string, TList * > fOutputs
Outputs.
Definition: NGnTree.h:390
NGnNavigator * fNavigator
! Navigator object
Definition: NGnTree.h:392
Long64_t GetEntries() const
Get number of entries in storage tree.
Definition: NGnTree.h:237
NParameters * fParameters
Parameters object.
Definition: NGnTree.h:393
TList * Projection(const json &cfg, std::string binningName="")
Project tree data using configuration and binning name.
Definition: NGnTree.cxx:1135
NGnNavigator * GetResourceStatisticsNavigator(std::string binningName, std::vector< std::vector< int >> levels, int level=0, std::map< int, std::vector< int >> ranges={}, std::map< int, std::vector< int >> rangesBase={})
Returns a navigator for resource statistics based on binning and levels.
Definition: NGnTree.cxx:1250
NStorageTree * fTreeStorage
Tree storage.
Definition: NGnTree.h:389
static std::string BuildObjectPath(const json &cfg, const json &objCfg, const NBinningPoint *point)
Helper: build object path string from configuration and a binning point.
Definition: NGnTree.cxx:43
void SetNavigator(NGnNavigator *navigator)
Sets the navigator for this tree.
Definition: NGnTree.cxx:902
static NGnTree * Open(const std::string &filename, const std::string &branches="", const std::string &treename="ngnt")
Open NGnTree from file.
Definition: NGnTree.cxx:812
bool Process(NGnProcessFuncPtr func, const json &cfg=json::object(), std::string binningName="", NGnBeginFuncPtr beginFunc=nullptr, NGnEndFuncPtr endFunc=nullptr)
Process tree data using a function pointer and configuration.
Definition: NGnTree.cxx:496
bool fIsPureCopy
Flag indicating pure copy mode.
Definition: NGnTree.h:395
NWsClient * GetWsClient() const
Returns the associated NWsClient instance.
Definition: NGnTree.h:325
void Play(int timeout=0, std::string binning="", std::vector< int > outputPointIds={0}, std::vector< std::vector< int >> ranges={}, Option_t *option="", std::string ws="")
Play tree data with optional binning and output point IDs.
Definition: NGnTree.cxx:954
NParameters object.
Definition: NParameters.h:13
NDMSPC storage tree object for managing ROOT TTree-based data storage.
Definition: NStorageTree.h:22
Long64_t GetEntries() const
Get number of entries in the tree.
Definition: NStorageTree.h:69
WebSocket client for asynchronous communication using libwebsockets.
Definition: NWsClient.h:49