Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:41

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]"};
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("JEventUnfolder using default parameters") {
0044         app.Initialize();
0045         sut->DoInit();
0046         REQUIRE(sut->threshold() == 16.0);
0047         REQUIRE(sut->bucket_count() == 22);
0048     }
0049     SECTION("JEventUnfolder using overridden parameters") {
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 }
0057 } // component_unfolder_param_tests
0058 
0059 
0060 
0061 
0062 
0063 namespace component_processor_param_tests {
0064 
0065 struct TestProc : public JEventProcessor {
0066 
0067     Parameter<float> threshold {this, "threshold", 16.0, "The max cutoff threshold [V * A * kg^-1 * m^-2 * sec^-3]"};
0068     Parameter<int> bucket_count {this, "bucket_count", 22, "The total number of buckets [dimensionless]"};
0069 
0070     TestProc() {
0071         SetPrefix("my_proc");
0072     }
0073 };
0074 
0075 
0076 TEST_CASE("JEventProcessorParametersTests") {
0077     JApplication app;
0078     auto* sut = new TestProc;
0079     app.Add(sut);
0080 
0081     SECTION("JEventProcessor using default parameters") {
0082         app.Initialize();
0083         sut->DoInitialize();
0084         REQUIRE(sut->threshold() == 16.0);
0085         REQUIRE(sut->bucket_count() == 22);
0086     }
0087     SECTION("JEventProcessor using overridden parameters") {
0088         app.SetParameterValue("my_proc:threshold", 12.0);
0089         app.Initialize();
0090         sut->DoInitialize();
0091         REQUIRE(sut->threshold() == 12.0);
0092         REQUIRE(sut->bucket_count() == 22);
0093     }
0094 
0095 }
0096 
0097 } // namsepace component_processor_param_tests
0098 
0099 
0100 namespace component_omnifactory_param_tests {
0101 
0102 struct MyCluster {
0103     int x;
0104 };
0105 
0106 struct TestFac : public JOmniFactory<TestFac> {
0107 
0108     Output<MyCluster> clusters_out {this, "clusters_out"};
0109 
0110     Parameter<float> threshold {this, "threshold", 16.0, "The max cutoff threshold [V * A * kg^-1 * m^-2 * sec^-3]"};
0111     Parameter<int> bucket_count {this, "bucket_count", 22, "The total number of buckets [dimensionless]"};
0112 
0113     TestFac() {
0114     }
0115 
0116     void Configure() {
0117     }
0118     
0119     void ChangeRun(int32_t) final {
0120     }
0121 
0122 
0123     // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
0124     void Execute(int64_t, uint64_t) {
0125     }
0126 };
0127 
0128 
0129 TEST_CASE("JOmniFactoryParametersTests") {
0130     JApplication app;
0131 
0132 
0133     SECTION("JOmniFactory using default parameters") {
0134         app.Initialize();
0135         JOmniFactoryGeneratorT<TestFac> facgen;
0136         facgen.AddWiring("ECalTestAlg", {}, {"specific_clusters_out"});
0137         JFactorySet facset;
0138         facgen.SetApplication(&app);
0139         facgen.GenerateFactories(&facset);
0140         auto sut = RetrieveMultifactory<MyCluster,TestFac>(&facset, "specific_clusters_out");
0141         // RetrieveMultifactory() will call DoInitialize() for us
0142         
0143         REQUIRE(sut->threshold() == 16.0);
0144         REQUIRE(sut->bucket_count() == 22);
0145     }
0146 
0147     /*
0148      * FIXME: In EICrecon first though
0149 
0150     SECTION("JOmniFactory using facgen parameters") {
0151         app.Initialize();
0152         JOmniFactoryGeneratorT<TestFac> facgen (&app);
0153         facgen.AddWiring("my_fac", {}, {"specific_clusters_out"}, {{"bucket_count","444"}});
0154         JFactorySet facset;
0155         facgen.GenerateFactories(&facset);
0156         auto sut = RetrieveMultifactory<MyCluster,TestFac>(&facset, "specific_clusters_out");
0157         // RetrieveMultifactory() will call DoInitialize() for us
0158 
0159         REQUIRE(sut->threshold() == 16.0);
0160         REQUIRE(sut->bucket_count() == 444);
0161     }
0162 
0163     SECTION("JOmniFactory using overridden parameters") {
0164         app.SetParameterValue("my_fac:threshold", 12.0);
0165         app.Initialize();
0166 
0167         JOmniFactoryGeneratorT<TestFac> facgen (&app);
0168         facgen.AddWiring("my_fac", {}, {"specific_clusters_out"}, {{"threshold", "55.5"}});
0169         JFactorySet facset;
0170         facgen.GenerateFactories(&facset);
0171         auto sut = RetrieveMultifactory<MyCluster,TestFac>(&facset, "specific_clusters_out");
0172 
0173         REQUIRE(sut->threshold() == 12.0);
0174         REQUIRE(sut->bucket_count() == 22);
0175     }
0176 
0177     */
0178 
0179 } // TEST_CASE
0180 
0181 } // namespace component_omnifactory_param_tests
0182 } // namespace jana