8#include <calibration/CalibObjManager.h>
11#include <boost/algorithm/string/split.hpp>
12#include <boost/algorithm/string/classification.hpp>
17using namespace Calibration;
27 B2DEBUG(100,
"Held object is a TTree which will be have CloneTree() called.");
30 TTree* dest = source->CloneTree(0);
31 dest->SetName(newName.c_str());
51 if (
m_dir->GetDirectory(x.first.c_str()) == 0) {
52 m_dir->mkdir(x.first.c_str());
53 TDirectory* objectDir =
m_dir->GetDirectory(x.first.c_str());
54 objectDir->SetWritable(
true);
55 B2DEBUG(100,
"Made TDirectory: " << x.first);
63 TDirectory* objectDir =
m_dir->GetDirectory(x.first.c_str());
64 string dirName = x.first +
getSuffix(expRun);
65 TDirectory* newDir = objectDir->GetDirectory(dirName.c_str());
67 newDir = objectDir->mkdir(dirName.c_str());
68 newDir->SetWritable(
true);
69 B2DEBUG(100,
"Made TDirectory " << newDir->GetPath());
78 B2DEBUG(100,
"Writing for " << x.first);
79 for (
auto key : * (objectDir->GetList())) {
80 B2DEBUG(100,
"Writing for " << key->GetName());
81 TNamed* objMemory =
dynamic_cast<TNamed*
>(objectDir->FindObject(key->GetName()));
83 objectDir->WriteTObject(objMemory, key->GetName(),
"Overwrite");
93 B2DEBUG(100,
"We are deleting all the in-memory + file objects " << objectDir->GetPath());
94 objectDir->DeleteAll();
100 unsigned int index = 0;
102 for (
auto key : * (dir->GetList())) {
103 string keyName = key->GetName();
104 if (keyName.find(name) != std::string::npos) {
105 B2DEBUG(1000,
"Found previous Object " << keyName <<
" in the directory " << dir->GetPath());
107 if (currentIndex > index) {
108 index = currentIndex;
113 for (
auto key : * (dir->GetListOfKeys())) {
114 string keyName = key->GetName();
115 if (keyName.find(name) != std::string::npos) {
116 B2DEBUG(1000,
"Found previous Key " << keyName <<
" in the directory " << dir->GetPath());
118 if (currentIndex > index) {
119 index = currentIndex;
123 B2DEBUG(1000,
"Returning highest index " << index);
129 return "_" + encodeExpRun(expRun);
146 boost::split(strs, keyName, boost::is_any_of(
"_"));
147 string indexString = strs.back();
148 return stoi(indexString);
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.
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.
Struct containing exp number and run number.