@@ -105,7 +105,7 @@ class O2PrimaryServerDevice final : public fair::mq::Device
105105 if (conf.getGenerator ().compare (" extkin" ) != 0 || conf.getGenerator ().compare (" extkinO2" ) != 0 ) {
106106 auto iter = mPrimGeneratorCache .find (conf.getGenerator ());
107107 if (iter != mPrimGeneratorCache .end ()) {
108- mPrimGen = iter->second ;
108+ mPrimGen = iter->second . get () ;
109109 LOG (info) << " Found cached generator for " << conf.getGenerator ();
110110 }
111111 }
@@ -133,7 +133,9 @@ class O2PrimaryServerDevice final : public fair::mq::Device
133133
134134 mPrimGen ->Init ();
135135
136- mPrimGeneratorCache [conf.getGenerator ()] = mPrimGen ;
136+ std::unique_ptr<o2::eventgen::PrimaryGenerator> ptr_wrapper;
137+ ptr_wrapper.reset (mPrimGen );
138+ mPrimGeneratorCache [conf.getGenerator ()] = std::move (ptr_wrapper);
137139 }
138140 mPrimGen ->SetEvent (&mEventHeader );
139141
@@ -668,11 +670,11 @@ class O2PrimaryServerDevice final : public fair::mq::Device
668670
669671 // Keeps various generators instantiated in memory
670672 // useful when running simulation as a service (when generators
671- // change between batches)
673+ // change between batches). Also takes care of resource management of Primary generators via unique ptr
672674 // TODO: some care needs to be taken (or the user warned) that the caching is based on generator name
673675 // and that parameter-based reconfiguration is not yet implemented (for which we would need to hash all
674676 // configuration parameters as well)
675- std::map<std::string, o2::eventgen::PrimaryGenerator* > mPrimGeneratorCache ;
677+ std::map<std::string, std::unique_ptr< o2::eventgen::PrimaryGenerator> > mPrimGeneratorCache ;
676678
677679 std::atomic<O2PrimaryServerState> mState {O2PrimaryServerState::Initializing};
678680 std::atomic<int > mWaitingControlInput {0 };
0 commit comments