Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:18

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 
0006 #ifndef JANA2_GROUPEDEVENTPROCESSOR_H
0007 #define JANA2_GROUPEDEVENTPROCESSOR_H
0008 
0009 
0010 #include <JANA/JEventProcessor.h>
0011 #include <JANA/JLogger.h>
0012 #include <JANA/Services/JEventGroupTracker.h>
0013 #include <JANA/Utils/JBenchUtils.h>
0014 
0015 #include "TridasEvent.h"
0016 
0017 /// GroupedEventProcessor demonstrates basic usage of JEventGroups
0018 
0019 class GroupedEventProcessor : public JEventProcessor {
0020     JBenchUtils m_bench_utils = JBenchUtils();
0021 public:
0022     GroupedEventProcessor() {
0023         SetTypeName(NAME_OF_THIS);
0024         SetCallbackStyle(CallbackStyle::LegacyMode);
0025     }
0026 
0027     void Process(const std::shared_ptr<const JEvent>& event) override {
0028 
0029         m_bench_utils.set_seed(event->GetEventNumber(), NAME_OF_THIS);
0030         // In parallel, perform a random amount of (slow) computation
0031         m_bench_utils.consume_cpu_ms(100, 1.0);
0032 
0033         auto tridas_event = event->GetSingle<TridasEvent>();
0034         tridas_event->should_keep = true;
0035 
0036         auto group = event->GetSingle<JEventGroup>();
0037 
0038         // Sequentially, process each event and report when a group finishes
0039         std::lock_guard<std::mutex> lock(m_mutex);
0040 
0041         LOG << "Processed group #" << group->GetGroupId() << ", event #" << event->GetEventNumber() << LOG_END;
0042 
0043         bool finishes_group = group->FinishEvent();
0044         if (finishes_group) {
0045             LOG << "Processed last element in group " << group->GetGroupId() << LOG_END;
0046         }
0047     }
0048 };
0049 
0050 
0051 
0052 
0053 #endif //JANA2_GROUPEDEVENTPROCESSOR_H