-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from JeffersonLab/nbrei_timeslices
Add support for timeslices
- Loading branch information
Showing
47 changed files
with
2,338 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
if (USE_PODIO) | ||
set (TimesliceExample_SOURCES | ||
TimesliceExample.cc | ||
) | ||
|
||
add_library(TimesliceExample SHARED ${TimesliceExample_SOURCES}) | ||
target_link_libraries(TimesliceExample jana2 podio::podio PodioExampleDatamodel PodioExampleDatamodelDict podio::podioRootIO) | ||
set_target_properties(TimesliceExample PROPERTIES PREFIX "" SUFFIX ".so" OUTPUT_NAME "TimesliceExample") | ||
install(TARGETS TimesliceExample DESTINATION programs) | ||
|
||
else() | ||
message(STATUS "Skipping examples/TimesliceExample because USE_PODIO=Off") | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2024, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
|
||
#include <JANA/JObject.h> | ||
|
||
struct MyHit : public JObject { | ||
int hit_id; | ||
int energy, x, y; | ||
}; | ||
|
||
struct MyCluster : public JObject { | ||
int cluster_id; | ||
int energy, x, y; | ||
std::vector<int> hits; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
|
||
|
||
// Copyright 2024, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
#include "MyDataModel.h" | ||
#include <JANA/JFactoryT.h> | ||
#include <JANA/Omni/JOmniFactory.h> | ||
|
||
|
||
struct MyClusterFactory : public JFactoryT<MyCluster> { | ||
|
||
int init_call_count = 0; | ||
int change_run_call_count = 0; | ||
int process_call_count = 0; | ||
|
||
MyClusterFactory() { | ||
SetLevel(JEventLevel::Event); | ||
} | ||
|
||
void Init() override { | ||
++init_call_count; | ||
} | ||
|
||
void ChangeRun(const std::shared_ptr<const JEvent>&) override { | ||
++change_run_call_count; | ||
} | ||
|
||
void Process(const std::shared_ptr<const JEvent>& event) override { | ||
++process_call_count; | ||
|
||
auto protos = event->Get<MyCluster>("protos"); | ||
// TODO: Output something sensible | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
// Copyright 2024, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
#include "MyDataModel.h" | ||
#include <JANA/JEventProcessor.h> | ||
|
||
struct ExampleEventProcessor : public JEventProcessor { | ||
|
||
std::mutex m_mutex; | ||
|
||
ExampleTimesliceProcessor() { | ||
SetEventLevel(JEvent::Level::Event); | ||
} | ||
|
||
void Process(const std::shared_ptr<const JEvent>& event) { | ||
|
||
std::lock_guard<std::mutex> guard(m_mutex); | ||
|
||
auto outputs = event->Get<MyOutput>(); | ||
// assert(outputs.size() == 4); | ||
// assert(outputs[0]->z == 25.6f); | ||
// assert(outputs[1]->z == 26.5f); | ||
// assert(outputs[2]->z == 27.4f); | ||
// assert(outputs[3]->z == 28.3f); | ||
LOG << " Contents of event " << event->GetEventNumber() << LOG_END; | ||
for (auto output : outputs) { | ||
LOG << " " << output->evt << ":" << output->sub << " " << output->z << LOG_END; | ||
} | ||
LOG << " DONE with contents of event " << event->GetEventNumber() << LOG_END; | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2024, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
#include "MyDataModel.h" | ||
|
||
#include <JANA/Omni/JOmniFactory.h> | ||
#include <JANA/JFactoryT.h> | ||
|
||
|
||
struct MyProtoClusterFactory : public JFactoryT<MyCluster> { | ||
|
||
int init_call_count = 0; | ||
int change_run_call_count = 0; | ||
int process_call_count = 0; | ||
|
||
MyProtoClusterFactory() { | ||
SetLevel(JEventLevel::Timeslice); | ||
} | ||
|
||
void Init() override { | ||
++init_call_count; | ||
} | ||
|
||
void ChangeRun(const std::shared_ptr<const JEvent>&) override { | ||
++change_run_call_count; | ||
} | ||
|
||
void Process(const std::shared_ptr<const JEvent>& event) override { | ||
++process_call_count; | ||
|
||
auto protos = event->Get<MyCluster>("protos"); | ||
// TODO: Output something sensible | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
#include "MyDataModel.h" | ||
#include <JANA/JEventSource.h> | ||
|
||
|
||
struct MyTimesliceSource : public JEventSource { | ||
|
||
MyTimesliceSource(std::string source_name, JApplication *app) : JEventSource(source_name, app) { | ||
SetLevel(JEventLevel::Timeslice); | ||
} | ||
|
||
static std::string GetDescription() { return "MyTimesliceSource"; } | ||
|
||
std::string GetType(void) const override { return JTypeInfo::demangle<decltype(*this)>(); } | ||
|
||
void Open() override { } | ||
|
||
void GetEvent(std::shared_ptr<JEvent> event) override { | ||
|
||
auto evt = event->GetEventNumber(); | ||
std::vector<MyInput*> inputs; | ||
inputs.push_back(new MyInput(22,3.6,evt,0)); | ||
inputs.push_back(new MyInput(23,3.5,evt,1)); | ||
inputs.push_back(new MyInput(24,3.4,evt,2)); | ||
inputs.push_back(new MyInput(25,3.3,evt,3)); | ||
inputs.push_back(new MyInput(26,3.2,evt,4)); | ||
event->Insert(inputs); | ||
|
||
auto hits = std::make_unique<ExampleHitCollection>(); | ||
hits.push_back(ExampleHit(22)); | ||
hits.push_back(ExampleHit(23)); | ||
hits.push_back(ExampleHit(24)); | ||
event->InsertCollection(hits); | ||
|
||
jout << "MyTimesliceSource: Emitting " << event->GetEventNumber() << jendl; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
#include "MyDataModel.h" | ||
#include <JANA/JEventUnfolder.h> | ||
|
||
struct ExampleTimesliceUnfolder : public JEventUnfolder { | ||
|
||
MyTimesliceUnfolder() { | ||
SetParentLevel(JEventLevel::Timeslice); | ||
SetChildLevel(JEventLevel::Event); | ||
} | ||
|
||
void Preprocess(const JEvent& parent) const override { | ||
parent->Get<MyCluster>("protos"); | ||
} | ||
|
||
Result Unfold(const JEvent& parent, JEvent& child, int item) override { | ||
auto protos = parent->Get<MyCluster>("protos"); | ||
|
||
child.SetEventNumber(parent.GetEventNumber()*10 + item); | ||
LOG << "Unfolding parent=" << parent.GetEventNumber() << ", child=" << child.GetEventNumber() << ", item=" << item << LOG_END; | ||
|
||
std::vector<MyCluster*> child_protos; | ||
for (auto proto: protos) { | ||
if (true) { | ||
// TODO: condition | ||
child_protos.push_back(proto); | ||
} | ||
} | ||
child->Insert(child_protos, "event_protos")->SetFactoryFlag(JFactoryFlag::NOT_OBJECT_OWNER); | ||
|
||
if (item == 3) { | ||
jout << "Unfold found item 3, finishing join" << jendl; | ||
return Result::Finished; | ||
} | ||
return Result::KeepGoing; | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2024, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
|
||
#include "MyTimesliceSource.h" | ||
#include "MyTimesliceUnfolder.h" | ||
#include "MyEventProcessor.h" | ||
#include "MyTimesliceFactory.h" | ||
#include "MyEventFactory.h" | ||
|
||
#include <JANA/JApplication.h> | ||
|
||
|
||
extern "C"{ | ||
void InitPlugin(JApplication *app) { | ||
|
||
InitJANAPlugin(app); | ||
|
||
app->Add(new MyTimesliceSource("Dummy")); | ||
app->Add(new MyTimesliceUnfolder); | ||
app->Add(new MyEventProcessor); | ||
|
||
app->Add(new JFactoryGeneratorT<MyTimesliceFactory>()); | ||
app->Add(new JFactoryGeneratorT<MyEventFactory>()); | ||
|
||
app->SetParameterValue("jana:extended_report", 0); | ||
} | ||
} // "C" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.