File indexing completed on 2026-04-17 08:29:02
0001 #ifndef PODIO_DATASOURCE_H
0002 #define PODIO_DATASOURCE_H
0003
0004
0005 #include <podio/CollectionBase.h>
0006 #include <podio/Frame.h>
0007 #include <podio/Reader.h>
0008
0009
0010 #include <ROOT/RDataFrame.hxx>
0011 #include <ROOT/RDataSource.hxx>
0012
0013
0014 #include <memory>
0015 #include <string>
0016 #include <typeinfo>
0017 #include <utility>
0018 #include <vector>
0019
0020 namespace podio {
0021 class DataSource : public ROOT::RDF::RDataSource {
0022 public:
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 explicit DataSource(const std::string& filePath, int nEvents = -1, const std::vector<std::string>& collsToRead = {});
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 explicit DataSource(const std::vector<std::string>& filePathList, int nEvents = -1,
0044 const std::vector<std::string>& collsToRead = {});
0045
0046
0047
0048
0049 void SetNSlots(unsigned int nSlots) override;
0050
0051
0052
0053
0054 void Initialize() override;
0055
0056
0057
0058
0059
0060 std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() override;
0061
0062
0063
0064
0065
0066 void InitSlot(unsigned int slot, ULong64_t firstEntry) override;
0067
0068
0069
0070
0071
0072 bool SetEntry(unsigned int slot, ULong64_t entry) override;
0073
0074
0075
0076
0077
0078 void FinalizeSlot(unsigned int slot) override;
0079
0080
0081
0082
0083 void Finalize() override;
0084
0085
0086
0087
0088
0089 const std::vector<std::string>& GetColumnNames() const override;
0090
0091
0092
0093
0094 bool HasColumn(std::string_view columnName) const override;
0095
0096
0097
0098
0099 std::string GetTypeName(std::string_view columnName) const override;
0100
0101 std::string GetLabel() override {
0102 return "PODIO Datasource";
0103 };
0104
0105 protected:
0106
0107
0108
0109
0110 std::vector<void*> GetColumnReadersImpl(std::string_view name, const std::type_info& typeInfo) override;
0111
0112 std::string AsString() override {
0113 return "Podio data source";
0114 }
0115
0116 private:
0117
0118 unsigned int m_nSlots = 1;
0119
0120
0121 std::vector<std::string> m_filePathList = {};
0122
0123
0124 ULong64_t m_nEvents = 0;
0125
0126
0127 std::vector<std::pair<ULong64_t, ULong64_t>> m_rangesAvailable = {};
0128
0129
0130 std::vector<std::pair<ULong64_t, ULong64_t>> m_rangesAll = {};
0131
0132
0133 std::vector<std::string> m_columnNames{};
0134
0135
0136 std::vector<std::string> m_columnTypes = {};
0137
0138
0139 std::vector<std::vector<const podio::CollectionBase*>> m_Collections = {};
0140
0141
0142 std::vector<unsigned int> m_activeCollections = {};
0143
0144
0145 std::vector<std::unique_ptr<podio::Reader>> m_podioReaders = {};
0146
0147
0148 std::vector<std::unique_ptr<podio::Frame>> m_frames = {};
0149
0150
0151
0152
0153
0154
0155 void SetupInput(int nEvents, const std::vector<std::string>& collsToRead);
0156 };
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 ROOT::RDataFrame CreateDataFrame(const std::vector<std::string>& filePathList,
0169 const std::vector<std::string>& collsToRead = {});
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 ROOT::RDataFrame CreateDataFrame(const std::string& filePath, const std::vector<std::string>& collsToRead = {});
0182 }
0183
0184 #endif