Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:14

0001 #include "FWCore/Framework/interface/ScheduleItems.h"
0002 
0003 #include "DataFormats/Provenance/interface/BranchDescription.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/SubProcessParentageHelper.h"
0008 #include "DataFormats/Provenance/interface/SelectedProducts.h"
0009 #include "FWCore/Common/interface/SubProcessBlockHelper.h"
0010 #include "FWCore/Framework/interface/ExceptionActions.h"
0011 #include "FWCore/Framework/src/CommonParams.h"
0012 #include "FWCore/Framework/interface/ConstProductRegistry.h"
0013 #include "FWCore/Framework/interface/SubProcess.h"
0014 #include "FWCore/Framework/interface/Schedule.h"
0015 #include "FWCore/Framework/interface/TriggerNamesService.h"
0016 #include "FWCore/Framework/interface/SignallingProductRegistry.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
0021 #include "FWCore/Utilities/interface/BranchType.h"
0022 #include "FWCore/Utilities/interface/GetPassID.h"
0023 #include "FWCore/Utilities/interface/ResourceInformation.h"
0024 #include "FWCore/Version/interface/GetReleaseVersion.h"
0025 
0026 #include <memory>
0027 
0028 #include <set>
0029 #include <string>
0030 #include <vector>
0031 
0032 namespace edm {
0033   ScheduleItems::ScheduleItems()
0034       : actReg_(std::make_shared<ActivityRegistry>()),
0035         preg_(std::make_shared<SignallingProductRegistry>()),
0036         branchIDListHelper_(std::make_shared<BranchIDListHelper>()),
0037         thinnedAssociationsHelper_(std::make_shared<ThinnedAssociationsHelper>()),
0038         subProcessParentageHelper_(),
0039         act_table_(),
0040         processConfiguration_() {}
0041 
0042   ScheduleItems::ScheduleItems(ProductRegistry const& preg,
0043                                SubProcess const& om,
0044                                SubProcessBlockHelper& subProcessBlockHelper,
0045                                ProcessBlockHelperBase const& parentProcessBlockHelper)
0046       : actReg_(std::make_shared<ActivityRegistry>()),
0047         preg_(std::make_shared<SignallingProductRegistry>(preg)),
0048         branchIDListHelper_(std::make_shared<BranchIDListHelper>()),
0049         thinnedAssociationsHelper_(std::make_shared<ThinnedAssociationsHelper>()),
0050         subProcessParentageHelper_(std::make_shared<SubProcessParentageHelper>()),
0051         act_table_(),
0052         processConfiguration_() {
0053     for (auto& item : preg_->productListUpdator()) {
0054       BranchDescription& prod = item.second;
0055       prod.setOnDemand(false);
0056       prod.setProduced(false);
0057     }
0058 
0059     // Mark dropped branches as dropped in the product registry.
0060     std::set<BranchID> keptBranches;
0061     SelectedProducts const& keptVectorP = om.keptProducts()[InProcess];
0062     for (auto const& item : keptVectorP) {
0063       BranchDescription const& desc = *item.first;
0064       keptBranches.insert(desc.branchID());
0065     }
0066     SelectedProducts const& keptVectorR = om.keptProducts()[InRun];
0067     for (auto const& item : keptVectorR) {
0068       BranchDescription const& desc = *item.first;
0069       keptBranches.insert(desc.branchID());
0070     }
0071     SelectedProducts const& keptVectorL = om.keptProducts()[InLumi];
0072     for (auto const& item : keptVectorL) {
0073       BranchDescription const& desc = *item.first;
0074       keptBranches.insert(desc.branchID());
0075     }
0076     SelectedProducts const& keptVectorE = om.keptProducts()[InEvent];
0077     for (auto const& item : keptVectorE) {
0078       BranchDescription const& desc = *item.first;
0079       keptBranches.insert(desc.branchID());
0080     }
0081     for (auto& item : preg_->productListUpdator()) {
0082       BranchDescription& prod = item.second;
0083       if (keptBranches.find(prod.branchID()) == keptBranches.end()) {
0084         prod.setDropped(true);
0085       }
0086     }
0087     subProcessBlockHelper.updateFromParentProcess(parentProcessBlockHelper, *preg_);
0088   }
0089 
0090   ServiceToken ScheduleItems::initServices(std::vector<ParameterSet>& pServiceSets,
0091                                            ParameterSet& parameterSet,
0092                                            ServiceToken const& iToken,
0093                                            serviceregistry::ServiceLegacy iLegacy,
0094                                            bool associate) {
0095     //create the services
0096     ServiceToken token(ServiceRegistry::createSet(pServiceSets, iToken, iLegacy, associate));
0097 
0098     //see if any of the Services have to have their PSets stored
0099     for (auto const& item : pServiceSets) {
0100       if (item.exists("@save_config")) {
0101         parameterSet.addParameter(item.getParameter<std::string>("@service_type"), item);
0102       }
0103     }
0104     // Copy slots that hold all the registered callback functions like
0105     // PostBeginJob into an ActivityRegistry
0106     token.copySlotsTo(*actReg_);
0107     return token;
0108   }
0109 
0110   ServiceToken ScheduleItems::addCPRandTNS(ParameterSet const& parameterSet, ServiceToken const& token) {
0111     //add the ProductRegistry as a service ONLY for the construction phase
0112     typedef serviceregistry::ServiceWrapper<ConstProductRegistry> w_CPR;
0113     auto reg = std::make_shared<w_CPR>(std::make_unique<ConstProductRegistry>(*preg_));
0114     ServiceToken tempToken(ServiceRegistry::createContaining(reg, token, serviceregistry::kOverlapIsError));
0115 
0116     // the next thing is ugly: pull out the trigger path pset and
0117     // create a service and extra token for it
0118 
0119     typedef service::TriggerNamesService TNS;
0120     typedef serviceregistry::ServiceWrapper<TNS> w_TNS;
0121 
0122     auto tnsptr = std::make_shared<w_TNS>(std::make_unique<TNS>(parameterSet));
0123 
0124     return ServiceRegistry::createContaining(tnsptr, tempToken, serviceregistry::kOverlapIsError);
0125   }
0126 
0127   std::shared_ptr<CommonParams> ScheduleItems::initMisc(ParameterSet& parameterSet) {
0128     edm::Service<edm::ResourceInformation> resourceInformationService;
0129     if (resourceInformationService.isAvailable()) {
0130       auto const& selectedAccelerators =
0131           parameterSet.getUntrackedParameter<std::vector<std::string>>("@selected_accelerators");
0132       resourceInformationService->initializeAcceleratorTypes(selectedAccelerators);
0133     }
0134 
0135     act_table_ = std::make_unique<ExceptionToActionTable>(parameterSet);
0136     std::string processName = parameterSet.getParameter<std::string>("@process_name");
0137     processConfiguration_ = std::make_shared<ProcessConfiguration>(
0138         processName, getReleaseVersion(), getPassID());  // propagate_const<T> has no reset() function
0139     auto common = std::make_shared<CommonParams>(
0140         parameterSet.getUntrackedParameterSet("maxEvents").getUntrackedParameter<int>("input"),
0141         parameterSet.getUntrackedParameterSet("maxLuminosityBlocks").getUntrackedParameter<int>("input"),
0142         parameterSet.getUntrackedParameterSet("maxSecondsUntilRampdown").getUntrackedParameter<int>("input"));
0143     return common;
0144   }
0145 
0146   std::unique_ptr<Schedule> ScheduleItems::initSchedule(ParameterSet& parameterSet,
0147                                                         bool hasSubprocesses,
0148                                                         PreallocationConfiguration const& config,
0149                                                         ProcessContext const* processContext,
0150                                                         ModuleTypeResolverMaker const* typeResolverMaker,
0151                                                         ProcessBlockHelperBase& processBlockHelper) {
0152     auto& tns = ServiceRegistry::instance().get<service::TriggerNamesService>();
0153     auto ret = std::make_unique<Schedule>(parameterSet,
0154                                           tns,
0155                                           *preg_,
0156                                           *act_table_,
0157                                           actReg_,
0158                                           processConfiguration(),
0159                                           config,
0160                                           processContext,
0161                                           typeResolverMaker);
0162     ret->finishSetup(parameterSet,
0163                      tns,
0164                      *preg_,
0165                      *branchIDListHelper_,
0166                      processBlockHelper,
0167                      *thinnedAssociationsHelper_,
0168                      subProcessParentageHelper_ ? subProcessParentageHelper_.get() : nullptr,
0169                      actReg_,
0170                      processConfiguration(),
0171                      hasSubprocesses,
0172                      config,
0173                      processContext);
0174     return ret;
0175   }
0176 
0177   ScheduleItems::MadeModules ScheduleItems::initModules(ParameterSet& parameterSet,
0178                                                         service::TriggerNamesService const& tns,
0179                                                         PreallocationConfiguration const& config,
0180                                                         ProcessContext const* processContext,
0181                                                         ModuleTypeResolverMaker const* typeResolverMaker) {
0182     return MadeModules(std::make_unique<Schedule>(parameterSet,
0183                                                   tns,
0184                                                   *preg_,
0185                                                   *act_table_,
0186                                                   actReg_,
0187                                                   processConfiguration(),
0188                                                   config,
0189                                                   processContext,
0190                                                   typeResolverMaker));
0191   }
0192 
0193   std::unique_ptr<Schedule> ScheduleItems::finishSchedule(MadeModules madeModules,
0194                                                           ParameterSet& parameterSet,
0195                                                           service::TriggerNamesService const& tns,
0196                                                           bool hasSubprocesses,
0197                                                           PreallocationConfiguration const& config,
0198                                                           ProcessContext const* processContext,
0199                                                           ProcessBlockHelperBase& processBlockHelper) {
0200     auto sched = std::move(madeModules.m_schedule);
0201     sched->finishSetup(parameterSet,
0202                        tns,
0203                        *preg_,
0204                        *branchIDListHelper_,
0205                        processBlockHelper,
0206                        *thinnedAssociationsHelper_,
0207                        subProcessParentageHelper_ ? subProcessParentageHelper_.get() : nullptr,
0208                        actReg_,
0209                        processConfiguration(),
0210                        hasSubprocesses,
0211                        config,
0212                        processContext);
0213     return sched;
0214   }
0215 
0216 }  // namespace edm