Skip to content

Commit

Permalink
Make arrow attachment mechanism consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Oct 29, 2024
1 parent 014a666 commit 8e5d097
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 89 deletions.
3 changes: 3 additions & 0 deletions src/libraries/JANA/Topology/JEventMapArrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class JEvent;

class JEventMapArrow : public JTriggeredArrow<JEventMapArrow> {

public:
enum PortIndex {EVENT_IN=0, EVENT_OUT=1};

private:
std::vector<JEventSource*> m_sources;
std::vector<JEventUnfolder*> m_unfolders;
Expand Down
20 changes: 1 addition & 19 deletions src/libraries/JANA/Topology/JEventSourceArrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

class JEventSourceArrow : public JTriggeredArrow<JEventSourceArrow> {
public:
const size_t EVENT_IN = 0;
const size_t EVENT_OUT = 1;
enum PortIndex {EVENT_IN=0, EVENT_OUT=1};

private:
std::vector<JEventSource*> m_sources;
Expand All @@ -20,23 +19,6 @@ class JEventSourceArrow : public JTriggeredArrow<JEventSourceArrow> {
public:
JEventSourceArrow(std::string name, std::vector<JEventSource*> sources);

void set_input(JMailbox<JEvent*>* queue) {
m_ports[EVENT_IN].queue = queue;
m_ports[EVENT_IN].pool = nullptr;
}
void set_input(JEventPool* pool) {
m_ports[EVENT_IN].queue = nullptr;
m_ports[EVENT_IN].pool = pool;
}
void set_output(JMailbox<JEvent*>* queue) {
m_ports[EVENT_OUT].queue = queue;
m_ports[EVENT_OUT].pool = nullptr;
}
void set_output(JEventPool* pool) {
m_ports[EVENT_OUT].queue = nullptr;
m_ports[EVENT_OUT].pool = pool;
}

void initialize() final;
void finalize() final;
void fire(JEvent* input, OutputData& outputs, size_t& output_count, JArrowMetrics::Status& status);
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/JANA/Topology/JEventTapArrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class JEvent;


class JEventTapArrow : public JTriggeredArrow<JEventTapArrow> {
public:
enum PortIndex {EVENT_IN=0, EVENT_OUT=1};

private:
std::vector<JEventProcessor*> m_procs;
Expand Down
29 changes: 1 addition & 28 deletions src/libraries/JANA/Topology/JFoldArrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class JFoldArrow : public JTriggeredArrow<JFoldArrow> {
public:
const int CHILD_IN = 0;
const int CHILD_OUT = 1;
const int PARENT_OUT = 2;
enum PortIndex {CHILD_IN=0, CHILD_OUT=1, PARENT_OUT=2};

private:
JEventFolder* m_folder = nullptr;
Expand All @@ -36,31 +34,6 @@ class JFoldArrow : public JTriggeredArrow<JFoldArrow> {
m_folder = folder;
}

void attach_child_in(JMailbox<JEvent*>* child_in) {
m_ports[CHILD_IN].queue = child_in;
m_ports[CHILD_IN].pool = nullptr;
}

void attach_child_out(JMailbox<JEvent*>* child_out) {
m_ports[CHILD_OUT].queue = child_out;
m_ports[CHILD_OUT].pool = nullptr;
}

void attach_child_out(JEventPool* child_out) {
m_ports[CHILD_OUT].queue = nullptr;
m_ports[CHILD_OUT].pool = child_out;
}

void attach_parent_out(JEventPool* parent_out) {
m_ports[PARENT_OUT].queue = nullptr;
m_ports[PARENT_OUT].pool = parent_out;
}

void attach_parent_out(JMailbox<JEvent*>* parent_out) {
m_ports[PARENT_OUT].queue = parent_out;
m_ports[PARENT_OUT].pool = nullptr;
}

void initialize() final {
if (m_folder != nullptr) {
m_folder->DoInit();
Expand Down
22 changes: 11 additions & 11 deletions src/libraries/JANA/Topology/JTopologyBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ void JTopologyBuilder::attach_level(JEventLevel current_level, JUnfoldArrow* par
bool need_source = !sources_at_level.empty();
if (need_source) {
src_arrow = new JEventSourceArrow(level_str+"Source", sources_at_level);
src_arrow->set_input(pool_at_level);
src_arrow->set_output(pool_at_level);
src_arrow->attach(pool_at_level, JEventSourceArrow::EVENT_IN);
src_arrow->attach(pool_at_level, JEventSourceArrow::EVENT_OUT);
arrows.push_back(src_arrow);
}

Expand All @@ -285,8 +285,8 @@ void JTopologyBuilder::attach_level(JEventLevel current_level, JUnfoldArrow* par
for (JEventUnfolder* unf: unfolders_at_level) {
map1_arrow->add_unfolder(unf);
}
map1_arrow->attach(pool_at_level, 0);
map1_arrow->attach(pool_at_level, 1);
map1_arrow->attach(pool_at_level, JEventMapArrow::EVENT_IN);
map1_arrow->attach(pool_at_level, JEventMapArrow::EVENT_OUT);
arrows.push_back(map1_arrow);
}

Expand All @@ -308,7 +308,7 @@ void JTopologyBuilder::attach_level(JEventLevel current_level, JUnfoldArrow* par
if(need_fold) {
fold_arrow = new JFoldArrow(level_str+"Fold", current_level, unfolders_at_level[0]->GetChildLevel());
arrows.push_back(fold_arrow);
fold_arrow->attach_parent_out(pool_at_level);
fold_arrow->attach(pool_at_level, JFoldArrow::PARENT_OUT);
}

// --------------------------
Expand All @@ -320,8 +320,8 @@ void JTopologyBuilder::attach_level(JEventLevel current_level, JUnfoldArrow* par
map2_arrow = new JEventMapArrow(level_str+"Map2");
for (JEventProcessor* proc : mappable_procs_at_level) {
map2_arrow->add_processor(proc);
map2_arrow->attach(pool_at_level, 0);
map2_arrow->attach(pool_at_level, 1);
map2_arrow->attach(pool_at_level, JEventMapArrow::EVENT_IN);
map2_arrow->attach(pool_at_level, JEventMapArrow::EVENT_OUT);
}
arrows.push_back(map2_arrow);
}
Expand All @@ -335,8 +335,8 @@ void JTopologyBuilder::attach_level(JEventLevel current_level, JUnfoldArrow* par
tap_arrow = new JEventTapArrow(level_str+"Tap");
for (JEventProcessor* proc : tappable_procs_at_level) {
tap_arrow->add_processor(proc);
tap_arrow->attach(pool_at_level, 0);
tap_arrow->attach(pool_at_level, 1);
tap_arrow->attach(pool_at_level, JEventTapArrow::EVENT_IN);
tap_arrow->attach(pool_at_level, JEventTapArrow::EVENT_OUT);
}
arrows.push_back(tap_arrow);
}
Expand All @@ -347,7 +347,7 @@ void JTopologyBuilder::attach_level(JEventLevel current_level, JUnfoldArrow* par
// 1. Source
// --------------------------
if (parent_unfolder != nullptr) {
parent_unfolder->attach_child_in(pool_at_level);
parent_unfolder->attach(pool_at_level, JUnfoldArrow::CHILD_IN);
connect_to_first_available(parent_unfolder, {map1_arrow, unfold_arrow, map2_arrow, tap_arrow, parent_folder});
}
if (src_arrow != nullptr) {
Expand All @@ -366,7 +366,7 @@ void JTopologyBuilder::attach_level(JEventLevel current_level, JUnfoldArrow* par
connect_to_first_available(tap_arrow, {parent_folder});
}
if (parent_folder != nullptr) {
parent_folder->attach_child_out(pool_at_level);
parent_folder->attach(pool_at_level, JFoldArrow::CHILD_OUT);
}

// Finally, we recur over lower levels!
Expand Down
24 changes: 1 addition & 23 deletions src/libraries/JANA/Topology/JUnfoldArrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

class JUnfoldArrow : public JTriggeredArrow<JUnfoldArrow> {
public:
const int PARENT_IN = 0;
const int CHILD_IN = 1;
const int CHILD_OUT = 2;
enum PortIndex {PARENT_IN=0, CHILD_IN=1, CHILD_OUT=2};

private:
JEventUnfolder* m_unfolder = nullptr;
Expand All @@ -25,26 +23,6 @@ class JUnfoldArrow : public JTriggeredArrow<JUnfoldArrow> {
m_next_input_port = PARENT_IN;
}

void attach_parent_in(JMailbox<JEvent*>* parent_in) {
m_ports[PARENT_IN].queue = parent_in;
m_ports[PARENT_IN].pool = nullptr;
}

void attach_child_in(JEventPool* child_in) {
m_ports[CHILD_IN].queue = nullptr;
m_ports[CHILD_IN].pool = child_in;
}

void attach_child_in(JMailbox<JEvent*>* child_in) {
m_ports[CHILD_IN].queue = child_in;
m_ports[CHILD_IN].pool = nullptr;
}

void attach_child_out(JMailbox<JEvent*>* child_out) {
m_ports[CHILD_OUT].queue = child_out;
m_ports[CHILD_OUT].pool = nullptr;
}

void initialize() final {
m_unfolder->DoInit();
LOG_INFO(m_logger) << "Initialized JEventUnfolder '" << m_unfolder->GetTypeName() << "'" << LOG_END;
Expand Down
12 changes: 6 additions & 6 deletions src/programs/unit_tests/Components/UnfoldTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ TEST_CASE("UnfoldTests_Basic") {

TestUnfolder unfolder;
JUnfoldArrow arrow("sut", &unfolder);
arrow.attach_parent_in(&parent_queue);
arrow.attach_child_in(&child_pool);
arrow.attach_child_out(&child_queue);
arrow.attach(&parent_queue, JUnfoldArrow::PARENT_IN);
arrow.attach(&child_pool, JUnfoldArrow::CHILD_IN);
arrow.attach(&child_queue, JUnfoldArrow::CHILD_OUT);

JArrowMetrics m;
arrow.initialize();
Expand Down Expand Up @@ -97,9 +97,9 @@ TEST_CASE("FoldArrowTests") {
JMailbox<JEvent*> parent_out;

JFoldArrow arrow("sut", JEventLevel::Timeslice, JEventLevel::PhysicsEvent);
arrow.attach_child_in(&child_in);
arrow.attach_child_out(&child_out);
arrow.attach_parent_out(&parent_out);
arrow.attach(&child_in, JFoldArrow::CHILD_IN);
arrow.attach(&child_out, JFoldArrow::CHILD_OUT);
arrow.attach(&parent_out, JFoldArrow::PARENT_OUT);
JArrowMetrics metrics;
arrow.initialize();

Expand Down
4 changes: 2 additions & 2 deletions src/programs/unit_tests/Topology/SubeventTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ TEST_CASE("Basic subevent arrow functionality") {
topology->set_configure_fn([&](JTopologyBuilder& topology) {

auto source_arrow = new JEventSourceArrow("simpleSource", {new SimpleSource});
source_arrow->set_input(topology.event_pool);
source_arrow->set_output(&events_in);
source_arrow->attach(topology.event_pool, JEventSourceArrow::EVENT_IN);
source_arrow->attach(&events_in, JEventSourceArrow::EVENT_OUT);

auto proc_arrow = new JEventMapArrow("simpleProcessor");
proc_arrow->attach(&events_out, 0);
Expand Down

0 comments on commit 8e5d097

Please sign in to comment.