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 70 of file Recorder.cc.

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

◆ ~Impl()

~Impl ( )

Destructor finalising the tree.

Definition at line 95 of file Recorder.cc.

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

Member Function Documentation

◆ capture()

void capture ( )

Capture the registered variable values and write them out.

Definition at line 133 of file Recorder.cc.

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

◆ write()

void write ( )

Write all captured variables to disk.

Definition at line 107 of file Recorder.cc.

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

Member Data Documentation

◆ m_tFile

TFile* m_tFile
private

Reference to the open TFile.

Definition at line 51 of file Recorder.cc.

◆ m_tTree

StoreObjPtr<RootMergeable<TTree> > m_tTree
private

Reference to the TTree.

Definition at line 54 of file Recorder.cc.


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