Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:12:04

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 #pragma once
0006 
0007 #include <vector>
0008 #include <memory>
0009 
0010 
0011 #include <JANA/JApplication.h>
0012 #include <JANA/JEventSource.h>
0013 #include <JANA/JEventSourceGeneratorT.h>
0014 
0015 #include <JANA/Utils/JBenchUtils.h>
0016 
0017 
0018 #include "JTestDataObjects.h"
0019 
0020 
0021 class JTestParser : public JEventSource {
0022 
0023     size_t m_cputime_ms = 0;
0024     size_t m_write_bytes = 2000000;
0025     double m_cputime_spread = 0.25;
0026     double m_write_spread = 0.25;
0027     JBenchUtils m_bench_utils = JBenchUtils();
0028     std::shared_ptr<std::vector<char>> m_latest_entangled_buffer;
0029 
0030     size_t m_events_generated = 0;
0031 
0032 public:
0033 
0034     JTestParser() {
0035         SetTypeName(NAME_OF_THIS);
0036         SetCallbackStyle(CallbackStyle::ExpertMode);
0037     }
0038 
0039     static std::string GetDescription() {
0040         return "JTest Fake Event Source";
0041     }
0042 
0043     void Init() override {
0044         auto app = GetApplication();
0045         app->SetDefaultParameter("jtest:parser_ms", m_cputime_ms, "Time spent during parsing");
0046         app->SetDefaultParameter("jtest:parser_spread", m_cputime_spread, "Spread of time spent during parsing");
0047         app->SetDefaultParameter("jtest:parser_bytes", m_write_bytes, "Bytes written during parsing");
0048         app->SetDefaultParameter("jtest:parser_bytes_spread", m_write_spread, "Spread of bytes written during parsing");
0049     }
0050 
0051     void Open() override {
0052     }
0053 
0054     Result Emit(JEvent& event) override {
0055 
0056         const auto prev_m_events_generated = m_events_generated;
0057         m_events_generated++;
0058         event.SetEventNumber(m_events_generated);
0059 
0060         m_bench_utils.set_seed(m_events_generated, typeid(*this).name());
0061 
0062         if ((prev_m_events_generated % 40) == 0) {
0063             // "Read" new entangled event every 40 events
0064             m_latest_entangled_buffer = std::shared_ptr<std::vector<char>>(new std::vector<char>);
0065             m_bench_utils.write_memory(*m_latest_entangled_buffer, m_write_bytes, m_write_spread);
0066         }
0067 
0068         // Spin the CPU
0069         m_bench_utils.consume_cpu_ms(m_cputime_ms, m_cputime_spread);
0070 
0071         // Emit a shared pointer to the entangled event buffer
0072         auto eec = new JTestEntangledEventData;
0073         eec->buffer = m_latest_entangled_buffer;
0074         event.Insert<JTestEntangledEventData>(eec);
0075 
0076 
0077         event.SetRunNumber(1);
0078         return Result::Success;
0079     }
0080 
0081 };
0082 
0083 // This ensures sources supplied by other plugins that use the default CheckOpenable
0084 // which returns 0.01 will still win out over this one.
0085 template<> double JEventSourceGeneratorT<JTestParser>::CheckOpenable(std::string /* source */) {
0086     return 1.0E-6;
0087 }
0088 
0089 
0090