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

#include <ROOTFrameReader.h>

Public Member Functions

 ROOTFrameReader ()=default
 
 ~ROOTFrameReader ()=default
 
 ROOTFrameReader (const ROOTFrameReader &)=delete
 
ROOTFrameReaderoperator= (const ROOTFrameReader &)=delete
 
void openFile (const std::string &filename)
 
void openFiles (const std::vector< std::string > &filenames)
 
std::unique_ptr< podio::ROOTFrameDatareadNextEntry (const std::string &name)
 
std::unique_ptr< podio::ROOTFrameDatareadEntry (const std::string &name, const unsigned entry)
 
unsigned getEntries (const std::string &name) const
 Returns number of entries for the given name.
 
podio::version::Version currentFileVersion () const
 Get the build version of podio that has been used to write the current file.
 
std::vector< std::string_view > getAvailableCategories () const
 Get the names of all the availalable Frame categories in the current file(s)
 
const std::string_view getDatamodelDefinition (const std::string &name) const
 Get the datamodel definition for the given name.
 
std::vector< std::string > getAvailableDatamodels () const
 Get all names of the datamodels that ara available from this reader.
 

Detailed Description

This class has the function to read available data from disk and to prepare collections and buffers.

Definition at line 44 of file ROOTFrameReader.h.

Constructor & Destructor Documentation

◆ ROOTFrameReader() [1/2]

podio::ROOTFrameReader::ROOTFrameReader ( )
default

◆ ~ROOTFrameReader()

podio::ROOTFrameReader::~ROOTFrameReader ( )
default

◆ ROOTFrameReader() [2/2]

podio::ROOTFrameReader::ROOTFrameReader ( const ROOTFrameReader )
delete

Member Function Documentation

◆ currentFileVersion()

podio::version::Version podio::ROOTFrameReader::currentFileVersion ( ) const
inline

Get the build version of podio that has been used to write the current file.

Definition at line 76 of file ROOTFrameReader.h.

76 {
77 return m_fileVersion;
78 }

◆ getAvailableCategories()

std::vector< std::string_view > podio::ROOTFrameReader::getAvailableCategories ( ) const

Get the names of all the availalable Frame categories in the current file(s)

Definition at line 248 of file ROOTFrameReader.cc.

248 {
249 std::vector<std::string_view> cats;
250 cats.reserve(m_categories.size());
251 for (const auto& [cat, _] : m_categories) {
252 cats.emplace_back(cat);
253 }
254 return cats;
255}

◆ getAvailableDatamodels()

std::vector< std::string > podio::ROOTFrameReader::getAvailableDatamodels ( ) const
inline

Get all names of the datamodels that ara available from this reader.

Definition at line 89 of file ROOTFrameReader.h.

89 {
90 return m_datamodelHolder.getAvailableDatamodels();
91 }
std::vector< std::string > getAvailableDatamodels() const

◆ getDatamodelDefinition()

const std::string_view podio::ROOTFrameReader::getDatamodelDefinition ( const std::string &  name) const
inline

Get the datamodel definition for the given name.

Definition at line 84 of file ROOTFrameReader.h.

84 {
85 return m_datamodelHolder.getDatamodelDefinition(name);
86 }
const std::string_view getDatamodelDefinition(const std::string &name) const

◆ getEntries()

unsigned podio::ROOTFrameReader::getEntries ( const std::string &  name) const

Returns number of entries for the given name.

Definition at line 240 of file ROOTFrameReader.cc.

240 {
241 if (auto it = m_categories.find(name); it != m_categories.end()) {
242 return it->second.chain->GetEntries();
243 }
244
245 return 0;
246}

◆ openFile()

void podio::ROOTFrameReader::openFile ( const std::string &  filename)

Definition at line 196 of file ROOTFrameReader.cc.

196 {
197 openFiles({filename});
198}
void openFiles(const std::vector< std::string > &filenames)

◆ openFiles()

void podio::ROOTFrameReader::openFiles ( const std::vector< std::string > &  filenames)

Definition at line 200 of file ROOTFrameReader.cc.

200 {
201 m_metaChain = std::make_unique<TChain>(root_utils::metaTreeName);
202 // NOTE: We simply assume that the meta data doesn't change throughout the
203 // chain! This essentially boils down to the assumption that all files that
204 // are read this way were written with the same settings.
205 // Reading all files is done to check that all file exists
206 for (const auto& filename : filenames) {
207 if (!m_metaChain->Add(filename.c_str(), -1)) {
208 throw std::runtime_error("File " + filename + " couldn't be found");
209 }
210 }
211
212 podio::version::Version* versionPtr{nullptr};
213 if (auto* versionBranch = root_utils::getBranch(m_metaChain.get(), root_utils::versionBranchName)) {
214 versionBranch->SetAddress(&versionPtr);
215 versionBranch->GetEntry(0);
216 }
217 m_fileVersion = versionPtr ? *versionPtr : podio::version::Version{0, 0, 0};
218 delete versionPtr;
219
220 if (auto* edmDefBranch = root_utils::getBranch(m_metaChain.get(), root_utils::edmDefBranchName)) {
221 auto* datamodelDefs = new DatamodelDefinitionHolder::MapType{};
222 edmDefBranch->SetAddress(&datamodelDefs);
223 edmDefBranch->GetEntry(0);
224 m_datamodelHolder = DatamodelDefinitionHolder(std::move(*datamodelDefs));
225 delete datamodelDefs;
226 }
227
228 // Do some work up front for setting up categories and setup all the chains
229 // and record the available categories. The rest of the setup follows on
230 // demand when the category is first read
231 m_availCategories = ::podio::getAvailableCategories(m_metaChain.get());
232 for (const auto& cat : m_availCategories) {
233 auto [it, _] = m_categories.try_emplace(cat, std::make_unique<TChain>(cat.c_str()));
234 for (const auto& fn : filenames) {
235 it->second.chain->Add(fn.c_str());
236 }
237 }
238}
std::vector< std::tuple< std::string, std::string > > MapType
The "map" type that is used internally.
TBranch * getBranch(Tree *chain, const char *name)
Definition: rootUtils.h:66
std::vector< std::string > getAvailableCategories(TChain *metaChain)

Referenced by openFile().

◆ operator=()

ROOTFrameReader & podio::ROOTFrameReader::operator= ( const ROOTFrameReader )
delete

◆ readEntry()

std::unique_ptr< ROOTFrameData > podio::ROOTFrameReader::readEntry ( const std::string &  name,
const unsigned  entry 
)

Read the specified data entry from which a Frame can be constructed for the given name. In case the entry does not exist for this name or in case there is no data for this name, this returns a nullptr.

Definition at line 41 of file ROOTFrameReader.cc.

41 {
42 auto& catInfo = getCategoryInfo(name);
43 catInfo.entry = entNum;
44 return readEntry(catInfo);
45}
std::unique_ptr< podio::ROOTFrameData > readEntry(const std::string &name, const unsigned entry)

Referenced by readEntry(), and readNextEntry().

◆ readNextEntry()

std::unique_ptr< ROOTFrameData > podio::ROOTFrameReader::readNextEntry ( const std::string &  name)

Read the next data entry from which a Frame can be constructed for the given name. In case there are no more entries left for this name or in case there is no data for this name, this returns a nullptr.

Definition at line 36 of file ROOTFrameReader.cc.

36 {
37 auto& catInfo = getCategoryInfo(name);
38 return readEntry(catInfo);
39}

The documentation for this class was generated from the following files: