diff --git a/CMakeLists.txt b/CMakeLists.txt index 008d93b..330263e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ k4edm4hep2lcioconv_set_linker_flags() find_package(LCIO 2.22 REQUIRED) find_package(podio 1.0 REQUIRED) find_package(EDM4HEP 0.99 REQUIRED) +find_package(k4FWCore REQUIRED) find_package(ROOT REQUIRED COMPONENTS MathCore) add_subdirectory(k4EDM4hep2LcioConv) diff --git a/k4EDM4hep2LcioConv/CMakeLists.txt b/k4EDM4hep2LcioConv/CMakeLists.txt index f0ed44f..c4d2d7e 100644 --- a/k4EDM4hep2LcioConv/CMakeLists.txt +++ b/k4EDM4hep2LcioConv/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(k4EDM4hep2LcioConv PUBLIC EDM4HEP::edm4hep EDM4HEP::utils ROOT::MathCore + k4FWCore::k4FWCore ) set(public_headers diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp index 0598ba2..3d05c13 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp @@ -2,20 +2,35 @@ #include +#include "podio/Frame.h" + #include #include +#include "k4FWCore/MetadataUtils.h" + namespace LCIO2EDM4hepConv { template -void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) { +void convertObjectParameters(LCIOType* lcioobj, std::optional>& event) { const auto& params = lcioobj->getParameters(); + + // When using the PodioDataSvc there is always access to the event frame + // but when using IOSvc there is not a frame + auto putParamFun = [&](const std::string& key, const auto& value) { + if (event) { + event->get().putParameter(key, value); + } else { + k4FWCore::putParameter(key, value); + } + }; + // 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 +38,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 +46,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 +54,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); } } diff --git a/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp b/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp index e380139..8ee4bbf 100644 --- a/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp +++ b/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp @@ -126,8 +126,9 @@ podio::Frame convertEvent(EVENT::LCEvent* evt, const std::vector> eventOpt = event; // convert put the event parameters into the frame - convertObjectParameters(evt, event); + convertObjectParameters(evt, eventOpt); // only create CaloHitContributions if necessary (i.e. if we have converted // SimCalorimeterHits) @@ -154,7 +155,8 @@ podio::Frame convertRunHeader(EVENT::LCRunHeader* rheader) { runHeaderFrame.putParameter("activeSubdetectors", *subdetectors); // convert everything set as a parameter - convertObjectParameters(rheader, runHeaderFrame); + std::optional> runHeaderFrameOpt = runHeaderFrame; + convertObjectParameters(rheader, runHeaderFrameOpt); return runHeaderFrame; }