8#include <tracking/trackingUtilities/mva/Recorder.h>
11#include <framework/datastore/StoreObjPtr.h>
12#include <framework/pcore/RootMergeable.h>
25 namespace TrackingUtilities {
35 Impl(
const std::function<
void(TTree&)>& setBranches,
36 const std::string& rootFileName,
37 const std::string& treeName =
"recorded_tree");
61#include <framework/datastore/DataStore.h>
62#include <framework/pcore/ProcHandler.h>
68using namespace TrackingUtilities;
71 const std::string& rootFileName,
72 const std::string& treeName)
76 TDirectory* ptrSavedCurrentTDirectory = gDirectory;
78 m_tFile =
new TFile(rootFileName.c_str(),
"RECREATE");
82 m_tTree.construct(treeName.c_str(), treeName.c_str());
88 if (ptrSavedCurrentTDirectory) {
89 ptrSavedCurrentTDirectory->cd();
99 m_tTree->get().SetDirectory(
nullptr);
113 TDirectory* ptrSavedCurrentTDirectory = gDirectory;
115 TFile* tFile =
m_tTree->get().GetCurrentFile();
119 m_tTree->get().Write(
"", TObject::kOverwrite);
120 m_tTree->get().SetDirectory(
nullptr);
123 if (ptrSavedCurrentTDirectory) {
124 ptrSavedCurrentTDirectory->cd();
141 const std::string& rootFileName,
142 const std::string& treeName)
143 :
m_impl(
std::make_unique<
Impl>(setBranches, rootFileName, treeName))
148 const std::string& rootFileName,
149 const std::string& treeName) :
150 Recorder([ & namedVariables](TTree & tree)
153 std::string name = namedVariable.getName();
154 Float_t* variable = namedVariable;
155 tree.Branch(name.c_str(), variable);
In the store you can park objects that have to be accessed by various modules.
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
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.
Type-safe access to single objects in the data store.
A mixin class to attach a name to an object.
Record the MVA variables.
~Impl()
Destructor finalising the tree.
TFile * m_tFile
Reference to the open TFile.
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.
void capture()
Capture the registered variable values and write them out.
void write()
Write all captured variables to disk.
StoreObjPtr< RootMergeable< TTree > > m_tTree
Reference to the TTree.
Recorder(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 gi...
std::unique_ptr< Impl > m_impl
Pointer to implementation hiding the details.
void capture()
Capture the registered variable values and write them out.
void write()
Write all captured variables to disk.
~Recorder()
Destructor writing the TTree and closing the ROOT File.
Abstract base class for different kinds of events.