Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-17 01:30:21

0001 #include "FWCore/Framework/interface/ScheduleItems.h"
0002 
0003 #include "DataFormats/Provenance/interface/ProductDescription.h"
0004 #include "DataFormats/Provenance/interface/BranchID.h"
0005 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
0006 #include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
0007 #include "DataFormats/Provenance/interface/SelectedProducts.h"
0008 #include "FWCore/AbstractServices/interface/ResourceInformation.h"
0009 #include "FWCore/Framework/interface/ExceptionActions.h"
0010 #include "FWCore/Framework/src/CommonParams.h"
0011 #include "FWCore/Framework/interface/Schedule.h"
0012 #include "FWCore/Framework/interface/TriggerNamesService.h"
0013 #include "FWCore/Framework/interface/SignallingProductRegistryFiller.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0016 #include "FWCore/ServiceRegistry/interface/Service.h"
0017 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0018 #include "FWCore/Utilities/interface/BranchType.h"
0019 #include "FWCore/Version/interface/GetReleaseVersion.h"
0020 
0021 #include <memory>
0022 
0023 #include <set>
0024 #include <string>
0025 #include <vector>
0026 
0027 namespace edm {
0028   ScheduleItems::ScheduleItems()
0029       : actReg_(std::make_shared<ActivityRegistry>()),
0030         preg_(std::make_shared<SignallingProductRegistryFiller>()),
0031         branchIDListHelper_(std::make_shared<BranchIDListHelper>()),
0032         thinnedAssociationsHelper_(std::make_shared<ThinnedAssociationsHelper>()),
0033         act_table_(),
0034         processConfiguration_() {}
0035 
0036   ServiceToken ScheduleItems::initServices(std::vector<ParameterSet>& pServiceSets,
0037                                            ParameterSet& parameterSet,
0038                                            ServiceToken const& iToken,
0039                                            serviceregistry::ServiceLegacy iLegacy) {
0040     //create the services
0041     ServiceToken token(ServiceRegistry::createSet(pServiceSets, iToken, iLegacy));
0042 
0043     //see if any of the Services have to have their PSets stored
0044     for (auto const& item : pServiceSets) {
0045       if (item.exists("@save_config")) {
0046         parameterSet.addParameter(item.getParameter<std::string>("@service_type"), item);
0047       }
0048     }
0049     // Copy slots that hold all the registered callback functions like
0050     // PostBeginJob into an ActivityRegistry
0051     token.copySlotsTo(*actReg_);
0052     return token;
0053   }
0054 
0055   ServiceToken ScheduleItems::addTNS(ParameterSet const& parameterSet, ServiceToken const& token) {
0056     // This is ugly: pull out the trigger path pset and
0057     // create a service and extra token for it
0058 
0059     typedef service::TriggerNamesService TNS;
0060     typedef serviceregistry::ServiceWrapper<TNS> w_TNS;
0061 
0062     auto tnsptr = std::make_shared<w_TNS>(std::make_unique<TNS>(parameterSet));
0063 
0064     return ServiceRegistry::createContaining(tnsptr, token, serviceregistry::kOverlapIsError);
0065   }
0066 
0067   std::shared_ptr<CommonParams> ScheduleItems::initMisc(ParameterSet& parameterSet) {
0068     edm::Service<edm::ResourceInformation> resourceInformationService;
0069     edm::HardwareResourcesDescription hwResources;
0070     if (resourceInformationService.isAvailable()) {
0071       auto const& selectedAccelerators =
0072           parameterSet.getUntrackedParameter<std::vector<std::string>>("@selected_accelerators");
0073       resourceInformationService->setSelectedAccelerators(selectedAccelerators);
0074       // HardwareResourcesDescription is optional here in order to not
0075       // require ResourceInformationService in TestProcessor
0076       hwResources = resourceInformationService->hardwareResourcesDescription();
0077     }
0078 
0079     act_table_ = std::make_unique<ExceptionToActionTable>(parameterSet);
0080     std::string processName = parameterSet.getParameter<std::string>("@process_name");
0081     std::string releaseVersion;
0082     if (parameterSet.existsAs<std::string>("@special_override_release_version_only_for_testing", false)) {
0083       releaseVersion =
0084           parameterSet.getUntrackedParameter<std::string>("@special_override_release_version_only_for_testing");
0085     } else {
0086       releaseVersion = getReleaseVersion();
0087     }
0088     // propagate_const<T> has no reset() function
0089     processConfiguration_ = std::make_shared<ProcessConfiguration>(processName, releaseVersion, hwResources);
0090     auto common = std::make_shared<CommonParams>(
0091         parameterSet.getUntrackedParameterSet("maxEvents").getUntrackedParameter<int>("input"),
0092         parameterSet.getUntrackedParameterSet("maxLuminosityBlocks").getUntrackedParameter<int>("input"),
0093         parameterSet.getUntrackedParameterSet("maxSecondsUntilRampdown").getUntrackedParameter<int>("input"));
0094     return common;
0095   }
0096 
0097   std::unique_ptr<Schedule> ScheduleItems::initSchedule(ParameterSet& parameterSet,
0098                                                         PreallocationConfiguration const& config,
0099                                                         ProcessContext const* processContext,
0100                                                         ModuleTypeResolverMaker const* typeResolverMaker,
0101                                                         ProcessBlockHelperBase& processBlockHelper) {
0102     auto& tns = ServiceRegistry::instance().get<service::TriggerNamesService>();
0103     auto ret = std::make_unique<Schedule>(parameterSet,
0104                                           tns,
0105                                           *preg_,
0106                                           *act_table_,
0107                                           actReg_,
0108                                           processConfiguration(),
0109                                           config,
0110                                           processContext,
0111                                           typeResolverMaker);
0112     ret->finishSetup(parameterSet,
0113                      tns,
0114                      *preg_,
0115                      *branchIDListHelper_,
0116                      processBlockHelper,
0117                      *thinnedAssociationsHelper_,
0118                      actReg_,
0119                      processConfiguration(),
0120                      config,
0121                      processContext);
0122     return ret;
0123   }
0124 
0125   ScheduleItems::MadeModules ScheduleItems::initModules(ParameterSet& parameterSet,
0126                                                         service::TriggerNamesService const& tns,
0127                                                         PreallocationConfiguration const& config,
0128                                                         ProcessContext const* processContext,
0129                                                         ModuleTypeResolverMaker const* typeResolverMaker) {
0130     return MadeModules(std::make_unique<Schedule>(parameterSet,
0131                                                   tns,
0132                                                   *preg_,
0133                                                   *act_table_,
0134                                                   actReg_,
0135                                                   processConfiguration(),
0136                                                   config,
0137                                                   processContext,
0138                                                   typeResolverMaker));
0139   }
0140 
0141   std::unique_ptr<Schedule> ScheduleItems::finishSchedule(MadeModules madeModules,
0142                                                           ParameterSet& parameterSet,
0143                                                           service::TriggerNamesService const& tns,
0144                                                           PreallocationConfiguration const& config,
0145                                                           ProcessContext const* processContext,
0146                                                           ProcessBlockHelperBase& processBlockHelper) {
0147     auto sched = std::move(madeModules.m_schedule);
0148     sched->finishSetup(parameterSet,
0149                        tns,
0150                        *preg_,
0151                        *branchIDListHelper_,
0152                        processBlockHelper,
0153                        *thinnedAssociationsHelper_,
0154                        actReg_,
0155                        processConfiguration(),
0156                        config,
0157                        processContext);
0158     return sched;
0159   }
0160 
0161 }  // namespace edm