Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-11 22:29:31

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       Event e(info, moduleDescription_, mcc);
0059       e.setConsumer(this);
0060       const auto streamIndex = e.streamID().value();
0061       e.setProducer(this, &previousParentages_[streamIndex]);
0062       EventSignalsSentry sentry(act, mcc);
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::doTransform(size_t iTransformIndex,
0072                                      EventPrincipal const& iEvent,
0073                                      ActivityRegistry*,
0074                                      ModuleCallingContext const* iMCC) {
0075       EventForTransformer ev(iEvent, iMCC);
0076       transform_(iTransformIndex, ev);
0077     }
0078 
0079     size_t EDProducerBase::transformIndex_(edm::BranchDescription const& iBranch) const { return -1; }
0080     ProductResolverIndex EDProducerBase::transformPrefetch_(std::size_t iIndex) const { return 0; }
0081     void EDProducerBase::transform_(std::size_t iIndex, edm::EventForTransformer& iEvent) const {}
0082 
0083     void EDProducerBase::doPreallocate(PreallocationConfiguration const& iPrealloc) {
0084       auto const nStreams = iPrealloc.numberOfStreams();
0085       previousParentages_ = std::make_unique<std::vector<BranchID>[]>(nStreams);
0086       previousParentageIds_ = std::make_unique<ParentageID[]>(nStreams);
0087       preallocStreams(nStreams);
0088       preallocLumis(iPrealloc.numberOfLuminosityBlocks());
0089       preallocLumisSummary(iPrealloc.numberOfLuminosityBlocks());
0090       preallocate(iPrealloc);
0091     }
0092 
0093     void EDProducerBase::doBeginJob() { this->beginJob(); }
0094 
0095     void EDProducerBase::doEndJob() { this->endJob(); }
0096 
0097     void EDProducerBase::doBeginProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0098       ProcessBlock processBlock(pbp, moduleDescription_, mcc, false);
0099       processBlock.setConsumer(this);
0100       ProcessBlock const& constProcessBlock = processBlock;
0101       this->doBeginProcessBlock_(constProcessBlock);
0102       processBlock.setProducer(this);
0103       this->doBeginProcessBlockProduce_(processBlock);
0104       commit_(processBlock);
0105     }
0106 
0107     void EDProducerBase::doAccessInputProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0108       ProcessBlock processBlock(pbp, moduleDescription_, mcc, false);
0109       processBlock.setConsumer(this);
0110       ProcessBlock const& constProcessBlock = processBlock;
0111       this->doAccessInputProcessBlock_(constProcessBlock);
0112     }
0113 
0114     void EDProducerBase::doEndProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0115       ProcessBlock processBlock(pbp, moduleDescription_, mcc, true);
0116       processBlock.setConsumer(this);
0117       ProcessBlock const& constProcessBlock = processBlock;
0118       this->doEndProcessBlock_(constProcessBlock);
0119       processBlock.setProducer(this);
0120       this->doEndProcessBlockProduce_(processBlock);
0121       commit_(processBlock);
0122     }
0123 
0124     void EDProducerBase::doBeginRun(RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0125       Run r(info, moduleDescription_, mcc, false);
0126       r.setConsumer(this);
0127       Run const& cnstR = r;
0128       ESParentContext parentC(mcc);
0129       const EventSetup c{
0130           info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC};
0131       this->doBeginRun_(cnstR, c);
0132       this->doBeginRunSummary_(cnstR, c);
0133       r.setProducer(this);
0134       this->doBeginRunProduce_(r, c);
0135       commit_(r);
0136     }
0137 
0138     void EDProducerBase::doEndRun(RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0139       Run r(info, moduleDescription_, mcc, true);
0140       r.setConsumer(this);
0141       r.setProducer(this);
0142       Run const& cnstR = r;
0143       ESParentContext parentC(mcc);
0144       const EventSetup c{
0145           info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
0146       this->doEndRunSummary_(r, c);
0147       this->doEndRunProduce_(r, c);
0148       this->doEndRun_(cnstR, c);
0149       commit_(r);
0150     }
0151 
0152     void EDProducerBase::doBeginLuminosityBlock(LumiTransitionInfo const& info, ModuleCallingContext const* mcc) {
0153       LuminosityBlock lb(info, moduleDescription_, mcc, false);
0154       lb.setConsumer(this);
0155       LuminosityBlock const& cnstLb = lb;
0156       ESParentContext parentC(mcc);
0157       const EventSetup c{info,
0158                          static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0159                          esGetTokenIndices(Transition::BeginLuminosityBlock),
0160                          parentC};
0161       this->doBeginLuminosityBlock_(cnstLb, c);
0162       this->doBeginLuminosityBlockSummary_(cnstLb, c);
0163       lb.setProducer(this);
0164       this->doBeginLuminosityBlockProduce_(lb, c);
0165       commit_(lb);
0166     }
0167 
0168     void EDProducerBase::doEndLuminosityBlock(LumiTransitionInfo const& info, ModuleCallingContext const* mcc) {
0169       LuminosityBlock lb(info, moduleDescription_, mcc, true);
0170       lb.setConsumer(this);
0171       lb.setProducer(this);
0172       LuminosityBlock const& cnstLb = lb;
0173       ESParentContext parentC(mcc);
0174       const EventSetup c{info,
0175                          static_cast<unsigned int>(Transition::EndLuminosityBlock),
0176                          esGetTokenIndices(Transition::EndLuminosityBlock),
0177                          parentC};
0178       this->doEndLuminosityBlockSummary_(cnstLb, c);
0179       this->doEndLuminosityBlockProduce_(lb, c);
0180       this->doEndLuminosityBlock_(cnstLb, c);
0181       commit_(lb);
0182     }
0183 
0184     void EDProducerBase::doBeginStream(StreamID id) { doBeginStream_(id); }
0185     void EDProducerBase::doEndStream(StreamID id) { doEndStream_(id); }
0186     void EDProducerBase::doStreamBeginRun(StreamID id, RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0187       Run r(info, moduleDescription_, mcc, false);
0188       r.setConsumer(this);
0189       ESParentContext parentC(mcc);
0190       const EventSetup c{
0191           info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC};
0192       this->doStreamBeginRun_(id, r, c);
0193     }
0194     void EDProducerBase::doStreamEndRun(StreamID id, RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0195       Run r(info, moduleDescription_, mcc, true);
0196       r.setConsumer(this);
0197       ESParentContext parentC(mcc);
0198       const EventSetup c{
0199           info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
0200       this->doStreamEndRun_(id, r, c);
0201       this->doStreamEndRunSummary_(id, r, c);
0202     }
0203     void EDProducerBase::doStreamBeginLuminosityBlock(StreamID id,
0204                                                       LumiTransitionInfo const& info,
0205                                                       ModuleCallingContext const* mcc) {
0206       LuminosityBlock lb(info, moduleDescription_, mcc, false);
0207       lb.setConsumer(this);
0208       ESParentContext parentC(mcc);
0209       const EventSetup c{info,
0210                          static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0211                          esGetTokenIndices(Transition::BeginLuminosityBlock),
0212                          parentC};
0213       this->doStreamBeginLuminosityBlock_(id, lb, c);
0214     }
0215 
0216     void EDProducerBase::doStreamEndLuminosityBlock(StreamID id,
0217                                                     LumiTransitionInfo const& info,
0218                                                     ModuleCallingContext const* mcc) {
0219       LuminosityBlock lb(info, moduleDescription_, mcc, true);
0220       lb.setConsumer(this);
0221       ESParentContext parentC(mcc);
0222       const EventSetup c{info,
0223                          static_cast<unsigned int>(Transition::EndLuminosityBlock),
0224                          esGetTokenIndices(Transition::EndLuminosityBlock),
0225                          parentC};
0226       this->doStreamEndLuminosityBlock_(id, lb, c);
0227       this->doStreamEndLuminosityBlockSummary_(id, lb, c);
0228     }
0229 
0230     void EDProducerBase::preallocStreams(unsigned int) {}
0231     void EDProducerBase::preallocLumis(unsigned int) {}
0232     void EDProducerBase::preallocLumisSummary(unsigned int) {}
0233     void EDProducerBase::preallocate(PreallocationConfiguration const&) {}
0234     void EDProducerBase::doBeginStream_(StreamID id) {}
0235     void EDProducerBase::doEndStream_(StreamID id) {}
0236     void EDProducerBase::doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c) {}
0237     void EDProducerBase::doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c) {}
0238     void EDProducerBase::doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c) {}
0239     void EDProducerBase::doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) {}
0240     void EDProducerBase::doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) {}
0241     void EDProducerBase::doStreamEndLuminosityBlockSummary_(StreamID id,
0242                                                             LuminosityBlock const& lbp,
0243                                                             EventSetup const& c) {}
0244 
0245     void EDProducerBase::doBeginProcessBlock_(ProcessBlock const&) {}
0246     void EDProducerBase::doAccessInputProcessBlock_(ProcessBlock const&) {}
0247     void EDProducerBase::doEndProcessBlock_(ProcessBlock const&) {}
0248     void EDProducerBase::doBeginRun_(Run const& rp, EventSetup const& c) {}
0249     void EDProducerBase::doEndRun_(Run const& rp, EventSetup const& c) {}
0250     void EDProducerBase::doBeginRunSummary_(Run const& rp, EventSetup const& c) {}
0251     void EDProducerBase::doEndRunSummary_(Run const& rp, EventSetup const& c) {}
0252 
0253     void EDProducerBase::doBeginLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c) {}
0254     void EDProducerBase::doEndLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c) {}
0255     void EDProducerBase::doBeginLuminosityBlockSummary_(LuminosityBlock const& rp, EventSetup const& c) {}
0256     void EDProducerBase::doEndLuminosityBlockSummary_(LuminosityBlock const& lb, EventSetup const& c) {}
0257 
0258     void EDProducerBase::doBeginProcessBlockProduce_(ProcessBlock&) {}
0259     void EDProducerBase::doEndProcessBlockProduce_(ProcessBlock&) {}
0260     void EDProducerBase::doBeginRunProduce_(Run& rp, EventSetup const& c) {}
0261     void EDProducerBase::doEndRunProduce_(Run& rp, EventSetup const& c) {}
0262     void EDProducerBase::doBeginLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) {}
0263     void EDProducerBase::doEndLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) {}
0264 
0265     void EDProducerBase::clearInputProcessBlockCaches() {}
0266 
0267     void EDProducerBase::fillDescriptions(ConfigurationDescriptions& descriptions) {
0268       ParameterSetDescription desc;
0269       desc.setUnknown();
0270       descriptions.addDefault(desc);
0271     }
0272 
0273     void EDProducerBase::prevalidate(ConfigurationDescriptions& iConfig) { edmodule_mightGet_config(iConfig); }
0274 
0275     static const std::string kBaseType("EDProducer");
0276 
0277     const std::string& EDProducerBase::baseType() { return kBaseType; }
0278 
0279   }  // namespace limited
0280 }  // namespace edm