ndmspc  v1.1.1-1
NGnThreadData.cxx
1 #include <NGnTree.h>
2 #include <NStorageTree.h>
3 #include <TROOT.h>
4 #include <TCanvas.h>
5 #include <mutex>
6 #include "THnSparse.h"
7 #include "NBinningPoint.h"
8 #include "NLogger.h"
9 #include "NUtils.h"
10 #include "NGnThreadData.h"
11 
13 ClassImp(Ndmspc::NGnThreadData);
15 
16 namespace Ndmspc {
19 bool NGnThreadData::Init(size_t id, NGnProcessFuncPtr func, NGnBeginFuncPtr funcBegin, NGnEndFuncPtr endFunc,
20  NGnTree * ngnt, NBinning * binningIn, NGnTree * input, const std::string & filename,
21  const std::string & treename)
22 {
26  SetAssignedIndex(id);
27  SetThreadId(std::this_thread::get_id());
28 
29  TH1::AddDirectory(kFALSE); // Disable ROOT auto directory management
30 
31  // if (!func) {
32  // NLogError("NGnThreadData::Init: Process function is not set !!!");
33  // return false;
34  // }
35  fBeginFunc = funcBegin;
36  fProcessFunc = func;
37  fEndFunc = endFunc;
38 
39  if (ngnt == nullptr) {
40  NLogError("NGnThreadData::Init: NGnTree is nullptr !!!");
41  return false;
42  }
43 
44  fIsPureCopy = ngnt->IsPureCopy();
45 
46  fBiningSource = binningIn;
47 
48  if (fBiningSource == nullptr) {
49  NLogError("NGnThreadData::Init: Binning Source is nullptr !!!");
50  return false;
51  }
52 
53  fHnSparseBase = (NGnTree *)ngnt->Clone();
54  // fHnSparseBase = new NGnTree(hnsb->GetBinning(), (NStorageTree *)hnsb->GetStorageTree()->Clone());
55  // fHnSparseBase = new NGnTree(hnsb->GetBinning(), new NStorageTree(hnsb->GetBinning()));
56  // fHnSparseBase = new NGnTree(hnsb->GetBinning(), nullptr);
57 
58  if (fHnSparseBase->GetBinning() == nullptr) {
59  NLogError("NGnThreadData::InitStorage: Binning is not set !!!");
60  return false;
61  }
62 
63  if (fHnSparseBase->GetStorageTree() == nullptr) {
64  NLogError("NGnThreadData::InitStorage: Storage tree is not set !!!");
65  return false;
66  }
67 
68  // NLogDebug("NGnThreadData::Init: Initializing storage for thread %zu", id);
69  // NGnTree * ngntIn = new NGnTree(ngnt->GetInput(), "");
70  //
71  // fHnSparseBase->SetInput(ngntIn); // Clear input for the thread local NGnTree
72 
74  std::string fn = ts->GetFileName();
75  ts->Clear("F");
76  ts->InitTree(filename.empty() ? fn : filename, treename);
77 
78  NTreeBranch * b = nullptr;
79  // loop over all branches and add them to the new storage tree
80  for (auto & kv : ngnt->GetStorageTree()->GetBranchesMap()) {
81  NLogTrace("NGnThreadData::Init: Adding branch '%s' to thread %zu", kv.first.c_str(), id);
82  b = ts->GetBranch(kv.first);
83  if (b) continue;
84 
85  b = ts->GetBranch(kv.first);
86  if (b) continue;
87 
88  ts->AddBranch(kv.first, nullptr, kv.second.GetObjectClassName());
89  }
90  b = ts->GetBranch("_outputPoint");
91  if (!b) ts->AddBranch("_outputPoint", nullptr, "TList");
92 
93  if (ngnt->GetParameters()) {
94  NLogTrace("NGnThreadData::Init: Setting parameters branch for thread %zu", id);
95  b = ts->GetBranch("_params");
96  if (!b) ts->AddBranch("_params", nullptr, "Ndmspc::NParameters");
97 
98  NParameters * params = (NParameters *)ngnt->GetParameters()->Clone();
99  ts->GetBranch("_params")->SetAddress(params);
101  }
102 
103  // Recreate the point and set the storage tree
105 
106  // for (auto & kv : ts->GetBranchesMap()) {
107  // NLogTrace("NGnThreadData::Init: Adding branch '%s' to thread %zu", kv.first.c_str(), id);
108  // fHnSparseBase->GetStorageTree()->AddBranch(kv.first, nullptr, kv.second.GetObjectClassName());
109  // }
110 
111  // TODO: check if needed or move it somewhere else like Reset();
112  //
113  // Loop over aoll definitions and reset their content and ids
114  for (const auto & name : fHnSparseBase->GetBinning()->GetDefinitionNames()) {
116  if (def) {
117  def->GetContent()->Reset();
118  def->GetIds().clear();
119  }
120  }
121 
122  if (input) {
123  NLogTrace("NGnThreadData::Init: Setting input NGnTree for thread %zu '%s'", id,
124  input->GetStorageTree()->GetFileName().c_str());
125  std::string branches = NUtils::Join(input->GetStorageTree()->GetBrancheNames(true), ',');
126  fHnSparseBase->SetInput(NGnTree::Open(input->GetStorageTree()->GetFileName(), branches)); // Set the input NGnTree
127  }
128 
129  if (ngnt->GetWsClient()) {
131  }
132 
133  // fHnSparseBase->GetBinning()->GetDefinition()->GetContent()->Reset();
134  // fHnSparseBase->GetBinning()->GetDefinition()->GetIds().clear();
135 
136  ExecuteBeginFunction();
137 
138  return true;
139 }
140 
141 void NGnThreadData::Process(const std::vector<int> & coords)
142 {
146  TH1::AddDirectory(kFALSE); // Disable ROOT auto directory management
147 
148  // Ensure this thread has a current pad so that user code calling h->Fit()
149  // does not trigger the non-thread-safe TCanvas::MakeDefCanvas().
150  // gPad is thread_local in ROOT 6: each worker thread starts with nullptr.
151  // We create a minimal batch canvas (batch mode is already set by
152  // NGnTree::Process before ExecuteParallel) and serialise the one-time
153  // TCanvas::Constructor call with a static mutex. After this block gPad is
154  // set for this thread and subsequent Fit() calls find it non-null.
155  if (!gPad) {
156  static std::mutex sPadMutex;
157  std::lock_guard<std::mutex> lk(sPadMutex);
158  // gPad is still nullptr for THIS thread even inside the lock (thread-local);
159  // the mutex only serialises concurrent TCanvas::Constructor calls.
160  TString cname = TString::Format("_ndmspc_wk%zu", GetAssignedIndex());
161  auto * c = new TCanvas(cname, cname, 1, 1);
162  fDeferredDeletes.push_back(c); // cleaned up by FlushDeferredDeletes
163  }
164 
165  fNProcessed++;
166  // NThreadData::Process(coords);
167 
168  // NLogDebug("NGnThreadData::Process: Thread %d processing coordinates %s", GetAssignedIndex(),
169  // NUtils::GetCoordsString(coords).c_str());
170 
171  if (!fHnSparseBase) {
172  NLogError("NGnThreadData::Process: NGnTree is not set in NGnThreadData !!!");
173  return;
174  }
175 
176  if (!fProcessFunc) {
177  NLogError("NGnThreadData::Process: Process function is not set in NGnThreadData !!!");
178  return;
179  }
180 
181  // NBinning * binning = fBiningSource;
182  NBinningDef * binningDef = fBiningSource->GetDefinition();
183  if (binningDef == nullptr) {
184  NLogError("NGnThreadData::Process: Binning definition is not set in NGnThreadData !!!");
185  return;
186  }
187 
189  NGnTree * in = fHnSparseBase->GetInput();
190 
192 
193  Long64_t entry = fBiningSource->GetDefinition()->GetId(coords[0]);
194 
195  if (entry < fHnSparseBase->GetBinning()->GetContent()->GetNbins()) {
196  fHnSparseBase->GetBinning()->GetDefinition()->GetIds().push_back(entry);
197  // entry = binningDef->GetContent()->GetBinContent(entry);
198  // point->SetEntryNumber(entry);
199  NLogDebug("NGnThreadData::Process: [%zu] Skipping entry=%lld, because it was already process !!!",
200  GetAssignedIndex(), entry);
201  return;
202  }
203 
204  if (fResourceMonitor == nullptr) {
206  fResourceMonitor->Initialize(binningDef->GetContent());
208  }
209 
210  // Long64_t entry = binningDef->GetId(coords[0]);
211  // NLogDebug("NGnThreadData::Process: [%zu] Entry in global content mapping: %lld",
212  // GetAssignedIndex(), entry);
213  fBiningSource->GetContent()->GetBinContent(entry, point->GetCoords());
214  point->RecalculateStorageCoords(entry, false);
215  point->SetCfg(fCfg); // Set configuration to the point
216  // point->Print("C");
217 
218  // TODO: check if entry was already processed
219  // So we dont execute the function again
220 
221  // NLogDebug(
222  // "AAA NGnThreadData::Process: Thread %zu processing entry %lld for coordinates %s", GetAssignedIndex(),
223  // entry,
224  // NUtils::GetCoordsString(NUtils::ArrayToVector(point->GetCoords(), point->GetNDimensionsContent())).c_str());
225  point->SetTreeStorage(ts); // Set the storage tree to the binning point
226  point->SetInput(in); // Set the input NGnTree to the binning point
227  TList * outputPoint = new TList();
228 
230 
231  fProcessFunc(point, fHnSparseBase->GetOutput(), outputPoint, GetAssignedIndex());
232 
235 
236  if (!point->GetCfg()["_ndmspc"].is_null()) {
237  fCfg["_ndmspc"] = point->GetCfg()["_ndmspc"]; // Get configuration from the point
238  }
239 
240  // NLogTrace(
241  // "NGnThreadData::Process: [%zu] entry=%lld coords=%s outputPoint=%d", GetAssignedIndex(), entry,
242  // NUtils::GetCoordsString(NUtils::ArrayToVector(point->GetCoords(), point->GetNDimensionsContent())).c_str(),
243  // outputPoint->GetEntries());
244  if (outputPoint->GetEntries() > 0) {
245  NLogTrace(
246  "NGnThreadData::Process: [%zu] Entry '%lld' was accepted. %s", GetAssignedIndex(), entry,
248 
249  if (!fIsPureCopy) {
250  ts->GetBranch("_outputPoint")->SetAddress(outputPoint); // Set the output list as branch address
251  }
252  //
253  // ts->Fill(point, nullptr, false, {}, false);
254  Int_t bytes = ts->Fill(point, nullptr, false, {}, false);
255  if (bytes > 0) {
256  // Long64_t entryInBinDef = binningDefgcc->GetId(coords[0]);
257  // NLogDebug("NGnThreadData::Process: Thread %zu: Filled %d bytes for coordinates %s entry=%lld",
258  // GetAssignedIndex(), bytes, NUtils::GetCoordsString(coords).c_str(), entry);
259 
260  fHnSparseBase->GetBinning()->GetDefinition()->GetIds().push_back(entry);
261  // NLogInfo("Entry number in storage tree: %lld", point->GetEntryNumber());
262  // fHnSparseBase->GetBinning()->GetDefinition()->GetIds().push_back(point->GetEntryNumber());
263  }
264  else {
265  NLogTrace("NGnThreadData::Process: [%zu] Entry '%lld' Fill was done with 0 bytes. Skipping ...",
266  GetAssignedIndex(), entry);
267  // NLogError("NGnThreadData::Process: Thread %zu: zero bytes were writtent for coordinates %s
268  // entry=%lld",
269  // GetAssignedIndex(), NUtils::GetCoordsString(coords).c_str(), entry);
270  }
271  // outputPoint->Print();
272  // outputPoint->Clear(); // Clear the list to avoid memory leaks
273  }
274  else {
275  NLogTrace(
276  "NGnThreadData::Process: [%zu] Entry '%lld' No output %s. Skipping ...", GetAssignedIndex(), entry,
278  // NLogTrace(
279  // "No output for coordinates %s",
280  // NUtils::GetCoordsString(NUtils::ArrayToVector(point->GetCoords(),
281  // point->GetNDimensionsContent())).c_str());
282  }
283 
284  // Defer deletion to FlushDeferredDeletes() on the main thread.
285  // ROOT's cleanup machinery (GarbageCollect, RecursiveRemove) is not thread-safe.
286  {
287  NLogTrace("NGnThreadData::Process: [%zu] Cleaning output list with %d entries for entry '%lld' ...",
288  GetAssignedIndex(), outputPoint->GetEntries(), entry);
289 
290  TObject * obj = nullptr;
291  while ((obj = outputPoint->First())) {
292  outputPoint->Remove(obj);
293  fDeferredDeletes.push_back(obj);
294  }
295  delete outputPoint;
296  }
297 }
298 
299 Long64_t NGnThreadData::Merge(TCollection * list)
300 {
304  Long64_t nmerged = 0;
305 
306  NLogTrace("NGnThreadData::Merge: BEGIN ------------------------------------------------");
307  NLogTrace("NGnThreadData::Merge: Merging thread data from %zu threads ...", list->GetEntries());
308 
309  NStorageTree * ts = nullptr;
310  std::map<std::string, TList *> listOutputs;
311 
312  // TList * listOut = new TList();
313  TList * listTreeStorage = new TList();
314 
315  for (auto obj : *list) {
316  if (obj->IsA() == NGnThreadData::Class()) {
317  NGnThreadData * hnsttd = (NGnThreadData *)obj;
318  NLogDebug("NGnThreadData::Merge: Merging thread %zu processed %lld ...", hnsttd->GetAssignedIndex(),
319  hnsttd->GetNProcessed());
320  ts = hnsttd->GetHnSparseBase()->GetStorageTree();
321  if (!ts) {
322  NLogError("NGnThreadData::Merge: Storage tree is not set in NGnTree !!!");
323  continue;
324  }
325  // hnsttd->Print();
326 
327  for (auto & kv : hnsttd->GetHnSparseBase()->GetOutputs()) {
328  NLogTrace("NGnThreadData::Merge: Found output list '%s' with %d objects", kv.first.c_str(),
329  kv.second ? kv.second->GetEntries() : 0);
330  if (kv.second && !kv.second->IsEmpty()) {
331  NLogTrace("NGnThreadData::Merge: Merging output list '%s' with %d objects", kv.first.c_str(),
332  kv.second->GetEntries());
333  if (listOutputs.find(kv.first) == listOutputs.end()) {
334  if (fHnSparseBase->GetOutput(kv.first)->IsEmpty()) {
335  listOutputs[kv.first] = new TList();
336  fHnSparseBase->GetOutput(kv.first)->AddAll(kv.second);
337  }
338  }
339  else {
340  listOutputs[kv.first]->Add(kv.second);
341  }
342  }
343  }
344 
345  // if (fOutput == nullptr) {
346  // fOutput = hnsttd->GetOutput();
347  // }
348  // else {
349  // listOut->Add(hnsttd->GetOutput());
350  // }
351 
352  NGnTree * hnsb = NGnTree::Open(ts->GetFileName());
353  if (!hnsb) {
354  NLogError("NGnThreadData::Merge: Failed to open NGnTree from file '%s' !!!", ts->GetFileName().c_str());
355  continue;
356  }
357 
358  // hnsb->Print();
359  listTreeStorage->Add(hnsb->GetStorageTree());
360 
361  // TODO: check if needed
362  // fHnSparseBase->GetBinning()->GetDefinition()->GetContent()->Add(
363  // hnsb->GetBinning()->GetDefinition()->GetContent());
364  nmerged++;
365  }
366  }
367  // FIXME: Fix this properly [it should be ok now]
368  fHnSparseBase->GetBinning()->GetContent()->Reset();
369  // Print hnsb binning definition ids
370  for (const auto & name : fBiningSource->GetDefinitionNames()) {
371  NBinningDef * targetBinningDef = fBiningSource->GetDefinition(name);
372  for (auto id : targetBinningDef->GetIds()) {
374  fBiningSource->GetContent()->GetBinContent(id, point.GetCoords());
375  Long64_t bin = fHnSparseBase->GetBinning()->GetContent()->GetBin(point.GetCoords());
376  NLogTrace("NGnThreadData::Merge: Adding def_id=%lld to content_bin=%lld", id, bin);
377  fHnSparseBase->GetBinning()->GetContent()->SetBinContent(bin, id);
378 
379  // fHnSparseBase->GetBinning()->GetDefinition(name)->GetContent()->SetBinContent(bin, id);
380  fHnSparseBase->GetBinning()->GetDefinition(name)->GetIds().push_back(id);
381  }
382  // fHnSparseBase->GetBinning()->GetDefinition(name)->Print();
383  }
384  // FIXME: End
385  NLogDebug("NGnThreadData::Merge: Total entries to merge: %lld", nmerged);
386 
387  for (const auto & name : fHnSparseBase->GetBinning()->GetDefinitionNames()) {
388  auto binningDef = fHnSparseBase->GetBinning()->GetDefinition(name);
389  if (!binningDef) {
390  NLogError("NGnThreadData::Merge: Binning definition '%s' not found in NGnTree !!!", name.c_str());
391  continue;
392  }
393  // add ids from fBiningSource to binningDef
394  // binningDef->GetIds().insert(binningDef->GetIds().end(), fBiningSource->GetDefinition(name)->GetIds().begin(),
395  // fBiningSource->GetDefinition(name)->GetIds().end());
396  NLogTrace("NGnThreadData::Merge: Final IDs in definition '%s': %s", name.c_str(),
397  NUtils::GetCoordsString(binningDef->GetIds(), -1).c_str());
398  }
399 
400  // fHnSparseBase->GetBinning()->GetContent()->Projection(5)->Print("all");
401  // NLogDebug("Not ready to merge, exiting ...");
402  // return 0;
403 
404  NLogTrace("NGnThreadData::Merge: Merging %d storage trees ...", listTreeStorage->GetEntries());
405  // fHnSparseBase->GetBinning()->GetPoint()->Reset();
406  // fHnSparseBase->GetBinning()->GetDefinition("default")->Print();
407  // fHnSparseBase->GetBinning()->GetDefinition("b2")->Print();
408  fHnSparseBase->GetStorageTree()->SetBinning(fHnSparseBase->GetBinning()); // Update binning to the merged one
409  fHnSparseBase->GetStorageTree()->Merge(listTreeStorage);
410  // NLogDebug("Not ready to merge after Storage merge, exiting ...");
411  // return 0;
412 
413  // loop over all output lists and merge them
414  for (auto & kv : listOutputs) {
415  if (kv.second && !kv.second->IsEmpty()) {
416  NLogTrace("NGnThreadData::Merge: Merging output list '%s' with %d objects", kv.first.c_str(),
417  kv.second->GetEntries() + 1);
418  fHnSparseBase->GetOutput(kv.first)->Merge(kv.second);
419  // fHnSparseBase->GetOutput(kv.first)->Print();
420  }
421  }
422 
423  // Loop over binning definitions and merge their contents
425  for (const auto & name : fHnSparseBase->GetBinning()->GetDefinitionNames()) {
426  NBinningDef * binningDef = fHnSparseBase->GetBinning()->GetDefinition(name);
427  if (!binningDef) {
428  NLogError("NGnThreadData::Merge: Binning definition '%s' not found in NGnTree !!!", name.c_str());
429  continue;
430  }
431  // binningDef->Print();
432  // Recalculate binningDef content based on ids
433  binningDef->GetContent()->Reset();
434  for (auto id : binningDef->GetIds()) {
435  fHnSparseBase->GetEntry(id, false);
436  Long64_t bin = binningDef->GetContent()->GetBin(fHnSparseBase->GetBinning()->GetPoint()->GetStorageCoords());
437  binningDef->GetContent()->SetBinContent(bin, id);
438  // binningDef->GetIds().push_back(id);
439  NLogTrace("NGnThreadData::Merge: -> Setting content bin %lld to id %lld", bin, id);
440  }
441  }
442 
443  // print all definitions
444  // for (const auto & name : fHnSparseBase->GetBinning()->GetDefinitionNames()) {
445  // fHnSparseBase->GetBinning()->GetDefinition(name)->Print();
446  // }
447 
448  if (fHnSparseBase->GetInput()) {
449  fHnSparseBase->GetInput()->Close(false);
450  }
451 
452  // Set default setting
456 
457  NLogTrace("NGnThreadData::Merge: END ------------------------------------------------");
458 
460  // NLogError("NGnThreadData::Merge: Not implemented !!!");
462  return nmerged;
463 }
464 
465 void NGnThreadData::ExecuteBeginFunction()
466 {
467  if (fBeginFunc) {
469  }
470 }
471 
472 void NGnThreadData::ExecuteEndFunction()
473 {
474  if (fEndFunc) {
476  }
477 }
478 
480 {
481  if (fDeferredDeletes.empty()) return;
482 
483  NLogTrace("NGnThreadData::FlushDeferredDeletes: [%zu] Deleting %zu deferred objects ...",
485 
487 }
488 
489 } // namespace Ndmspc
Defines binning mapping and content for NDMSPC histograms.
Definition: NBinningDef.h:26
THnSparse * GetContent() const
Get the template content histogram.
Definition: NBinningDef.h:118
Long64_t GetId(size_t index) const
Get bin ID at specified index.
std::vector< Long64_t > GetIds() const
Get list of bin IDs.
Definition: NBinningDef.h:93
Represents a single point in multi-dimensional binning.
Definition: NBinningPoint.h:23
void SetTreeStorage(NStorageTree *s)
Set storage tree object pointer.
bool RecalculateStorageCoords(Long64_t entry=-1, bool useBinningDefCheck=false)
Recalculate storage coordinates for the point.
Int_t * GetStorageCoords() const
Get pointer to storage coordinates array.
Definition: NBinningPoint.h:69
void SetCfg(json cfg)
Set configuration JSON object.
Int_t * GetCoords() const
Get pointer to content coordinates array.
Definition: NBinningPoint.h:57
void SetParameters(NParameters *params)
Set the parameters for this binning point.
void SetInput(NGnTree *input)
Set input NGnTree object pointer.
virtual void Reset()
Reset the binning point to initial state.
json & GetCfg()
Get reference to configuration JSON object.
Int_t GetNDimensionsContent() const
Get number of dimensions in content histogram.
Definition: NBinningPoint.h:51
NBinning object for managing multi-dimensional binning and axis definitions.
Definition: NBinning.h:45
NBinningDef * GetDefinition(const std::string &name="")
Get binning definition by name.
Definition: NBinning.cxx:1021
std::vector< std::string > GetDefinitionNames() const
Get all definition names.
Definition: NBinning.h:270
NBinningPoint * GetPoint()
Get the current binning point.
Definition: NBinning.cxx:1104
THnSparse * GetContent() const
Get the content histogram.
Definition: NBinning.h:217
void SetCurrentDefinitionName(const std::string &name)
Set current definition name.
Definition: NBinning.cxx:1160
Thread-local data object for NDMSPC processing.
Definition: NGnThreadData.h:19
NGnEndFuncPtr fEndFunc
Function pointer to the end function.
NGnBeginFuncPtr fBeginFunc
Function pointer to the begin function.
bool Init(size_t id, NGnProcessFuncPtr func, NGnBeginFuncPtr beginFunc, NGnEndFuncPtr endFunc, NGnTree *ngnt, NBinning *binningIn, NGnTree *input=nullptr, const std::string &filename="", const std::string &treename="ngnt")
Initialize thread data for processing.
NGnThreadData()
Constructor.
NGnTree * GetHnSparseBase() const
Get pointer to base NGnTree object.
Definition: NGnThreadData.h:65
NBinning * fBiningSource
Pointer to the source binning (from the original NGnTree)
virtual void Process(const std::vector< int > &coords)
Process coordinates (virtual).
Long64_t GetNProcessed() const
Get number of processed entries.
Definition: NGnThreadData.h:71
virtual Long64_t Merge(TCollection *list)
Merge thread data from a collection (virtual).
virtual ~NGnThreadData()
Destructor.
json fCfg
Configuration object.
void FlushDeferredDeletes()
Delete deferred ROOT objects, skipping TCanvas/TPad (leaked safely).
std::vector< TObject * > fDeferredDeletes
Objects deferred for single-threaded deletion.
NGnTree * fHnSparseBase
Pointer to the base class.
Long64_t fNProcessed
Number of processed entries.
bool fIsPureCopy
Flag indicating pure copy mode.
NGnProcessFuncPtr fProcessFunc
Function pointer to the processing function.
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
bool Close(bool write=false)
Close the tree, optionally writing data.
Definition: NGnTree.cxx:916
bool IsPureCopy() const
Checks if the tree is a pure copy.
Definition: NGnTree.h:224
Int_t GetEntry(Long64_t entry, bool checkBinningDef=true)
Get entry by index.
Definition: NGnTree.cxx:930
void SetInput(NGnTree *input)
Set input NGnTree pointer.
Definition: NGnTree.h:205
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
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
static NGnTree * Open(const std::string &filename, const std::string &branches="", const std::string &treename="ngnt")
Open NGnTree from file.
Definition: NGnTree.cxx:812
NWsClient * GetWsClient() const
Returns the associated NWsClient instance.
Definition: NGnTree.h:325
NParameters object.
Definition: NParameters.h:13
Monitors and records resource usage (CPU, memory, wall time) for processes or threads.
void Start()
Records the starting resource usage and wall time.
void End()
Records the ending resource usage and wall time.
void Fill(Int_t *coords, int threadId)
Fills resource usage data into the histogram.
THnSparse * GetHnSparse() const
Returns the pointer to the THnSparse histogram.
THnSparse * Initialize(THnSparse *hns)
Initializes the THnSparse histogram for resource data.
NDMSPC storage tree object for managing ROOT TTree-based data storage.
Definition: NStorageTree.h:22
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.
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.
std::vector< std::string > GetBrancheNames(bool onlyEnabled=false) const
Branches handling.
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.
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
Thread-local data object for NDMSPC processing.
Definition: NThreadData.h:21
size_t GetAssignedIndex() const
Get the assigned index for the thread.
Definition: NThreadData.h:96
void SetAssignedIndex(size_t assignedIndex)
Set the assigned index for the thread.
Definition: NThreadData.h:53
NResourceMonitor * fResourceMonitor
Pointer to resource monitor.
Definition: NThreadData.h:133
void SetThreadId(std::thread::id threadId)
Set the thread's unique identifier.
Definition: NThreadData.h:41
NDMSPC tree branch object for managing ROOT TBranch and associated data.
Definition: NTreeBranch.h:18
void SetAddress(void *address, bool deleteExisting=false)
Set address for branch data.
Definition: NTreeBranch.cxx:59
static std::string Join(const std::vector< std::string > &values, const char delim=',')
Join vector of strings into a single string with delimiter.
Definition: NUtils.cxx:966
static std::string GetCoordsString(const std::vector< int > &coords, int index=-1, int width=0)
Get string representation of coordinates.
Definition: NUtils.cxx:1443
static void SafeDeleteObjects(std::vector< TObject * > &objects)
Safely delete a vector of ROOT objects, bypassing GarbageCollect.
Definition: NUtils.cxx:1808
static std::vector< int > ArrayToVector(Int_t *v1, int size)
Convert array to vector.
Definition: NUtils.cxx:1406