Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /jana2/src/programs/unit_tests/Components/JComponentTests.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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