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

Change an argument for converting the parameters to be std::optional #102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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);
}
};
Comment on lines +17 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a template parameter to the convertObjecParameters? Then we could externalize the k4FWCore dependency and simply define this in the wrapper, where we already have that dependency. I suppose the main issue is that it would need to be a templated function because it has to work for several datatypes?


// 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
Loading