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::EDAnalyzerAdaptorBase
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/EDAnalyzerAdaptorBase.h"
0019 #include "FWCore/Framework/interface/stream/EDAnalyzerBase.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/LuminosityBlock.h"
0022 #include "FWCore/Framework/interface/Run.h"
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/Framework/interface/EventPrincipal.h"
0025 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
0026 #include "FWCore/Framework/interface/RunPrincipal.h"
0027 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0028 
0029 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0030 #include "FWCore/Framework/src/EventSignalsSentry.h"
0031 #include "FWCore/Framework/interface/TransitionInfoTypes.h"
0032 
0033 using namespace edm::stream;
0034 //
0035 // constants, enums and typedefs
0036 //
0037 
0038 //
0039 // static data member definitions
0040 //
0041 
0042 //
0043 // constructors and destructor
0044 //
0045 EDAnalyzerAdaptorBase::EDAnalyzerAdaptorBase() {}
0046 
0047 // EDAnalyzerAdaptorBase::EDAnalyzerAdaptorBase(const EDAnalyzerAdaptorBase& rhs)
0048 // {
0049 //    // do actual copying here;
0050 // }
0051 
0052 EDAnalyzerAdaptorBase::~EDAnalyzerAdaptorBase() {
0053   for (auto m : m_streamModules) {
0054     delete m;
0055   }
0056 }
0057 
0058 void EDAnalyzerAdaptorBase::deleteModulesEarly() {
0059   for (auto m : m_streamModules) {
0060     delete m;
0061   }
0062   m_streamModules.clear();
0063 }
0064 
0065 //
0066 // assignment operators
0067 //
0068 // const EDAnalyzerAdaptorBase& EDAnalyzerAdaptorBase::operator=(const EDAnalyzerAdaptorBase& rhs)
0069 // {
0070 //   //An exception safe implementation is
0071 //   EDAnalyzerAdaptorBase temp(rhs);
0072 //   swap(rhs);
0073 //
0074 //   return *this;
0075 // }
0076 
0077 //
0078 // member functions
0079 //
0080 void EDAnalyzerAdaptorBase::doPreallocate(PreallocationConfiguration const& iPrealloc) {
0081   m_streamModules.resize(iPrealloc.numberOfStreams(), static_cast<stream::EDAnalyzerBase*>(nullptr));
0082   setupStreamModules();
0083   preallocLumis(iPrealloc.numberOfLuminosityBlocks());
0084 }
0085 
0086 void EDAnalyzerAdaptorBase::registerProductsAndCallbacks(EDAnalyzerAdaptorBase const*, ProductRegistry* reg) {
0087   for (auto mod : m_streamModules) {
0088     mod->registerProductsAndCallbacks(mod, reg);
0089   }
0090 }
0091 
0092 void EDAnalyzerAdaptorBase::itemsToGet(BranchType iType, std::vector<ProductResolverIndexAndSkipBit>& iIndices) const {
0093   assert(not m_streamModules.empty());
0094   m_streamModules[0]->itemsToGet(iType, iIndices);
0095 }
0096 void EDAnalyzerAdaptorBase::itemsMayGet(BranchType iType, std::vector<ProductResolverIndexAndSkipBit>& iIndices) const {
0097   assert(not m_streamModules.empty());
0098   m_streamModules[0]->itemsMayGet(iType, iIndices);
0099 }
0100 
0101 std::vector<edm::ProductResolverIndexAndSkipBit> const& EDAnalyzerAdaptorBase::itemsToGetFrom(BranchType iType) const {
0102   assert(not m_streamModules.empty());
0103   return m_streamModules[0]->itemsToGetFrom(iType);
0104 }
0105 
0106 std::vector<edm::ESProxyIndex> const& EDAnalyzerAdaptorBase::esGetTokenIndicesVector(edm::Transition iTrans) const {
0107   assert(not m_streamModules.empty());
0108   return m_streamModules[0]->esGetTokenIndicesVector(iTrans);
0109 }
0110 
0111 std::vector<edm::ESRecordIndex> const& EDAnalyzerAdaptorBase::esGetTokenRecordIndicesVector(
0112     edm::Transition iTrans) const {
0113   assert(not m_streamModules.empty());
0114   return m_streamModules[0]->esGetTokenRecordIndicesVector(iTrans);
0115 }
0116 
0117 void EDAnalyzerAdaptorBase::updateLookup(BranchType iType,
0118                                          ProductResolverIndexHelper const& iHelper,
0119                                          bool iPrefetchMayGet) {
0120   for (auto mod : m_streamModules) {
0121     mod->updateLookup(iType, iHelper, iPrefetchMayGet);
0122   }
0123 }
0124 
0125 void EDAnalyzerAdaptorBase::updateLookup(eventsetup::ESRecordsToProxyIndices const& iPI) {
0126   for (auto mod : m_streamModules) {
0127     mod->updateLookup(iPI);
0128   }
0129 }
0130 
0131 const edm::EDConsumerBase* EDAnalyzerAdaptorBase::consumer() const { return m_streamModules[0]; }
0132 
0133 void EDAnalyzerAdaptorBase::modulesWhoseProductsAreConsumed(
0134     std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modules,
0135     std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0136     ProductRegistry const& preg,
0137     std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0138     std::string const& processName) const {
0139   assert(not m_streamModules.empty());
0140   return m_streamModules[0]->modulesWhoseProductsAreConsumed(
0141       modules, modulesInPreviousProcesses, preg, labelsToDesc, processName);
0142 }
0143 
0144 void EDAnalyzerAdaptorBase::convertCurrentProcessAlias(std::string const& processName) {
0145   for (auto mod : m_streamModules) {
0146     mod->convertCurrentProcessAlias(processName);
0147   }
0148 }
0149 
0150 std::vector<edm::ConsumesInfo> EDAnalyzerAdaptorBase::consumesInfo() const {
0151   assert(not m_streamModules.empty());
0152   return m_streamModules[0]->consumesInfo();
0153 }
0154 
0155 bool EDAnalyzerAdaptorBase::doEvent(EventTransitionInfo const& info,
0156                                     ActivityRegistry* act,
0157                                     ModuleCallingContext const* mcc) {
0158   EventPrincipal const& ep = info.principal();
0159   assert(ep.streamID() < m_streamModules.size());
0160   auto mod = m_streamModules[ep.streamID()];
0161   Event e(ep, moduleDescription_, mcc);
0162   e.setConsumer(mod);
0163   ESParentContext parentC(mcc);
0164   const EventSetup c{
0165       info, static_cast<unsigned int>(Transition::Event), mod->esGetTokenIndices(Transition::Event), parentC};
0166   EventSignalsSentry sentry(act, mcc);
0167   mod->analyze(e, c);
0168   return true;
0169 }
0170 
0171 void EDAnalyzerAdaptorBase::doBeginStream(StreamID id) { m_streamModules[id]->beginStream(id); }
0172 void EDAnalyzerAdaptorBase::doEndStream(StreamID id) { m_streamModules[id]->endStream(); }
0173 
0174 void EDAnalyzerAdaptorBase::doStreamBeginRun(StreamID id,
0175                                              RunTransitionInfo const& info,
0176                                              ModuleCallingContext const* mcc) {
0177   RunPrincipal const& rp = info.principal();
0178   auto mod = m_streamModules[id];
0179   setupRun(mod, rp.index());
0180 
0181   Run r(rp, moduleDescription_, mcc, false);
0182   ESParentContext parentC(mcc);
0183   const EventSetup c{
0184       info, static_cast<unsigned int>(Transition::BeginRun), mod->esGetTokenIndices(Transition::BeginRun), parentC};
0185   r.setConsumer(mod);
0186   mod->beginRun(r, c);
0187 }
0188 
0189 void EDAnalyzerAdaptorBase::doStreamEndRun(StreamID id,
0190                                            RunTransitionInfo const& info,
0191                                            ModuleCallingContext const* mcc) {
0192   auto mod = m_streamModules[id];
0193   Run r(info, moduleDescription_, mcc, true);
0194   r.setConsumer(mod);
0195   ESParentContext parentC(mcc);
0196   const EventSetup c{
0197       info, static_cast<unsigned int>(Transition::EndRun), mod->esGetTokenIndices(Transition::EndRun), parentC};
0198   mod->endRun(r, c);
0199   streamEndRunSummary(mod, r, c);
0200 }
0201 
0202 void EDAnalyzerAdaptorBase::doStreamBeginLuminosityBlock(StreamID id,
0203                                                          LumiTransitionInfo const& info,
0204                                                          ModuleCallingContext const* mcc) {
0205   LuminosityBlockPrincipal const& lbp = info.principal();
0206   auto mod = m_streamModules[id];
0207   setupLuminosityBlock(mod, lbp.index());
0208 
0209   LuminosityBlock lb(lbp, moduleDescription_, mcc, false);
0210   lb.setConsumer(mod);
0211   ESParentContext parentC(mcc);
0212   const EventSetup c{info,
0213                      static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0214                      mod->esGetTokenIndices(Transition::BeginLuminosityBlock),
0215                      parentC};
0216   mod->beginLuminosityBlock(lb, c);
0217 }
0218 void EDAnalyzerAdaptorBase::doStreamEndLuminosityBlock(StreamID id,
0219                                                        LumiTransitionInfo const& info,
0220                                                        ModuleCallingContext const* mcc) {
0221   auto mod = m_streamModules[id];
0222   LuminosityBlock lb(info, moduleDescription_, mcc, true);
0223   lb.setConsumer(mod);
0224   ESParentContext parentC(mcc);
0225   const EventSetup c{info,
0226                      static_cast<unsigned int>(Transition::EndLuminosityBlock),
0227                      mod->esGetTokenIndices(Transition::EndLuminosityBlock),
0228                      parentC};
0229   mod->endLuminosityBlock(lb, c);
0230   streamEndLuminosityBlockSummary(mod, lb, c);
0231 }
0232 
0233 void EDAnalyzerAdaptorBase::setModuleDescriptionPtr(EDAnalyzerBase* m) {
0234   m->setModuleDescriptionPtr(&moduleDescription_);
0235 }