File indexing completed on 2025-01-18 10:01:38
0001
0002
0003
0004
0005
0006
0007 #ifndef JANA2_GROUPEDEVENTSOURCE_H
0008 #define JANA2_GROUPEDEVENTSOURCE_H
0009
0010 #include <JANA/JEventSource.h>
0011 #include <JANA/Services/JEventGroupTracker.h>
0012
0013 class GroupedEventSource : public JEventSource {
0014
0015 JEventGroupManager m_egm;
0016
0017 int m_remaining_events_in_group;
0018 int m_current_group_id;
0019 int m_current_event_number;
0020
0021 public:
0022 GroupedEventSource(std::string res_name, JApplication* app) : JEventSource(std::move(res_name), app) {
0023
0024 SetCallbackStyle(CallbackStyle::ExpertMode);
0025 m_remaining_events_in_group = 5;
0026 m_current_group_id = 0;
0027 m_current_event_number = 0;
0028 };
0029
0030 Result Emit(JEvent& event) override {
0031
0032 if (m_current_group_id == 5) {
0033 return Result::FailureFinished;
0034 }
0035
0036
0037 auto current_group = m_egm.GetEventGroup(m_current_group_id);
0038
0039 current_group->StartEvent();
0040 event.Insert(current_group);
0041 event.GetFactory<JEventGroup>()->SetFactoryFlag(JFactory::JFactory_Flags_t::NOT_OBJECT_OWNER);
0042 event.SetEventNumber(++m_current_event_number);
0043 event.SetRunNumber(m_current_group_id);
0044
0045 m_remaining_events_in_group -= 1;
0046 if (m_remaining_events_in_group == 0) {
0047 current_group->CloseGroup();
0048 m_remaining_events_in_group = 5;
0049 m_current_group_id += 1;
0050 }
0051
0052 return Result::Success;
0053 }
0054 };
0055
0056
0057 #endif