File indexing completed on 2025-01-18 10:17:41
0001
0002
0003
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 #include "JTestDataObjects.h"
0018
0019
0020 class JTestParser : public JEventSource {
0021
0022 Parameter<size_t> m_cputime_ms {this, "cputime_ms", 0, "Time spent during parsing" };
0023 Parameter<size_t> m_write_bytes {this, "bytes", 2000000, "Bytes written during parsing"};
0024 Parameter<double> m_cputime_spread {this, "cputime_spread", 0.25, "Spread of time spent during parsing"};
0025 Parameter<double> m_write_spread {this, "bytes_spread", 0.25, "Spread of bytes written during parsing"};
0026
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 SetPrefix("jtest:parser");
0036 SetTypeName(NAME_OF_THIS);
0037 SetCallbackStyle(CallbackStyle::ExpertMode);
0038 }
0039
0040 static std::string GetDescription() {
0041 return "JTest Fake Event Source";
0042 }
0043
0044 void Open() override {
0045 }
0046
0047 Result Emit(JEvent& event) override {
0048
0049 const auto prev_m_events_generated = m_events_generated;
0050 m_events_generated++;
0051 event.SetEventNumber(m_events_generated);
0052
0053 m_bench_utils.set_seed(m_events_generated, typeid(*this).name());
0054
0055 if ((prev_m_events_generated % 40) == 0) {
0056
0057 m_latest_entangled_buffer = std::shared_ptr<std::vector<char>>(new std::vector<char>);
0058 m_bench_utils.write_memory(*m_latest_entangled_buffer, *m_write_bytes, *m_write_spread);
0059 }
0060
0061
0062 m_bench_utils.consume_cpu_ms(*m_cputime_ms, *m_cputime_spread);
0063
0064
0065 auto eec = new JTestEntangledEventData;
0066 eec->buffer = m_latest_entangled_buffer;
0067 event.Insert<JTestEntangledEventData>(eec);
0068
0069
0070 event.SetRunNumber(1);
0071 return Result::Success;
0072 }
0073
0074 };
0075
0076
0077
0078 template<> double JEventSourceGeneratorT<JTestParser>::CheckOpenable(std::string ) {
0079 return 1.0E-6;
0080 }
0081
0082
0083