Belle II Software development
Recorder::Impl Class Reference

Record the MVA variables. More...

Public Member Functions

 Impl (const std::function< void(TTree &)> &setBranches, const std::string &rootFileName, const std::string &treeName="recorded_tree")
 Constructor creating the TFile and TTree as well as setting up the branches with the given function.
 
 ~Impl ()
 Destructor finalising the tree.
 
void write ()
 Write all captured variables to disk.
 
void capture ()
 Capture the registered variable values and write them out.
 

Private Attributes

TFile * m_tFile
 Reference to the open TFile.
 
StoreObjPtr< RootMergeable< TTree > > m_tTree
 Reference to the TTree.
 

Detailed Description

Record the MVA variables.

Definition at line 28 of file Recorder.cc.

Constructor & Destructor Documentation

◆ Impl()

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

Constructor creating the TFile and TTree as well as setting up the branches with the given function.

Definition at line 69 of file Recorder.cc.

72 : m_tFile(nullptr)
74{
75 TDirectory* ptrSavedCurrentTDirectory = gDirectory;
76
77 m_tFile = new TFile(rootFileName.c_str(), "RECREATE");
78 m_tFile->cd();
79
81 m_tTree.construct(treeName.c_str(), treeName.c_str());
82
83 if (m_tTree) {
84 setBranches(m_tTree->get());
85 }
86
87 if (ptrSavedCurrentTDirectory) {
88 ptrSavedCurrentTDirectory->cd();
89 } else {
90 gROOT->cd();
91 }
92}
@ 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
Reference to the open TFile.
Definition: Recorder.cc:50
StoreObjPtr< RootMergeable< TTree > > m_tTree
Reference to the TTree.
Definition: Recorder.cc:53

◆ ~Impl()

~Impl ( )

Destructor finalising the tree.

Definition at line 94 of file Recorder.cc.

95{
97 if (m_tTree) {
98 m_tTree->get().SetDirectory(nullptr);
99 }
100 if (m_tFile) {
101 m_tFile->Close();
102 }
103 }
104}
static bool isOutputProcess()
Return true if the process is an output process.
Definition: ProcHandler.cc:232
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
Definition: ProcHandler.cc:226

Member Function Documentation

◆ capture()

void capture ( )

Capture the registered variable values and write them out.

Definition at line 132 of file Recorder.cc.

133{
134 m_tTree->get().Fill();
135}

◆ write()

void write ( )

Write all captured variables to disk.

Definition at line 106 of file Recorder.cc.

107{
109 if (m_tTree) {
110 // Due to some weird behaviour we have to cd to the file of the TTree
111 // before saving in order to have the tree in the correct file.
112 TDirectory* ptrSavedCurrentTDirectory = gDirectory;
113
114 TFile* tFile = m_tTree->get().GetCurrentFile();
115 if (tFile) {
116 // We still own the TFile.
117 tFile->cd();
118 m_tTree->get().Write("", TObject::kOverwrite);
119 m_tTree->get().SetDirectory(nullptr);
120 }
121
122 if (ptrSavedCurrentTDirectory) {
123 ptrSavedCurrentTDirectory->cd();
124 } else {
125 gROOT->cd();
126 }
127
128 }
129 }
130}

Member Data Documentation

◆ m_tFile

TFile* m_tFile
private

Reference to the open TFile.

Definition at line 50 of file Recorder.cc.

◆ m_tTree

StoreObjPtr<RootMergeable<TTree> > m_tTree
private

Reference to the TTree.

Definition at line 53 of file Recorder.cc.


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