File indexing completed on 2025-01-18 10:06:09
0001 #ifndef PODIO_RNTUPLEREADER_H
0002 #define PODIO_RNTUPLEREADER_H
0003
0004 #include "podio/ROOTFrameData.h"
0005 #include "podio/SchemaEvolution.h"
0006 #include "podio/podioVersion.h"
0007 #include "podio/utilities/DatamodelRegistryIOHelpers.h"
0008
0009 #include <string>
0010 #include <string_view>
0011 #include <unordered_map>
0012 #include <vector>
0013
0014 #include <ROOT/RNTuple.hxx>
0015 #include <RVersion.h>
0016 #if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
0017 #include <ROOT/RNTupleReader.hxx>
0018 #endif
0019
0020 namespace podio {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 class RNTupleReader {
0032
0033 public:
0034
0035 RNTupleReader() = default;
0036
0037 ~RNTupleReader() = default;
0038
0039 RNTupleReader(const RNTupleReader&) = delete;
0040
0041 RNTupleReader& operator=(const RNTupleReader&) = delete;
0042
0043
0044
0045
0046 void openFile(const std::string& filename);
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 void openFiles(const std::vector<std::string>& filenames);
0060
0061
0062
0063
0064
0065
0066
0067
0068 std::unique_ptr<podio::ROOTFrameData> readNextEntry(const std::string& name);
0069
0070
0071
0072
0073
0074
0075
0076
0077 std::unique_ptr<podio::ROOTFrameData> readEntry(const std::string& name, const unsigned entry);
0078
0079
0080
0081
0082 std::vector<std::string_view> getAvailableCategories() const;
0083
0084
0085
0086
0087
0088
0089 unsigned getEntries(const std::string& name);
0090
0091
0092
0093
0094
0095 podio::version::Version currentFileVersion() const {
0096 return m_fileVersion;
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106 std::optional<podio::version::Version> currentFileVersion(const std::string& name) const {
0107 return m_datamodelHolder.getDatamodelVersion(name);
0108 }
0109
0110
0111
0112
0113
0114
0115 const std::string_view getDatamodelDefinition(const std::string& name) const {
0116 return m_datamodelHolder.getDatamodelDefinition(name);
0117 }
0118
0119
0120
0121
0122 std::vector<std::string> getAvailableDatamodels() const {
0123 return m_datamodelHolder.getAvailableDatamodels();
0124 }
0125
0126 private:
0127
0128
0129
0130
0131 bool initCategory(const std::string& category);
0132
0133
0134
0135
0136 GenericParameters readEventMetaData(const std::string& name, unsigned entNum);
0137
0138 template <typename T>
0139 void readParams(const std::string& name, unsigned entNum, GenericParameters& params);
0140
0141 std::unique_ptr<ROOT::Experimental::RNTupleReader> m_metadata{};
0142
0143 podio::version::Version m_fileVersion{};
0144 DatamodelDefinitionHolder m_datamodelHolder{};
0145
0146 std::unordered_map<std::string, std::vector<std::unique_ptr<ROOT::Experimental::RNTupleReader>>> m_readers{};
0147 std::unordered_map<std::string, std::unique_ptr<ROOT::Experimental::RNTupleReader>> m_metadata_readers{};
0148 std::vector<std::string> m_filenames{};
0149
0150 std::unordered_map<std::string, int> m_entries{};
0151 std::unordered_map<std::string, unsigned> m_totalEntries{};
0152
0153 struct CollectionInfo {
0154 std::vector<unsigned int> id{};
0155 std::vector<std::string> name{};
0156 std::vector<std::string> type{};
0157 std::vector<short> isSubsetCollection{};
0158 std::vector<SchemaVersionT> schemaVersion{};
0159 };
0160
0161 std::unordered_map<std::string, CollectionInfo> m_collectionInfo{};
0162
0163 std::vector<std::string> m_availableCategories{};
0164
0165 std::unordered_map<std::string, std::shared_ptr<podio::CollectionIDTable>> m_idTables{};
0166 };
0167
0168 }
0169
0170 #endif