Skip to content

Commit

Permalink
Merge pull request #389 from JeffersonLab/nbrei_podio_deprecation_war…
Browse files Browse the repository at this point in the history
…ning

Fix Podio deprecation warnings
  • Loading branch information
nathanwbrei authored Dec 5, 2024
2 parents ef4877d + 350aa81 commit abdb575
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 21 deletions.
9 changes: 4 additions & 5 deletions src/examples/InteractiveStreamingExample/DecodeDASSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ DecodeDASSource::~DecodeDASSource() {
void DecodeDASSource::Open() {

// open the file stream
ifs.open(GetName());
if (!ifs) throw JException("Unable to open '%s'", GetName().c_str());
ifs.open(GetResourceName());
if (!ifs) throw JException("Unable to open '%s'", GetResourceName().c_str());

}

void DecodeDASSource::Close() {
// Close the file/stream here.
std::cout << "Closing " << GetName() << std::endl;
std::cout << "Closing " << GetResourceName() << std::endl;
ifs.close();
}

JEventSource::Result DecodeDASSource::Emit(JEvent& event) {

// TODO: Put these somewhere that makes sense
size_t MAX_CHANNELS = 80;
size_t MAX_SAMPLES = 1024;
// open the file stream and parse the data
Expand All @@ -59,7 +58,7 @@ JEventSource::Result DecodeDASSource::Emit(JEvent& event) {
return Result::Success;
}
// close file stream when the end of file is reached
std::cout << "Reached end of file/stream " << GetName() << std::endl;
std::cout << "Reached end of file/stream " << GetResourceName() << std::endl;
}
return Result::FailureFinished;

Expand Down
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
4 changes: 2 additions & 2 deletions src/libraries/JANA/Utils/JCpuInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ uint32_t GetCpuID() {
#ifdef __cpuid_count
GETCPU(cpuid);
#else // __cpuid_count
#warning __cpuid_count is not defined on this system.
// cpuid_count is not defined on this system.
return 0;
#endif // __cpuid_count
return cpuid;
// TODO: Clean this up

#else //__APPLE__
return sched_getcpu();
Expand Down

0 comments on commit abdb575

Please sign in to comment.