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  :     global::EDProducerBase
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Thu, 02 May 2013 21:56:04 GMT
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include <memory>
0017 
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 #include "FWCore/Framework/interface/LuminosityBlock.h"
0021 #include "FWCore/Framework/interface/ProcessBlock.h"
0022 #include "FWCore/Framework/interface/Run.h"
0023 #include "FWCore/Framework/interface/global/EDProducerBase.h"
0024 #include "FWCore/Framework/src/EventAcquireSignalsSentry.h"
0025 #include "FWCore/Framework/src/EventSignalsSentry.h"
0026 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0027 #include "FWCore/Framework/src/edmodule_mightGet_config.h"
0028 #include "FWCore/Framework/interface/TransitionInfoTypes.h"
0029 #include "FWCore/Framework/interface/EventForTransformer.h"
0030 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0031 
0032 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0034 
0035 //
0036 // constants, enums and typedefs
0037 //
0038 namespace edm {
0039 
0040   class WaitingTaskWithArenaHolder;
0041 
0042   namespace global {
0043     //
0044     // static data member definitions
0045     //
0046 
0047     //
0048     // constructors and destructor
0049     //
0050     EDProducerBase::EDProducerBase()
0051         : ProducerBase(),
0052           moduleDescription_(),
0053           previousParentages_(),
0054           gotBranchIDsFromAcquire_(),
0055           previousParentageIds_() {}
0056 
0057     EDProducerBase::~EDProducerBase() {}
0058 
0059     bool EDProducerBase::doEvent(EventTransitionInfo const& info,
0060                                  ActivityRegistry* act,
0061                                  ModuleCallingContext const* mcc) {
0062       EventSignalsSentry sentry(act, mcc);
0063       Event e(info, moduleDescription_, mcc);
0064       e.setConsumer(this);
0065       const auto streamIndex = e.streamID().value();
0066       e.setProducer(
0067           this, &previousParentages_[streamIndex], hasAcquire() ? &gotBranchIDsFromAcquire_[streamIndex] : nullptr);
0068       ESParentContext parentC(mcc);
0069       this->produce(
0070           e.streamID(),
0071           e,
0072           EventSetup{
0073               info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC});
0074       commit_(e, &previousParentageIds_[streamIndex]);
0075       return true;
0076     }
0077 
0078     void EDProducerBase::doAcquire(EventTransitionInfo const& info,
0079                                    ActivityRegistry* act,
0080                                    ModuleCallingContext const* mcc,
0081                                    WaitingTaskWithArenaHolder& holder) {
0082       EventAcquireSignalsSentry sentry(act, mcc);
0083       Event e(info, moduleDescription_, mcc);
0084       e.setConsumer(this);
0085       const auto streamIndex = e.streamID().value();
0086       e.setProducerForAcquire(this, nullptr, gotBranchIDsFromAcquire_[streamIndex]);
0087       ESParentContext parentC(mcc);
0088       const EventSetup c{
0089           info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC};
0090       this->doAcquire_(e.streamID(), e, c, holder);
0091     }
0092 
0093     void EDProducerBase::doTransformAsync(WaitingTaskHolder iTask,
0094                                           size_t iTransformIndex,
0095                                           EventPrincipal const& iEvent,
0096                                           ActivityRegistry* iAct,
0097                                           ModuleCallingContext iMCC,
0098                                           ServiceWeakToken const& iToken) noexcept {
0099       EventForTransformer ev(iEvent, iMCC);
0100       transformAsync_(iTask, iTransformIndex, ev, iAct, iToken);
0101     }
0102 
0103     size_t EDProducerBase::transformIndex_(edm::BranchDescription const& iBranch) const noexcept { return -1; }
0104     ProductResolverIndex EDProducerBase::transformPrefetch_(std::size_t iIndex) const noexcept { return 0; }
0105     void EDProducerBase::transformAsync_(WaitingTaskHolder iTask,
0106                                          std::size_t iIndex,
0107                                          edm::EventForTransformer& iEvent,
0108                                          edm::ActivityRegistry* iAct,
0109                                          ServiceWeakToken const& iToken) const noexcept {}
0110 
0111     void EDProducerBase::doPreallocate(PreallocationConfiguration const& iPrealloc) {
0112       auto const nStreams = iPrealloc.numberOfStreams();
0113       previousParentages_ = std::make_unique<std::vector<BranchID>[]>(nStreams);
0114       if (hasAcquire()) {
0115         gotBranchIDsFromAcquire_ = std::make_unique<std::vector<BranchID>[]>(nStreams);
0116       }
0117       previousParentageIds_ = std::make_unique<ParentageID[]>(nStreams);
0118       preallocStreams(nStreams);
0119       preallocRuns(iPrealloc.numberOfRuns());
0120       preallocRunsSummary(iPrealloc.numberOfRuns());
0121       preallocLumis(iPrealloc.numberOfLuminosityBlocks());
0122       preallocLumisSummary(iPrealloc.numberOfLuminosityBlocks());
0123       preallocate(iPrealloc);
0124     }
0125 
0126     void EDProducerBase::doBeginJob() { this->beginJob(); }
0127 
0128     void EDProducerBase::doEndJob() { this->endJob(); }
0129 
0130     void EDProducerBase::doBeginProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0131       ProcessBlock processBlock(pbp, moduleDescription_, mcc, false);
0132       processBlock.setConsumer(this);
0133       ProcessBlock const& constProcessBlock = processBlock;
0134       this->doBeginProcessBlock_(constProcessBlock);
0135       processBlock.setProducer(this);
0136       this->doBeginProcessBlockProduce_(processBlock);
0137       commit_(processBlock);
0138     }
0139 
0140     void EDProducerBase::doAccessInputProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0141       ProcessBlock processBlock(pbp, moduleDescription_, mcc, false);
0142       processBlock.setConsumer(this);
0143       ProcessBlock const& constProcessBlock = processBlock;
0144       this->doAccessInputProcessBlock_(constProcessBlock);
0145     }
0146 
0147     void EDProducerBase::doEndProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0148       ProcessBlock processBlock(pbp, moduleDescription_, mcc, true);
0149       processBlock.setConsumer(this);
0150       ProcessBlock const& constProcessBlock = processBlock;
0151       this->doEndProcessBlock_(constProcessBlock);
0152       processBlock.setProducer(this);
0153       this->doEndProcessBlockProduce_(processBlock);
0154       commit_(processBlock);
0155     }
0156 
0157     void EDProducerBase::doBeginRun(RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0158       Run r(info, moduleDescription_, mcc, false);
0159       r.setConsumer(this);
0160       Run const& cnstR = r;
0161       ESParentContext parentC(mcc);
0162       const EventSetup c{
0163           info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC};
0164       this->doBeginRun_(cnstR, c);
0165       this->doBeginRunSummary_(cnstR, c);
0166       r.setProducer(this);
0167       this->doBeginRunProduce_(r, c);
0168       commit_(r);
0169     }
0170 
0171     void EDProducerBase::doEndRun(RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0172       Run r(info, moduleDescription_, mcc, true);
0173       r.setConsumer(this);
0174       r.setProducer(this);
0175       Run const& cnstR = r;
0176       ESParentContext parentC(mcc);
0177       const EventSetup c{
0178           info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
0179       this->doEndRunSummary_(r, c);
0180       this->doEndRunProduce_(r, c);
0181       this->doEndRun_(cnstR, c);
0182       commit_(r);
0183     }
0184 
0185     void EDProducerBase::doBeginLuminosityBlock(LumiTransitionInfo const& info, ModuleCallingContext const* mcc) {
0186       LuminosityBlock lb(info, moduleDescription_, mcc, false);
0187       lb.setConsumer(this);
0188       LuminosityBlock const& cnstLb = lb;
0189       ESParentContext parentC(mcc);
0190       const EventSetup c{info,
0191                          static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0192                          esGetTokenIndices(Transition::BeginLuminosityBlock),
0193                          parentC};
0194       this->doBeginLuminosityBlock_(cnstLb, c);
0195       this->doBeginLuminosityBlockSummary_(cnstLb, c);
0196       lb.setProducer(this);
0197       this->doBeginLuminosityBlockProduce_(lb, c);
0198       commit_(lb);
0199     }
0200 
0201     void EDProducerBase::doEndLuminosityBlock(LumiTransitionInfo const& info, ModuleCallingContext const* mcc) {
0202       LuminosityBlock lb(info, moduleDescription_, mcc, true);
0203       lb.setConsumer(this);
0204       lb.setProducer(this);
0205       LuminosityBlock const& cnstLb = lb;
0206       ESParentContext parentC(mcc);
0207       const EventSetup c{info,
0208                          static_cast<unsigned int>(Transition::EndLuminosityBlock),
0209                          esGetTokenIndices(Transition::EndLuminosityBlock),
0210                          parentC};
0211       this->doEndLuminosityBlockSummary_(cnstLb, c);
0212       this->doEndLuminosityBlockProduce_(lb, c);
0213       this->doEndLuminosityBlock_(cnstLb, c);
0214       commit_(lb);
0215     }
0216 
0217     void EDProducerBase::doBeginStream(StreamID id) { doBeginStream_(id); }
0218     void EDProducerBase::doEndStream(StreamID id) { doEndStream_(id); }
0219     void EDProducerBase::doStreamBeginRun(StreamID id, RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0220       Run r(info, moduleDescription_, mcc, false);
0221       r.setConsumer(this);
0222       ESParentContext parentC(mcc);
0223       this->doStreamBeginRun_(
0224           id,
0225           r,
0226           EventSetup{
0227               info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC});
0228     }
0229     void EDProducerBase::doStreamEndRun(StreamID id, RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0230       Run r(info, moduleDescription_, mcc, true);
0231       r.setConsumer(this);
0232       ESParentContext parentC(mcc);
0233       const EventSetup c{
0234           info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
0235       this->doStreamEndRun_(id, r, c);
0236       this->doStreamEndRunSummary_(id, r, c);
0237     }
0238     void EDProducerBase::doStreamBeginLuminosityBlock(StreamID id,
0239                                                       LumiTransitionInfo const& info,
0240                                                       ModuleCallingContext const* mcc) {
0241       LuminosityBlock lb(info, moduleDescription_, mcc, false);
0242       lb.setConsumer(this);
0243       ESParentContext parentC(mcc);
0244 
0245       this->doStreamBeginLuminosityBlock_(id,
0246                                           lb,
0247                                           EventSetup{info,
0248                                                      static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0249                                                      esGetTokenIndices(Transition::BeginLuminosityBlock),
0250                                                      parentC});
0251     }
0252 
0253     void EDProducerBase::doStreamEndLuminosityBlock(StreamID id,
0254                                                     LumiTransitionInfo const& info,
0255                                                     ModuleCallingContext const* mcc) {
0256       LuminosityBlock lb(info, moduleDescription_, mcc, true);
0257       lb.setConsumer(this);
0258       ESParentContext parentC(mcc);
0259       const EventSetup c{info,
0260                          static_cast<unsigned int>(Transition::EndLuminosityBlock),
0261                          esGetTokenIndices(Transition::EndLuminosityBlock),
0262                          parentC};
0263       this->doStreamEndLuminosityBlock_(id, lb, c);
0264       this->doStreamEndLuminosityBlockSummary_(id, lb, c);
0265     }
0266 
0267     void EDProducerBase::preallocStreams(unsigned int) {}
0268     void EDProducerBase::preallocRuns(unsigned int) {}
0269     void EDProducerBase::preallocRunsSummary(unsigned int) {}
0270     void EDProducerBase::preallocLumis(unsigned int) {}
0271     void EDProducerBase::preallocLumisSummary(unsigned int) {}
0272     void EDProducerBase::preallocate(PreallocationConfiguration const&) {}
0273     void EDProducerBase::doBeginStream_(StreamID id) {}
0274     void EDProducerBase::doEndStream_(StreamID id) {}
0275     void EDProducerBase::doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c) {}
0276     void EDProducerBase::doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c) {}
0277     void EDProducerBase::doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c) {}
0278     void EDProducerBase::doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) {}
0279     void EDProducerBase::doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) {}
0280     void EDProducerBase::doStreamEndLuminosityBlockSummary_(StreamID id,
0281                                                             LuminosityBlock const& lbp,
0282                                                             EventSetup const& c) {}
0283 
0284     void EDProducerBase::doBeginProcessBlock_(ProcessBlock const&) {}
0285     void EDProducerBase::doAccessInputProcessBlock_(ProcessBlock const&) {}
0286     void EDProducerBase::doEndProcessBlock_(ProcessBlock const&) {}
0287     void EDProducerBase::doBeginRun_(Run const& rp, EventSetup const& c) {}
0288     void EDProducerBase::doEndRun_(Run const& rp, EventSetup const& c) {}
0289     void EDProducerBase::doBeginRunSummary_(Run const& rp, EventSetup const& c) {}
0290     void EDProducerBase::doEndRunSummary_(Run const& rp, EventSetup const& c) {}
0291 
0292     void EDProducerBase::doBeginLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c) {}
0293     void EDProducerBase::doEndLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c) {}
0294     void EDProducerBase::doBeginLuminosityBlockSummary_(LuminosityBlock const& rp, EventSetup const& c) {}
0295     void EDProducerBase::doEndLuminosityBlockSummary_(LuminosityBlock const& lb, EventSetup const& c) {}
0296 
0297     void EDProducerBase::doBeginProcessBlockProduce_(ProcessBlock&) {}
0298     void EDProducerBase::doEndProcessBlockProduce_(ProcessBlock&) {}
0299     void EDProducerBase::doBeginRunProduce_(Run& rp, EventSetup const& c) {}
0300     void EDProducerBase::doEndRunProduce_(Run& rp, EventSetup const& c) {}
0301     void EDProducerBase::doBeginLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) {}
0302     void EDProducerBase::doEndLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) {}
0303 
0304     void EDProducerBase::clearInputProcessBlockCaches() {}
0305 
0306     void EDProducerBase::doAcquire_(StreamID, Event const&, EventSetup const&, WaitingTaskWithArenaHolder&) {}
0307 
0308     void EDProducerBase::fillDescriptions(ConfigurationDescriptions& descriptions) {
0309       ParameterSetDescription desc;
0310       desc.setUnknown();
0311       descriptions.addDefault(desc);
0312     }
0313 
0314     void EDProducerBase::prevalidate(ConfigurationDescriptions& iConfig) { edmodule_mightGet_config(iConfig); }
0315 
0316     static const std::string kBaseType("EDProducer");
0317 
0318     const std::string& EDProducerBase::baseType() { return kBaseType; }
0319 
0320   }  // namespace global
0321 }  // namespace edm