@@ -210,10 +210,20 @@ void GeneratorHybrid::stop()
210210 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now () - t0).count ();
211211 LOG (info) << " HybridGen: stop() joined TBB task pool after " << ms << " ms" ;
212212 }
213+ // Forward the hook to the sub-generators
214+ for (auto & gen : gens) {
215+ if (gen) {
216+ gen->stop ();
217+ }
218+ }
213219}
214220
215221Bool_t GeneratorHybrid::Init ()
216222{
223+ // protection against additional Init() which would assign over a joinable mTBBTaskPoolRunner, which calls std::terminate
224+ if (mIsInitialized ) {
225+ return true ;
226+ }
217227 // init all sub-gens
218228 int count = 0 ;
219229 for (auto & gen : mGens ) {
@@ -474,6 +484,9 @@ bool GeneratorHybrid::importParticles()
474484 // this is important when using event pools where the full header information is forwarded from the generator
475485 // otherwise some events might have mixed header information from different generators
476486 mMCEventHeader .Reset ();
487+ // Once the event budget is exhausted there is no further event to prepare, and re-queueing a
488+ // sub-generator would start an event nobody consumes and that stop() then has to wait for
489+ const bool queueNextEvent = getTotalNEvents () == 0 || mEventCounter + 1 < getTotalNEvents ();
477490 if (mCocktailMode ) {
478491 // in cocktail mode we need to merge the particles from the different generators
479492 for (auto subIndex : subGenIndex) {
@@ -504,8 +517,10 @@ bool GeneratorHybrid::importParticles()
504517 gens[subIndex]->updateHeader (&mMCEventHeader );
505518 mHeaderGeneratorIndex = subIndex; // store index of generator updating the header
506519 }
507- mInputTaskQueue .push (subIndex);
508- mTasksStarted ++;
520+ if (queueNextEvent) {
521+ mInputTaskQueue .push (subIndex);
522+ mTasksStarted ++;
523+ }
509524 }
510525 } else {
511526 if (!mIsHyperloop ) {
@@ -528,8 +543,10 @@ bool GeneratorHybrid::importParticles()
528543 // fetch the event Header information from the underlying generator
529544 gens[genIndex]->updateHeader (&mMCEventHeader );
530545 mHeaderGeneratorIndex = genIndex; // store index of generator updating the header
531- mInputTaskQueue .push (genIndex);
532- mTasksStarted ++;
546+ if (queueNextEvent) {
547+ mInputTaskQueue .push (genIndex);
548+ mTasksStarted ++;
549+ }
533550 }
534551
535552 mseqCounter++;
0 commit comments