44#include " podio/CollectionIDTable.h"
55#include " podio/DatamodelRegistry.h"
66#include " podio/GenericParameters.h"
7+ #include " podio/utilities/RootHelpers.h"
78#include " rootUtils.h"
89
910#include < ROOT/RError.hxx>
1011
1112#include < algorithm>
13+ #include < cstdint>
1214#include < memory>
1315
1416// Adjust for the move of this out of ROOT v7 in
@@ -48,27 +50,11 @@ bool RNTupleReader::initCategory(const std::string& category) {
4850 // Assume that the metadata is the same in all files
4951 auto filename = m_filenames[0 ];
5052
51- auto & collInfo = m_collectionInfo[category];
53+ auto collInfo = m_metadata_readers[filename]->GetView <std::vector<root_utils::CollectionWriteInfo>>(
54+ {root_utils::collInfoName (category)});
5255
53- auto id = m_metadata_readers[filename]->GetView <std::vector<unsigned int >>(root_utils::idTableName (category));
54- collInfo.id = id (0 );
55-
56- auto collectionName =
57- m_metadata_readers[filename]->GetView <std::vector<std::string>>(root_utils::collectionName (category));
58- collInfo.name = collectionName (0 );
59-
60- auto collectionType =
61- m_metadata_readers[filename]->GetView <std::vector<std::string>>(root_utils::collInfoName (category));
62- collInfo.type = collectionType (0 );
63-
64- auto subsetCollection =
65- m_metadata_readers[filename]->GetView <std::vector<short >>(root_utils::subsetCollection (category));
66- collInfo.isSubsetCollection = subsetCollection (0 );
67-
68- auto schemaVersion = m_metadata_readers[filename]->GetView <std::vector<SchemaVersionT>>(" schemaVersion_" + category);
69- collInfo.schemaVersion = schemaVersion (0 );
70-
71- m_idTables[category] = std::make_shared<CollectionIDTable>(collInfo.id , collInfo.name );
56+ m_collectionInfo[category] = collInfo (0 );
57+ m_idTables[category] = root_utils::makeCollIdTable (collInfo (0 ));
7258
7359 return true ;
7460}
@@ -162,7 +148,7 @@ std::unique_ptr<ROOTFrameData> RNTupleReader::readEntry(const std::string& categ
162148 // Make sure to not silently ignore non-existant but requested collections
163149 if (!collsToRead.empty ()) {
164150 for (const auto & name : collsToRead) {
165- if (std::ranges::find (collInfo. name , name) == collInfo. name .end ()) {
151+ if (std::ranges::find (collInfo, name, &root_utils::CollectionWriteInfo:: name) == collInfo.end ()) {
166152 throw std::invalid_argument (name + " is not available from Frame" );
167153 }
168154 }
@@ -184,47 +170,46 @@ std::unique_ptr<ROOTFrameData> RNTupleReader::readEntry(const std::string& categ
184170 // we set all the fields there in any case.
185171 auto dentry = m_readers[category][readerIndex]->GetModel ().CreateEntry ();
186172
187- for (size_t i = 0 ; i < collInfo. id . size (); ++i ) {
188- if (!collsToRead.empty () && std::ranges::find (collsToRead, collInfo .name [i] ) == collsToRead.end ()) {
173+ for (const auto & coll : collInfo) {
174+ if (!collsToRead.empty () && std::ranges::find (collsToRead, coll .name ) == collsToRead.end ()) {
189175 continue ;
190176 }
191- const auto & collType = collInfo. type [i] ;
177+ const auto & collType = coll. dataType ;
192178 const auto & bufferFactory = podio::CollectionBufferFactory::instance ();
193- auto maybeBuffers =
194- bufferFactory.createBuffers (collType, collInfo.schemaVersion [i], collInfo.isSubsetCollection [i]);
179+ auto maybeBuffers = bufferFactory.createBuffers (collType, coll.schemaVersion , coll.isSubset );
195180 auto collBuffers = maybeBuffers.value_or (podio::CollectionReadBuffers{});
196181
197182 if (!maybeBuffers) {
198- std::cout << " WARNING: Buffers couldn't be created for collection " << collInfo .name [i] << " of type "
199- << collInfo. type [i] << " and schema version " << collInfo .schemaVersion [i] << std::endl;
183+ std::cout << " WARNING: Buffers couldn't be created for collection " << coll .name << " of type " << coll. dataType
184+ << " and schema version " << coll .schemaVersion << std::endl;
200185 return nullptr ;
201186 }
202187
203- if (collInfo. isSubsetCollection [i] ) {
204- auto brName = root_utils::subsetBranch (collInfo .name [i] );
188+ if (coll. isSubset ) {
189+ auto brName = root_utils::subsetBranch (coll .name );
205190 auto vec = new std::vector<podio::ObjectID>;
206191 dentry->BindRawPtr (brName, vec);
207192 collBuffers.references ->at (0 ) = std::unique_ptr<std::vector<podio::ObjectID>>(vec);
208193 } else {
209- dentry->BindRawPtr (collInfo .name [i] , collBuffers.data );
194+ dentry->BindRawPtr (coll .name , collBuffers.data );
210195
211196 const auto relVecNames = podio::DatamodelRegistry::instance ().getRelationNames (collType);
212197 for (size_t j = 0 ; j < relVecNames.relations .size (); ++j) {
213198 const auto relName = relVecNames.relations [j];
214199 auto vec = new std::vector<podio::ObjectID>;
215- const auto brName = root_utils::refBranch (collInfo .name [i] , relName);
200+ const auto brName = root_utils::refBranch (coll .name , relName);
216201 dentry->BindRawPtr (brName, vec);
217202 collBuffers.references ->at (j) = std::unique_ptr<std::vector<podio::ObjectID>>(vec);
218203 }
219204
220205 for (size_t j = 0 ; j < relVecNames.vectorMembers .size (); ++j) {
221206 const auto vecName = relVecNames.vectorMembers [j];
222- const auto brName = root_utils::vecBranch (collInfo .name [i] , vecName);
207+ const auto brName = root_utils::vecBranch (coll .name , vecName);
223208 dentry->BindRawPtr (brName, collBuffers.vectorMembers ->at (j).second );
224209 }
225210 }
226211
227- buffers.emplace (collInfo .name [i] , std::move (collBuffers));
212+ buffers.emplace (coll .name , std::move (collBuffers));
228213 }
229214
230215 m_readers[category][readerIndex]->LoadEntry (localEntry, *dentry);
0 commit comments