File indexing completed on 2025-01-18 10:17:43
0001
0002
0003
0004
0005 #include <catch.hpp>
0006 #include <JANA/Utils/JCallGraphRecorder.h>
0007 #include "JANA/JEvent.h"
0008 #include "JANA/JFactoryGenerator.h"
0009
0010 TEST_CASE("Test topological sort algorithm in isolation") {
0011
0012
0013
0014
0015
0016
0017 JCallGraphRecorder sut;
0018 sut.SetEnabled();
0019
0020
0021
0022
0023 sut.AddToCallGraph(JCallGraphRecorder::JCallGraphNode("BName", "BTag", "AName", "ATag"));
0024 sut.AddToCallGraph(JCallGraphRecorder::JCallGraphNode("BName", "BTag", "CName", "CTag"));
0025 sut.AddToCallGraph(JCallGraphRecorder::JCallGraphNode("DName", "DTag", "BName", "BTag"));
0026 sut.AddToCallGraph(JCallGraphRecorder::JCallGraphNode("DName", "DTag", "CName", "CTag"));
0027 REQUIRE(sut.GetCallGraph().size() == 4);
0028
0029 auto result = sut.TopologicalSort();
0030 REQUIRE(result.size() == 4);
0031 REQUIRE(result[0].first == "AName");
0032 REQUIRE(result[1].second == "CTag");
0033 REQUIRE(result[2].first == "BName");
0034 REQUIRE(result[3].first == "DName");
0035 }
0036
0037
0038 struct ObjA {};
0039 struct ObjB {};
0040 struct ObjC {};
0041 struct ObjD {};
0042
0043 struct FacA: public JFactoryT<ObjA> {
0044 void Process(const std::shared_ptr<const JEvent>&) override {
0045 }
0046 };
0047
0048 struct FacB: public JFactoryT<ObjB> {
0049 FacB() {
0050 SetTag("WeirdBTag");
0051 }
0052 void Process(const std::shared_ptr<const JEvent>& event) override {
0053 event->Get<ObjA>();
0054 }
0055 };
0056
0057 struct FacC: public JFactoryT<ObjC> {
0058 void Process(const std::shared_ptr<const JEvent>&) override {
0059 }
0060 };
0061
0062 struct FacD: public JFactoryT<ObjD> {
0063 void Process(const std::shared_ptr<const JEvent>& event) override {
0064 event->Get<ObjB>("WeirdBTag");
0065 event->Get<ObjC>();
0066 }
0067 };
0068
0069
0070 TEST_CASE("Test topological sort algorithm using actual Factories") {
0071 JApplication app;
0072 app.Add(new JFactoryGeneratorT<FacA>());
0073 app.Add(new JFactoryGeneratorT<FacB>());
0074 app.Add(new JFactoryGeneratorT<FacC>());
0075 app.Add(new JFactoryGeneratorT<FacD>());
0076 auto event = std::make_shared<JEvent>(&app);
0077 event->GetJCallGraphRecorder()->SetEnabled();
0078 event->Get<ObjD>();
0079 auto result = event->GetJCallGraphRecorder()->TopologicalSort();
0080 REQUIRE(result.size() == 4);
0081 REQUIRE(result[0].first == "ObjA");
0082 REQUIRE(result[1].first == "ObjC");
0083 REQUIRE(result[2].first == "ObjB");
0084 REQUIRE(result[2].second == "WeirdBTag");
0085 REQUIRE(result[3].first == "ObjD");
0086 }
0087