Skip to content

Commit

Permalink
Add const when possible in the writer
Browse files Browse the repository at this point in the history
and add [[maybe_unused]] for released pointer values
  • Loading branch information
jmcarcell committed Dec 9, 2024
1 parent fab6d3b commit de26891
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions k4FWCore/components/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
error() << "Failed to retrieve object leaves" << endmsg;
return;
}
for (auto& pReg : leaves) {
for (const auto& pReg : leaves) {
if (pReg->name() == k4FWCore::frameLocation) {
continue;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
// This is the case when we are reading from a file
// Putting it into a unique_ptr will make sure it's deleted
if (code.isSuccess()) {
auto sc = m_dataSvc->unregisterObject(p);
const auto sc = m_dataSvc->unregisterObject(p);
if (!sc.isSuccess()) {
error() << "Failed to unregister object" << endmsg;
return;
Expand Down Expand Up @@ -221,7 +221,7 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
// Remove the collections owned by a Frame (if any) so that they are not
// deleted by the store (and later deleted by the Frame, triggering a double
// delete)
for (auto& coll : frameCollections) {
for (const auto& coll : frameCollections) {
DataObject* storeCollection;
if (m_dataSvc->retrieveObject("/Event/" + coll, storeCollection).isFailure()) {
error() << "Failed to retrieve collection " << coll << endmsg;
Expand All @@ -233,12 +233,12 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
return;
}
// We still have to delete the AnyDataWrapper to avoid a leak
auto storePtr = dynamic_cast<AnyDataWrapper<std::unique_ptr<podio::CollectionBase>>*>(storeCollection);
storePtr->getData().release();
const auto storePtr = dynamic_cast<AnyDataWrapper<std::unique_ptr<podio::CollectionBase>>*>(storeCollection);
[[maybe_unused]] auto releasedPtr = storePtr->getData().release();
delete storePtr;
}

for (auto& coll : m_collectionsToAdd) {
for (const auto& coll : m_collectionsToAdd) {
DataObject* storeCollection;
if (m_dataSvc->retrieveObject("/Event/" + coll, storeCollection).isFailure()) {
error() << "Failed to retrieve collection " << coll << endmsg;
Expand Down

0 comments on commit de26891

Please sign in to comment.