Skip to content

Commit 6a3801d

Browse files
authored
Extract common members into a common base (#954)
1 parent 2b67243 commit 6a3801d

8 files changed

Lines changed: 89 additions & 172 deletions

File tree

doc/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ ALWAYS_DETAILED_SEC = NO
155155
# operators of the base classes will not be shown.
156156
# The default value is: NO.
157157

158-
INLINE_INHERITED_MEMB = NO
158+
INLINE_INHERITED_MEMB = YES
159159

160160
# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
161161
# before files name in the file list and in the header files. If set to NO the

include/podio/RNTupleReader.h

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#define PODIO_RNTUPLEREADER_H
33

44
#include "podio/ROOTFrameData.h"
5-
#include "podio/podioVersion.h"
6-
#include "podio/utilities/DatamodelRegistryIOHelpers.h"
5+
#include "podio/utilities/ReaderCommon.h"
76
#include "podio/utilities/RootHelpers.h"
87

98
#include <string>
@@ -32,7 +31,7 @@ namespace root_compat {
3231
///
3332
/// The RNTupleReader provides the data as ROOTFrameData from which a podio::Frame
3433
/// can be constructed. It can be used to read files written by the RNTupleWriter.
35-
class RNTupleReader {
34+
class RNTupleReader : public ReaderCommon {
3635

3736
public:
3837
RNTupleReader() = default;
@@ -91,53 +90,13 @@ class RNTupleReader {
9190
std::unique_ptr<podio::ROOTFrameData> readEntry(std::string_view name, const unsigned entry,
9291
const std::vector<std::string>& collsToRead = {});
9392

94-
/// Get the names of all the available Frame categories in the current file(s).
95-
///
96-
/// @returns The names of the available categores from the file
97-
std::vector<std::string_view> getAvailableCategories() const;
98-
9993
/// Get the number of entries for the given name
10094
///
10195
/// @param name The name of the category
10296
///
10397
/// @returns The number of entries that are available for the category
10498
unsigned getEntries(std::string_view name) const;
10599

106-
/// Get the build version of podio that has been used to write the current
107-
/// file
108-
///
109-
/// @returns The podio build version
110-
podio::version::Version currentFileVersion() const {
111-
return m_fileVersion;
112-
}
113-
114-
/// Get the (build) version of a datamodel that has been used to write the
115-
/// current file
116-
///
117-
/// @param name The name of the datamodel
118-
///
119-
/// @returns The (build) version of the datamodel if available or an empty
120-
/// optional
121-
std::optional<podio::version::Version> currentFileVersion(std::string_view name) const {
122-
return m_datamodelHolder.getDatamodelVersion(name);
123-
}
124-
125-
/// Get the datamodel definition for the given name
126-
///
127-
/// @param name The name of the datamodel
128-
///
129-
/// @returns The high level definition of the datamodel in JSON format
130-
const std::string_view getDatamodelDefinition(std::string_view name) const {
131-
return m_datamodelHolder.getDatamodelDefinition(name);
132-
}
133-
134-
/// Get all names of the datamodels that are available from this reader
135-
///
136-
/// @returns The names of the datamodels
137-
std::vector<std::string> getAvailableDatamodels() const {
138-
return m_datamodelHolder.getAvailableDatamodels();
139-
}
140-
141100
private:
142101
/**
143102
* Initialize the given category by filling the maps with metadata information
@@ -152,9 +111,6 @@ class RNTupleReader {
152111

153112
std::unique_ptr<root_compat::RNTupleReader> m_metadata{};
154113

155-
podio::version::Version m_fileVersion{};
156-
DatamodelDefinitionHolder m_datamodelHolder{};
157-
158114
std::unordered_map<std::string_view, std::vector<std::unique_ptr<root_compat::RNTupleReader>>> m_readers{};
159115
std::unordered_map<std::string, std::unique_ptr<root_compat::RNTupleReader>> m_metadata_readers{};
160116
std::vector<std::string> m_filenames{};
@@ -170,8 +126,6 @@ class RNTupleReader {
170126
/// Map each category to the collections that have been written and are available
171127
std::unordered_map<std::string_view, std::vector<podio::root_utils::CollectionWriteInfo>> m_collectionInfo{};
172128

173-
std::vector<std::string> m_availableCategories{};
174-
175129
std::unordered_map<std::string_view, std::shared_ptr<podio::CollectionIDTable>> m_idTables{};
176130
};
177131

include/podio/ROOTReader.h

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#define PODIO_ROOTREADER_H
33

44
#include "podio/ROOTFrameData.h"
5-
#include "podio/podioVersion.h"
6-
#include "podio/utilities/DatamodelRegistryIOHelpers.h"
5+
#include "podio/utilities/ReaderCommon.h"
76
#include "podio/utilities/ReaderUtils.h"
87
#include "podio/utilities/RootHelpers.h"
98

@@ -46,7 +45,7 @@ struct CollectionReadBuffers;
4645
///
4746
/// The ROOTReader provides the data as ROOTFrameData from which a podio::Frame
4847
/// can be constructed. It can be used to read files written by the ROOTWriter.
49-
class ROOTReader {
48+
class ROOTReader : public ReaderCommon {
5049

5150
public:
5251
ROOTReader() = default;
@@ -112,45 +111,6 @@ class ROOTReader {
112111
/// @returns The number of entries that are available for the category
113112
unsigned getEntries(std::string_view name) const;
114113

115-
/// Get the build version of podio that has been used to write the current
116-
/// file
117-
///
118-
/// @returns The podio build version
119-
podio::version::Version currentFileVersion() const {
120-
return m_fileVersion;
121-
}
122-
123-
/// Get the (build) version of a datamodel that has been used to write the
124-
/// current file
125-
///
126-
/// @param name The name of the datamodel
127-
///
128-
/// @returns The (build) version of the datamodel if available or an empty
129-
/// optional
130-
std::optional<podio::version::Version> currentFileVersion(std::string_view name) const {
131-
return m_datamodelHolder.getDatamodelVersion(name);
132-
}
133-
134-
/// Get the names of all the available Frame categories in the current file(s).
135-
///
136-
/// @returns The names of the available categories from the file
137-
std::vector<std::string_view> getAvailableCategories() const;
138-
139-
/// Get the datamodel definition for the given name
140-
///
141-
/// @param name The name of the datamodel
142-
///
143-
/// @returns The high level definition of the datamodel in JSON format
144-
const std::string_view getDatamodelDefinition(std::string_view name) const {
145-
return m_datamodelHolder.getDatamodelDefinition(name);
146-
}
147-
148-
/// Get all names of the datamodels that are available from this reader
149-
///
150-
/// @returns The names of the datamodels
151-
std::vector<std::string> getAvailableDatamodels() const {
152-
return m_datamodelHolder.getAvailableDatamodels();
153-
}
154114
std::optional<std::map<std::string, SizeStats>> getSizeStats(std::string_view category);
155115

156116
private:
@@ -200,10 +160,6 @@ class ROOTReader {
200160

201161
std::unique_ptr<TChain> m_metaChain{nullptr}; ///< The metadata tree
202162
std::unordered_map<std::string_view, CategoryInfo> m_categories{}; ///< All categories
203-
std::vector<std::string> m_availCategories{}; ///< All available categories from this file
204-
205-
podio::version::Version m_fileVersion{0, 0, 0};
206-
DatamodelDefinitionHolder m_datamodelHolder{};
207163
};
208164

209165
} // namespace podio

include/podio/SIOReader.h

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
#include "podio/SIOBlock.h"
55
#include "podio/SIOFrameData.h"
6-
#include "podio/podioVersion.h"
7-
#include "podio/utilities/DatamodelRegistryIOHelpers.h"
6+
#include "podio/utilities/ReaderCommon.h"
87

98
#include <sio/definitions.h>
109

@@ -22,7 +21,7 @@ class CollectionIDTable;
2221
///
2322
/// The SIOReader provides the data as SIOFrameData from which a podio::Frame
2423
/// can be constructed. It can be used to read files written by the SIOWriter.
25-
class SIOReader {
24+
class SIOReader : public ReaderCommon {
2625

2726
public:
2827
/// Create an SIOReader
@@ -83,46 +82,6 @@ class SIOReader {
8382
/// @param filename The path to the file to read from
8483
void openFile(const std::string& filename);
8584

86-
/// Get the build version of podio that has been used to write the current
87-
/// file
88-
///
89-
/// @returns The podio build version
90-
podio::version::Version currentFileVersion() const {
91-
return m_fileVersion;
92-
}
93-
94-
/// Get the (build) version of a datamodel that has been used to write the
95-
/// current file
96-
///
97-
/// @param name The name of the datamodel
98-
///
99-
/// @returns The (build) version of the datamodel if available or an empty
100-
/// optional
101-
std::optional<podio::version::Version> currentFileVersion(std::string_view name) const {
102-
return m_datamodelHolder.getDatamodelVersion(name);
103-
}
104-
105-
/// Get the names of all the available Frame categories in the current file.
106-
///
107-
/// @returns The names of the available categores from the file
108-
std::vector<std::string_view> getAvailableCategories() const;
109-
110-
/// Get the datamodel definition for the given name
111-
///
112-
/// @param name The name of the datamodel
113-
///
114-
/// @returns The high level definition of the datamodel in JSON format
115-
const std::string_view getDatamodelDefinition(std::string_view name) const {
116-
return m_datamodelHolder.getDatamodelDefinition(name);
117-
}
118-
119-
/// Get all names of the datamodels that are available from this reader
120-
///
121-
/// @returns The names of the datamodels
122-
std::vector<std::string> getAvailableDatamodels() const {
123-
return m_datamodelHolder.getAvailableDatamodels();
124-
}
125-
12685
private:
12786
void readPodioHeader();
12887

@@ -138,10 +97,6 @@ class SIOReader {
13897

13998
/// Table of content record where starting points of named entries can be read from
14099
SIOFileTOCRecord m_tocRecord{};
141-
/// The podio version that has been used to write the file
142-
podio::version::Version m_fileVersion{0};
143-
144-
DatamodelDefinitionHolder m_datamodelHolder{};
145100
};
146101

147102
} // namespace podio
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#ifndef PODIO_UTILITIES_READERCOMMON_H
2+
#define PODIO_UTILITIES_READERCOMMON_H
3+
4+
#include "podio/podioVersion.h"
5+
#include "podio/utilities/DatamodelRegistryIOHelpers.h"
6+
7+
#include <optional>
8+
#include <string>
9+
#include <string_view>
10+
#include <vector>
11+
12+
namespace podio {
13+
14+
/// Common base class for podio reader classes providing the shared members and
15+
/// functionality related to the file version and the datamodel definitions.
16+
///
17+
/// The population of the members is left to the derived reader classes.
18+
class ReaderCommon {
19+
public:
20+
/// Get the build version of podio that has been used to write the current
21+
/// file
22+
///
23+
/// @returns The podio build version
24+
podio::version::Version currentFileVersion() const {
25+
return m_fileVersion;
26+
}
27+
28+
/// Get the (build) version of a datamodel that has been used to write the
29+
/// current file
30+
///
31+
/// @param name The name of the datamodel
32+
///
33+
/// @returns The (build) version of the datamodel if available or an empty
34+
/// optional
35+
std::optional<podio::version::Version> currentFileVersion(std::string_view name) const {
36+
return m_datamodelHolder.getDatamodelVersion(name);
37+
}
38+
39+
/// Get the datamodel definition for the given name
40+
///
41+
/// @param name The name of the datamodel
42+
///
43+
/// @returns The high level definition of the datamodel in JSON format
44+
const std::string_view getDatamodelDefinition(std::string_view name) const {
45+
return m_datamodelHolder.getDatamodelDefinition(name);
46+
}
47+
48+
/// Get all names of the datamodels that are available from this reader
49+
///
50+
/// @returns The names of the datamodels
51+
std::vector<std::string> getAvailableDatamodels() const {
52+
return m_datamodelHolder.getAvailableDatamodels();
53+
}
54+
55+
/// Get the names of all the available Frame categories in the current file(s).
56+
///
57+
/// @returns The names of the available categories from the file
58+
std::vector<std::string_view> getAvailableCategories() const {
59+
return std::vector<std::string_view>(m_availableCategories.cbegin(), m_availableCategories.cend());
60+
}
61+
62+
protected:
63+
podio::version::Version m_fileVersion{};
64+
DatamodelDefinitionHolder m_datamodelHolder{};
65+
std::vector<std::string> m_availableCategories{};
66+
};
67+
68+
} // namespace podio
69+
70+
#endif // PODIO_UTILITIES_READERCOMMON_H

src/RNTupleReader.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ unsigned RNTupleReader::getEntries(std::string_view name) const {
129129
return 0;
130130
}
131131

132-
std::vector<std::string_view> RNTupleReader::getAvailableCategories() const {
133-
std::vector<std::string_view> cats;
134-
cats.reserve(m_availableCategories.size());
135-
for (const auto& cat : m_availableCategories) {
136-
cats.emplace_back(cat);
137-
}
138-
return cats;
139-
}
140-
141132
std::unique_ptr<ROOTFrameData> RNTupleReader::readNextEntry(std::string_view category,
142133
const std::vector<std::string>& collsToRead) {
143134
return readEntry(category, m_entries[category], collsToRead);

src/ROOTReader.cc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ void ROOTReader::openFiles(const std::vector<std::string>& filenames) {
331331
// Do some work up front for setting up categories and setup all the chains
332332
// and record the available categories. The rest of the setup follows on
333333
// demand when the category is first read
334-
m_availCategories = ::podio::getAvailableCategories(m_metaChain.get());
335-
for (const auto& cat : m_availCategories) {
334+
m_availableCategories = ::podio::getAvailableCategories(m_metaChain.get());
335+
for (const auto& cat : m_availableCategories) {
336336
const auto [it, _] = m_categories.try_emplace(cat, std::make_unique<TChain>(cat.c_str()));
337337
for (const auto& fn : filenames) {
338338
it->second.chain->Add(fn.c_str());
@@ -348,15 +348,6 @@ unsigned ROOTReader::getEntries(std::string_view name) const {
348348
return 0;
349349
}
350350

351-
std::vector<std::string_view> ROOTReader::getAvailableCategories() const {
352-
std::vector<std::string_view> cats;
353-
cats.reserve(m_categories.size());
354-
for (const auto& [cat, _] : m_categories) {
355-
cats.emplace_back(cat);
356-
}
357-
return cats;
358-
}
359-
360351
std::tuple<std::vector<root_utils::CollectionBranches>, std::vector<detail::NamedCollInfo>>
361352
createCollectionBranchesIndexBased(TChain* chain, const podio::CollectionIDTable& idTable,
362353
const std::vector<root_utils::CollectionWriteInfo>& collInfo) {

0 commit comments

Comments
 (0)