Back to home page

EIC code displayed by LXR

 
 

    


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

0001 
0002 
0003 #include <catch.hpp>
0004 #include <JANA/JApplication.h>
0005 #include <JANA/JFactoryGenerator.h>
0006 #include <JANA/Services/JComponentManager.h>
0007 
0008 
0009 // -----------------------------------
0010 // UserDefined
0011 // -----------------------------------
0012 namespace jana::components::jfactorygeneratortests_userdefined {
0013 
0014 struct MyData { int x; };
0015 
0016 class MyFac : public JFactoryT<MyData> {
0017     void Init() override {
0018         GetApplication(); // This will throw if nullptr
0019     }
0020     void Process(const std::shared_ptr<const JEvent>&) override {
0021         std::vector<MyData*> results;
0022         results.push_back(new MyData {22});
0023         Set(results);
0024     }
0025 };
0026 
0027 class MyFacGen : public JFactoryGenerator { 
0028 
0029     void GenerateFactories(JFactorySet *factory_set) override {
0030         factory_set->Add(new MyFac);
0031     }
0032 };
0033 
0034 TEST_CASE("JFactoryGeneratorTests_UserDefined") {
0035     JApplication app;
0036     app.Add(new MyFacGen());
0037     auto event = std::make_shared<JEvent>(&app);
0038 
0039     auto data = event->Get<MyData>();
0040     REQUIRE(data.at(0)->x == 22);
0041 }
0042 }