Skip to content

Commit 57c6a21

Browse files
committed
Cleanup and minor refactoring
1 parent c6ef36f commit 57c6a21

File tree

3 files changed

+15
-41
lines changed

3 files changed

+15
-41
lines changed

include/podio/RNTupleReader.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,7 @@ class RNTupleReader {
162162
std::unordered_map<std::string, std::vector<unsigned>> m_readerEntries{};
163163
std::unordered_map<std::string, unsigned> m_totalEntries{};
164164

165-
// struct CollectionInfo {
166-
// std::vector<unsigned int> id{};
167-
// std::vector<std::string> name{};
168-
// std::vector<std::string> type{};
169-
// std::vector<short> isSubsetCollection{};
170-
// std::vector<SchemaVersionT> schemaVersion{};
171-
// };
172-
165+
/// Map each category to the collections that have been written and are available
173166
std::unordered_map<std::string, std::vector<podio::root_utils::CollectionWriteInfo>> m_collectionInfo{};
174167

175168
std::vector<std::string> m_availableCategories{};

src/RNTupleReader.cc

+12-33
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,10 @@ bool RNTupleReader::initCategory(const std::string& category) {
5050
// Assume that the metadata is the same in all files
5151
auto filename = m_filenames[0];
5252

53-
// auto& collInfo = m_collectionInfo[category];
54-
5553
auto collInfo = m_metadata_readers[filename]->GetView<std::vector<root_utils::CollectionWriteInfo>>(
5654
{root_utils::collInfoName(category)});
5755

5856
m_collectionInfo[category] = collInfo(0);
59-
60-
// auto id = m_metadata_readers[filename]->GetView<std::vector<unsigned int>>(root_utils::idTableName(category));
61-
// collInfo.collectionID = id(0);
62-
63-
// auto collectionName =
64-
// m_metadata_readers[filename]->GetView<std::vector<std::string>>(root_utils::collectionName(category));
65-
// collInfo.name = collectionName(0);
66-
67-
// auto collectionType =
68-
// m_metadata_readers[filename]->GetView<std::vector<std::string>>(root_utils::collInfoName(category));
69-
// collInfo.type = collectionType(0);
70-
71-
// auto subsetCollection =
72-
// m_metadata_readers[filename]->GetView<std::vector<short>>(root_utils::subsetCollection(category));
73-
// collInfo.isSubset = subsetCollection(0);
74-
75-
// auto schemaVersion = m_metadata_readers[filename]->GetView<std::vector<SchemaVersionT>>("schemaVersion_" +
76-
// category); collInfo.schemaVersion = schemaVersion(0);
77-
7857
m_idTables[category] = root_utils::makeCollIdTable(collInfo(0));
7958

8059
return true;
@@ -191,46 +170,46 @@ std::unique_ptr<ROOTFrameData> RNTupleReader::readEntry(const std::string& categ
191170
// we set all the fields there in any case.
192171
auto dentry = m_readers[category][readerIndex]->GetModel().CreateEntry();
193172

194-
for (size_t i = 0; i < collInfo.size(); ++i) {
195-
if (!collsToRead.empty() && std::ranges::find(collsToRead, collInfo[i].name) == collsToRead.end()) {
173+
for (const auto& coll : collInfo) {
174+
if (!collsToRead.empty() && std::ranges::find(collsToRead, coll.name) == collsToRead.end()) {
196175
continue;
197176
}
198-
const auto& collType = collInfo[i].dataType;
177+
const auto& collType = coll.dataType;
199178
const auto& bufferFactory = podio::CollectionBufferFactory::instance();
200-
auto maybeBuffers = bufferFactory.createBuffers(collType, collInfo[i].schemaVersion, collInfo[i].isSubset);
179+
auto maybeBuffers = bufferFactory.createBuffers(collType, coll.schemaVersion, coll.isSubset);
201180
auto collBuffers = maybeBuffers.value_or(podio::CollectionReadBuffers{});
202181

203182
if (!maybeBuffers) {
204-
std::cout << "WARNING: Buffers couldn't be created for collection " << collInfo[i].name << " of type "
205-
<< collInfo[i].dataType << " and schema version " << collInfo[i].schemaVersion << 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;
206185
return nullptr;
207186
}
208187

209-
if (collInfo[i].isSubset) {
210-
auto brName = root_utils::subsetBranch(collInfo[i].name);
188+
if (coll.isSubset) {
189+
auto brName = root_utils::subsetBranch(coll.name);
211190
auto vec = new std::vector<podio::ObjectID>;
212191
dentry->BindRawPtr(brName, vec);
213192
collBuffers.references->at(0) = std::unique_ptr<std::vector<podio::ObjectID>>(vec);
214193
} else {
215-
dentry->BindRawPtr(collInfo[i].name, collBuffers.data);
194+
dentry->BindRawPtr(coll.name, collBuffers.data);
216195

217196
const auto relVecNames = podio::DatamodelRegistry::instance().getRelationNames(collType);
218197
for (size_t j = 0; j < relVecNames.relations.size(); ++j) {
219198
const auto relName = relVecNames.relations[j];
220199
auto vec = new std::vector<podio::ObjectID>;
221-
const auto brName = root_utils::refBranch(collInfo[i].name, relName);
200+
const auto brName = root_utils::refBranch(coll.name, relName);
222201
dentry->BindRawPtr(brName, vec);
223202
collBuffers.references->at(j) = std::unique_ptr<std::vector<podio::ObjectID>>(vec);
224203
}
225204

226205
for (size_t j = 0; j < relVecNames.vectorMembers.size(); ++j) {
227206
const auto vecName = relVecNames.vectorMembers[j];
228-
const auto brName = root_utils::vecBranch(collInfo[i].name, vecName);
207+
const auto brName = root_utils::vecBranch(coll.name, vecName);
229208
dentry->BindRawPtr(brName, collBuffers.vectorMembers->at(j).second);
230209
}
231210
}
232211

233-
buffers.emplace(collInfo[i].name, std::move(collBuffers));
212+
buffers.emplace(coll.name, std::move(collBuffers));
234213
}
235214

236215
m_readers[category][readerIndex]->LoadEntry(localEntry, *dentry);

src/rootUtils.h

+2
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ inline std::string getInconsistentCollsMsg(const std::vector<std::string>& exist
370370
return sstr.str();
371371
}
372372

373+
/// Create a collection id table from the information in the
374+
/// CollectionWriteInfos
373375
inline std::shared_ptr<podio::CollectionIDTable> makeCollIdTable(const std::vector<CollectionWriteInfo>& collInfo) {
374376
std::vector<uint32_t> ids{};
375377
ids.reserve(collInfo.size());

0 commit comments

Comments
 (0)