Skip to content

Commit

Permalink
Merge pull request #290 from JeffersonLab/nbrei_polish_timeslice_example
Browse files Browse the repository at this point in the history
Polish timeslice example
  • Loading branch information
nathanwbrei authored Apr 24, 2024
2 parents 2d125be + 4daa43c commit 59c2a54
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 124 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0074 NEW) # find_package() uses <PackageName>_ROOT implicit hints

project(jana2 VERSION 2.1.2)
project(jana2 VERSION 2.2.0)

set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Enable -fPIC for all targets

Expand Down
4 changes: 2 additions & 2 deletions src/examples/TimesliceExample/MyClusterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

struct MyClusterFactory : public JOmniFactory<MyClusterFactory> {

PodioInput<ExampleCluster> m_protoclusters_in {this, "evt_protoclusters"};
PodioOutput<ExampleCluster> m_clusters_out {this, "clusters"};
PodioInput<ExampleCluster> m_protoclusters_in {this};
PodioOutput<ExampleCluster> m_clusters_out {this};


void Configure() {
Expand Down
1 change: 1 addition & 0 deletions src/examples/TimesliceExample/MyFileReaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class MyFileReaderGenerator : public JEventSourceGenerator {
JEventSource* MakeJEventSource(std::string resource_name) override {

auto source = new MyFileReader;
source->SetResourceName(resource_name);

// Check if the string "timeslices" appears anywhere in our filename.
// If so, we assume the file contains timeslices, otherwise it contains physics events.
Expand Down
14 changes: 7 additions & 7 deletions src/examples/TimesliceExample/MyFileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
struct MyFileWriter : public JEventProcessor {

// Trigger the creation of clusters
PodioInput<ExampleCluster> m_evt_clusters_in {this, "clusters"};
PodioInput<ExampleCluster> m_evt_clusters_in {this, {.name="clusters"}};

// Retrieve the PODIO frame so we can write it directly
Input<podio::Frame> m_evt_frame_in {this, "", JEventLevel::PhysicsEvent};
Input<podio::Frame> m_evt_frame_in {this, {.name = "",
.level = JEventLevel::PhysicsEvent}};

// TODO: Support optional inputs
// Input<podio::Frame> m_ts_frame_in {this, "", JEventLevel::Timeslice};
Input<podio::Frame> m_ts_frame_in {this, {.name = "",
.level = JEventLevel::Timeslice,
.is_optional = true }};

std::unique_ptr<podio::ROOTFrameWriter> m_writer = nullptr;
std::mutex m_mutex;
Expand All @@ -44,9 +46,7 @@ struct MyFileWriter : public JEventProcessor {
auto ts_nr = ts.GetEventNumber();

if (event->GetEventIndex() == 0) {
// m_writer->writeFrame(*(m_ts_frame_in().at(0)), "timeslices");
auto ts_frame_in = ts.Get<podio::Frame>();
m_writer->writeFrame(*(ts_frame_in.at(0)), "timeslices");
m_writer->writeFrame(*(m_ts_frame_in().at(0)), "timeslices");
}

LOG_DEBUG(GetLogger())
Expand Down
4 changes: 2 additions & 2 deletions src/examples/TimesliceExample/MyProtoclusterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

struct MyProtoclusterFactory : public JOmniFactory<MyProtoclusterFactory> {

PodioInput<ExampleHit> hits_in {this, "hits"};
PodioOutput<ExampleCluster> clusters_out {this, "protoclusters"};
PodioInput<ExampleHit> hits_in {this};
PodioOutput<ExampleCluster> clusters_out {this};

void Configure() {
}
Expand Down
3 changes: 2 additions & 1 deletion src/examples/TimesliceExample/MyTimesliceSplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

struct MyTimesliceSplitter : public JEventUnfolder {

PodioInput<ExampleCluster> m_timeslice_clusters_in {this, "ts_protoclusters", JEventLevel::Timeslice};
PodioInput<ExampleCluster> m_timeslice_clusters_in {this, {.name = "ts_protoclusters",
.level = JEventLevel::Timeslice}};

PodioOutput<ExampleCluster> m_event_clusters_out {this, "evt_protoclusters"};
PodioOutput<EventInfo> m_event_info_out {this, "evt_info"};
Expand Down
12 changes: 6 additions & 6 deletions src/examples/TimesliceExample/TimesliceExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ void InitPlugin(JApplication *app) {
app->Add(new JOmniFactoryGeneratorT<MyProtoclusterFactory>(
{ .tag = "timeslice_protoclusterizer",
.level = JEventLevel::Timeslice,
.input_tags = {"hits"},
.output_tags = {"ts_protoclusters"}
.input_names = {"hits"},
.output_names = {"ts_protoclusters"}
}));

// Factory that produces event-level protoclusters from event-level hits
app->Add(new JOmniFactoryGeneratorT<MyProtoclusterFactory>(
{ .tag = "event_protoclusterizer",
.input_tags = {"hits"},
.output_tags = {"evt_protoclusters"}}
.input_names = {"hits"},
.output_names = {"evt_protoclusters"}}
));

// Factory that produces event-level clusters from event-level protoclusters
app->Add(new JOmniFactoryGeneratorT<MyClusterFactory>(
{ .tag = "clusterizer",
.input_tags = {"evt_protoclusters"},
.output_tags = {"clusters"}}
.input_names = {"evt_protoclusters"},
.output_names = {"clusters"}}
));


Expand Down
16 changes: 9 additions & 7 deletions src/libraries/JANA/JEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ class JEvent : public std::enable_shared_from_this<JEvent>
//OBJECTS
// C style getters
template<class T> JFactoryT<T>* Get(const T** item, const std::string& tag="") const;
template<class T> JFactoryT<T>* Get(std::vector<const T*> &vec, const std::string& tag = "") const;
template<class T> JFactoryT<T>* Get(std::vector<const T*> &vec, const std::string& tag = "", bool strict=true) const;
template<class T> void GetAll(std::vector<const T*> &vec) const;

// C++ style getters
template<class T> const T* GetSingle(const std::string& tag = "") const;
template<class T> const T* GetSingleStrict(const std::string& tag = "") const;
template<class T> std::vector<const T*> Get(const std::string& tag = "") const;
template<class T> std::vector<const T*> Get(const std::string& tag = "", bool strict=true) const;
template<class T> typename JFactoryT<T>::PairType GetIterators(const std::string& aTag = "") const;
template<class T> std::vector<const T*> GetAll() const;
template<class T> std::map<std::pair<std::string,std::string>,std::vector<T*>> GetAllChildren() const;
Expand Down Expand Up @@ -336,9 +336,10 @@ JFactoryT<T>* JEvent::Get(const T** destination, const std::string& tag) const


template<class T>
JFactoryT<T>* JEvent::Get(std::vector<const T*>& destination, const std::string& tag) const
JFactoryT<T>* JEvent::Get(std::vector<const T*>& destination, const std::string& tag, bool strict) const
{
auto factory = GetFactory<T>(tag, true);
auto factory = GetFactory<T>(tag, strict);
if (factory == nullptr) return nullptr; // Will have thrown already if strict==true
JCallGraphEntryMaker cg_entry(mCallGraph, factory); // times execution until this goes out of scope
auto iterators = factory->CreateAndGetData(this->shared_from_this());
for (auto it=iterators.first; it!=iterators.second; it++) {
Expand Down Expand Up @@ -392,12 +393,13 @@ template<class T> const T* JEvent::GetSingleStrict(const std::string& tag) const


template<class T>
std::vector<const T*> JEvent::Get(const std::string& tag) const {
std::vector<const T*> JEvent::Get(const std::string& tag, bool strict) const {

auto factory = GetFactory<T>(tag, true);
auto factory = GetFactory<T>(tag, strict);
std::vector<const T*> vec;
if (factory == nullptr) return vec; // Will have thrown already if strict==true
JCallGraphEntryMaker cg_entry(mCallGraph, factory); // times execution until this goes out of scope
auto iters = factory->CreateAndGetData(this->shared_from_this());
std::vector<const T*> vec;
for (auto it=iters.first; it!=iters.second; ++it) {
vec.push_back(*it);
}
Expand Down
24 changes: 24 additions & 0 deletions src/libraries/JANA/JEventSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,24 @@ class JEventSource : public jana::omni::JComponent, public jana::omni::JHasOutpu
std::lock_guard<std::mutex> lock(m_mutex);
if (m_status == Status::Uninitialized) {
Open();
if (GetResourceName().empty()) {
LOG_INFO(GetLogger()) << "Opened event source" << LOG_END;
}
else {
LOG_INFO(GetLogger()) << "Opened event source '" << GetResourceName() << "'" << LOG_END;
}
m_status = Status::Initialized;
}
}
else {
if (m_status == Status::Uninitialized) {
Open();
if (GetResourceName().empty()) {
LOG_INFO(GetLogger()) << "Opened event source" << LOG_END;
}
else {
LOG_INFO(GetLogger()) << "Opened event source '" << GetResourceName() << "'" << LOG_END;
}
m_status = Status::Initialized;
}
}
Expand Down Expand Up @@ -147,10 +159,22 @@ class JEventSource : public jana::omni::JComponent, public jana::omni::JHasOutpu
if (with_lock) {
std::lock_guard<std::mutex> lock(m_mutex);
Close();
if (GetResourceName().empty()) {
LOG_INFO(GetLogger()) << "Closed event source" << LOG_END;
}
else {
LOG_INFO(GetLogger()) << "Closed event source '" << GetResourceName() << "'" << LOG_END;
}
m_status = Status::Finalized;
}
else {
Close();
if (GetResourceName().empty()) {
LOG_INFO(GetLogger()) << "Closed event source" << LOG_END;
}
else {
LOG_INFO(GetLogger()) << "Closed event source '" << GetResourceName() << "'" << LOG_END;
}
m_status = Status::Finalized;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/libraries/JANA/JService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

void JService::DoInit(JServiceLocator* sl) {
std::lock_guard<std::mutex> lock(m_mutex);
if (this->m_status != Status::Uninitialized) return;
try {
for (auto* parameter : m_parameters) {
parameter->Configure(*(m_app->GetJParameterManager()), m_prefix);
Expand Down
Loading

0 comments on commit 59c2a54

Please sign in to comment.