File indexing completed on 2025-08-28 09:13:25
0001
0002 #include <catch.hpp>
0003 #include <JANA/JVersion.h>
0004 #include <JANA/JApplicationFwd.h>
0005 #include <JANA/Components/JOmniFactory.h>
0006 #include <JANA/Components/JOmniFactoryGeneratorT.h>
0007
0008 struct MyHit {int e; };
0009
0010 #if JANA2_HAVE_PODIO
0011
0012 #include <PodioDatamodel/ExampleHitCollection.h>
0013
0014 struct MyFac : public JOmniFactory<MyFac> {
0015 Input<MyHit> hits_in {this};
0016 VariadicPodioInput<ExampleHit> variadic_podio_hits_in {this};
0017 PodioInput<ExampleHit> podio_hits_in {this};
0018
0019 Output<MyHit> hits_out {this};
0020 VariadicPodioOutput<ExampleHit> variadic_podio_hits_out {this};
0021 PodioOutput<ExampleHit> podio_hits_out {this};
0022
0023 MyFac() {
0024 hits_out.SetNotOwnerFlag(true);
0025 }
0026 void Configure() { }
0027 void ChangeRun(int32_t ) { }
0028 void Execute(int32_t , uint64_t ) {
0029
0030 REQUIRE(hits_out().size() == 0);
0031 REQUIRE(podio_hits_out()->size() == 0);
0032 REQUIRE(variadic_podio_hits_out().size() == 2);
0033 REQUIRE(variadic_podio_hits_out().at(0)->size() == 0);
0034 REQUIRE(variadic_podio_hits_out().at(1)->size() == 0);
0035
0036 for (auto hit : *hits_in) {
0037 hits_out().push_back(const_cast<MyHit*>(hit));
0038 }
0039
0040 podio_hits_out()->setSubsetCollection();
0041 variadic_podio_hits_out().at(0)->setSubsetCollection();
0042
0043 for (auto hit : *podio_hits_in) {
0044 podio_hits_out()->push_back(hit);
0045 variadic_podio_hits_out().at(0)->push_back(hit);
0046 }
0047
0048 variadic_podio_hits_out().at(1)->push_back(MutableExampleHit(22, 1.1, 1.1, 1.1, 10, 0));
0049 }
0050 };
0051
0052 void test_single_event(JEvent& event) {
0053 event.Insert(new MyHit{99}, "lw");
0054 ExampleHitCollection coll;
0055 coll.push_back(MutableExampleHit{14,0.0,0.0,0.0,100,0});
0056 coll.push_back(MutableExampleHit{21,0.0,0.0,0.0,100,0});
0057 event.InsertCollection<ExampleHit>(std::move(coll), "podio");
0058
0059 ExampleHitCollection coll2;
0060 coll2.push_back(MutableExampleHit{30,0.0,0.0,0.0,100,0});
0061 event.InsertCollection<ExampleHit>(std::move(coll2), "v_podio_0");
0062
0063 ExampleHitCollection coll3;
0064 coll3.push_back(MutableExampleHit{10101,0.0,0.0,0.0,100,0});
0065 event.InsertCollection<ExampleHit>(std::move(coll3), "v_podio_1");
0066
0067 auto hits = event.Get<MyHit>("lw2");
0068 REQUIRE(hits.size() == 1);
0069 REQUIRE(hits.at(0)->e == 99);
0070
0071 auto podio_hits = event.GetCollection<ExampleHit>("podio2");
0072 REQUIRE(podio_hits->size() == 2);
0073 REQUIRE(podio_hits->at(0).cellID() == 14);
0074 REQUIRE(podio_hits->at(1).cellID() == 21);
0075
0076 auto podio_hits_v2 = event.GetCollection<ExampleHit>("v_podio_2");
0077 REQUIRE(podio_hits_v2 ->size() == 2);
0078 REQUIRE(podio_hits_v2->at(0).cellID() == 14);
0079 REQUIRE(podio_hits_v2->at(1).cellID() == 21);
0080
0081 auto podio_hits_v3 = event.GetCollection<ExampleHit>("v_podio_3");
0082 REQUIRE(podio_hits_v3 ->size() == 1);
0083 REQUIRE(podio_hits_v3->at(0).cellID() == 22);
0084 }
0085
0086 TEST_CASE("JOmniFactoryTests_VariadicWiring") {
0087 JApplication app;
0088 app.Add(new JOmniFactoryGeneratorT<MyFac>(
0089 "sut",
0090 {"lw", "v_podio_0", "v_podio_1", "podio"},
0091 {"lw2", "v_podio_2", "v_podio_3", "podio2"}));
0092
0093 auto event = std::make_shared<JEvent>(&app);
0094 event->GetFactorySet()->Print();
0095 test_single_event(*event);
0096 event->Clear();
0097 test_single_event(*event);
0098 }
0099
0100 #endif
0101
0102
0103 struct MyFac2 : public JOmniFactory<MyFac2> {
0104 Output<MyHit> hits_out {this};
0105
0106 void Configure() { }
0107 void ChangeRun(int32_t ) { }
0108 void Execute(int32_t , uint64_t ) {
0109 REQUIRE(hits_out().size() == 0);
0110 hits_out().push_back(new MyHit{22});
0111 }
0112 };
0113
0114
0115 TEST_CASE("JOmniFactoryTests_OutputsCleared") {
0116 JApplication app;
0117 app.Add(new JOmniFactoryGeneratorT<MyFac2>(
0118 "sut",
0119 {},
0120 {"huegelgrab"}));
0121
0122 auto event = std::make_shared<JEvent>(&app);
0123 REQUIRE(event->GetSingleStrict<MyHit>("huegelgrab")->e == 22);
0124
0125 event->Clear();
0126 REQUIRE(event->GetSingleStrict<MyHit>("huegelgrab")->e == 22);
0127 }
0128
0129 struct MyFac3 : public JOmniFactory<MyFac3> {
0130 Input<MyHit> hits_in {this};
0131 Output<MyHit> hits_out {this};
0132
0133 void Configure() { }
0134 void ChangeRun(int32_t ) { }
0135 void Execute(int32_t , uint64_t ) {
0136 REQUIRE(hits_in().at(0)->e == 123);
0137 hits_out().push_back(new MyHit{1234});
0138 }
0139 };
0140
0141
0142 TEST_CASE("JOmniFactoryTests_LightweightInputTag") {
0143 JApplication app;
0144 app.Add(new JOmniFactoryGeneratorT<MyFac3>(
0145 "sut",
0146 {"huegelgrab"},
0147 {"schlafen"}));
0148
0149 auto event = std::make_shared<JEvent>(&app);
0150 event->Insert<MyHit>(new MyHit{123}, "huegelgrab");
0151 REQUIRE(event->GetSingleStrict<MyHit>("schlafen")->e == 1234);
0152
0153 }