 |
Belle II Software
release-05-01-25
|
6 #include <TDirectory.h>
10 #include <framework/dataobjects/EventMetaData.h>
11 #include <framework/logging/Logger.h>
13 #include <calibration/Utilities.h>
21 class CalibObjManager {
43 void addObject(
const std::string& name, std::shared_ptr<TNamed>
object);
73 T*
getObject(
const std::string& name,
const Belle2::Calibration::ExpRun expRun)
75 std::string objectDirName = name +
'/' + getObjectExpRunName(name, expRun);
76 TDirectory* objectDir =
m_dir->GetDirectory(objectDirName.c_str());
81 B2ERROR(
"The requested object name '" << name <<
"' isn't known to CalibObjManager!");
84 B2FATAL(
"TDirectory for registered object " << name <<
" not found: " << objectDirName);
87 std::string highestIndexName = name +
"_" + std::to_string(highestIndex);
89 T* obj =
dynamic_cast<T*
>(objectDir->FindObject(highestIndexName.c_str()));
91 B2DEBUG(100,
"Highest index is only file resident for " << highestIndexName <<
" in " << objectDir->GetPath() <<
92 ". Will make a higher one");
93 std::string newName = name +
"_" + std::to_string(highestIndex + 1);
95 obj->SetDirectory(objectDir);
99 objectDir->GetObject(newName.c_str(), objTest);
101 B2DEBUG(100,
"SetDirectory was a dummy function. Adding to Object to TDirectory manually.");
111 T* cloneObj(T* source,
const std::string& newName)
const
113 B2DEBUG(100,
"Held object " << source->GetName() <<
" will be treated as a generic TNamed and have Clone(newname) called.");
114 return dynamic_cast<T*
>(source->Clone(newName.c_str()));
127 std::string
getSuffix(
const Belle2::Calibration::ExpRun& key)
const;
132 std::string getObjectExpRunName(
const std::string& name,
const Calibration::ExpRun& expRun)
const;
134 unsigned int extractKeyIndex(
const std::string& keyName)
const;
138 TTree* CalibObjManager::cloneObj(TTree* source,
const std::string& newName)
const;
void setDirectory(TDirectory *dir)
Change the directory that we will be using to find/store all our objects, we don't own it.
virtual ~CalibObjManager()
Destructor: Every object we are managing is ultimately either saved into a file to write out,...
void createDirectories()
Each object gets its own TDirectory under the main manager directory to store its objects.
void clearCurrentObjects(const Calibration::ExpRun &expRun)
Deletes all in-memory objects in the exprun directories for all the collector objects we know about.
CalibObjManager(TDirectory *dir=nullptr)
Constructor.
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,...
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.
Abstract base class for different kinds of events.
void deleteHeldObjects()
Clears the map of templated objects -> causing their destruction.
void createExpRunDirectories(Calibration::ExpRun &expRun) const
For each templated object, we create a new TDirectory for this exprun.
std::string getSuffix(const Belle2::Calibration::ExpRun &key) const
We rename objects based on the Exp,Run that they contain so we need to generate a nice naming convent...
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.
T * getObject(const std::string &name, const Belle2::Calibration::ExpRun expRun)
Gets the collector object of this name for the given exprun.
TDirectory * m_dir
The TDirectory where all of our managed objects should be found, and where we should create new ones.
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...