Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:59:00

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Framework
0004 // Class  :     edm::stream::ProducingModuleAdaptorBase
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Fri, 02 Aug 2013 21:43:44 GMT
0011 //
0012 
0013 // system include files
0014 #include <array>
0015 #include <cassert>
0016 
0017 // user include files
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/ServiceRegistry/interface/ESParentContext.h"
0027 
0028 //
0029 // constants, enums and typedefs
0030 //
0031 
0032 //
0033 // static data member definitions
0034 //
0035 
0036 //
0037 // constructors and destructor
0038 //
0039 namespace edm {
0040   namespace stream {
0041     template <typename T>
0042     ProducingModuleAdaptorBase<T>::ProducingModuleAdaptorBase() {}
0043 
0044     template <typename T>
0045     ProducingModuleAdaptorBase<T>::~ProducingModuleAdaptorBase() {
0046       for (auto m : m_streamModules) {
0047         delete m;
0048       }
0049     }
0050 
0051     template <typename T>
0052     void ProducingModuleAdaptorBase<T>::deleteModulesEarly() {
0053       for (auto m : m_streamModules) {
0054         delete m;
0055       }
0056       m_streamModules.clear();
0057     }
0058 
0059     //
0060     // member functions
0061     //
0062 
0063     template <typename T>
0064     void ProducingModuleAdaptorBase<T>::doPreallocate(PreallocationConfiguration const& iPrealloc) {
0065       m_streamModules.resize(iPrealloc.numberOfStreams(), static_cast<T*>(nullptr));
0066       setupStreamModules();
0067       preallocLumis(iPrealloc.numberOfLuminosityBlocks());
0068     }
0069 
0070     template <typename T>
0071     void ProducingModuleAdaptorBase<T>::registerProductsAndCallbacks(ProducingModuleAdaptorBase const*,
0072                                                                      ProductRegistry* reg) {
0073       auto firstMod = m_streamModules[0];
0074       if (firstMod->registrationCallback() and m_streamModules.size() > 1) {
0075         //we have a callback so we will collect all callbacks and create a new callback which calls them all.
0076 
0077         std::vector<std::function<void(BranchDescription const&)>> callbacks;
0078         callbacks.reserve(m_streamModules.size());
0079 
0080         for (auto mod : m_streamModules) {
0081           callbacks.push_back(mod->registrationCallback());
0082         }
0083         //Since only the first module will actually do the registration
0084         // we will change its callback to call all the callbacks
0085         firstMod->callWhenNewProductsRegistered([callbacks](BranchDescription const& iBD) {
0086           for (const auto& c : callbacks) {
0087             c(iBD);
0088           }
0089         });
0090       }
0091       firstMod->registerProducts(firstMod, reg, moduleDescription_);
0092     }
0093 
0094     template <typename T>
0095     void ProducingModuleAdaptorBase<T>::itemsToGet(BranchType iType,
0096                                                    std::vector<ProductResolverIndexAndSkipBit>& iIndices) const {
0097       assert(not m_streamModules.empty());
0098       m_streamModules[0]->itemsToGet(iType, iIndices);
0099     }
0100 
0101     template <typename T>
0102     void ProducingModuleAdaptorBase<T>::itemsMayGet(BranchType iType,
0103                                                     std::vector<ProductResolverIndexAndSkipBit>& iIndices) const {
0104       assert(not m_streamModules.empty());
0105       m_streamModules[0]->itemsMayGet(iType, iIndices);
0106     }
0107 
0108     template <typename T>
0109     std::vector<edm::ProductResolverIndexAndSkipBit> const& ProducingModuleAdaptorBase<T>::itemsToGetFrom(
0110         BranchType iType) const {
0111       assert(not m_streamModules.empty());
0112       return m_streamModules[0]->itemsToGetFrom(iType);
0113     }
0114 
0115     template <typename T>
0116     std::vector<ESProxyIndex> const& ProducingModuleAdaptorBase<T>::esGetTokenIndicesVector(
0117         edm::Transition iTrans) const {
0118       assert(not m_streamModules.empty());
0119       return m_streamModules[0]->esGetTokenIndicesVector(iTrans);
0120     }
0121 
0122     template <typename T>
0123     std::vector<ESRecordIndex> const& ProducingModuleAdaptorBase<T>::esGetTokenRecordIndicesVector(
0124         edm::Transition iTrans) const {
0125       assert(not m_streamModules.empty());
0126       return m_streamModules[0]->esGetTokenRecordIndicesVector(iTrans);
0127     }
0128 
0129     template <typename T>
0130     void ProducingModuleAdaptorBase<T>::modulesWhoseProductsAreConsumed(
0131         std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modules,
0132         std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0133         ProductRegistry const& preg,
0134         std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0135         std::string const& processName) const {
0136       assert(not m_streamModules.empty());
0137       return m_streamModules[0]->modulesWhoseProductsAreConsumed(
0138           modules, modulesInPreviousProcesses, preg, labelsToDesc, processName);
0139     }
0140 
0141     template <typename T>
0142     void ProducingModuleAdaptorBase<T>::convertCurrentProcessAlias(std::string const& processName) {
0143       for (auto mod : m_streamModules) {
0144         mod->convertCurrentProcessAlias(processName);
0145       }
0146     }
0147 
0148     template <typename T>
0149     std::vector<edm::ConsumesInfo> ProducingModuleAdaptorBase<T>::consumesInfo() const {
0150       assert(not m_streamModules.empty());
0151       return m_streamModules[0]->consumesInfo();
0152     }
0153 
0154     template <typename T>
0155     void ProducingModuleAdaptorBase<T>::updateLookup(BranchType iType,
0156                                                      ProductResolverIndexHelper const& iHelper,
0157                                                      bool iPrefetchMayGet) {
0158       for (auto mod : m_streamModules) {
0159         mod->updateLookup(iType, iHelper, iPrefetchMayGet);
0160       }
0161     }
0162     template <typename T>
0163     void ProducingModuleAdaptorBase<T>::updateLookup(eventsetup::ESRecordsToProxyIndices const& iPI) {
0164       for (auto mod : m_streamModules) {
0165         mod->updateLookup(iPI);
0166       }
0167     }
0168 
0169     template <typename T>
0170     void ProducingModuleAdaptorBase<T>::resolvePutIndicies(BranchType iBranchType,
0171                                                            ModuleToResolverIndicies const& iIndicies,
0172                                                            std::string const& moduleLabel) {
0173       for (auto mod : m_streamModules) {
0174         mod->resolvePutIndicies(iBranchType, iIndicies, moduleLabel);
0175       }
0176     }
0177 
0178     template <typename T>
0179     std::vector<edm::ProductResolverIndex> const& ProducingModuleAdaptorBase<T>::indiciesForPutProducts(
0180         BranchType iBranchType) const {
0181       return m_streamModules[0]->indiciesForPutProducts(iBranchType);
0182     }
0183 
0184     template <typename T>
0185     void ProducingModuleAdaptorBase<T>::doBeginStream(StreamID id) {
0186       m_streamModules[id]->beginStream(id);
0187     }
0188     template <typename T>
0189     void ProducingModuleAdaptorBase<T>::doEndStream(StreamID id) {
0190       m_streamModules[id]->endStream();
0191     }
0192 
0193     template <typename T>
0194     void ProducingModuleAdaptorBase<T>::doStreamBeginRun(StreamID id,
0195                                                          RunTransitionInfo const& info,
0196                                                          ModuleCallingContext const* mcc) {
0197       RunPrincipal const& rp = info.principal();
0198       auto mod = m_streamModules[id];
0199       setupRun(mod, rp.index());
0200 
0201       Run r(rp, moduleDescription_, mcc, false);
0202       r.setConsumer(mod);
0203       ESParentContext parentC(mcc);
0204       const EventSetup c{
0205           info, static_cast<unsigned int>(Transition::BeginRun), mod->esGetTokenIndices(Transition::BeginRun), parentC};
0206       mod->beginRun(r, c);
0207     }
0208 
0209     template <typename T>
0210     void ProducingModuleAdaptorBase<T>::doStreamEndRun(StreamID id,
0211                                                        RunTransitionInfo const& info,
0212                                                        ModuleCallingContext const* mcc) {
0213       auto mod = m_streamModules[id];
0214       Run r(info, moduleDescription_, mcc, true);
0215       r.setConsumer(mod);
0216       ESParentContext parentC(mcc);
0217       const EventSetup c{
0218           info, static_cast<unsigned int>(Transition::EndRun), mod->esGetTokenIndices(Transition::EndRun), parentC};
0219       mod->endRun(r, c);
0220       streamEndRunSummary(mod, r, c);
0221     }
0222 
0223     template <typename T>
0224     void ProducingModuleAdaptorBase<T>::doStreamBeginLuminosityBlock(StreamID id,
0225                                                                      LumiTransitionInfo const& info,
0226                                                                      ModuleCallingContext const* mcc) {
0227       LuminosityBlockPrincipal const& lbp = info.principal();
0228       auto mod = m_streamModules[id];
0229       setupLuminosityBlock(mod, lbp.index());
0230 
0231       LuminosityBlock lb(lbp, moduleDescription_, mcc, false);
0232       lb.setConsumer(mod);
0233       ESParentContext parentC(mcc);
0234       const EventSetup c{info,
0235                          static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0236                          mod->esGetTokenIndices(Transition::BeginLuminosityBlock),
0237                          parentC};
0238       mod->beginLuminosityBlock(lb, c);
0239     }
0240 
0241     template <typename T>
0242     void ProducingModuleAdaptorBase<T>::doStreamEndLuminosityBlock(StreamID id,
0243                                                                    LumiTransitionInfo const& info,
0244                                                                    ModuleCallingContext const* mcc) {
0245       auto mod = m_streamModules[id];
0246       LuminosityBlock lb(info, moduleDescription_, mcc, true);
0247       lb.setConsumer(mod);
0248       ESParentContext parentC(mcc);
0249       const EventSetup c{info,
0250                          static_cast<unsigned int>(Transition::EndLuminosityBlock),
0251                          mod->esGetTokenIndices(Transition::EndLuminosityBlock),
0252                          parentC};
0253       mod->endLuminosityBlock(lb, c);
0254       streamEndLuminosityBlockSummary(mod, lb, c);
0255     }
0256 
0257     template <typename T>
0258     void ProducingModuleAdaptorBase<T>::doRegisterThinnedAssociations(ProductRegistry const& registry,
0259                                                                       ThinnedAssociationsHelper& helper) {
0260       assert(not m_streamModules.empty());
0261       auto mod = m_streamModules[0];
0262       mod->registerThinnedAssociations(registry, helper);
0263     }
0264   }  // namespace stream
0265 }  // namespace edm