5353
5454#include " FWCore/AbstractServices/interface/RandomNumberGenerator.h"
5555#include " FWCore/AbstractServices/interface/RootHandlers.h"
56+ #include " FWCore/AbstractServices/interface/TimingServiceBase.h"
5657
5758#include " FWCore/ServiceRegistry/interface/ServiceRegistry.h"
5859#include " FWCore/ServiceRegistry/interface/Service.h"
@@ -109,6 +110,18 @@ namespace {
109110 private:
110111 edm::SerialTaskQueue& queue_;
111112 };
113+
114+ template <typename T>
115+ requires std::is_invocable_v<T>
116+ struct Guard {
117+ Guard (T&& signal) : final_(std::forward<T>(signal)) {}
118+ ~Guard () { final_ (); }
119+ T final_;
120+ };
121+ template <typename T>
122+ Guard<T> makeGuard (T&& signal) {
123+ return Guard{std::forward<T>(signal)};
124+ }
112125} // namespace
113126
114127namespace edm {
@@ -423,9 +436,11 @@ namespace edm {
423436 ScheduleItems items;
424437
425438 // initialize the services
439+ edm::TimingServiceBase::servicesStarting ();
426440 auto & serviceSets = processDesc->getServicesPSets ();
427441 ServiceToken token = items.initServices (serviceSets, *parameterSet, iToken, iLegacy);
428442 serviceToken_ = items.addTNS (*parameterSet, token);
443+ items.actReg_ ->postServicesConstructionSignal_ ();
429444
430445 // make the services available
431446 ServiceRegistry::Operate operate (serviceToken_);
@@ -440,9 +455,13 @@ namespace edm {
440455 std::shared_ptr<CommonParams> common (items.initMisc (*parameterSet));
441456
442457 // intialize the event setup provider
443- ParameterSet const & eventSetupPset (optionsPset.getUntrackedParameterSet (" eventSetup" ));
444- esp_ = espController_->makeProvider (
445- *parameterSet, items.actReg_ .get (), &eventSetupPset, maxConcurrentIOVs, dumpOptions);
458+ items.actReg_ ->preEventSetupModulesConstructionSignal_ ();
459+ {
460+ auto guard = makeGuard ([&items]() { items.actReg_ ->postEventSetupModulesConstructionSignal_ (); });
461+ ParameterSet const & eventSetupPset (optionsPset.getUntrackedParameterSet (" eventSetup" ));
462+ esp_ = espController_->makeProvider (
463+ *parameterSet, items.actReg_ .get (), &eventSetupPset, maxConcurrentIOVs, dumpOptions);
464+ }
446465
447466 // initialize the looper, if any
448467 if (!loopers.empty ()) {
@@ -497,6 +516,8 @@ namespace edm {
497516 group.wait ();
498517 items.preg ()->addFromInput (input_->productRegistry ());
499518 {
519+ items.actReg_ ->preFinishScheduleSignal_ ();
520+ auto guard = makeGuard ([&items]() { items.actReg_ ->postFinishScheduleSignal_ (); });
500521 auto const & tns = ServiceRegistry::instance ().get <service::TriggerNamesService>();
501522 schedule_ = items.finishSchedule (
502523 std::move (*madeModules), *parameterSet, tns, preallocations_, &processContext_, *processBlockHelper_);
@@ -524,44 +545,48 @@ namespace edm {
524545
525546 FDEBUG (2 ) << parameterSet << std::endl;
526547
527- principalCache_.setNumberOfConcurrentPrincipals (preallocations_);
528- for (unsigned int index = 0 ; index < preallocations_.numberOfStreams (); ++index) {
529- // Reusable event principal
530- auto ep = std::make_shared<EventPrincipal>(preg (),
548+ {
549+ actReg_->prePrincipalsCreationSignal_ ();
550+ auto guard = makeGuard ([this ]() { actReg_->postPrincipalsCreationSignal_ (); });
551+ principalCache_.setNumberOfConcurrentPrincipals (preallocations_);
552+ for (unsigned int index = 0 ; index < preallocations_.numberOfStreams (); ++index) {
553+ // Reusable event principal
554+ auto ep = std::make_shared<EventPrincipal>(preg (),
555+ productResolversFactory::makePrimary,
556+ branchIDListHelper (),
557+ thinnedAssociationsHelper (),
558+ *processConfiguration_,
559+ historyAppender_.get (),
560+ index,
561+ &*processBlockHelper_);
562+ principalCache_.insert (std::move (ep));
563+ }
564+
565+ for (unsigned int index = 0 ; index < preallocations_.numberOfRuns (); ++index) {
566+ auto rp = std::make_unique<RunPrincipal>(preg (),
531567 productResolversFactory::makePrimary,
532- branchIDListHelper (),
533- thinnedAssociationsHelper (),
534568 *processConfiguration_,
535569 historyAppender_.get (),
536570 index,
537- &*processBlockHelper_);
538- principalCache_.insert (std::move (ep));
539- }
540-
541- for (unsigned int index = 0 ; index < preallocations_.numberOfRuns (); ++index) {
542- auto rp = std::make_unique<RunPrincipal>(preg (),
543- productResolversFactory::makePrimary,
544- *processConfiguration_,
545- historyAppender_.get (),
546- index,
547- &mergeableRunProductProcesses_);
548- principalCache_.insert (std::move (rp));
549- }
571+ &mergeableRunProductProcesses_);
572+ principalCache_.insert (std::move (rp));
573+ }
550574
551- for (unsigned int index = 0 ; index < preallocations_.numberOfLuminosityBlocks (); ++index) {
552- auto lp = std::make_unique<LuminosityBlockPrincipal>(
553- preg (), productResolversFactory::makePrimary, *processConfiguration_, historyAppender_.get (), index);
554- principalCache_.insert (std::move (lp));
555- }
575+ for (unsigned int index = 0 ; index < preallocations_.numberOfLuminosityBlocks (); ++index) {
576+ auto lp = std::make_unique<LuminosityBlockPrincipal>(
577+ preg (), productResolversFactory::makePrimary, *processConfiguration_, historyAppender_.get (), index);
578+ principalCache_.insert (std::move (lp));
579+ }
556580
557- {
558- auto pb = std::make_unique<ProcessBlockPrincipal>(
559- preg (), productResolversFactory::makePrimary, *processConfiguration_);
560- principalCache_.insert (std::move (pb));
581+ {
582+ auto pb = std::make_unique<ProcessBlockPrincipal>(
583+ preg (), productResolversFactory::makePrimary, *processConfiguration_);
584+ principalCache_.insert (std::move (pb));
561585
562- auto pbForInput = std::make_unique<ProcessBlockPrincipal>(
563- preg (), productResolversFactory::makePrimary, *processConfiguration_);
564- principalCache_.insertForInput (std::move (pbForInput));
586+ auto pbForInput = std::make_unique<ProcessBlockPrincipal>(
587+ preg (), productResolversFactory::makePrimary, *processConfiguration_);
588+ principalCache_.insertForInput (std::move (pbForInput));
589+ }
565590 }
566591 } catch (...) {
567592 // in case of an exception, make sure Services are available
@@ -617,43 +642,47 @@ namespace edm {
617642 schedule_->convertCurrentProcessAlias (processConfiguration_->processName ());
618643
619644 PathsAndConsumesOfModules pathsAndConsumesOfModules;
620- pathsAndConsumesOfModules.initialize (schedule_.get (), preg ());
621-
622- // Note: all these may throw
623- checkForModuleDependencyCorrectness (pathsAndConsumesOfModules, printDependencies_);
624- if (deleteNonConsumedUnscheduledModules_) {
625- if (auto const unusedModules = nonConsumedUnscheduledModules (pathsAndConsumesOfModules);
626- not unusedModules.empty ()) {
627- pathsAndConsumesOfModules.removeModules (unusedModules);
628-
629- edm::LogInfo (" DeleteModules" ).log ([&unusedModules](auto & l) {
630- l << " The following modules are not in any Path or EndPath, nor is their output consumed by any other "
631- " module, "
632- " and therefore they are deleted before the beginJob transition." ;
645+ {
646+ actReg_->preScheduleConsistencyCheckSignal_ ();
647+ auto guard = makeGuard ([this ]() { actReg_->postScheduleConsistencyCheckSignal_ (); });
648+ pathsAndConsumesOfModules.initialize (schedule_.get (), preg ());
649+
650+ // Note: all these may throw
651+ checkForModuleDependencyCorrectness (pathsAndConsumesOfModules, printDependencies_);
652+ if (deleteNonConsumedUnscheduledModules_) {
653+ if (auto const unusedModules = nonConsumedUnscheduledModules (pathsAndConsumesOfModules);
654+ not unusedModules.empty ()) {
655+ pathsAndConsumesOfModules.removeModules (unusedModules);
656+
657+ edm::LogInfo (" DeleteModules" ).log ([&unusedModules](auto & l) {
658+ l << " The following modules are not in any Path or EndPath, nor is their output consumed by any other "
659+ " module, "
660+ " and therefore they are deleted before the beginJob transition." ;
661+ for (auto const & description : unusedModules) {
662+ l << " \n " << description->moduleLabel ();
663+ }
664+ });
633665 for (auto const & description : unusedModules) {
634- l << " \n " << description->moduleLabel ();
666+ schedule_-> deleteModule ( description->moduleLabel (), actReg_. get () );
635667 }
636- });
637- for (auto const & description : unusedModules) {
638- schedule_->deleteModule (description->moduleLabel (), actReg_.get ());
639668 }
640669 }
641- }
642- // Initialize after the deletion of non-consumed unscheduled
643- // modules to avoid non-consumed non-run modules to keep the
644- // products unnecessarily alive
645- if (not branchesToDeleteEarly_.empty ()) {
646- auto modulesToSkip = std::move (modulesToIgnoreForDeleteEarly_);
647- auto branchesToDeleteEarly = std::move (branchesToDeleteEarly_);
648- auto referencesToBranches = std::move (referencesToBranches_);
649- schedule_->initializeEarlyDelete (branchesToDeleteEarly, referencesToBranches, modulesToSkip, *preg_);
650- }
670+ // Initialize after the deletion of non-consumed unscheduled
671+ // modules to avoid non-consumed non-run modules to keep the
672+ // products unnecessarily alive
673+ if (not branchesToDeleteEarly_.empty ()) {
674+ auto modulesToSkip = std::move (modulesToIgnoreForDeleteEarly_);
675+ auto branchesToDeleteEarly = std::move (branchesToDeleteEarly_);
676+ auto referencesToBranches = std::move (referencesToBranches_);
677+ schedule_->initializeEarlyDelete (branchesToDeleteEarly, referencesToBranches, modulesToSkip, *preg_);
678+ }
651679
652- if (preallocations_.numberOfLuminosityBlocks () > 1 ) {
653- throwAboutModulesRequiringLuminosityBlockSynchronization ();
654- }
655- if (preallocations_.numberOfRuns () > 1 ) {
656- warnAboutModulesRequiringRunSynchronization ();
680+ if (preallocations_.numberOfLuminosityBlocks () > 1 ) {
681+ throwAboutModulesRequiringLuminosityBlockSynchronization ();
682+ }
683+ if (preallocations_.numberOfRuns () > 1 ) {
684+ warnAboutModulesRequiringRunSynchronization ();
685+ }
657686 }
658687
659688 // NOTE: This implementation assumes 'Job' means one call
@@ -670,8 +699,11 @@ namespace edm {
670699 // if(looper_) {
671700 // looper_->beginOfJob(es);
672701 // }
673- espController_->finishConfiguration ();
674-
702+ {
703+ actReg_->preEventSetupConfigurationFinalizedSignal_ ();
704+ auto guard = makeGuard ([this ]() { actReg_->postEventSetupConfigurationFinalizedSignal_ (); });
705+ espController_->finishConfiguration ();
706+ }
675707 eventsetup::ESRecordsToProductResolverIndices esRecordsToProductResolverIndices = esp_->recordsToResolverIndices ();
676708
677709 actReg_->eventSetupConfigurationSignal_ (esRecordsToProductResolverIndices, processContext_);
0 commit comments