File indexing completed on 2025-01-31 02:19:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <array>
0015 #include <cassert>
0016
0017
0018 #include "FWCore/Framework/interface/stream/ProducingModuleAdaptorBase.h"
0019 #include "FWCore/Framework/interface/LuminosityBlock.h"
0020 #include "FWCore/Framework/interface/Run.h"
0021 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/RunPrincipal.h"
0024 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0025 #include "FWCore/Framework/interface/TransitionInfoTypes.h"
0026 #include "FWCore/Framework/interface/EventForTransformer.h"
0027 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 namespace edm {
0041 namespace stream {
0042 template <typename T>
0043 ProducingModuleAdaptorBase<T>::ProducingModuleAdaptorBase() {}
0044
0045 template <typename T>
0046 ProducingModuleAdaptorBase<T>::~ProducingModuleAdaptorBase() {
0047 for (auto m : m_streamModules) {
0048 delete m;
0049 }
0050 }
0051
0052 template <typename T>
0053 void ProducingModuleAdaptorBase<T>::deleteModulesEarly() {
0054 for (auto m : m_streamModules) {
0055 delete m;
0056 }
0057 m_streamModules.clear();
0058 }
0059
0060
0061
0062
0063
0064 template <typename T>
0065 void ProducingModuleAdaptorBase<T>::doPreallocate(PreallocationConfiguration const& iPrealloc) {
0066 m_streamModules.resize(iPrealloc.numberOfStreams(), static_cast<T*>(nullptr));
0067 setupStreamModules();
0068 preallocRuns(iPrealloc.numberOfRuns());
0069 preallocLumis(iPrealloc.numberOfLuminosityBlocks());
0070 }
0071
0072 template <typename T>
0073 void ProducingModuleAdaptorBase<T>::registerProductsAndCallbacks(ProducingModuleAdaptorBase const*,
0074 SignallingProductRegistry* reg) {
0075 auto firstMod = m_streamModules[0];
0076 if (firstMod->registrationCallback() and m_streamModules.size() > 1) {
0077
0078
0079 std::vector<std::function<void(ProductDescription const&)>> callbacks;
0080 callbacks.reserve(m_streamModules.size());
0081
0082 for (auto mod : m_streamModules) {
0083 callbacks.push_back(mod->registrationCallback());
0084 }
0085
0086
0087 firstMod->callWhenNewProductsRegistered([callbacks](ProductDescription const& iBD) {
0088 for (const auto& c : callbacks) {
0089 c(iBD);
0090 }
0091 });
0092 }
0093 firstMod->registerProducts(firstMod, reg, moduleDescription_);
0094 }
0095
0096 template <typename T>
0097 void ProducingModuleAdaptorBase<T>::itemsToGet(BranchType iType,
0098 std::vector<ProductResolverIndexAndSkipBit>& iIndices) const {
0099 assert(not m_streamModules.empty());
0100 m_streamModules[0]->itemsToGet(iType, iIndices);
0101 }
0102
0103 template <typename T>
0104 void ProducingModuleAdaptorBase<T>::itemsMayGet(BranchType iType,
0105 std::vector<ProductResolverIndexAndSkipBit>& iIndices) const {
0106 assert(not m_streamModules.empty());
0107 m_streamModules[0]->itemsMayGet(iType, iIndices);
0108 }
0109
0110 template <typename T>
0111 std::vector<edm::ProductResolverIndexAndSkipBit> const& ProducingModuleAdaptorBase<T>::itemsToGetFrom(
0112 BranchType iType) const {
0113 assert(not m_streamModules.empty());
0114 return m_streamModules[0]->itemsToGetFrom(iType);
0115 }
0116
0117 template <typename T>
0118 std::vector<ESResolverIndex> const& ProducingModuleAdaptorBase<T>::esGetTokenIndicesVector(
0119 edm::Transition iTrans) const {
0120 assert(not m_streamModules.empty());
0121 return m_streamModules[0]->esGetTokenIndicesVector(iTrans);
0122 }
0123
0124 template <typename T>
0125 std::vector<ESRecordIndex> const& ProducingModuleAdaptorBase<T>::esGetTokenRecordIndicesVector(
0126 edm::Transition iTrans) const {
0127 assert(not m_streamModules.empty());
0128 return m_streamModules[0]->esGetTokenRecordIndicesVector(iTrans);
0129 }
0130
0131 template <typename T>
0132 void ProducingModuleAdaptorBase<T>::modulesWhoseProductsAreConsumed(
0133 std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modules,
0134 std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0135 ProductRegistry const& preg,
0136 std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0137 std::string const& processName) const {
0138 assert(not m_streamModules.empty());
0139 return m_streamModules[0]->modulesWhoseProductsAreConsumed(
0140 modules, modulesInPreviousProcesses, preg, labelsToDesc, processName);
0141 }
0142
0143 template <typename T>
0144 void ProducingModuleAdaptorBase<T>::convertCurrentProcessAlias(std::string const& processName) {
0145 for (auto mod : m_streamModules) {
0146 mod->convertCurrentProcessAlias(processName);
0147 }
0148 }
0149
0150 template <typename T>
0151 std::vector<edm::ConsumesInfo> ProducingModuleAdaptorBase<T>::consumesInfo() const {
0152 assert(not m_streamModules.empty());
0153 return m_streamModules[0]->consumesInfo();
0154 }
0155
0156 template <typename T>
0157 void ProducingModuleAdaptorBase<T>::updateLookup(BranchType iType,
0158 ProductResolverIndexHelper const& iHelper,
0159 bool iPrefetchMayGet) {
0160 for (auto mod : m_streamModules) {
0161 mod->updateLookup(iType, iHelper, iPrefetchMayGet);
0162 }
0163 }
0164 template <typename T>
0165 void ProducingModuleAdaptorBase<T>::updateLookup(eventsetup::ESRecordsToProductResolverIndices const& iPI) {
0166 for (auto mod : m_streamModules) {
0167 mod->updateLookup(iPI);
0168 }
0169 }
0170
0171 template <typename T>
0172 void ProducingModuleAdaptorBase<T>::resolvePutIndicies(BranchType iBranchType,
0173 ModuleToResolverIndicies const& iIndicies,
0174 std::string const& moduleLabel) {
0175 for (auto mod : m_streamModules) {
0176 mod->resolvePutIndicies(iBranchType, iIndicies, moduleLabel);
0177 }
0178 }
0179
0180 template <typename T>
0181 std::vector<edm::ProductResolverIndex> const& ProducingModuleAdaptorBase<T>::indiciesForPutProducts(
0182 BranchType iBranchType) const {
0183 return m_streamModules[0]->indiciesForPutProducts(iBranchType);
0184 }
0185
0186 template <typename T>
0187 ProductResolverIndex ProducingModuleAdaptorBase<T>::transformPrefetch_(size_t iTransformIndex) const noexcept {
0188 return 0;
0189 }
0190 template <typename T>
0191 size_t ProducingModuleAdaptorBase<T>::transformIndex_(edm::ProductDescription const& iBranch) const noexcept {
0192 return 0;
0193 }
0194 template <typename T>
0195 void ProducingModuleAdaptorBase<T>::doTransformAsync(WaitingTaskHolder iTask,
0196 size_t iTransformIndex,
0197 EventPrincipal const& iEvent,
0198 ActivityRegistry*,
0199 ModuleCallingContext iMCC,
0200 ServiceWeakToken const&) noexcept {}
0201
0202 template <typename T>
0203 void ProducingModuleAdaptorBase<T>::doBeginStream(StreamID id) {
0204 m_streamModules[id]->beginStream(id);
0205 }
0206 template <typename T>
0207 void ProducingModuleAdaptorBase<T>::doEndStream(StreamID id) {
0208 m_streamModules[id]->endStream();
0209 }
0210
0211 template <typename T>
0212 void ProducingModuleAdaptorBase<T>::doStreamBeginRun(StreamID id,
0213 RunTransitionInfo const& info,
0214 ModuleCallingContext const* mcc) {
0215 RunPrincipal const& rp = info.principal();
0216 auto mod = m_streamModules[id];
0217 setupRun(mod, rp.index());
0218
0219 Run r(rp, moduleDescription_, mcc, false);
0220 r.setConsumer(mod);
0221 ESParentContext parentC(mcc);
0222 const EventSetup c{
0223 info, static_cast<unsigned int>(Transition::BeginRun), mod->esGetTokenIndices(Transition::BeginRun), parentC};
0224 mod->beginRun(r, c);
0225 }
0226
0227 template <typename T>
0228 void ProducingModuleAdaptorBase<T>::doStreamEndRun(StreamID id,
0229 RunTransitionInfo const& info,
0230 ModuleCallingContext const* mcc) {
0231 auto mod = m_streamModules[id];
0232 Run r(info, moduleDescription_, mcc, true);
0233 r.setConsumer(mod);
0234 ESParentContext parentC(mcc);
0235 const EventSetup c{
0236 info, static_cast<unsigned int>(Transition::EndRun), mod->esGetTokenIndices(Transition::EndRun), parentC};
0237 mod->endRun(r, c);
0238 streamEndRunSummary(mod, r, c);
0239 }
0240
0241 template <typename T>
0242 void ProducingModuleAdaptorBase<T>::doStreamBeginLuminosityBlock(StreamID id,
0243 LumiTransitionInfo const& info,
0244 ModuleCallingContext const* mcc) {
0245 LuminosityBlockPrincipal const& lbp = info.principal();
0246 auto mod = m_streamModules[id];
0247 setupLuminosityBlock(mod, lbp.index());
0248
0249 LuminosityBlock lb(lbp, moduleDescription_, mcc, false);
0250 lb.setConsumer(mod);
0251 ESParentContext parentC(mcc);
0252 const EventSetup c{info,
0253 static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0254 mod->esGetTokenIndices(Transition::BeginLuminosityBlock),
0255 parentC};
0256 mod->beginLuminosityBlock(lb, c);
0257 }
0258
0259 template <typename T>
0260 void ProducingModuleAdaptorBase<T>::doStreamEndLuminosityBlock(StreamID id,
0261 LumiTransitionInfo const& info,
0262 ModuleCallingContext const* mcc) {
0263 auto mod = m_streamModules[id];
0264 LuminosityBlock lb(info, moduleDescription_, mcc, true);
0265 lb.setConsumer(mod);
0266 ESParentContext parentC(mcc);
0267 const EventSetup c{info,
0268 static_cast<unsigned int>(Transition::EndLuminosityBlock),
0269 mod->esGetTokenIndices(Transition::EndLuminosityBlock),
0270 parentC};
0271 mod->endLuminosityBlock(lb, c);
0272 streamEndLuminosityBlockSummary(mod, lb, c);
0273 }
0274
0275 template <typename T>
0276 void ProducingModuleAdaptorBase<T>::doRegisterThinnedAssociations(ProductRegistry const& registry,
0277 ThinnedAssociationsHelper& helper) {
0278 assert(not m_streamModules.empty());
0279 auto mod = m_streamModules[0];
0280 mod->registerThinnedAssociations(registry, helper);
0281 }
0282 }
0283 }