Skip to content

Commit

Permalink
Remove no longer necessary special casing
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jan 31, 2025
1 parent 8dc4bf3 commit f7fae2b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 55 deletions.
4 changes: 1 addition & 3 deletions include/podio/RNTupleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
#include <vector>

#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleReader.hxx>
#include <RVersion.h>
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
#include <ROOT/RNTupleReader.hxx>
#endif

namespace podio {

Expand Down
4 changes: 1 addition & 3 deletions include/podio/RNTupleWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#include "TFile.h"
#include <ROOT/RNTuple.hxx>
#include <ROOT/RNTupleModel.hxx>
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
#include <ROOT/RNTupleWriter.hxx>
#endif
#include <ROOT/RNTupleWriter.hxx>

#include <string>
#include <unordered_map>
Expand Down
20 changes: 0 additions & 20 deletions src/RNTupleReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,11 @@ std::unique_ptr<ROOTFrameData> RNTupleReader::readEntry(const std::string& categ
auto readerIndex = upper - 1 - m_readerEntries[category].begin();

ROOTFrameData::BufferMap buffers;
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
// We need to create a non-bare entry here, because the entries for the
// parameters are not explicitly (re)set and we need them default initialized.
// In principle we would only need a bare entry for the collection data, since
// we set all the fields there in any case.
auto dentry = m_readers[category][readerIndex]->GetModel().CreateEntry();
#else
auto dentry = m_readers[category][readerIndex]->GetModel()->GetDefaultEntry();
#endif

for (size_t i = 0; i < collInfo.id.size(); ++i) {
if (!collsToRead.empty() && std::ranges::find(collsToRead, collInfo.name[i]) == collsToRead.end()) {
Expand All @@ -207,40 +203,24 @@ std::unique_ptr<ROOTFrameData> RNTupleReader::readEntry(const std::string& categ
if (collInfo.isSubsetCollection[i]) {
auto brName = root_utils::subsetBranch(collInfo.name[i]);
auto vec = new std::vector<podio::ObjectID>;
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
dentry->BindRawPtr(brName, vec);
#else
dentry->CaptureValueUnsafe(brName, vec);
#endif
collBuffers.references->at(0) = std::unique_ptr<std::vector<podio::ObjectID>>(vec);
} else {
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
dentry->BindRawPtr(collInfo.name[i], collBuffers.data);
#else
dentry->CaptureValueUnsafe(collInfo.name[i], collBuffers.data);
#endif

const auto relVecNames = podio::DatamodelRegistry::instance().getRelationNames(collType);
for (size_t j = 0; j < relVecNames.relations.size(); ++j) {
const auto relName = relVecNames.relations[j];
auto vec = new std::vector<podio::ObjectID>;
const auto brName = root_utils::refBranch(collInfo.name[i], relName);
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
dentry->BindRawPtr(brName, vec);
#else
dentry->CaptureValueUnsafe(brName, vec);
#endif
collBuffers.references->at(j) = std::unique_ptr<std::vector<podio::ObjectID>>(vec);
}

for (size_t j = 0; j < relVecNames.vectorMembers.size(); ++j) {
const auto vecName = relVecNames.vectorMembers[j];
const auto brName = root_utils::vecBranch(collInfo.name[i], vecName);
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
dentry->BindRawPtr(brName, collBuffers.vectorMembers->at(j).second);
#else
dentry->CaptureValueUnsafe(brName, collBuffers.vectorMembers->at(j).second);
#endif
}
}

Expand Down
29 changes: 0 additions & 29 deletions src/RNTupleWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ void RNTupleWriter::fillParams(const GenericParameters& params, CategoryInfo& ca
ROOT::Experimental::REntry* entry) {
auto& paramStorage = getParamStorage<T>(catInfo);
paramStorage = params.getKeysAndValues<T>();
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
entry->BindRawPtr(root_utils::getGPKeyName<T>(), &paramStorage.keys);
entry->BindRawPtr(root_utils::getGPValueName<T>(), &paramStorage.values);
#else
entry->CaptureValueUnsafe(root_utils::getGPKeyName<T>(), &paramStorage.keys);
entry->CaptureValueUnsafe(root_utils::getGPValueName<T>(), &paramStorage.values);
#endif
}

void RNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& category) {
Expand Down Expand Up @@ -99,33 +94,21 @@ void RNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& cat
}
}

#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
auto entry = m_categories[category].writer->GetModel().CreateBareEntry();
#else
auto entry = m_categories[category].writer->GetModel()->CreateBareEntry();
#endif

ROOT::Experimental::RNTupleWriteOptions options;
options.SetCompression(ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose);

for (const auto& [name, coll] : collections) {
auto collBuffers = coll->getBuffers();
if (collBuffers.vecPtr) {
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
entry->BindRawPtr(name, static_cast<void*>(collBuffers.vecPtr));
#else
entry->CaptureValueUnsafe(name, static_cast<void*>(collBuffers.vecPtr));
#endif
}

if (coll->isSubsetCollection()) {
auto& refColl = (*collBuffers.references)[0];
const auto brName = root_utils::subsetBranch(name);
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
entry->BindRawPtr(brName, refColl.get());
#else
entry->CaptureValueUnsafe(brName, refColl.get());
#endif

} else {

Expand All @@ -134,11 +117,7 @@ void RNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& cat
int i = 0;
for (auto& c : (*refColls)) {
const auto brName = root_utils::refBranch(name, relVecNames.relations[i]);
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
entry->BindRawPtr(brName, c.get());
#else
entry->CaptureValueUnsafe(brName, c.get());
#endif
++i;
}
}
Expand All @@ -149,11 +128,7 @@ void RNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& cat
const auto typeName = "vector<" + type + ">";
const auto brName = root_utils::vecBranch(name, relVecNames.vectorMembers[i]);
auto ptr = *static_cast<std::vector<int>**>(vec);
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
entry->BindRawPtr(brName, ptr);
#else
entry->CaptureValueUnsafe(brName, ptr);
#endif
++i;
}
}
Expand All @@ -177,11 +152,7 @@ std::unique_ptr<ROOT::Experimental::RNTupleModel>
RNTupleWriter::createModels(const std::vector<root_utils::StoreCollection>& collections) {
auto model = ROOT::Experimental::RNTupleModel::CreateBare();

#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 31, 0)
using ROOT::Experimental::RFieldBase;
#else
using ROOT::Experimental::Detail::RFieldBase;
#endif

for (auto& [name, coll] : collections) {
// For the first entry in each category we also record the datamodel
Expand Down

0 comments on commit f7fae2b

Please sign in to comment.