Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:58:17

0001 
0002 #include "JANA/Components/JDatabundle.h"
0003 #include "JANA/JApplicationFwd.h"
0004 #include <catch.hpp>
0005 #include <JANA/JFactoryT.h>
0006 #include <JANA/JFactoryGenerator.h>
0007 #include <JANA/JEvent.h>
0008 
0009 namespace jana::databundletests::jfactoryt {
0010 
0011 struct Hit { double E; };
0012 
0013 class MyFac : public JFactoryT<Hit> {
0014     void Process(const std::shared_ptr<const JEvent>&) {
0015         mData.push_back(new Hit{22.2});
0016     }
0017 };
0018 
0019 TEST_CASE("JDatabundle_JFactoryT") {
0020 
0021     JApplication app;
0022     app.Add(new JFactoryGeneratorT<MyFac>);
0023     auto event = std::make_shared<JEvent>(&app);
0024 
0025     SECTION("OldMechanism") {
0026         auto data = event->Get<Hit>();
0027         REQUIRE(data.size() == 1);
0028         REQUIRE(data.at(0)->E == 22.2);
0029     }
0030     SECTION("NewMechanism") {
0031 
0032         auto databundle = event->GetFactorySet()->GetDatabundle("jana::databundletests::jfactoryt::Hit");
0033 
0034         REQUIRE(databundle != nullptr); // Databundle should ALWAYS exist whether factory runs or not
0035         REQUIRE(databundle->GetStatus() == JDatabundle::Status::Empty);
0036         REQUIRE(databundle->GetFactory() != nullptr);
0037 
0038         databundle->GetFactory()->Create(*event);
0039 
0040         REQUIRE(databundle->GetStatus() == JDatabundle::Status::Created);
0041         REQUIRE(databundle->GetSize() == 1);
0042 
0043         auto typed_databundle = dynamic_cast<JLightweightDatabundleT<Hit>*>(databundle);
0044 
0045         REQUIRE(typed_databundle != nullptr);
0046         REQUIRE(typed_databundle->GetData().size() == 1);
0047         REQUIRE(typed_databundle->GetData().at(0)->E == 22.2);
0048     }
0049 }
0050 
0051 }
0052