Skip to content

Commit

Permalink
Change an argument for converting the parameters to be std::optional
Browse files Browse the repository at this point in the history
so that a Frame may be passed or not
  • Loading branch information
jmcarcell committed Dec 10, 2024
1 parent 6c80e81 commit ae3da96
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions k4EDM4hep2LcioConv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target_link_libraries(k4EDM4hep2LcioConv PUBLIC
EDM4HEP::edm4hep
EDM4HEP::utils
ROOT::MathCore
k4FWCore::k4FWCore
)

set(public_headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,59 @@

#include <UTIL/PIDHandler.h>

#include "podio/Frame.h"

#include <edm4hep/ParticleIDCollection.h>
#include <edm4hep/RecDqdxCollection.h>

#include "k4FWCore/MetadataUtils.h"

namespace LCIO2EDM4hepConv {
template <typename LCIOType>
void convertObjectParameters(LCIOType* lcioobj, podio::Frame& event) {
void convertObjectParameters(LCIOType* lcioobj, std::optional<std::reference_wrapper<podio::Frame>>& 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;
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
6 changes: 4 additions & 2 deletions k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ podio::Frame convertEvent(EVENT::LCEvent* evt, const std::vector<std::pair<std::

// Now everything is done and we simply populate a Frame
podio::Frame event;
std::optional<std::reference_wrapper<podio::Frame>> eventOpt = event;
// convert put the event parameters into the frame
convertObjectParameters<EVENT::LCEvent>(evt, event);
convertObjectParameters<EVENT::LCEvent>(evt, eventOpt);

// only create CaloHitContributions if necessary (i.e. if we have converted
// SimCalorimeterHits)
Expand All @@ -154,7 +155,8 @@ podio::Frame convertRunHeader(EVENT::LCRunHeader* rheader) {
runHeaderFrame.putParameter("activeSubdetectors", *subdetectors);

// convert everything set as a parameter
convertObjectParameters<EVENT::LCRunHeader>(rheader, runHeaderFrame);
std::optional<std::reference_wrapper<podio::Frame>> runHeaderFrameOpt = runHeaderFrame;
convertObjectParameters<EVENT::LCRunHeader>(rheader, runHeaderFrameOpt);

return runHeaderFrame;
}
Expand Down

0 comments on commit ae3da96

Please sign in to comment.