Skip to content

Commit

Permalink
Clear PodioStorage correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Sep 20, 2024
1 parent d29d6aa commit 2463f26
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/libraries/JANA/Components/JPodioStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ class JPodioStorage : public JStorage {

public:
size_t GetSize() const override {
if (m_collection == nullptr) {
return 0;
}
return m_collection->size();
}

virtual void ClearData() override {
m_collection = nullptr;
m_frame = nullptr;
SetStatus(JStorage::Status::Empty);
// Podio clears the data itself when the frame is destroyed.
// Until then, the collection is immutable.
//
Expand Down
1 change: 1 addition & 0 deletions src/libraries/JANA/Components/JStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <typeindex>
#include <vector>
#include <memory>
#include <unordered_map>


class JFactory;
Expand Down
1 change: 1 addition & 0 deletions src/libraries/JANA/JFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class JFactory : public jana::components::JComponent,
: mObjectName(std::move(aName)),
mTag(std::move(aTag)),
mStatus(Status::Uninitialized) {
SetTypeName(mObjectName);
SetPrefix(aTag.empty() ? mObjectName : mObjectName + ":" + mTag);
};

Expand Down
4 changes: 2 additions & 2 deletions src/programs/unit_tests/Components/JStorageTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct TestFactory : public JFactory {
}
void Init() {
}
void Process(const std::shared_ptr<const JEvent>& event) {
void Process(const std::shared_ptr<const JEvent>&) {
LOG_WARN(GetLogger()) << "Calling TestFactory::Process" << LOG_END;
m_clusters()->push_back(MutableExampleCluster(22.2));
m_clusters()->push_back(MutableExampleCluster(27));
Expand All @@ -61,7 +61,7 @@ struct RegeneratingTestFactory : public JFactory {
}
void Init() {
}
void Process(const std::shared_ptr<const JEvent>& event) {
void Process(const std::shared_ptr<const JEvent>&) {
LOG_WARN(GetLogger()) << "Calling TestFactory::Process" << LOG_END;
m_clusters()->push_back(MutableExampleCluster(22.2));
m_clusters()->push_back(MutableExampleCluster(27));
Expand Down
43 changes: 43 additions & 0 deletions src/programs/unit_tests/Components/PodioTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,49 @@ TEST_CASE("Podio JMultifactory::Init gets called") {
REQUIRE(multifac_typed != nullptr);
REQUIRE(multifac_typed->init_called == true);
}
TEST_CASE("PodioTests_InsertMultiple") {

JApplication app;
auto event = std::make_shared<JEvent>(&app);

// Insert a cluster

auto coll1 = ExampleClusterCollection();
auto cluster1 = coll1.create(22.0);
auto storage = event->InsertCollection<ExampleCluster>(std::move(coll1), "clusters");

REQUIRE(storage->GetSize() == 1);
REQUIRE(storage->GetStatus() == JStorage::Status::Inserted);

// Retrieve and validate cluster

auto cluster1_retrieved = event->GetCollection<ExampleCluster>("clusters");
REQUIRE(cluster1_retrieved->at(0).energy() == 22.0);

// Clear event

event->GetFactorySet()->Release(); // Simulate a trip to the JEventPool

// After clearing, the JStorage will still exist, but it will be empty
auto storage2 = event->GetStorage("clusters", false);
REQUIRE(storage2->GetStatus() == JStorage::Status::Empty);
REQUIRE(storage2->GetSize() == 0);

// Insert a cluster. If event isn't being cleared correctly, this will throw

auto coll2 = ExampleClusterCollection();
auto cluster2 = coll2.create(33.0);
auto storage3 = event->InsertCollection<ExampleCluster>(std::move(coll2), "clusters");
REQUIRE(storage3->GetStatus() == JStorage::Status::Inserted);
REQUIRE(storage3->GetSize() == 1);

// Retrieve and validate cluster

auto cluster2_retrieved = event->GetCollection<ExampleCluster>("clusters");
REQUIRE(cluster2_retrieved->at(0).energy() == 33.0);
}


} // namespace multifactory
} // namespace podiotests

0 comments on commit 2463f26

Please sign in to comment.