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