diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h index c8bc622..607b156 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h @@ -159,12 +159,33 @@ std::unique_ptr fillSubset(EVENT::LCCollection* LCCollect template std::vector 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 + * 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 +void convertObjectParameters(LCIOType* lcioobj, PutParamF putParamFun); + /** * Converting all parameters of an LCIO Object and attaching them to the * passed podio::Frame. */ template -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]); } diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp index 637ece5..f684515 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp @@ -6,16 +6,18 @@ #include namespace LCIO2EDM4hepConv { -template -void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) { + +template +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; @@ -23,7 +25,7 @@ void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) { 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; @@ -31,7 +33,7 @@ void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) { 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; @@ -39,7 +41,7 @@ void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) { 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); } }