Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-13 10:34:17

0001 
0002 // Copyright 2022, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #include "JANA/Components/JComponentFwd.h"
0006 #include "catch.hpp"
0007 #include <JANA/Utils/JAutoActivator.h>
0008 #include <JANA/JApplication.h>
0009 #include <JANA/JEventSource.h>
0010 #include <JANA/JFactoryT.h>
0011 #include <JANA/JEventProcessor.h>
0012 
0013 
0014 
0015 TEST_CASE("Autoactivate_Split") {
0016     auto pair = JAutoActivator::Split("all_just_objname");
0017     REQUIRE(pair.first == "all_just_objname");
0018     REQUIRE(pair.second == "");
0019 
0020     pair = JAutoActivator::Split("objname:tag");
0021     REQUIRE(pair.first == "objname");
0022     REQUIRE(pair.second == "tag");
0023 
0024     pair = JAutoActivator::Split("name::type:factag");
0025     REQUIRE(pair.first == "name::type");
0026     REQUIRE(pair.second == "factag");
0027 
0028     pair = JAutoActivator::Split("name::type");
0029     REQUIRE(pair.first == "name::type");
0030     REQUIRE(pair.second == "");
0031 
0032     pair = JAutoActivator::Split("name::type:tag:more_tag");
0033     REQUIRE(pair.first == "name::type");
0034     REQUIRE(pair.second == "tag:more_tag");
0035 
0036     pair = JAutoActivator::Split("name::type:tag:more_tag::most_tag");
0037     REQUIRE(pair.first == "name::type");
0038     REQUIRE(pair.second == "tag:more_tag::most_tag");
0039 
0040     pair = JAutoActivator::Split("::name::type:tag:more_tag::most_tag");
0041     REQUIRE(pair.first == "::name::type");
0042     REQUIRE(pair.second == "tag:more_tag::most_tag");
0043 
0044     pair = JAutoActivator::Split(":I_guess_this_should_be_a_tag_idk");
0045     REQUIRE(pair.first == "");
0046     REQUIRE(pair.second == "I_guess_this_should_be_a_tag_idk");
0047 }
0048 
0049 namespace jana::autoactivate_ordering_tests {
0050 
0051 struct TestData {int x = 22;};
0052 
0053 class TestFac : public JFactoryT<TestData> {
0054     void Process(const std::shared_ptr<const JEvent>&) override {
0055         LOG_INFO(GetLogger()) << "Running TestFac";
0056         Insert(new TestData);
0057     }
0058 };
0059 
0060 struct TestProcLegacy : public JEventProcessor {
0061     TestProcLegacy() {
0062         SetTypeName("TestProcLegacy");
0063         SetCallbackStyle(CallbackStyle::LegacyMode);
0064     }
0065 
0066     void Process(const std::shared_ptr<const JEvent>& event) override {
0067         LOG_INFO(GetLogger()) << "Running TestProcLegacy";
0068         auto fac = event->GetFactory<TestData>();
0069         REQUIRE(fac->GetStatus() == JFactory::Status::Processed);
0070     }
0071 };
0072 
0073 struct TestProcExpert : public JEventProcessor {
0074     TestProcExpert() {
0075         SetTypeName("TestProcExpert");
0076         SetCallbackStyle(CallbackStyle::ExpertMode);
0077     }
0078     void ProcessSequential(const JEvent& event) override {
0079         LOG_INFO(GetLogger()) << "Running TestProcExpert";
0080         auto fac = event.GetFactory<TestData>();
0081         REQUIRE(fac->GetStatus() == JFactory::Status::Processed);
0082     }
0083 };
0084 
0085 
0086 TEST_CASE("Autoactivate_Ordering") {
0087     JApplication app;
0088     app.SetParameterValue("jana:nevents", 1);
0089     app.SetParameterValue("jana:loglevel", "debug");
0090     app.SetParameterValue("autoactivate", "jana::autoactivate_ordering_tests::TestData");
0091     app.Add(new JEventSource);
0092     app.Add(new JFactoryGeneratorT<TestFac>);
0093 
0094     SECTION("LegacyMode") {
0095         app.Add(new TestProcLegacy);
0096         app.Run();
0097     }
0098     SECTION("ExpertMode") {
0099         app.Add(new TestProcExpert);
0100         app.Run();
0101     }
0102     SECTION("LegacyAndExpertMode") {
0103         app.Add(new TestProcLegacy);
0104         app.Add(new TestProcExpert);
0105         app.Run();
0106     }
0107 }
0108 
0109 
0110 } // namespace