Skip to content

Commit

Permalink
Re-enable calling JEventSource::GetObjects from any JFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Sep 16, 2024
1 parent 37df86e commit 8730188
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/libraries/JANA/JEventSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ class JEventSource : public jana::components::JComponent,

/// Calls the optional-and-discouraged user-provided FinishEvent virtual method, enforcing
/// 1. Thread safety
/// 2. The m_enable_free_event flag
/// 2. The m_enable_finish_event flag

void DoFinish(JEvent& event) {
if (m_enable_free_event) {
if (m_enable_finish_event) {
std::lock_guard<std::mutex> lock(m_mutex);
CallWithJExceptionWrapper("JEventSource::FinishEvent", [&](){
FinishEvent(event);
Expand Down Expand Up @@ -403,6 +403,9 @@ class JEventSource : public jana::components::JComponent,
// TODO: Deprecate me
std::string GetName() const { return m_resource_name; }

bool IsGetObjectsEnabled() const { return m_enable_get_objects; }
bool IsFinishEventEnabled() const { return m_enable_finish_event; }

// TODO: Deprecate me
virtual std::string GetVDescription() const {
return "<description unavailable>";
Expand All @@ -418,7 +421,8 @@ class JEventSource : public jana::components::JComponent,
/// have finished with a given event. This should only be enabled when absolutely necessary
/// (e.g. for backwards compatibility) because it introduces contention for the JEventSource mutex,
/// which will hurt performance. Conceptually, FinishEvent isn't great, and so should be avoided when possible.
void EnableFinishEvent() { m_enable_free_event = true; }
void EnableFinishEvent(bool enable=true) { m_enable_finish_event = enable; }
void EnableGetObjects(bool enable=true) { m_enable_get_objects = enable; }

// Meant to be called by JANA
void SetNEvents(uint64_t nevents) { m_nevents = nevents; };
Expand All @@ -432,7 +436,8 @@ class JEventSource : public jana::components::JComponent,
std::atomic_ullong m_event_count {0};
uint64_t m_nskip = 0;
uint64_t m_nevents = 0;
bool m_enable_free_event = false;
bool m_enable_finish_event = false;
bool m_enable_get_objects = false;

};

Expand Down
18 changes: 18 additions & 0 deletions src/libraries/JANA/JFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <JANA/JFactory.h>
#include <JANA/JEvent.h>
#include <JANA/JEventSource.h>
#include <JANA/Utils/JTypeInfo.h>


Expand All @@ -14,6 +15,23 @@ void JFactory::Create(const std::shared_ptr<const JEvent>& event) {
mStatus = Status::Unprocessed;
}

auto src = event->GetJEventSource();
if (!TestFactoryFlag(REGENERATE) && src != nullptr && src->IsGetObjectsEnabled()) {
// Attempt to obtain factory data via source->GetObjects(). This will eventually be deprecated,
// but for now we want it for migration purposes. If GetObjects() is not implemented, the default
// implementation returns false with a minimal performance penalty.
bool found_data = false;

CallWithJExceptionWrapper("JEventSource::GetObjects", [&](){
found_data = src->GetObjects(event, this); });

if (found_data) {
mStatus = Status::Inserted;
mCreationStatus = CreationStatus::InsertedViaGetObjects;
return;
}
}

if (TestFactoryFlag(REGENERATE) && (mStatus == Status::Inserted)) {
ClearData();
// ClearData will reset mStatus to Status::Unprocessed
Expand Down

0 comments on commit 8730188

Please sign in to comment.