Skip to content

Commit

Permalink
Fix podio deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Dec 5, 2024
1 parent ef4877d commit 7620f68
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
15 changes: 13 additions & 2 deletions src/examples/PodioExample/PodioExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@

#include "PodioDatamodel/EventInfoCollection.h"
#include "PodioDatamodel/ExampleHitCollection.h"
#include <podio/podioVersion.h>

#if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 99
#include <podio/ROOTFrameWriter.h>
#include <podio/ROOTFrameReader.h>
namespace podio {
using ROOTWriter = podio::ROOTFrameWriter;
using ROOTReader = podio::ROOTFrameReader;
}
#else
#include <podio/ROOTWriter.h>
#include <podio/ROOTReader.h>
#endif

#include <JANA/JApplication.h>
#include <JANA/JFactoryGenerator.h>
Expand Down Expand Up @@ -36,7 +47,7 @@ void create_hits_file() {
event1.put(std::move(hits1), "hits");
event1.put(std::move(eventinfos1), "eventinfos");

podio::ROOTFrameWriter writer("hits.root");
podio::ROOTWriter writer("hits.root");
writer.writeFrame(event1, "events");

MutableEventInfo eventinfo2(8, 0, 22);
Expand All @@ -59,7 +70,7 @@ void create_hits_file() {
}

void verify_clusters_file() {
podio::ROOTFrameReader reader;
podio::ROOTReader reader;
reader.openFile("podio_output.root");
auto event0 = podio::Frame(reader.readEntry("events", 0));

Expand Down
12 changes: 10 additions & 2 deletions src/examples/PodioFileReader/PodioFileReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@
#include <PodioDatamodel/ExampleHitCollection.h>
#include <PodioDatamodel/ExampleClusterCollection.h>

#include <podio/podioVersion.h>
#if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 99
#include <podio/ROOTFrameReader.h>
namespace podio {
using ROOTReader = podio::ROOTFrameReader;
}
#else
#include <podio/ROOTReader.h>
#endif



class PodioFileReader : public JEventSource {

private:
uint64_t m_entry_count = 0;
podio::ROOTFrameReader m_reader;
// ROOTFrameReader emits a lot of deprecation warnings, but the supposed replacement
podio::ROOTReader m_reader;
// ROOTReader emits a lot of deprecation warnings, but the supposed replacement
// won't actually be a replacement until the next version

public:
Expand Down
13 changes: 11 additions & 2 deletions src/examples/PodioFileWriter/PodioFileWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
// Author: Nathan Brei

#include <JANA/JEventProcessor.h>

#include <podio/podioVersion.h>
#if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 99
#include <podio/ROOTFrameWriter.h>
namespace podio {
using ROOTWriter = podio::ROOTFrameWriter;
}
#else
#include <podio/ROOTWriter.h>
#endif

class PodioFileWriter : public JEventProcessor {

Expand All @@ -23,7 +32,7 @@ class PodioFileWriter : public JEventProcessor {
"events",
"Name of branch to store data in the output file"};

std::unique_ptr<podio::ROOTFrameWriter> m_writer;
std::unique_ptr<podio::ROOTWriter> m_writer;


public:
Expand All @@ -33,7 +42,7 @@ class PodioFileWriter : public JEventProcessor {
}

void Init() override {
m_writer = std::make_unique<podio::ROOTFrameWriter>(*m_output_filename);
m_writer = std::make_unique<podio::ROOTWriter>(*m_output_filename);
}

void Finish() override {
Expand Down
17 changes: 12 additions & 5 deletions src/examples/TimesliceExample/MyFileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

#pragma once

#include <podio/ROOTFrameWriter.h>
#include "CollectionTabulators.h"
#include <JANA/JEventProcessor.h>
#include "CollectionTabulators.h"

#include <set>
#include <podio/podioVersion.h>
#if podio_VERSION_MAJOR == 0 && podio_VERSION_MINOR < 99
#include <podio/ROOTFrameWriter.h>
namespace podio {
using ROOTWriter = podio::ROOTFrameWriter;
}
#else
#include <podio/ROOTWriter.h>
#endif



Expand All @@ -25,7 +32,7 @@ struct MyFileWriter : public JEventProcessor {
.level = JEventLevel::Timeslice,
.is_optional = true }};

std::unique_ptr<podio::ROOTFrameWriter> m_writer = nullptr;
std::unique_ptr<podio::ROOTWriter> m_writer = nullptr;
std::mutex m_mutex;

MyFileWriter() {
Expand All @@ -34,7 +41,7 @@ struct MyFileWriter : public JEventProcessor {
}

void Init() {
m_writer = std::make_unique<podio::ROOTFrameWriter>("output.root");
m_writer = std::make_unique<podio::ROOTWriter>("output.root");
}

void Process(const JEvent& event) {
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/JANA/JEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ template <typename T>
JFactoryPodioT<T>* JEvent::InsertCollectionAlreadyInFrame(const podio::CollectionBase* collection, std::string name) {
/// InsertCollection inserts the provided PODIO collection into a JFactoryPodioT<T>. It assumes that the collection pointer
/// is _already_ owned by the podio::Frame corresponding to this JEvent. This is meant to be used if you are starting out
/// with a PODIO frame (e.g. a JEventSource that uses podio::ROOTFrameReader).
/// with a PODIO frame (e.g. a JEventSource that uses podio::ROOTReader).

const auto* typed_collection = dynamic_cast<const typename T::collection_type*>(collection);
if (typed_collection == nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/JANA/Podio/JFactoryPodioT.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ void JFactoryPodioT<T>::Create(const std::shared_ptr<const JEvent>& event) {
catch (...) {
if (mCollection == nullptr) {
// If calling Create() excepts, we still create an empty collection
// so that podio::ROOTFrameWriter doesn't segfault on the null mCollection pointer
// so that podio::ROOTWriter doesn't segfault on the null mCollection pointer
SetCollection(CollectionT());
}
throw;
}
if (mCollection == nullptr) {
SetCollection(CollectionT());
// If calling Process() didn't result in a call to Set() or SetCollection(), we create an empty collection
// so that podio::ROOTFrameWriter doesn't segfault on the null mCollection pointer
// so that podio::ROOTWriter doesn't segfault on the null mCollection pointer
}
}

Expand Down

0 comments on commit 7620f68

Please sign in to comment.