Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 08:56:12

0001 #include <catch.hpp>
0002 
0003 #include <JANA/JApplication.h>
0004 #include <JANA/JEventUnfolder.h>
0005 #include <JANA/JEventProcessor.h>
0006 #include <JANA/Components/JOmniFactory.h>
0007 #include <JANA/Components/JOmniFactoryGeneratorT.h>
0008 
0009 namespace jana {
0010 
0011 template <typename OutputCollectionT, typename MultifactoryT>
0012 MultifactoryT* RetrieveMultifactory(JFactorySet* facset, std::string output_collection_name) {
0013     auto fac = facset->GetFactory<OutputCollectionT>(output_collection_name);
0014     REQUIRE(fac != nullptr);
0015     auto helper = dynamic_cast<JMultifactoryHelper<OutputCollectionT>*>(fac);
0016     REQUIRE(helper != nullptr);
0017     auto multifactory = helper->GetMultifactory();
0018     REQUIRE(multifactory != nullptr);
0019     auto typed = dynamic_cast<MultifactoryT*>(multifactory);
0020     REQUIRE(typed != nullptr);
0021     return typed;
0022 }
0023 
0024 namespace component_unfolder_param_tests {
0025 
0026 
0027 struct TestUnfolder : public JEventUnfolder {
0028 
0029     Parameter<float> threshold {this, "threshold", 16.0, "The max cutoff threshold [V * A * kg^-1 * m^-2 * sec^-3]"};
0030     Parameter<int> bucket_count {this, "bucket_count", 22, "The total number of buckets [dimensionless]", true};
0031 
0032     TestUnfolder() {
0033         SetPrefix("my_unfolder");
0034     }
0035 };
0036 
0037 
0038 TEST_CASE("JEventUnfolderParametersTests") {
0039     JApplication app;
0040     auto* sut = new TestUnfolder;
0041     app.Add(sut);
0042 
0043     SECTION("DefaultParameters") {
0044         app.Initialize();
0045         sut->DoInit();
0046         REQUIRE(sut->threshold() == 16.0);
0047         REQUIRE(sut->bucket_count() == 22);
0048     }
0049     SECTION("OverrideNonSharedParameter") {
0050         app.SetParameterValue("my_unfolder:threshold", 12.0);
0051         app.Initialize();
0052         sut->DoInit();
0053         REQUIRE(sut->threshold() == 12.0);
0054         REQUIRE(sut->bucket_count() == 22);
0055     }
0056     SECTION("OverrideSharedParameter") {
0057         app.SetParameterValue("bucket_count", 33);
0058         app.Initialize();
0059         sut->DoInit();
0060         REQUIRE(sut->threshold() == 16.0);
0061         REQUIRE(sut->bucket_count() == 33);
0062     }
0063 }
0064 } // component_unfolder_param_tests
0065 
0066 
0067 
0068 
0069 
0070 namespace component_processor_param_tests {
0071 
0072 struct TestProc : public JEventProcessor {
0073 
0074     Parameter<float> threshold {this, "threshold", 16.0, "The max cutoff threshold [V * A * kg^-1 * m^-2 * sec^-3]"};
0075     Parameter<int> bucket_count {this, "bucket_count", 22, "The total number of buckets [dimensionless]"};
0076 
0077     TestProc() {
0078         SetPrefix("my_proc");
0079         bucket_count.SetShared(true);
0080     }
0081 };
0082 
0083 
0084 TEST_CASE("JEventProcessorParametersTests") {
0085     JApplication app;
0086     auto* sut = new TestProc;
0087     app.Add(sut);
0088 
0089     SECTION("JEventProcessor using default parameters") {
0090         app.Initialize();
0091         sut->DoInitialize();
0092         REQUIRE(sut->threshold() == 16.0);
0093         REQUIRE(sut->bucket_count() == 22);
0094     }
0095     SECTION("JEventProcessor using overridden parameters") {
0096         app.SetParameterValue("my_proc:threshold", 12.0);
0097         app.Initialize();
0098         sut->DoInitialize();
0099         REQUIRE(sut->threshold() == 12.0);
0100         REQUIRE(sut->bucket_count() == 22);
0101     }
0102     SECTION("OverrideSharedParameter") {
0103         app.SetParameterValue("bucket_count", 33);
0104         app.Initialize();
0105         sut->DoInitialize();
0106         REQUIRE(sut->threshold() == 16.0);
0107         REQUIRE(sut->bucket_count() == 33);
0108     }
0109 
0110 }
0111 
0112 } // namsepace component_processor_param_tests
0113 
0114 
0115 namespace component_omnifactory_param_tests {
0116 
0117 struct MyCluster {
0118     int x;
0119 };
0120 
0121 struct TestConfigT {
0122     float threshold = 16.0;
0123     int bucket_count = 22;
0124 };
0125 
0126 struct TestFac : public JOmniFactory<TestFac, TestConfigT> {
0127 
0128     Output<MyCluster> clusters_out {this, "clusters_out"};
0129 
0130     ParameterRef<float> threshold {this, "threshold", config().threshold, "The max cutoff threshold [V * A * kg^-1 * m^-2 * sec^-3]"};
0131     ParameterRef<int> bucket_count {this, "bucket_count", config().bucket_count, "The total number of buckets [dimensionless]"};
0132 
0133     TestFac() {
0134     }
0135 
0136     void Configure() {
0137     }
0138     
0139     void ChangeRun(int32_t) final {
0140     }
0141 
0142 
0143     // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
0144     void Execute(int64_t, uint64_t) {
0145     }
0146 };
0147 
0148 
0149 TEST_CASE("JOmniFactoryParametersTests") {
0150     JApplication app;
0151 
0152     SECTION("JOmniFactory using default parameters") {
0153         app.Initialize();
0154         JOmniFactoryGeneratorT<TestFac> facgen;
0155         facgen.AddWiring("ECalTestAlg", {}, {"specific_clusters_out"});
0156         JFactorySet facset;
0157         facgen.SetApplication(&app);
0158         facgen.GenerateFactories(&facset);
0159         auto sut = RetrieveMultifactory<MyCluster,TestFac>(&facset, "specific_clusters_out");
0160         // RetrieveMultifactory() will call DoInitialize() for us
0161 
0162         REQUIRE(sut->threshold() == 16.0);
0163         REQUIRE(sut->bucket_count() == 22);
0164     }
0165 
0166     SECTION("JOmniFactory using facgen parameters") {
0167         app.Initialize();
0168         JOmniFactoryGeneratorT<TestFac> facgen;
0169         facgen.AddWiring("my_fac", {}, {"specific_clusters_out"}, {.bucket_count=444});
0170         JFactorySet facset;
0171         facgen.SetApplication(&app);
0172         facgen.GenerateFactories(&facset);
0173         auto sut = RetrieveMultifactory<MyCluster,TestFac>(&facset, "specific_clusters_out");
0174         // RetrieveMultifactory() will call DoInitialize() for us
0175 
0176         REQUIRE(sut->threshold() == 16.0);
0177         REQUIRE(sut->bucket_count() == 444);
0178     }
0179 
0180     SECTION("JOmniFactory using overridden parameters") {
0181         app.SetParameterValue("my_fac:threshold", 12.0);
0182         app.Initialize();
0183 
0184         JOmniFactoryGeneratorT<TestFac> facgen;
0185         facgen.AddWiring("my_fac", {}, {"specific_clusters_out"}, {.threshold=55.5});
0186         JFactorySet facset;
0187         facgen.SetApplication(&app);
0188         facgen.GenerateFactories(&facset);
0189         auto sut = RetrieveMultifactory<MyCluster,TestFac>(&facset, "specific_clusters_out");
0190         sut->DoInit();
0191 
0192         REQUIRE(sut->threshold() == 12.0);
0193         REQUIRE(sut->bucket_count() == 22);
0194     }
0195 
0196 } // TEST_CASE
0197 
0198 } // namespace component_omnifactory_param_tests
0199 } // namespace jana