Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize the functionality of converting parameters #102

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,33 @@ std::unique_ptr<podio::CollectionBase> fillSubset(EVENT::LCCollection* LCCollect
template <typename LCVecType>
std::vector<CollNamePair> convertLCVec(const std::string& name, EVENT::LCCollection* LCCollection);

/**
* Converting all parameters of an LCIO Object and passing them to the PutParamF
* function that takes care of storing them appropriately.
*
* The indirection is necessary for better integration with k4FWCore where
* direct access to a Frame is not possible, but a putParameter method is
* available instead.
*
* The PutParamF has to provide the following interface
*
* template<typename T>
* void(std::string const&, T const&)
*
* It will be called for all T that are currently supported as parameters (int,
* float, double, std::string resp. std::vector of those).
*/
template <typename LCIOType, typename PutParamF>
void convertObjectParameters(LCIOType* lcioobj, PutParamF putParamFun);

/**
* Converting all parameters of an LCIO Object and attaching them to the
* passed podio::Frame.
*/
template <typename LCIOType>
void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event);
void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) {
convertObjectParameters(lcioobj, [&event](const std::string& key, const auto& v) { event.putParameter(key, v); });
}

inline edm4hep::Vector3f Vector3fFrom(const double* v) { return edm4hep::Vector3f(v[0], v[1], v[2]); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,42 @@
#include <edm4hep/RecDqdxCollection.h>

namespace LCIO2EDM4hepConv {
template <typename LCIOType>
void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) {

template <typename LCIOType, typename PutParamF>
void convertObjectParameters(LCIOType* lcioobj, PutParamF putParamFun) {
const auto& params = lcioobj->getParameters();

// handle srting params
EVENT::StringVec keys;
const auto stringKeys = params.getStringKeys(keys);
for (auto i = 0u; i < stringKeys.size(); i++) {
EVENT::StringVec sValues;
const auto stringVals = params.getStringVals(stringKeys[i], sValues);
event.putParameter(stringKeys[i], stringVals);
putParamFun(stringKeys[i], stringVals);
}
// handle float params
EVENT::StringVec fkeys;
const auto floatKeys = params.getFloatKeys(fkeys);
for (auto i = 0u; i < floatKeys.size(); i++) {
EVENT::FloatVec fValues;
const auto floatVals = params.getFloatVals(floatKeys[i], fValues);
event.putParameter(floatKeys[i], floatVals);
putParamFun(floatKeys[i], floatVals);
}
// handle int params
EVENT::StringVec ikeys;
const auto intKeys = params.getIntKeys(ikeys);
for (auto i = 0u; i < intKeys.size(); i++) {
EVENT::IntVec iValues;
const auto intVals = params.getIntVals(intKeys[i], iValues);
event.putParameter(intKeys[i], intVals);
putParamFun(intKeys[i], intVals);
}
// handle double params
EVENT::StringVec dkeys;
const auto dKeys = params.getDoubleKeys(dkeys);
for (auto i = 0u; i < dKeys.size(); i++) {
EVENT::DoubleVec dValues;
const auto dVals = params.getDoubleVals(dKeys[i], dValues);
event.putParameter(dKeys[i], dVals);
putParamFun(dKeys[i], dVals);
}
}

Expand Down
Loading