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

#include <ROOTLegacyReader.h>

Public Member Functions

 ROOTLegacyReader ()=default
 
 ~ROOTLegacyReader ()=default
 
 ROOTLegacyReader (const ROOTLegacyReader &)=delete
 
ROOTLegacyReaderoperator= (const ROOTLegacyReader &)=delete
 
void openFile (const std::string &filename)
 
void openFiles (const std::vector< std::string > &filenames)
 
std::unique_ptr< podio::ROOTFrameDatareadNextEntry (const std::string &)
 
std::unique_ptr< podio::ROOTFrameDatareadEntry (const std::string &, const unsigned entry)
 
unsigned getEntries (const std::string &) const
 Returns number of entries for a given category.
 
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)
 

Detailed Description

A root reader for reading legacy podio root files that have been written using the legacy, non Frame based I/O model. This reader grants Frame based access to those files, by mimicking the Frame I/O functionality and the interfaces of those readers.

NOTE: Since there was only one category ("events") for those legacy podio files this reader will really only work if you try to read that category, and will simply return no data if you try to read anything else.

Definition at line 48 of file ROOTLegacyReader.h.

Constructor & Destructor Documentation

◆ ROOTLegacyReader() [1/2]

podio::ROOTLegacyReader::ROOTLegacyReader ( )
default

◆ ~ROOTLegacyReader()

podio::ROOTLegacyReader::~ROOTLegacyReader ( )
default

◆ ROOTLegacyReader() [2/2]

podio::ROOTLegacyReader::ROOTLegacyReader ( const ROOTLegacyReader )
delete

Member Function Documentation

◆ currentFileVersion()

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

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

Definition at line 84 of file ROOTLegacyReader.h.

84 {
85 return m_fileVersion;
86 }

◆ getAvailableCategories()

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

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

Definition at line 233 of file ROOTLegacyReader.cc.

233 {
234 return {m_categoryName};
235}

◆ getEntries()

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

Returns number of entries for a given category.

Definition at line 178 of file ROOTLegacyReader.cc.

178 {
179 if (name != m_categoryName) {
180 return 0;
181 }
182 return m_chain->GetEntries();
183}

◆ openFile()

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

Definition at line 131 of file ROOTLegacyReader.cc.

131 {
132 openFiles({filename});
133}
void openFiles(const std::vector< std::string > &filenames)

◆ openFiles()

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

Definition at line 135 of file ROOTLegacyReader.cc.

135 {
136 m_chain = std::make_unique<TChain>("events");
137 for (const auto& filename : filenames) {
138 //-1 forces the headers to be read so that
139 // the validity of the files can be checked
140 if (!m_chain->Add(filename.c_str(), -1)) {
141 throw std::runtime_error("File " + filename + " couldn't be found");
142 }
143 }
144
145 // read the meta data and build the collectionBranches cache
146 // NOTE: This is a small pessimization, if we do not read all collections
147 // afterwards, but it makes the handling much easier in general
148 auto metadatatree = static_cast<TTree*>(m_chain->GetFile()->Get("metadata"));
149 m_table = std::make_shared<CollectionIDTable>();
150 auto* table = m_table.get();
151 metadatatree->SetBranchAddress("CollectionIDs", &table);
152
153 podio::version::Version* versionPtr{nullptr};
154 if (auto* versionBranch = root_utils::getBranch(metadatatree, "PodioVersion")) {
155 versionBranch->SetAddress(&versionPtr);
156 }
157
158 // Check if the CollectionTypeInfo branch is there and assume that the file
159 // has been written with with podio pre #197 (<0.13.1) if that is not the case
160 if (auto* collInfoBranch = root_utils::getBranch(metadatatree, "CollectionTypeInfo")) {
161 auto collectionInfo = new std::vector<root_utils::CollectionInfoT>;
162 collInfoBranch->SetAddress(&collectionInfo);
163 metadatatree->GetEntry(0);
164 createCollectionBranches(*collectionInfo);
165 delete collectionInfo;
166 } else {
167 std::cout << "PODIO: Reconstructing CollectionTypeInfo branch from other sources in file: \'"
168 << m_chain->GetFile()->GetName() << "\'" << std::endl;
169 metadatatree->GetEntry(0);
170 const auto collectionInfo = root_utils::reconstructCollectionInfo(m_chain.get(), *m_table);
171 createCollectionBranches(collectionInfo);
172 }
173
174 m_fileVersion = versionPtr ? *versionPtr : podio::version::Version{0, 0, 0};
175 delete versionPtr;
176}
auto reconstructCollectionInfo(TTree *eventTree, podio::CollectionIDTable const &idTable)
Definition: rootUtils.h:130
TBranch * getBranch(Tree *chain, const char *name)
Definition: rootUtils.h:66

Referenced by openFile().

◆ operator=()

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

◆ readEntry()

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

Read the specified data entry from which a Frame can be constructed In case the entry does not exist, this returns a nullptr.

NOTE: the category name has to be "events" in this case, as only that category is available for legacy files.

Definition at line 29 of file ROOTLegacyReader.cc.

29 {
30 if (name != m_categoryName) {
31 return nullptr;
32 }
33 m_eventNumber = entry;
34 return readEntry();
35}
std::unique_ptr< podio::ROOTFrameData > readEntry(const std::string &, const unsigned entry)

Referenced by operator=(), readEntry(), and readNextEntry().

◆ readNextEntry()

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

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

NOTE: the category name has to be "events" in this case, as only that category is available for legacy files.

Definition at line 22 of file ROOTLegacyReader.cc.

22 {
23 if (name != m_categoryName) {
24 return nullptr;
25 }
26 return readEntry();
27}

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