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 
0006 #ifndef JANA2_JTESTTRACKER_H
0007 #define JANA2_JTESTTRACKER_H
0008 
0009 #include <JANA/JFactoryT.h>
0010 #include <JANA/JEvent.h>
0011 #include <JANA/Utils/JBenchUtils.h>
0012 #include "JTestDataObjects.h"
0013 
0014 class JTestTracker : public JFactoryT<JTestTrackData> {
0015 
0016     size_t m_cputime_ms = 200;
0017     size_t m_write_bytes = 1000;
0018     double m_cputime_spread = 0.25;
0019     double m_write_spread = 0.25;
0020     JBenchUtils m_bench_utils = JBenchUtils();
0021 
0022 public:
0023 
0024     struct JTestTrackAuxilliaryData{
0025         int something = 1;
0026         float something2 = 2;
0027     };
0028 
0029     void Init() override {
0030 
0031         auto app = GetApplication();
0032         app->SetDefaultParameter("jtest:tracker_ms", m_cputime_ms, "Time spent during tracking");
0033         app->SetDefaultParameter("jtest:tracker_spread", m_cputime_spread, "Spread of time spent during tracking");
0034         app->SetDefaultParameter("jtest:tracker_bytes", m_write_bytes, "Bytes written during tracking");
0035         app->SetDefaultParameter("jtest:tracker_bytes_spread", m_write_spread, "Spread of bytes written during tracking");
0036     }
0037 
0038     void Process(const std::shared_ptr<const JEvent> &aEvent) override {
0039 
0040         m_bench_utils.set_seed(aEvent->GetEventNumber(), typeid(*this).name());
0041         // Read (large) event data
0042         auto ed = aEvent->GetSingle<JTestEventData>();
0043         m_bench_utils.read_memory(ed->buffer);
0044 
0045         // Do lots of computation
0046         m_bench_utils.consume_cpu_ms(m_cputime_ms, m_cputime_spread);
0047 
0048         // Write (small) track data
0049         auto td = new JTestTrackData;
0050         m_bench_utils.write_memory(td->buffer, m_write_bytes, m_write_spread);
0051         Insert(td);
0052 
0053         // Insert some additional objects
0054         std::vector<JTestTrackAuxilliaryData*> auxObjs;
0055         for(int i=0;i<4;i++) auxObjs.push_back( new JTestTrackAuxilliaryData);
0056         aEvent->Insert( auxObjs );
0057     }
0058 };
0059 
0060 #endif //JANA2_JTESTTRACKER_H