File indexing completed on 2021-08-26 03:15:59
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/ServiceRegistry.h"
0020 #include "FWCore/Utilities/interface/BranchType.h"
0021 #include "FWCore/Utilities/interface/GetPassID.h"
0022 #include "FWCore/Version/interface/GetReleaseVersion.h"
0023
0024 #include <memory>
0025
0026 #include <set>
0027
0028 namespace edm {
0029 ScheduleItems::ScheduleItems()
0030 : actReg_(std::make_shared<ActivityRegistry>()),
0031 preg_(std::make_shared<SignallingProductRegistry>()),
0032 branchIDListHelper_(std::make_shared<BranchIDListHelper>()),
0033 thinnedAssociationsHelper_(std::make_shared<ThinnedAssociationsHelper>()),
0034 subProcessParentageHelper_(),
0035 act_table_(),
0036 processConfiguration_() {}
0037
0038 ScheduleItems::ScheduleItems(ProductRegistry const& preg,
0039 SubProcess const& om,
0040 SubProcessBlockHelper& subProcessBlockHelper,
0041 ProcessBlockHelperBase const& parentProcessBlockHelper)
0042 : actReg_(std::make_shared<ActivityRegistry>()),
0043 preg_(std::make_shared<SignallingProductRegistry>(preg)),
0044 branchIDListHelper_(std::make_shared<BranchIDListHelper>()),
0045 thinnedAssociationsHelper_(std::make_shared<ThinnedAssociationsHelper>()),
0046 subProcessParentageHelper_(std::make_shared<SubProcessParentageHelper>()),
0047 act_table_(),
0048 processConfiguration_() {
0049 for (auto& item : preg_->productListUpdator()) {
0050 BranchDescription& prod = item.second;
0051 prod.setOnDemand(false);
0052 prod.setProduced(false);
0053 }
0054
0055
0056 std::set<BranchID> keptBranches;
0057 SelectedProducts const& keptVectorP = om.keptProducts()[InProcess];
0058 for (auto const& item : keptVectorP) {
0059 BranchDescription const& desc = *item.first;
0060 keptBranches.insert(desc.branchID());
0061 }
0062 SelectedProducts const& keptVectorR = om.keptProducts()[InRun];
0063 for (auto const& item : keptVectorR) {
0064 BranchDescription const& desc = *item.first;
0065 keptBranches.insert(desc.branchID());
0066 }
0067 SelectedProducts const& keptVectorL = om.keptProducts()[InLumi];
0068 for (auto const& item : keptVectorL) {
0069 BranchDescription const& desc = *item.first;
0070 keptBranches.insert(desc.branchID());
0071 }
0072 SelectedProducts const& keptVectorE = om.keptProducts()[InEvent];
0073 for (auto const& item : keptVectorE) {
0074 BranchDescription const& desc = *item.first;
0075 keptBranches.insert(desc.branchID());
0076 }
0077 for (auto& item : preg_->productListUpdator()) {
0078 BranchDescription& prod = item.second;
0079 if (keptBranches.find(prod.branchID()) == keptBranches.end()) {
0080 prod.setDropped(true);
0081 }
0082 }
0083 subProcessBlockHelper.updateFromParentProcess(parentProcessBlockHelper, *preg_);
0084 }
0085
0086 ServiceToken ScheduleItems::initServices(std::vector<ParameterSet>& pServiceSets,
0087 ParameterSet& parameterSet,
0088 ServiceToken const& iToken,
0089 serviceregistry::ServiceLegacy iLegacy,
0090 bool associate) {
0091
0092 ServiceToken token(ServiceRegistry::createSet(pServiceSets, iToken, iLegacy, associate));
0093
0094
0095 for (auto const& item : pServiceSets) {
0096 if (item.exists("@save_config")) {
0097 parameterSet.addParameter(item.getParameter<std::string>("@service_type"), item);
0098 }
0099 }
0100
0101
0102 token.copySlotsTo(*actReg_);
0103 return token;
0104 }
0105
0106 ServiceToken ScheduleItems::addCPRandTNS(ParameterSet const& parameterSet, ServiceToken const& token) {
0107
0108 typedef serviceregistry::ServiceWrapper<ConstProductRegistry> w_CPR;
0109 auto reg = std::make_shared<w_CPR>(std::make_unique<ConstProductRegistry>(*preg_));
0110 ServiceToken tempToken(ServiceRegistry::createContaining(reg, token, serviceregistry::kOverlapIsError));
0111
0112
0113
0114
0115 typedef service::TriggerNamesService TNS;
0116 typedef serviceregistry::ServiceWrapper<TNS> w_TNS;
0117
0118 auto tnsptr = std::make_shared<w_TNS>(std::make_unique<TNS>(parameterSet));
0119
0120 return ServiceRegistry::createContaining(tnsptr, tempToken, serviceregistry::kOverlapIsError);
0121 }
0122
0123 std::shared_ptr<CommonParams> ScheduleItems::initMisc(ParameterSet& parameterSet) {
0124 act_table_ = std::make_unique<ExceptionToActionTable>(parameterSet);
0125 std::string processName = parameterSet.getParameter<std::string>("@process_name");
0126 processConfiguration_ = std::make_shared<ProcessConfiguration>(
0127 processName, getReleaseVersion(), getPassID());
0128 auto common = std::make_shared<CommonParams>(
0129 parameterSet.getUntrackedParameterSet("maxEvents").getUntrackedParameter<int>("input"),
0130 parameterSet.getUntrackedParameterSet("maxLuminosityBlocks").getUntrackedParameter<int>("input"),
0131 parameterSet.getUntrackedParameterSet("maxSecondsUntilRampdown").getUntrackedParameter<int>("input"));
0132 return common;
0133 }
0134
0135 std::unique_ptr<Schedule> ScheduleItems::initSchedule(ParameterSet& parameterSet,
0136 bool hasSubprocesses,
0137 PreallocationConfiguration const& config,
0138 ProcessContext const* processContext,
0139 ProcessBlockHelperBase& processBlockHelper) {
0140 return std::make_unique<Schedule>(parameterSet,
0141 ServiceRegistry::instance().get<service::TriggerNamesService>(),
0142 *preg_,
0143 *branchIDListHelper_,
0144 processBlockHelper,
0145 *thinnedAssociationsHelper_,
0146 subProcessParentageHelper_ ? subProcessParentageHelper_.get() : nullptr,
0147 *act_table_,
0148 actReg_,
0149 processConfiguration(),
0150 hasSubprocesses,
0151 config,
0152 processContext);
0153 }
0154 }