Skip to content

Commit 97bb307

Browse files
committed
Test interleaved Insert and Process
1 parent 396f168 commit 97bb307

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

src/libraries/JANA/JFactory.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void JFactory::Create(const JEvent& event) {
9595
// ---------------------------------------------------------------------
9696

9797
// Check if init had _previously_ excepted but the cache was since cleared
98-
if (mInitStatus == InitStatus::Excepted && mStatus == Status::Empty) {
98+
if (mInitStatus == InitStatus::InitExcepted && mStatus == Status::Empty) {
9999
for (auto* output : GetOutputs()) {
100100
output->LagrangianStore(*event.GetFactorySet(), JDatabundle::Status::Excepted);
101101
}
@@ -191,7 +191,7 @@ void JFactory::Create(const JEvent& event) {
191191
}
192192

193193
void JFactory::DoInit() {
194-
if (mInitStatus != InitStatus::NotRun) {
194+
if (mInitStatus != InitStatus::InitNotRun) {
195195
return;
196196
}
197197
for (auto* parameter : m_parameters) {
@@ -202,17 +202,17 @@ void JFactory::DoInit() {
202202
}
203203
try {
204204
CallWithJExceptionWrapper("JFactory::Init", [&](){ Init(); });
205-
mInitStatus = InitStatus::Run;
205+
mInitStatus = InitStatus::InitRun;
206206
}
207207
catch (...) {
208-
mInitStatus = InitStatus::Excepted;
208+
mInitStatus = InitStatus::InitExcepted;
209209
mException = std::current_exception();
210210
throw;
211211
}
212212
}
213213

214214
void JFactory::DoFinish() {
215-
if (mInitStatus == InitStatus::Run) {
215+
if (mInitStatus == InitStatus::InitRun) {
216216
if (mPreviousRunNumber != -1) {
217217
CallWithJExceptionWrapper("JFactory::EndRun", [&](){ EndRun(); });
218218
}

src/libraries/JANA/JFactory.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class JFactory : public jana::components::JComponent,
3434
public jana::components::JHasOutputs {
3535
public:
3636

37-
enum class InitStatus {NotRun, Run, Excepted};
37+
enum class InitStatus {InitNotRun, InitRun, InitExcepted};
3838
enum class Status {Empty, Processed, Inserted, Excepted};
3939

4040
enum JFactory_Flags_t {
@@ -70,6 +70,7 @@ class JFactory : public jana::components::JComponent,
7070

7171
std::string GetFactoryName() const { return m_type_name; }
7272
Status GetStatus() const { return mStatus; }
73+
InitStatus GetInitStatus() const { return mInitStatus; }
7374
JCallGraphRecorder::JDataOrigin GetInsertOrigin() const { return m_insert_origin; } ///< If objects were placed here by JEvent::Insert() this records whether that call was made from a source or factory.
7475

7576
uint32_t GetPreviousRunNumber(void) const { return mPreviousRunNumber; }
@@ -186,7 +187,7 @@ class JFactory : public jana::components::JComponent,
186187
std::string mObjectName;
187188

188189
Status mStatus = Status::Empty;
189-
InitStatus mInitStatus = InitStatus::NotRun;
190+
InitStatus mInitStatus = InitStatus::InitNotRun;
190191
JCallGraphRecorder::JDataOrigin m_insert_origin = JCallGraphRecorder::ORIGIN_NOT_AVAILABLE; // (see note at top of JCallGraphRecorder.h)
191192
std::exception_ptr mException;
192193
};

src/programs/unit_tests/Components/PodioTests.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
#include "JANA/Components/JDatabundle.h"
23
#include "JANA/JApplicationFwd.h"
34
#include "PodioDatamodel/ExampleHit.h"
45
#include <catch.hpp>
@@ -494,7 +495,36 @@ TEST_CASE("PodioTests_ExceptionInFactoryInit") {
494495
}
495496
REQUIRE(frame->get<ExampleHitCollection>("ExampleHit").size() == 1);
496497
}
498+
}
499+
500+
TEST_CASE("PodioTests_InterleavedInsertAndProcess") {
501+
JApplication app;
502+
app.Add(new JFactoryGeneratorT<ExceptingPodioFactory>);
503+
app.SetParameterValue("myfac:except", 0); // Disable exceptions
504+
app.Initialize();
505+
506+
JEvent event(&app);
507+
508+
auto databundle = event.GetFactorySet()->GetDatabundle("ExampleHit");
509+
REQUIRE(databundle->GetStatus() == JDatabundle::Status::Empty);
510+
REQUIRE(databundle->GetFactory() != nullptr);
511+
REQUIRE(databundle->GetFactory()->GetStatus() == JFactory::Status::Empty);
512+
REQUIRE(databundle->GetFactory()->GetInitStatus() == JFactory::InitStatus::InitNotRun);
513+
514+
515+
// Insert hits. This will NOT trigger Init
516+
ExampleHitCollection hits;
517+
hits.push_back(MutableExampleHit());
518+
event.InsertCollection<ExampleHit>(std::move(hits), "ExampleHit");
519+
520+
event.GetCollectionBase("ExampleHit");
521+
REQUIRE(databundle->GetFactory()->GetInitStatus() == JFactory::InitStatus::InitNotRun);
522+
523+
event.Clear();
497524

525+
// Trigger Init and Process
526+
event.GetCollectionBase("ExampleHit");
527+
REQUIRE(databundle->GetFactory()->GetInitStatus() == JFactory::InitStatus::InitRun);
498528
}
499529

500530
} // namespace

0 commit comments

Comments
 (0)