Back to home page

EIC code displayed by LXR

 
 

    


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

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     Parameter<bool> m_except {this, "except", false, "Event #7 always excepts" };
0017     Parameter<bool> m_segfault {this, "segfault", false, "Event #7 always segfaults" };
0018     Parameter<bool> m_timeout {this, "timeout", false, "Event #7 always times out" };
0019     Parameter<size_t> m_cputime_ms {this, "cputime_ms", 200, "Time spent during tracking" };
0020     Parameter<size_t> m_write_bytes {this, "bytes", 1000, "Bytes written during tracking"};
0021     Parameter<double> m_cputime_spread {this, "cputime_spread", 0.25, "Spread of time spent during tracking"};
0022     Parameter<double> m_write_spread {this, "bytes_spread", 0.25, "Spread of bytes written during tracking"};
0023 
0024     JBenchUtils m_bench_utils;
0025 
0026 public:
0027     JTestTracker() {
0028         SetPrefix("jtest:tracker");
0029         SetTypeName(NAME_OF_THIS);
0030     }
0031 
0032     void Process(const std::shared_ptr<const JEvent> &aEvent) override {
0033 
0034         m_bench_utils.set_seed(aEvent->GetEventNumber(), typeid(*this).name());
0035         // Read (large) event data
0036         auto ed = aEvent->GetSingle<JTestEventData>();
0037         m_bench_utils.read_memory(ed->buffer);
0038 
0039         // Do lots of computation
0040         m_bench_utils.consume_cpu_ms(*m_cputime_ms, *m_cputime_spread);
0041 
0042         // Optionally trigger failure scenarios
0043         if(aEvent->GetEventNumber() == 7) {
0044             // Only one of these can happen, so in principle the param should be an enum
0045             if (*m_except) {
0046                 throw std::runtime_error("Something went wrong");
0047             }
0048             if (*m_segfault) {
0049                 // Trigger a segfault on purpose
0050                 JTestTrackData* d = nullptr;
0051                 d->buffer[0] = 22;
0052             }
0053             if (*m_timeout) {
0054                 m_bench_utils.consume_cpu_ms(1000000);
0055             }
0056         }
0057 
0058         // Write (small) track data
0059         auto td = new JTestTrackData;
0060         m_bench_utils.write_memory(td->buffer, *m_write_bytes, *m_write_spread);
0061         Insert(td);
0062 
0063         // Insert some additional objects
0064         std::vector<JTestTrackAuxilliaryData*> auxObjs;
0065         for(int i=0;i<4;i++) auxObjs.push_back( new JTestTrackAuxilliaryData);
0066         aEvent->Insert( auxObjs );
0067     }
0068 };
0069 
0070 #endif //JANA2_JTESTTRACKER_H