@@ -20,6 +20,7 @@ namespace jana::components {
20
20
21
21
// Free function in order to break circular dependence on JEvent
22
22
JFactorySet* GetFactorySetAtLevel (const JEvent& event, JEventLevel desired_level);
23
+ void FactoryCreate (const JEvent& event, JFactory* factory);
23
24
24
25
struct JHasInputs {
25
26
protected:
@@ -209,6 +210,12 @@ struct JHasInputs {
209
210
// JFactory in the same JFactorySet, though.
210
211
211
212
auto facset = GetFactorySetAtLevel (event, m_level);
213
+ if (facset == nullptr ) {
214
+ if (m_is_optional) {
215
+ return ;
216
+ }
217
+ throw JException (" Could not find parent at level=" + toString (m_level));
218
+ }
212
219
auto databundle = facset->GetDatabundle (std::type_index (typeid (T)), m_tag);
213
220
if (databundle == nullptr ) {
214
221
if (!m_is_optional) {
@@ -273,6 +280,12 @@ struct JHasInputs {
273
280
274
281
void Populate (const JEvent& event) {
275
282
auto facset = GetFactorySetAtLevel (event, m_level);
283
+ if (facset == nullptr ) {
284
+ if (m_is_optional) {
285
+ return ;
286
+ }
287
+ throw JException (" Could not find parent at level=" + toString (m_level));
288
+ }
276
289
auto databundle = facset->GetDatabundle (std::type_index (typeid (PodioT)), m_databundle_name);
277
290
if (databundle == nullptr ) {
278
291
if (!m_is_optional) {
@@ -283,6 +296,9 @@ struct JHasInputs {
283
296
m_data = nullptr ;
284
297
return ;
285
298
};
299
+ if (databundle->GetFactory () != nullptr ) {
300
+ FactoryCreate (event, databundle->GetFactory ());
301
+ }
286
302
auto * typed_databundle = dynamic_cast <JPodioDatabundle*>(databundle);
287
303
if (typed_databundle == nullptr ) {
288
304
facset->Print ();
@@ -335,7 +351,10 @@ struct JHasInputs {
335
351
void Populate (const JEvent& event) {
336
352
m_datas.clear ();
337
353
auto facset = GetFactorySetAtLevel (event, m_level);
338
- if (facset == nullptr && !m_is_optional) {
354
+ if (facset == nullptr ) {
355
+ if (m_is_optional) {
356
+ return ;
357
+ }
339
358
throw JException (" Could not find parent at level=" + toString (m_level));
340
359
}
341
360
if (!m_requested_databundle_names.empty ()) {
@@ -350,6 +369,9 @@ struct JHasInputs {
350
369
m_datas.push_back ({}); // If a databundle is optional and missing, we still insert an empty vector for it
351
370
continue ;
352
371
};
372
+ if (databundle->GetFactory () != nullptr ) {
373
+ FactoryCreate (event, databundle->GetFactory ());
374
+ }
353
375
auto * typed_databundle = dynamic_cast <JLightweightDatabundleT<T>*>(databundle);
354
376
if (typed_databundle == nullptr ) {
355
377
facset->Print ();
@@ -424,7 +446,10 @@ struct JHasInputs {
424
446
425
447
void Populate (const JEvent& event) {
426
448
auto facset = GetFactorySetAtLevel (event, m_level);
427
- if (facset == nullptr && !m_is_optional) {
449
+ if (facset == nullptr ) {
450
+ if (m_is_optional) {
451
+ return ;
452
+ }
428
453
throw JException (" Could not find parent at level=" + toString (m_level));
429
454
}
430
455
bool need_dynamic_realized_databundle_names = (m_requested_databundle_names.empty ()) && (m_empty_input_policy != EmptyInputPolicy::IncludeNothing);
@@ -443,6 +468,9 @@ struct JHasInputs {
443
468
m_datas.push_back (nullptr );
444
469
continue ;
445
470
}
471
+ if (databundle->GetFactory () != nullptr ) {
472
+ FactoryCreate (event, databundle->GetFactory ());
473
+ }
446
474
auto * typed_databundle = dynamic_cast <JPodioDatabundle*>(databundle);
447
475
if (typed_databundle == nullptr ) {
448
476
facset->Print ();
@@ -459,6 +487,9 @@ struct JHasInputs {
459
487
else if (m_empty_input_policy == EmptyInputPolicy::IncludeEverything) {
460
488
auto databundles = facset->GetDatabundles (std::type_index (typeid (PodioT)));
461
489
for (auto * databundle : databundles) {
490
+ if (databundle->GetFactory () != nullptr ) {
491
+ FactoryCreate (event, databundle->GetFactory ());
492
+ }
462
493
auto typed_databundle = dynamic_cast <JPodioDatabundle*>(databundle);
463
494
if (typed_databundle == nullptr ) {
464
495
throw JException (" Not a JPodioDatabundle: type_name=%s, unique_name=%s" , databundle->GetTypeName ().c_str (), databundle->GetUniqueName ().c_str ());
0 commit comments