1#ifndef PODIO_ROOT_UTILS_H
2#define PODIO_ROOT_UTILS_H
25constexpr static auto metaTreeName =
"podio_metadata";
31constexpr static auto paramBranchName =
"PARAMETERS";
37constexpr static auto versionBranchName =
"PodioBuildVersion";
43constexpr static auto edmDefBranchName =
"EDMDefinitions";
50 constexpr static auto suffix =
"___idTable";
51 return category + suffix;
59 constexpr static auto suffix =
"___CollectionTypeInfo";
60 return category + suffix;
67 return static_cast<TBranch*
>(chain->GetListOfBranches()->FindObject(name));
70template <
typename Tree>
71TBranch*
getBranch(Tree* chain,
const std::string& name) {
75inline std::string
refBranch(
const std::string& name,
size_t index) {
76 return name +
"#" + std::to_string(index);
79inline std::string
vecBranch(
const std::string& name,
size_t index) {
80 return name +
"_" + std::to_string(index);
83template <
typename BufferT>
86 if (
auto buffer = collBuffers.data) {
87 branches.
data->SetAddress(buffer);
90 if (
auto refCollections = collBuffers.references) {
91 for (
size_t i = 0; i < refCollections->size(); ++i) {
92 branches.
refs[i]->SetAddress(&(*refCollections)[i]);
96 if (
auto vecMembers = collBuffers.vectorMembers) {
97 for (
size_t i = 0; i < vecMembers->size(); ++i) {
98 branches.
vecs[i]->SetAddress((*vecMembers)[i].second);
111 branches.
data->GetEntry(entry);
113 for (
auto* br : branches.
refs) {
116 for (
auto* br : branches.
vecs) {
131 std::vector<CollectionInfoT> collInfo;
133 for (
size_t iColl = 0; iColl < idTable.
names().size(); ++iColl) {
134 const auto collID = idTable.
ids()[iColl];
135 const auto& name = idTable.
names()[iColl];
137 if (
auto branch =
getBranch(eventTree, name.c_str())) {
138 const std::string_view bufferClassName = branch->GetClassName();
140 std::string_view dataClass = bufferClassName;
141 dataClass.remove_suffix(5);
142 const auto collClass = std::string(dataClass.substr(7)) +
"Collection";
144 collInfo.emplace_back(collID, std::move(collClass),
false);
146 std::cerr <<
"Problems reconstructing collection info for collection: \'" << name <<
"\'\n";
const std::vector< int > & ids() const
return the ids
const std::vector< std::string > & names() const
return registered names
auto reconstructCollectionInfo(TTree *eventTree, podio::CollectionIDTable const &idTable)
std::string refBranch(const std::string &name, size_t index)
std::tuple< int, std::string, bool > CollectionInfoT
std::string vecBranch(const std::string &name, size_t index)
TBranch * getBranch(Tree *chain, const char *name)
void setCollectionAddresses(const BufferT &collBuffers, const CollectionBranches &branches)
std::string idTableName(const std::string &category)
void readBranchesData(const CollectionBranches &branches, Long64_t entry)
std::string collInfoName(const std::string &category)
std::vector< TBranch * > vecs
std::vector< TBranch * > refs