Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions form/root_storage/root_ttree_write_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ ROOT_TTree_Write_ContainerImp::ROOT_TTree_Write_ContainerImp(std::string const&
ROOT_TTree_Write_ContainerImp::~ROOT_TTree_Write_ContainerImp()
{
if (m_tree != nullptr) {
m_tree->Write();
m_tree->GetDirectory()->WriteTObject(m_tree);
Comment thread
aolivier23 marked this conversation as resolved.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_tree->GetDirectory()->WriteTObject(m_tree);
m_tree->Write();

It should already be doing what (and a few more thing) the PR does. (On the other the SetDirectory is probably necessary to ensure that the TTree ends up in the right file).

//m_tree->Write() is not good enough because that writes to the _current_ gDirectory.
//Sometimes gDirectory is getting reset even while m_tfile is still open! We think
//it may have to do with multithreading.
//I'm pretty sure we had a reason why the TFile destructor isn't good enough,
//but I don't remember what it is right now. Maybe recovering partial jobs?
delete m_tree;
}
}
Expand All @@ -42,8 +47,8 @@ void ROOT_TTree_Write_ContainerImp::setupWrite(std::type_info const& /* type*/)
m_tree = m_tfile->Get<TTree>(name().c_str());
}
if (m_tree == nullptr) {
TDirectory::TContext context(m_tfile.get());
Comment thread
aolivier23 marked this conversation as resolved.
m_tree = new TTree(name().c_str(), name().c_str());
m_tree->SetDirectory(m_tfile.get()); //I think this is necessary so other FORM containers for this tree can discover it. But shouldn't Storage take care of that?
Comment thread
aolivier23 marked this conversation as resolved.
Outdated
}
if (m_tree == nullptr) {
throw std::runtime_error("ROOT_TTree_Write_ContainerImp::setupWrite no tree created");
Expand Down
Loading