Skip to content

Commit

Permalink
fix frame variable shadowing in metadata service interface
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila authored and andresailer committed Aug 29, 2024
1 parent a2d1738 commit 4f12ea3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
8 changes: 4 additions & 4 deletions k4FWCore/components/MetadataSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <GaudiKernel/IDataProviderSvc.h>
#include <GaudiKernel/Service.h>

#include <memory>

StatusCode MetadataSvc::initialize() {
StatusCode sc = Service::initialize();
if (sc.isFailure()) {
Expand All @@ -36,14 +38,12 @@ StatusCode MetadataSvc::initialize() {
error() << "Unable to locate the EventDataSvc" << endmsg;
return StatusCode::FAILURE;
}

m_frame.reset(new podio::Frame());

return StatusCode::SUCCESS;
}

StatusCode MetadataSvc::finalize() { return Service::finalize(); }

void MetadataSvc::setFrame(podio::Frame&& fr) { m_frame.reset(new podio::Frame(std::move(fr))); }
podio::Frame* MetadataSvc::getFrame() { return m_frame.get(); }
void MetadataSvc::setFrame(podio::Frame&& frame) { m_frame = std::make_unique<podio::Frame>(std::move(frame)); }

DECLARE_COMPONENT(MetadataSvc)
5 changes: 4 additions & 1 deletion k4FWCore/components/MetadataSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "k4FWCore/IMetadataSvc.h"

#include <memory>

class MetadataSvc : public extends<Service, IMetadataSvc> {
using extends::extends;

Expand All @@ -40,7 +42,8 @@ class MetadataSvc : public extends<Service, IMetadataSvc> {

std::unique_ptr<podio::Frame> m_frame;

void setFrame(podio::Frame&& frame) override;
podio::Frame* getFrame() override;
void setFrame(podio::Frame&& frame) override;
};

#endif
4 changes: 2 additions & 2 deletions k4FWCore/components/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
}
iosvc->getWriter()->writeFrame(config_metadata_frame, "configuration_metadata");

if (m_metadataSvc->m_frame) {
iosvc->getWriter()->writeFrame(*std::move(m_metadataSvc->m_frame), podio::Category::Metadata);
if (auto* metadata_frame = m_metadataSvc->getFrame(); metadata_frame) {
iosvc->getWriter()->writeFrame(*metadata_frame, podio::Category::Metadata);
}

iosvc->deleteWriter();
Expand Down
13 changes: 7 additions & 6 deletions k4FWCore/include/k4FWCore/IMetadataSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ class IMetadataSvc : virtual public IInterface {
public:
DeclareInterfaceID(IMetadataSvc, 1, 0);

std::unique_ptr<podio::Frame> m_frame;
virtual podio::Frame* getFrame() = 0;
virtual void setFrame(podio::Frame&& frame) = 0;

virtual void setFrame(podio::Frame&& fr) = 0;
template <typename T> void put(const std::string& name, const T& obj) {
if (!m_frame) {
m_frame.reset(new podio::Frame());
if (!getFrame()) {
setFrame(podio::Frame{});
}
m_frame->putParameter(name, obj);
getFrame()->putParameter(name, obj);
}
template <typename T> std::optional<T> get(const std::string& name) { return m_frame->getParameter<T>(name); }

template <typename T> std::optional<T> get(const std::string& name) { return getFrame()->getParameter<T>(name); }
};

#endif

0 comments on commit 4f12ea3

Please sign in to comment.