Belle II Software  release-08-01-10
SimpleVariableRecorder Class Reference

Class to write collected variables into a root file, Used by VXDQETrainingDataCollectorModule. More...

#include <SimpleVariableRecorder.h>

Collaboration diagram for SimpleVariableRecorder:

Public Member Functions

 SimpleVariableRecorder (const std::function< void(TTree &)> &setBranches, const std::string &rootFileName, const std::string &treeName="recorded_tree")
 Construct the Recorder opening the given ROOT file and create the underlying TTree and add let the given function setup branches. More...
 
 SimpleVariableRecorder (std::vector< Named< float * >> &namedVariables, const std::string &fileName, const std::string &treeName)
 Construct the Recorder opening the given ROOT file and create the underlying TTree and add let the given function setup branches. More...
 
 ~SimpleVariableRecorder ()
 Destructor that closes used TTrees and TFiles.
 
 SimpleVariableRecorder (SimpleVariableRecorder &)=delete
 copy constructor needs to be implemented if needed as class has dynamic memory/resource allocation (as pointed out by cppcheck)
 
SimpleVariableRecorderoperator= (SimpleVariableRecorder &)=delete
 assignment operator ("=") needs to be implemented if needed as class has dynamic memory/resource allocation (as pointed out by cppcheck)
 
void record ()
 Record varibles by filling the TTree.
 
void write ()
 Write out TFile to root file.
 

Protected Attributes

TFile * m_tFile
 ROOT file to which should be written.
 
StoreObjPtr< RootMergeable< TTree > > m_tTree
 TTree that contains recorded variables.
 

Detailed Description

Class to write collected variables into a root file, Used by VXDQETrainingDataCollectorModule.

Definition at line 32 of file SimpleVariableRecorder.h.

Constructor & Destructor Documentation

◆ SimpleVariableRecorder() [1/2]

SimpleVariableRecorder ( const std::function< void(TTree &)> &  setBranches,
const std::string &  rootFileName,
const std::string &  treeName = "recorded_tree" 
)
inline

Construct the Recorder opening the given ROOT file and create the underlying TTree and add let the given function setup branches.

Parameters
setBranchesFunction invoked with the underlying TTree as argument which is supposed create Branches and provide the value adresses.
rootFileNameName of ROOT file to which should be written.
treeNameName of the TTree in the ROOT file.

Definition at line 45 of file SimpleVariableRecorder.h.

47  :
48  m_tFile(nullptr),
50  {
51  TDirectory* ptrSavedCurrentTDirectory = gDirectory;
52 
53  m_tFile = new TFile(rootFileName.c_str(), "RECREATE");
54  m_tFile->cd();
55 
57  m_tTree.construct(treeName.c_str(), treeName.c_str());
58  if (m_tTree) {
59  setBranches(m_tTree->get());
60  }
61 
62  if (ptrSavedCurrentTDirectory) {
63  ptrSavedCurrentTDirectory->cd();
64  } else {
65  gROOT->cd();
66  }
67  }
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
Definition: DataStore.h:72
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60
TFile * m_tFile
ROOT file to which should be written.
StoreObjPtr< RootMergeable< TTree > > m_tTree
TTree that contains recorded variables.

◆ SimpleVariableRecorder() [2/2]

SimpleVariableRecorder ( std::vector< Named< float * >> &  namedVariables,
const std::string &  fileName,
const std::string &  treeName 
)
inline

Construct the Recorder opening the given ROOT file and create the underlying TTree and add let the given function setup branches.

Parameters
namedVariablesVector of collected named varibles to be turned into Branches in a TTree
fileNameName of ROOT file to which should be written.
treeNameName of the TTree in the ROOT file.

Definition at line 79 of file SimpleVariableRecorder.h.


The documentation for this class was generated from the following file: