13#include <TDirectory.h>
17#include <framework/dataobjects/EventMetaData.h>
18#include <framework/logging/Logger.h>
20#include <calibration/Utilities.h>
50 void addObject(
const std::string& name, std::shared_ptr<TNamed>
object);
80 T*
getObject(
const std::string& name,
const Belle2::Calibration::ExpRun expRun)
83 TDirectory* objectDir =
m_dir->GetDirectory(objectDirName.c_str());
88 B2ERROR(
"The requested object name '" << name <<
"' isn't known to CalibObjManager!");
91 B2FATAL(
"TDirectory for registered object " << name <<
" not found: " << objectDirName);
94 std::string highestIndexName = name +
"_" + std::to_string(highestIndex);
96 T* obj =
dynamic_cast<T*
>(objectDir->FindObject(highestIndexName.c_str()));
98 B2DEBUG(100,
"Highest index is only file resident for " << highestIndexName <<
" in " << objectDir->GetPath() <<
99 ". Will make a higher one");
100 std::string newName = name +
"_" + std::to_string(highestIndex + 1);
102 obj->SetDirectory(objectDir);
106 objectDir->GetObject(newName.c_str(), objTest);
108 B2DEBUG(100,
"SetDirectory was a dummy function. Adding to Object to TDirectory manually.");
119 T*
cloneObj(T* source,
const std::string& newName)
const
121 B2DEBUG(100,
"Held object " << source->GetName() <<
" will be treated as a generic TNamed and have Clone(newname) called.");
122 return dynamic_cast<T*
>(source->Clone(newName.c_str()));
135 std::string
getSuffix(
const Calibration::ExpRun& key)
const;
141 std::string
getObjectExpRunName(
const std::string& name,
const Calibration::ExpRun& expRun)
const;
Manager class for collector registered data. Handles much of the TDirectory/TObject manipulation.
virtual ~CalibObjManager()
Destructor: Every object we are managing is ultimately either saved into a file to write out,...
std::map< std::string, std::shared_ptr< TNamed > > m_templateObjects
The objects that we are managing, these are template objects for all future objects for each (Exp,...
T * cloneObj(T *source, const std::string &newName) const
Clone object.
TDirectory * m_dir
The TDirectory where all of our managed objects should be found, and where we should create new ones.
T * getObject(const std::string &name, const Belle2::Calibration::ExpRun expRun)
Gets the collector object of this name for the given exprun.
void setDirectory(TDirectory *dir)
Change the directory that we will be using to find/store all our objects, we don't own it.
CalibObjManager(TDirectory *dir=nullptr)
Constructor.
unsigned int extractKeyIndex(const std::string &keyName) const
Extract key index.
void clearCurrentObjects(const Calibration::ExpRun &expRun)
Deletes all in-memory objects in the exprun directories for all the collector objects we know about.
void writeCurrentObjects(const Calibration::ExpRun &expRun)
For each templated object we know about, we find an in memory object for this exprun and write to the...
std::string getObjectExpRunName(const std::string &name, const Calibration::ExpRun &expRun) const
Get object experiment and run name.
unsigned int getHighestIndexObject(const std::string &name, const TDirectory *dir) const
Scans the directory to get the highest "_i" index of an object with this name.
void deleteHeldObjects()
Clears the map of templated objects -> causing their destruction.
void addObject(const std::string &name, std::shared_ptr< TNamed > object)
Add a new object to manage, this is used as a template for creating future/missing objects.
bool isRegistered(const std::string &name) const
Checks for the existence of a name in the templated object map to see if we registered the object.
void createExpRunDirectories(Calibration::ExpRun &expRun) const
For each templated object, we create a new TDirectory for this exprun.
std::string getSuffix(const Calibration::ExpRun &key) const
We rename objects based on the Exp,Run that they contain so we need to generate a nice naming convent...
void createDirectories()
Each object gets its own TDirectory under the main manager directory to store its objects.
Abstract base class for different kinds of events.