Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-19 23:20:03

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   preallocRuns(iPrealloc.numberOfRuns());
0084   preallocLumis(iPrealloc.numberOfLuminosityBlocks());
0085 }
0086 
0087 void EDAnalyzerAdaptorBase::registerProductsAndCallbacks(EDAnalyzerAdaptorBase const*, ProductRegistry* reg) {
0088   for (auto mod : m_streamModules) {
0089     mod->registerProductsAndCallbacks(mod, reg);
0090   }
0091 }
0092 
0093 void EDAnalyzerAdaptorBase::itemsToGet(BranchType iType, std::vector<ProductResolverIndexAndSkipBit>& iIndices) const {
0094   assert(not m_streamModules.empty());
0095   m_streamModules[0]->itemsToGet(iType, iIndices);
0096 }
0097 void EDAnalyzerAdaptorBase::itemsMayGet(BranchType iType, std::vector<ProductResolverIndexAndSkipBit>& iIndices) const {
0098   assert(not m_streamModules.empty());
0099   m_streamModules[0]->itemsMayGet(iType, iIndices);
0100 }
0101 
0102 std::vector<edm::ProductResolverIndexAndSkipBit> const& EDAnalyzerAdaptorBase::itemsToGetFrom(BranchType iType) const {
0103   assert(not m_streamModules.empty());
0104   return m_streamModules[0]->itemsToGetFrom(iType);
0105 }
0106 
0107 std::vector<edm::ESResolverIndex> const& EDAnalyzerAdaptorBase::esGetTokenIndicesVector(edm::Transition iTrans) const {
0108   assert(not m_streamModules.empty());
0109   return m_streamModules[0]->esGetTokenIndicesVector(iTrans);
0110 }
0111 
0112 std::vector<edm::ESRecordIndex> const& EDAnalyzerAdaptorBase::esGetTokenRecordIndicesVector(
0113     edm::Transition iTrans) const {
0114   assert(not m_streamModules.empty());
0115   return m_streamModules[0]->esGetTokenRecordIndicesVector(iTrans);
0116 }
0117 
0118 void EDAnalyzerAdaptorBase::updateLookup(BranchType iType,
0119                                          ProductResolverIndexHelper const& iHelper,
0120                                          bool iPrefetchMayGet) {
0121   for (auto mod : m_streamModules) {
0122     mod->updateLookup(iType, iHelper, iPrefetchMayGet);
0123   }
0124 }
0125 
0126 void EDAnalyzerAdaptorBase::updateLookup(eventsetup::ESRecordsToProductResolverIndices const& iPI) {
0127   for (auto mod : m_streamModules) {
0128     mod->updateLookup(iPI);
0129   }
0130 }
0131 
0132 const edm::EDConsumerBase* EDAnalyzerAdaptorBase::consumer() const { return m_streamModules[0]; }
0133 
0134 void EDAnalyzerAdaptorBase::modulesWhoseProductsAreConsumed(
0135     std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modules,
0136     std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0137     ProductRegistry const& preg,
0138     std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0139     std::string const& processName) const {
0140   assert(not m_streamModules.empty());
0141   return m_streamModules[0]->modulesWhoseProductsAreConsumed(
0142       modules, modulesInPreviousProcesses, preg, labelsToDesc, processName);
0143 }
0144 
0145 void EDAnalyzerAdaptorBase::convertCurrentProcessAlias(std::string const& processName) {
0146   for (auto mod : m_streamModules) {
0147     mod->convertCurrentProcessAlias(processName);
0148   }
0149 }
0150 
0151 std::vector<edm::ConsumesInfo> EDAnalyzerAdaptorBase::consumesInfo() const {
0152   assert(not m_streamModules.empty());
0153   return m_streamModules[0]->consumesInfo();
0154 }
0155 
0156 bool EDAnalyzerAdaptorBase::doEvent(EventTransitionInfo const& info,
0157                                     ActivityRegistry* act,
0158                                     ModuleCallingContext const* mcc) {
0159   EventPrincipal const& ep = info.principal();
0160   assert(ep.streamID() < m_streamModules.size());
0161   auto mod = m_streamModules[ep.streamID()];
0162   EventSignalsSentry sentry(act, mcc);
0163   Event e(ep, moduleDescription_, mcc);
0164   e.setConsumer(mod);
0165   ESParentContext parentC(mcc);
0166   const EventSetup c{
0167       info, static_cast<unsigned int>(Transition::Event), mod->esGetTokenIndices(Transition::Event), parentC};
0168   mod->analyze(e, c);
0169   return true;
0170 }
0171 
0172 void EDAnalyzerAdaptorBase::doBeginStream(StreamID id) { m_streamModules[id]->beginStream(id); }
0173 void EDAnalyzerAdaptorBase::doEndStream(StreamID id) { m_streamModules[id]->endStream(); }
0174 
0175 void EDAnalyzerAdaptorBase::doStreamBeginRun(StreamID id,
0176                                              RunTransitionInfo const& info,
0177                                              ModuleCallingContext const* mcc) {
0178   RunPrincipal const& rp = info.principal();
0179   auto mod = m_streamModules[id];
0180   setupRun(mod, rp.index());
0181 
0182   Run r(rp, moduleDescription_, mcc, false);
0183   ESParentContext parentC(mcc);
0184   const EventSetup c{
0185       info, static_cast<unsigned int>(Transition::BeginRun), mod->esGetTokenIndices(Transition::BeginRun), parentC};
0186   r.setConsumer(mod);
0187   mod->beginRun(r, c);
0188 }
0189 
0190 void EDAnalyzerAdaptorBase::doStreamEndRun(StreamID id,
0191                                            RunTransitionInfo const& info,
0192                                            ModuleCallingContext const* mcc) {
0193   auto mod = m_streamModules[id];
0194   Run r(info, moduleDescription_, mcc, true);
0195   r.setConsumer(mod);
0196   ESParentContext parentC(mcc);
0197   const EventSetup c{
0198       info, static_cast<unsigned int>(Transition::EndRun), mod->esGetTokenIndices(Transition::EndRun), parentC};
0199   mod->endRun(r, c);
0200   streamEndRunSummary(mod, r, c);
0201 }
0202 
0203 void EDAnalyzerAdaptorBase::doStreamBeginLuminosityBlock(StreamID id,
0204                                                          LumiTransitionInfo const& info,
0205                                                          ModuleCallingContext const* mcc) {
0206   LuminosityBlockPrincipal const& lbp = info.principal();
0207   auto mod = m_streamModules[id];
0208   setupLuminosityBlock(mod, lbp.index());
0209 
0210   LuminosityBlock lb(lbp, moduleDescription_, mcc, false);
0211   lb.setConsumer(mod);
0212   ESParentContext parentC(mcc);
0213   const EventSetup c{info,
0214                      static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0215                      mod->esGetTokenIndices(Transition::BeginLuminosityBlock),
0216                      parentC};
0217   mod->beginLuminosityBlock(lb, c);
0218 }
0219 void EDAnalyzerAdaptorBase::doStreamEndLuminosityBlock(StreamID id,
0220                                                        LumiTransitionInfo const& info,
0221                                                        ModuleCallingContext const* mcc) {
0222   auto mod = m_streamModules[id];
0223   LuminosityBlock lb(info, moduleDescription_, mcc, true);
0224   lb.setConsumer(mod);
0225   ESParentContext parentC(mcc);
0226   const EventSetup c{info,
0227                      static_cast<unsigned int>(Transition::EndLuminosityBlock),
0228                      mod->esGetTokenIndices(Transition::EndLuminosityBlock),
0229                      parentC};
0230   mod->endLuminosityBlock(lb, c);
0231   streamEndLuminosityBlockSummary(mod, lb, c);
0232 }
0233 
0234 void EDAnalyzerAdaptorBase::setModuleDescriptionPtr(EDAnalyzerBase* m) {
0235   m->setModuleDescriptionPtr(&moduleDescription_);
0236 }