Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-03 09:36:13

0001 #include "MultiLevelTopologyTests.h"
0002 #include "JANA/Engine/JExecutionEngine.h"
0003 #include "JANA/JApplicationFwd.h"
0004 #include "JANA/JEvent.h"
0005 #include "JANA/JException.h"
0006 #include "JANA/Topology/JArrow.h"
0007 #include "JANA/Topology/JTopologyBuilder.h"
0008 #include "JANA/Utils/JEventLevel.h"
0009 
0010 #include <iostream>
0011 
0012 
0013 namespace jana {
0014 namespace timeslice_tests {
0015 
0016 
0017 TEST_CASE("TimeslicesTests_FineGrained") {
0018 
0019     JApplication app;
0020     app.SetParameterValue("jana:loglevel", "trace");
0021     app.SetParameterValue("jana:nevents", "5");
0022     app.SetParameterValue("jana:max_inflight_timeslices", "2");
0023     app.SetParameterValue("jana:max_inflight_events", "4");
0024 
0025     app.Add(new MyTimesliceSource);
0026     app.Add(new MyTimesliceUnfolder);
0027     app.Add(new MyEventProcessor);
0028     app.Add(new JFactoryGeneratorT<MyProtoClusterFactory>);
0029     app.Add(new JFactoryGeneratorT<MyClusterFactory>);
0030     app.SetTicker(true);
0031 
0032     app.Initialize();
0033     auto ee = app.GetService<JExecutionEngine>();
0034     auto top = app.GetService<JTopologyBuilder>();
0035 
0036     auto src_arrow = top->GetArrow("TimesliceSource");
0037     auto ts_map_arrow = top->GetArrow("TimesliceMap1");
0038     auto unfold_arrow = top->GetArrow("PhysicsEventUnfold");
0039     auto pe_map_arrow = top->GetArrow("PhysicsEventMap2");
0040     auto pe_tap_arrow = top->GetArrow("PhysicsEventTap");
0041 
0042     auto ts_pool = top->GetOrCreatePool(JEventLevel::Timeslice);
0043     auto pe_pool = top->GetOrCreatePool(JEventLevel::PhysicsEvent);
0044 
0045     auto ts_map_queue = ts_map_arrow->GetPort(0).GetQueue();
0046     auto unfold_queue = unfold_arrow->GetPort(0).GetQueue();
0047     auto pe_map_queue = pe_map_arrow->GetPort(0).GetQueue();
0048     auto pe_tap_queue = pe_tap_arrow->GetPort(0).GetQueue();
0049 
0050     // Test connectivity
0051     REQUIRE(src_arrow->GetPort(0).GetPool() == ts_pool);
0052     REQUIRE(src_arrow->GetPort(1).GetQueue() == ts_map_queue);
0053     REQUIRE(ts_map_arrow->GetPort(1).GetQueue() == unfold_queue);
0054     REQUIRE(unfold_queue == unfold_arrow->GetPort(JEventLevel::Timeslice, JArrow::PortDirection::In).GetQueue());
0055     REQUIRE(pe_pool == unfold_arrow->GetPort(JEventLevel::PhysicsEvent, JArrow::PortDirection::In).GetPool());
0056     REQUIRE(unfold_arrow->GetPort(JEventLevel::Timeslice, JArrow::PortDirection::Out).GetPool() == ts_pool);
0057     REQUIRE(unfold_arrow->GetPort(JEventLevel::PhysicsEvent, JArrow::PortDirection::Out).GetQueue() == pe_map_queue);
0058     REQUIRE(pe_map_arrow->GetPort(1).GetQueue() == pe_tap_queue);
0059     REQUIRE(pe_tap_arrow->GetPort(1).GetPool() == pe_pool);
0060 
0061     JArrow::FireResult result = JArrow::FireResult::NotRunYet;
0062 
0063     result = ee->Fire(src_arrow->GetId(), 0);
0064     REQUIRE(result == JArrow::FireResult::KeepGoing);
0065 
0066     REQUIRE(ts_pool->GetCapacity() == 2);
0067     REQUIRE(ts_pool->GetSize(0) == 1);
0068     REQUIRE(ts_map_queue->GetSize(0) == 1);
0069 
0070     result = ee->Fire(ts_map_arrow->GetId(), 0);
0071     REQUIRE(result == JArrow::FireResult::KeepGoing);
0072     REQUIRE(ts_map_queue->GetSize(0) == 0);
0073     REQUIRE(unfold_queue->GetSize(0) == 1);
0074 
0075     // Parent
0076     result = ee->Fire(unfold_arrow->GetId(), 0);
0077     REQUIRE(result == JArrow::FireResult::KeepGoing);
0078     
0079     // Child
0080     result = ee->Fire(unfold_arrow->GetId(), 0);
0081     REQUIRE(result == JArrow::FireResult::KeepGoing);
0082    
0083     result = ee->Fire(pe_map_arrow->GetId(), 0);
0084     REQUIRE(result == JArrow::FireResult::KeepGoing);
0085    
0086     result = ee->Fire(pe_tap_arrow->GetId(), 0);
0087     REQUIRE(result == JArrow::FireResult::KeepGoing);
0088     
0089     REQUIRE(ts_pool->GetSize(0) == 1); // Unfolder still has parent
0090     REQUIRE(pe_pool->GetSize(0) == 4); // Child returned to pool
0091     
0092 }
0093 
0094 TEST_CASE("TimeslicesTests") {
0095 
0096     JApplication app;
0097     app.SetParameterValue("jana:loglevel", "trace");
0098     app.SetParameterValue("jana:nevents", "5");
0099     
0100     app.Add(new MyTimesliceSource);
0101     app.Add(new MyTimesliceUnfolder);
0102     app.Add(new MyEventProcessor);
0103     app.Add(new JFactoryGeneratorT<MyProtoClusterFactory>);
0104     app.Add(new JFactoryGeneratorT<MyClusterFactory>);
0105     app.SetTicker(true);
0106     try {
0107         app.Run();
0108     }
0109     catch (JException& e) {
0110         std::cout << e << std::endl;
0111         throw e;
0112     }
0113 }
0114 
0115 TEST_CASE("TimeslicesTests_NoEvtProcs") {
0116 
0117     JApplication app;
0118     app.SetParameterValue("jana:nevents", "5");
0119     app.SetParameterValue("jana:loglevel", "debug");
0120 
0121     app.Add(new MyTimesliceSource);
0122     app.Add(new MyTimesliceUnfolder);
0123     //app.Add(new MyEventProcessor);
0124     app.Add(new JFactoryGeneratorT<MyProtoClusterFactory>);
0125     app.Add(new JFactoryGeneratorT<MyClusterFactory>);
0126     app.SetTicker(true);
0127     try {
0128         app.Run();
0129     }
0130     catch (JException& e) {
0131         std::cout << e << std::endl;
0132         throw e;
0133     }
0134 }
0135 
0136 
0137 } // namespace timeslice_tests
0138 
0139 
0140 namespace multilevel_source_tests {
0141 
0142 TEST_CASE("MultilevelSource_Trivial") {
0143     // This test case demonstrates the multilevel source behaving just like the plain old JEventSource
0144 
0145     JApplication app;
0146     auto* source = new MyMultilevelSource;
0147     auto* proc = new MyMultilevelProcessor;
0148 
0149     source->SetLevel(JEventLevel::PhysicsEvent);
0150     source->data_stream = {{JEventLevel::PhysicsEvent, 4}, {JEventLevel::PhysicsEvent, 5}, {JEventLevel::PhysicsEvent, 6}};
0151     proc->expected_data_stream = {{-1,-1,4}, {-1,-1,5}, {-1,-1,6}};
0152 
0153     app.Add(source);
0154     app.Add(proc);
0155     app.Run();
0156 }
0157 
0158 
0159 } // namespace multilevel_source_tests
0160 } // namespce jana
0161 
0162 
0163 
0164 
0165 
0166