Back to home page

EIC code displayed by LXR

 
 

    


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

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_TERMINATIONTESTS_H
0007 #define JANA2_TERMINATIONTESTS_H
0008 
0009 #include <JANA/JEventSource.h>
0010 #include <JANA/JEventProcessor.h>
0011 
0012 #include "catch.hpp"
0013 
0014 struct InterruptedSource : public JEventSource {
0015     InterruptedSource() {
0016         SetCallbackStyle(CallbackStyle::ExpertMode);
0017     }
0018     void Open() override { GetApplication()->Stop(); }
0019     Result Emit(JEvent&) override { return Result::Success; }
0020 };
0021 
0022 struct BoundedSource : public JEventSource {
0023 
0024     uint64_t event_count = 0;
0025 
0026     BoundedSource() {
0027         SetCallbackStyle(CallbackStyle::ExpertMode);
0028     }
0029 
0030     void Open() override {
0031     }
0032 
0033     Result Emit(JEvent&) override {
0034         if (event_count >= 10) {
0035             return Result::FailureFinished;
0036         }
0037         event_count += 1;
0038         return Result::Success;
0039     }
0040 };
0041 
0042 struct UnboundedSource : public JEventSource {
0043 
0044     uint64_t event_count = 0;
0045 
0046     UnboundedSource() {
0047         SetCallbackStyle(CallbackStyle::ExpertMode);
0048     }
0049 
0050     void Open() override {
0051     }
0052 
0053     Result Emit(JEvent& event) override {
0054         event_count += 1;
0055         event.SetEventNumber(event_count);
0056         std::this_thread::sleep_for(std::chrono::milliseconds(200));
0057         return Result::Success;
0058     }
0059 };
0060 
0061 struct CountingProcessor : public JEventProcessor {
0062 
0063     std::atomic_int processed_count {0};
0064     std::atomic_int finish_call_count {0};
0065 
0066     CountingProcessor() {
0067         SetCallbackStyle(CallbackStyle::ExpertMode);
0068     }
0069 
0070     void Init() override {}
0071 
0072     void Process(const JEvent&) override {
0073         processed_count += 1;
0074         // jout << "Processing " << event->GetEventNumber() << jendl;
0075         REQUIRE(finish_call_count == 0);
0076     }
0077 
0078     void Finish() override {
0079         finish_call_count += 1;
0080     }
0081 };
0082 
0083 
0084 #endif //JANA2_TERMINATIONTESTS_H