5#include "podio/podioVersion.h"
14 m_file = std::make_unique<TFile>(filename.c_str(),
"recreate");
22 const std::vector<std::string>& collsToWrite) {
23 auto& catInfo = getCategoryInfo(category);
26 if (catInfo.tree ==
nullptr) {
28 catInfo.collsToWrite = collsToWrite;
29 catInfo.tree =
new TTree(category.c_str(), (category +
" data tree").c_str());
30 catInfo.tree->SetDirectory(m_file.get());
33 std::vector<StoreCollection> collections;
34 collections.reserve(catInfo.collsToWrite.size());
35 for (
const auto& name : catInfo.collsToWrite) {
44 if (catInfo.branches.empty()) {
54ROOTFrameWriter::CategoryInfo& ROOTFrameWriter::getCategoryInfo(
const std::string& category) {
55 if (
auto it = m_categories.find(category); it != m_categories.end()) {
59 auto [it, _] = m_categories.try_emplace(category, CategoryInfo{});
63void ROOTFrameWriter::initBranches(CategoryInfo& catInfo,
const std::vector<StoreCollection>& collections,
65 catInfo.branches.reserve(collections.size() + 1);
68 for (
auto& [name, coll] : collections) {
69 root_utils::CollectionBranches branches;
70 const auto buffers = coll->getBuffers();
74 auto bufferDataType =
"vector<" + coll->getDataTypeName() +
">";
75 branches.data = catInfo.tree->Branch(name.c_str(), bufferDataType.c_str(), buffers.data);
79 if (
auto refColls = buffers.references) {
81 for (
auto& c : (*refColls)) {
83 branches.refs.push_back(catInfo.tree->Branch(brName.c_str(), c.get()));
88 if (
auto vmInfo = buffers.vectorMembers) {
90 for (
auto& [type, vec] : (*vmInfo)) {
91 const auto typeName =
"vector<" + type +
">";
93 branches.vecs.push_back(catInfo.tree->Branch(brName.c_str(), typeName.c_str(), vec));
97 catInfo.branches.push_back(branches);
98 catInfo.collInfo.emplace_back(catInfo.idTable.collectionID(name), coll->getTypeName(), coll->isSubsetCollection());
102 root_utils::CollectionBranches branches;
103 branches.data = catInfo.tree->Branch(root_utils::paramBranchName, ¶meters);
104 catInfo.branches.push_back(branches);
107void ROOTFrameWriter::resetBranches(std::vector<root_utils::CollectionBranches>& branches,
108 const std::vector<ROOTFrameWriter::StoreCollection>& collections,
111 for (
auto& coll : collections) {
112 const auto& collBranches = branches[iColl];
117 branches.back().data->SetAddress(¶meters);
121 auto* metaTree =
new TTree(root_utils::metaTreeName,
"metadata tree for podio I/O functionality");
122 metaTree->SetDirectory(m_file.get());
125 for (
auto& [category, info] : m_categories) {
131 auto podioVersion = podio::version::build_version;
132 metaTree->Branch(root_utils::versionBranchName, &podioVersion);
135 metaTree->Branch(root_utils::edmDefBranchName, &edmDefinitions);
std::vector< std::tuple< std::string, std::string > > getDatamodelDefinitionsToWrite() const
Get all the names and JSON definitions that need to be written.
void registerDatamodelDefinition(const podio::CollectionBase *coll, const std::string &name)
podio::CollectionIDTable getCollectionIDTableForWrite() const
std::vector< std::string > getAvailableCollections() const
const podio::GenericParameters & getParameters() const
const podio::CollectionBase * getCollectionForWrite(const std::string &name) const
ROOTFrameWriter(const std::string &filename)
void writeFrame(const podio::Frame &frame, const std::string &category)
std::string refBranch(const std::string &name, size_t index)
std::string vecBranch(const std::string &name, size_t index)
void setCollectionAddresses(const BufferT &collBuffers, const CollectionBranches &branches)
std::string idTableName(const std::string &category)
std::string collInfoName(const std::string &category)