PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
podio::root_utils Namespace Reference

Classes

struct  CollectionBranches
 

Typedefs

using CollectionInfoT = std::tuple< int, std::string, bool >
 

Functions

std::string idTableName (const std::string &category)
 
std::string collInfoName (const std::string &category)
 
template<class Tree >
TBranch * getBranch (Tree *chain, const char *name)
 
template<typename Tree >
TBranch * getBranch (Tree *chain, const std::string &name)
 
std::string refBranch (const std::string &name, size_t index)
 
std::string vecBranch (const std::string &name, size_t index)
 
template<typename BufferT >
void setCollectionAddresses (const BufferT &collBuffers, const CollectionBranches &branches)
 
void readBranchesData (const CollectionBranches &branches, Long64_t entry)
 
auto reconstructCollectionInfo (TTree *eventTree, podio::CollectionIDTable const &idTable)
 

Typedef Documentation

◆ CollectionInfoT

using podio::root_utils::CollectionInfoT = typedef std::tuple<int, std::string, bool>

Definition at line 106 of file rootUtils.h.

Function Documentation

◆ collInfoName()

std::string podio::root_utils::collInfoName ( const std::string &  category)
inline

Name of the branch for storing the collection info for a given category in the meta data tree

Definition at line 58 of file rootUtils.h.

58 {
59 constexpr static auto suffix = "___CollectionTypeInfo";
60 return category + suffix;
61}

Referenced by podio::ROOTFrameWriter::finish().

◆ getBranch() [1/2]

template<class Tree >
TBranch * podio::root_utils::getBranch ( Tree *  chain,
const char *  name 
)

Definition at line 66 of file rootUtils.h.

66 {
67 return static_cast<TBranch*>(chain->GetListOfBranches()->FindObject(name));
68}

Referenced by podio::createCollectionBranches(), getBranch(), podio::ROOTFrameReader::openFiles(), podio::ROOTLegacyReader::openFiles(), podio::ROOTReader::openFiles(), and reconstructCollectionInfo().

◆ getBranch() [2/2]

template<typename Tree >
TBranch * podio::root_utils::getBranch ( Tree *  chain,
const std::string &  name 
)

Definition at line 71 of file rootUtils.h.

71 {
72 return getBranch(chain, name.c_str());
73}
TBranch * getBranch(Tree *chain, const char *name)
Definition: rootUtils.h:66

◆ idTableName()

std::string podio::root_utils::idTableName ( const std::string &  category)
inline

Name of the branch for storing the idTable for a given category in the meta data tree

Definition at line 49 of file rootUtils.h.

49 {
50 constexpr static auto suffix = "___idTable";
51 return category + suffix;
52}

Referenced by podio::ROOTFrameWriter::finish().

◆ readBranchesData()

void podio::root_utils::readBranchesData ( const CollectionBranches branches,
Long64_t  entry 
)
inline

Definition at line 108 of file rootUtils.h.

108 {
109 // Read all data
110 if (branches.data) {
111 branches.data->GetEntry(entry);
112 }
113 for (auto* br : branches.refs) {
114 br->GetEntry(entry);
115 }
116 for (auto* br : branches.vecs) {
117 br->GetEntry(entry);
118 }
119}

◆ reconstructCollectionInfo()

auto podio::root_utils::reconstructCollectionInfo ( TTree *  eventTree,
podio::CollectionIDTable const &  idTable 
)
inline

reconstruct the collection info from information that is available from other trees in the file.

NOTE: This function is only supposed to be called if there is no "CollectionTypeInfo" branch in the metadata tree, as it assumes that the file has been written with podio previous to #197 where there were no subset collections

Definition at line 130 of file rootUtils.h.

130 {
131 std::vector<CollectionInfoT> collInfo;
132
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];
136
137 if (auto branch = getBranch(eventTree, name.c_str())) {
138 const std::string_view bufferClassName = branch->GetClassName();
139 // this comes with vector<...Data>, where we only care about the ...
140 std::string_view dataClass = bufferClassName;
141 dataClass.remove_suffix(5);
142 const auto collClass = std::string(dataClass.substr(7)) + "Collection";
143 // Assume that there are no subset collections in "old files"
144 collInfo.emplace_back(collID, std::move(collClass), false);
145 } else {
146 std::cerr << "Problems reconstructing collection info for collection: \'" << name << "\'\n";
147 }
148 }
149
150 return collInfo;
151}

Referenced by podio::ROOTLegacyReader::openFiles(), and podio::ROOTReader::openFiles().

◆ refBranch()

std::string podio::root_utils::refBranch ( const std::string &  name,
size_t  index 
)
inline

Definition at line 75 of file rootUtils.h.

75 {
76 return name + "#" + std::to_string(index);
77}

Referenced by podio::createCollectionBranches().

◆ setCollectionAddresses()

template<typename BufferT >
void podio::root_utils::setCollectionAddresses ( const BufferT &  collBuffers,
const CollectionBranches branches 
)
inline

Definition at line 84 of file rootUtils.h.

84 {
85
86 if (auto buffer = collBuffers.data) {
87 branches.data->SetAddress(buffer);
88 }
89
90 if (auto refCollections = collBuffers.references) {
91 for (size_t i = 0; i < refCollections->size(); ++i) {
92 branches.refs[i]->SetAddress(&(*refCollections)[i]);
93 }
94 }
95
96 if (auto vecMembers = collBuffers.vectorMembers) {
97 for (size_t i = 0; i < vecMembers->size(); ++i) {
98 branches.vecs[i]->SetAddress((*vecMembers)[i].second);
99 }
100 }
101}

◆ vecBranch()

std::string podio::root_utils::vecBranch ( const std::string &  name,
size_t  index 
)
inline

Definition at line 79 of file rootUtils.h.

79 {
80 return name + "_" + std::to_string(index);
81}

Referenced by podio::createCollectionBranches().