File indexing completed on 2025-08-28 09:13:18
0001
0002 #include "JHasInputs.h"
0003
0004 #include <JANA/JEvent.h>
0005 #include <JANA/Utils/JEventLevel.h>
0006 #include <typeindex>
0007
0008 namespace jana::components {
0009
0010
0011 JFactorySet* GetFactorySetAtLevel(const JEvent& event, JEventLevel desired_level) {
0012
0013 if (desired_level == JEventLevel::None || desired_level == event.GetLevel()) {
0014 return event.GetFactorySet();
0015 }
0016 if (event.HasParent(desired_level)) {
0017 return event.GetParent(desired_level).GetFactorySet();
0018 }
0019 return nullptr;
0020 }
0021
0022 void FactoryCreate(const JEvent& event, JFactory* factory) {
0023 factory->Create(event);
0024 }
0025
0026
0027 JHasInputs::InputBase::~InputBase() {};
0028
0029 JHasInputs::VariadicInputBase::~VariadicInputBase() {};
0030
0031 void JHasInputs::InputBase::TriggerFactoryCreate(const JEvent& event) {
0032 auto facset = GetFactorySetAtLevel(event, m_level);
0033 if (facset == nullptr) {
0034 if (m_is_optional) {
0035 return;
0036 }
0037 throw JException("Could not find parent at level=" + toString(m_level));
0038 }
0039 auto databundle = facset->GetDatabundle(m_type_index, m_databundle_name);
0040 if (databundle == nullptr && !m_is_optional) {
0041 facset->Print();
0042 throw JException("Could not find databundle with type_index=" + m_type_name + " and tag=" + m_databundle_name);
0043 }
0044 if (databundle != nullptr) {
0045 auto fac = databundle->GetFactory();
0046 if (fac != nullptr) {
0047 fac->Create(event);
0048 }
0049 }
0050 }
0051
0052 void JHasInputs::VariadicInputBase::TriggerFactoryCreate(const JEvent& event) {
0053 auto facset = GetFactorySetAtLevel(event, m_level);
0054 if (facset == nullptr) {
0055 if (m_is_optional) {
0056 return;
0057 }
0058 throw JException("Could not find parent at level=" + toString(m_level));
0059 }
0060 if (!m_realized_databundle_names.empty()) {
0061 for (auto& tag : m_requested_databundle_names) {
0062 auto coll = facset->GetDatabundle(m_type_index, tag);
0063 if (coll == nullptr && !m_is_optional) {
0064 facset->Print();
0065 throw JException("Could not find databundle with type_index=" + m_type_name + " and tag=" + tag);
0066 }
0067 if (coll != nullptr) {
0068 auto fac = coll->GetFactory();
0069 if (fac != nullptr) {
0070 fac->Create(event);
0071 }
0072 }
0073 }
0074 }
0075 else if (m_empty_input_policy == EmptyInputPolicy::IncludeEverything) {
0076 auto databundles = facset->GetDatabundles(m_type_index);
0077 for (auto* databundle : databundles) {
0078 auto* factory = databundle->GetFactory();
0079 if (factory != nullptr) {
0080 factory->Create(event);
0081 }
0082 }
0083 }
0084 }
0085
0086 }