File indexing completed on 2025-01-18 10:17:36
0001
0002
0003
0004 #pragma once
0005
0006 #include <JANA/JEventFolder.h>
0007 #include <JANA/Topology/JArrow.h>
0008
0009 class JFoldArrow : public JArrow {
0010 public:
0011 enum PortIndex {CHILD_IN=0, CHILD_OUT=1, PARENT_OUT=2};
0012
0013 private:
0014 JEventFolder* m_folder = nullptr;
0015
0016 JEventLevel m_parent_level;
0017 JEventLevel m_child_level;
0018
0019 public:
0020 JFoldArrow(
0021 std::string name,
0022 JEventLevel parent_level,
0023 JEventLevel child_level)
0024
0025 : m_parent_level(parent_level),
0026 m_child_level(child_level)
0027 {
0028 set_name(name);
0029 create_ports(1, 2);
0030 m_next_input_port = CHILD_IN;
0031 }
0032
0033 void set_folder(JEventFolder* folder) {
0034 m_folder = folder;
0035 }
0036
0037 void initialize() final {
0038 if (m_folder != nullptr) {
0039 m_folder->DoInit();
0040 LOG_INFO(m_logger) << "Initialized JEventFolder '" << m_folder->GetTypeName() << "'" << LOG_END;
0041 }
0042 else {
0043 LOG_INFO(m_logger) << "Initialized JEventFolder (trivial)" << LOG_END;
0044 }
0045 }
0046
0047 void finalize() final {
0048 if (m_folder != nullptr) {
0049 m_folder->DoFinish();
0050 LOG_INFO(m_logger) << "Finalized JEventFolder '" << m_folder->GetTypeName() << "'" << LOG_END;
0051 }
0052 else {
0053 LOG_INFO(m_logger) << "Finalized JEventFolder (trivial)" << LOG_END;
0054 }
0055 }
0056
0057 void fire(JEvent* event, OutputData& outputs, size_t& output_count, JArrow::FireResult& status) final {
0058
0059 assert(m_next_input_port == CHILD_IN);
0060
0061
0062 if (event->GetLevel() != m_child_level) {
0063 throw JException("JFoldArrow received a child with the wrong event level");
0064 }
0065
0066 if (m_folder != nullptr) {
0067 auto parent = const_cast<JEvent*>(&event->GetParent(m_parent_level));
0068 m_folder->DoFold(*event, *parent);
0069 }
0070
0071 status = JArrow::FireResult::KeepGoing;
0072 outputs[0] = {event, CHILD_OUT};
0073 output_count = 1;
0074
0075 auto* released_parent = event->ReleaseParent(m_parent_level);
0076 if (released_parent != nullptr) {
0077
0078
0079
0080
0081
0082
0083 outputs[1] = {released_parent, PARENT_OUT};
0084 output_count = 2;
0085 }
0086 }
0087
0088 };
0089
0090