Skip to content

Commit

Permalink
make methods const when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Aug 16, 2024
1 parent 83b31b4 commit ea9a0b0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion k4FWCore/components/MetadataSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ StatusCode MetadataSvc::initialize() {

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

podio::Frame* MetadataSvc::getFrame() { return m_frame.get(); }
const podio::Frame* MetadataSvc::getFrame() const { return m_frame.get(); }
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: 3 additions & 2 deletions k4FWCore/components/MetadataSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class MetadataSvc : public extends<Service, IMetadataSvc> {

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

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

#endif
3 changes: 2 additions & 1 deletion k4FWCore/components/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <GaudiKernel/IHiveWhiteBoard.h>
#include <memory>
#include <utility>

class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&)> {
public:
Expand Down Expand Up @@ -121,7 +122,7 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
}
iosvc->getWriter()->writeFrame(config_metadata_frame, "configuration_metadata");

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

Expand Down
11 changes: 7 additions & 4 deletions k4FWCore/include/k4FWCore/IMetadataSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class IMetadataSvc : virtual public IInterface {
public:
DeclareInterfaceID(IMetadataSvc, 1, 0);

virtual podio::Frame* getFrame() = 0;
virtual void setFrame(podio::Frame&& frame) = 0;
virtual const podio::Frame* getFrame() const = 0;
virtual void setFrame(podio::Frame&& frame) = 0;

template <typename T> void put(const std::string& name, const T& obj) {
if (!getFrame()) {
Expand All @@ -37,13 +37,16 @@ class IMetadataSvc : virtual public IInterface {
getFrame()->putParameter(name, obj);
}

template <typename T> std::optional<T> get(const std::string& name) {
auto* frame = getFrame();
template <typename T> std::optional<T> get(const std::string& name) const {
const auto* frame = getFrame();
if (!frame) {
return std::nullopt;
}
return frame->getParameter<T>(name);
}

protected:
virtual podio::Frame* getFrame() = 0;
};

#endif

0 comments on commit ea9a0b0

Please sign in to comment.