Skip to content

Commit

Permalink
Add a loadFrom method to facilitate usage in RDataFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jun 12, 2024
1 parent f213527 commit b38c1d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
16 changes: 16 additions & 0 deletions include/podio/GenericParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class GenericParameters {
set<std::vector<T>>(key, std::move(values));
}

/// Load multiple key value pairs simultaneously
template <typename T>
void loadFrom(std::vector<std::string> keys, std::vector<std::vector<T>> values);

/// Get the number of elements stored under the given key for a type
template <typename T, typename = EnableIfValidGenericDataType<T>>
size_t getN(const std::string& key) const;
Expand Down Expand Up @@ -272,5 +276,17 @@ std::vector<std::vector<T>> GenericParameters::getValues() const {
}
return values;
}

template <typename T>
void GenericParameters::loadFrom(std::vector<std::string> keys, std::vector<std::vector<T>> values) {
auto& map = getMap<T>();
auto& mtx = getMutex<T>();

std::lock_guard lock{mtx};
for (size_t i = 0; i < keys.size(); ++i) {
map.emplace(std::move(keys[i]), std::move(values[i]));
}
}

} // namespace podio
#endif
4 changes: 1 addition & 3 deletions src/RNTupleReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ void RNTupleReader::readParams(const std::string& name, unsigned entNum, Generic
auto keyView = m_readers[name][0]->GetView<std::vector<std::string>>(root_utils::getGPKeyName<T>());
auto valueView = m_readers[name][0]->GetView<std::vector<std::vector<T>>>(root_utils::getGPValueName<T>());

for (size_t i = 0; i < keyView(entNum).size(); ++i) {
params.getMap<T>().emplace(std::move(keyView(entNum)[i]), std::move(valueView(entNum)[i]));
}
params.loadFrom(keyView(entNum), valueView(entNum));
}

GenericParameters RNTupleReader::readEventMetaData(const std::string& name, unsigned entNum) {
Expand Down
4 changes: 1 addition & 3 deletions src/ROOTReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ void ROOTReader::readParams(ROOTReader::CategoryInfo& catInfo, podio::GenericPar
valueBranch->SetAddress(storage.valuesPtr());
valueBranch->GetEntry(localEntry);

for (size_t i = 0; i < storage.keys.size(); ++i) {
params.getMap<T>().emplace(std::move(storage.keys[i]), std::move(storage.values[i]));
}
params.loadFrom(std::move(storage.keys), std::move(storage.values));
}

GenericParameters ROOTReader::readEntryParameters(ROOTReader::CategoryInfo& catInfo, bool reloadBranches,
Expand Down

0 comments on commit b38c1d6

Please sign in to comment.