File indexing completed on 2026-05-05 08:56:15
0001 #include "MultiLevelTopologyTests.h"
0002 #include "JANA/Engine/JExecutionEngine.h"
0003 #include "JANA/JApplicationFwd.h"
0004 #include "JANA/JException.h"
0005 #include "JANA/Topology/JArrow.h"
0006 #include "JANA/Topology/JTopologyBuilder.h"
0007 #include "JANA/Utils/JEventLevel.h"
0008
0009 #include <iostream>
0010
0011
0012 namespace jana {
0013 namespace timeslice_tests {
0014
0015
0016 TEST_CASE("TimeslicesTests_FineGrained") {
0017
0018 JApplication app;
0019 app.SetParameterValue("jana:loglevel", "trace");
0020 app.SetParameterValue("jana:nevents", "5");
0021 app.SetParameterValue("jana:max_inflight_timeslices", "2");
0022 app.SetParameterValue("jana:max_inflight_events", "4");
0023
0024 app.Add(new MyTimesliceSource);
0025 app.Add(new MyTimesliceUnfolder);
0026 app.Add(new MyEventProcessor);
0027 app.Add(new JFactoryGeneratorT<MyProtoClusterFactory>);
0028 app.Add(new JFactoryGeneratorT<MyClusterFactory>);
0029 app.SetTicker(true);
0030
0031 app.Initialize();
0032 auto ee = app.GetService<JExecutionEngine>();
0033 auto top = app.GetService<JTopologyBuilder>();
0034 enum ArrowId {TS_SRC=0, TS_MAP=1, TS_UNF=2, TS_FLD=3, PH_MAP=4, PH_TAP=5};
0035 JArrow::FireResult result = JArrow::FireResult::NotRunYet;
0036
0037 result = ee->Fire(TS_SRC, 0);
0038 REQUIRE(result == JArrow::FireResult::KeepGoing);
0039
0040 REQUIRE(top->GetArrows()[TS_SRC]->GetPort(1).GetQueue() == top->GetQueues()[0]);
0041 REQUIRE(top->GetPools()[0]->GetCapacity() == 2);
0042 REQUIRE(top->GetPools()[0]->GetSize(0) == 1);
0043 REQUIRE(top->GetQueues()[0]->GetSize(0) == 1);
0044
0045 result = ee->Fire(TS_MAP, 0);
0046 REQUIRE(result == JArrow::FireResult::KeepGoing);
0047 REQUIRE(top->GetQueues()[0]->GetSize(0) == 0);
0048 REQUIRE(top->GetQueues()[1]->GetSize(0) == 1);
0049
0050
0051 result = ee->Fire(TS_UNF, 0);
0052 REQUIRE(result == JArrow::FireResult::KeepGoing);
0053
0054
0055 result = ee->Fire(TS_UNF, 0);
0056 REQUIRE(result == JArrow::FireResult::KeepGoing);
0057
0058 result = ee->Fire(PH_MAP, 0);
0059 REQUIRE(result == JArrow::FireResult::KeepGoing);
0060
0061 result = ee->Fire(PH_TAP, 0);
0062 REQUIRE(result == JArrow::FireResult::KeepGoing);
0063
0064 result = ee->Fire(TS_FLD, 0);
0065 REQUIRE(result == JArrow::FireResult::KeepGoing);
0066
0067 REQUIRE(top->GetPools()[0]->GetSize(0) == 1);
0068 REQUIRE(top->GetPools()[1]->GetSize(0) == 4);
0069
0070 }
0071
0072 TEST_CASE("TimeslicesTests") {
0073
0074 JApplication app;
0075 app.SetParameterValue("jana:loglevel", "trace");
0076 app.SetParameterValue("jana:nevents", "5");
0077
0078 app.Add(new MyTimesliceSource);
0079 app.Add(new MyTimesliceUnfolder);
0080 app.Add(new MyEventProcessor);
0081 app.Add(new JFactoryGeneratorT<MyProtoClusterFactory>);
0082 app.Add(new JFactoryGeneratorT<MyClusterFactory>);
0083 app.SetTicker(true);
0084 try {
0085 app.Run();
0086 }
0087 catch (JException& e) {
0088 std::cout << e << std::endl;
0089 throw e;
0090 }
0091 }
0092
0093 TEST_CASE("TimeslicesTests_NoEvtProcs") {
0094
0095 JApplication app;
0096 app.SetParameterValue("jana:nevents", "5");
0097
0098 app.Add(new MyTimesliceSource);
0099 app.Add(new MyTimesliceUnfolder);
0100
0101 app.Add(new JFactoryGeneratorT<MyProtoClusterFactory>);
0102 app.Add(new JFactoryGeneratorT<MyClusterFactory>);
0103 app.SetTicker(true);
0104 try {
0105 app.Run();
0106 }
0107 catch (JException& e) {
0108 std::cout << e << std::endl;
0109 throw e;
0110 }
0111 }
0112
0113
0114 }
0115
0116
0117 namespace multilevel_source_tests {
0118
0119 TEST_CASE("MultilevelSource_Trivial") {
0120
0121
0122 JApplication app;
0123 auto* source = new MyMultilevelSource;
0124 auto* proc = new MyMultilevelProcessor;
0125
0126 source->SetEventLevels({JEventLevel::PhysicsEvent});
0127 source->data_stream = {{JEventLevel::PhysicsEvent, 4}, {JEventLevel::PhysicsEvent, 5}, {JEventLevel::PhysicsEvent, 6}};
0128 proc->expected_data_stream = {{-1,-1,4}, {-1,-1,5}, {-1,-1,6}};
0129
0130 app.Add(source);
0131 app.Add(proc);
0132 app.Run();
0133 }
0134
0135
0136
0137 }
0138 }
0139
0140
0141
0142
0143
0144