Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-05 03:11:55

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Framework
0004 // Class  :     limited::EDFilterBase
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/EDFilterBase.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     EDFilterBase::EDFilterBase(ParameterSet const& pset)
0047         : ProducerBase(),
0048           moduleDescription_(),
0049           previousParentages_(),
0050           previousParentageIds_(),
0051           queue_(pset.getUntrackedParameter<unsigned int>("concurrencyLimit")) {}
0052 
0053     EDFilterBase::~EDFilterBase() {}
0054 
0055     bool EDFilterBase::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       ESParentContext parentC(mcc);
0063       const EventSetup c{
0064           info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC};
0065       EventSignalsSentry sentry(act, mcc);
0066       bool returnValue = this->filter(e.streamID(), e, c);
0067       commit_(e, &previousParentageIds_[streamIndex]);
0068       return returnValue;
0069     }
0070 
0071     void EDFilterBase::doTransformAsync(WaitingTaskHolder iTask,
0072                                         size_t iTransformIndex,
0073                                         EventPrincipal const& iEvent,
0074                                         ActivityRegistry* iAct,
0075                                         ModuleCallingContext iMCC,
0076                                         ServiceWeakToken const& iToken) {
0077       EventForTransformer ev(iEvent, iMCC);
0078       transformAsync_(iTask, iTransformIndex, ev, iAct, iToken);
0079     }
0080 
0081     size_t EDFilterBase::transformIndex_(edm::BranchDescription const& iBranch) const { return -1; }
0082     ProductResolverIndex EDFilterBase::transformPrefetch_(std::size_t iIndex) const { return 0; }
0083     void EDFilterBase::transformAsync_(WaitingTaskHolder iTask,
0084                                        std::size_t iIndex,
0085                                        edm::EventForTransformer& iEvent,
0086                                        edm::ActivityRegistry* iAct,
0087                                        ServiceWeakToken const& iToken) const {}
0088 
0089     void EDFilterBase::doPreallocate(PreallocationConfiguration const& iPrealloc) {
0090       const auto 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 EDFilterBase::doBeginJob() { this->beginJob(); }
0102 
0103     void EDFilterBase::doEndJob() { this->endJob(); }
0104 
0105     void EDFilterBase::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 EDFilterBase::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 EDFilterBase::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 EDFilterBase::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 EDFilterBase::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 EDFilterBase::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 EDFilterBase::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 EDFilterBase::doBeginStream(StreamID id) { doBeginStream_(id); }
0193     void EDFilterBase::doEndStream(StreamID id) { doEndStream_(id); }
0194     void EDFilterBase::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 EDFilterBase::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 EDFilterBase::doStreamBeginLuminosityBlock(StreamID id,
0212                                                     LumiTransitionInfo const& info,
0213                                                     ModuleCallingContext const* mcc) {
0214       LuminosityBlock lb(info, moduleDescription_, mcc, false);
0215       ESParentContext parentC(mcc);
0216       const EventSetup c{info,
0217                          static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0218                          esGetTokenIndices(Transition::BeginLuminosityBlock),
0219                          parentC};
0220       lb.setConsumer(this);
0221       this->doStreamBeginLuminosityBlock_(id, lb, c);
0222     }
0223 
0224     void EDFilterBase::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 EDFilterBase::preallocStreams(unsigned int) {}
0239     void EDFilterBase::preallocRuns(unsigned int) {}
0240     void EDFilterBase::preallocRunsSummary(unsigned int) {}
0241     void EDFilterBase::preallocLumis(unsigned int) {}
0242     void EDFilterBase::preallocLumisSummary(unsigned int) {}
0243     void EDFilterBase::preallocate(PreallocationConfiguration const&) {}
0244     void EDFilterBase::doBeginStream_(StreamID id) {}
0245     void EDFilterBase::doEndStream_(StreamID id) {}
0246     void EDFilterBase::doStreamBeginRun_(StreamID id, Run const& rp, EventSetup const& c) {}
0247     void EDFilterBase::doStreamEndRun_(StreamID id, Run const& rp, EventSetup const& c) {}
0248     void EDFilterBase::doStreamEndRunSummary_(StreamID id, Run const& rp, EventSetup const& c) {}
0249     void EDFilterBase::doStreamBeginLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) {}
0250     void EDFilterBase::doStreamEndLuminosityBlock_(StreamID id, LuminosityBlock const& lbp, EventSetup const& c) {}
0251     void EDFilterBase::doStreamEndLuminosityBlockSummary_(StreamID id,
0252                                                           LuminosityBlock const& lbp,
0253                                                           EventSetup const& c) {}
0254 
0255     void EDFilterBase::doBeginProcessBlock_(ProcessBlock const&) {}
0256     void EDFilterBase::doAccessInputProcessBlock_(ProcessBlock const&) {}
0257     void EDFilterBase::doEndProcessBlock_(ProcessBlock const&) {}
0258     void EDFilterBase::doBeginRun_(Run const& rp, EventSetup const& c) {}
0259     void EDFilterBase::doEndRun_(Run const& rp, EventSetup const& c) {}
0260     void EDFilterBase::doBeginRunSummary_(Run const& rp, EventSetup const& c) {}
0261     void EDFilterBase::doEndRunSummary_(Run const& rp, EventSetup const& c) {}
0262 
0263     void EDFilterBase::doBeginLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c) {}
0264     void EDFilterBase::doEndLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c) {}
0265     void EDFilterBase::doBeginLuminosityBlockSummary_(LuminosityBlock const& rp, EventSetup const& c) {}
0266     void EDFilterBase::doEndLuminosityBlockSummary_(LuminosityBlock const& lb, EventSetup const& c) {}
0267 
0268     void EDFilterBase::doBeginProcessBlockProduce_(ProcessBlock&) {}
0269     void EDFilterBase::doEndProcessBlockProduce_(ProcessBlock&) {}
0270     void EDFilterBase::doBeginRunProduce_(Run& rp, EventSetup const& c) {}
0271     void EDFilterBase::doEndRunProduce_(Run& rp, EventSetup const& c) {}
0272     void EDFilterBase::doBeginLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) {}
0273     void EDFilterBase::doEndLuminosityBlockProduce_(LuminosityBlock& lbp, EventSetup const& c) {}
0274 
0275     void EDFilterBase::clearInputProcessBlockCaches() {}
0276 
0277     void EDFilterBase::fillDescriptions(ConfigurationDescriptions& descriptions) {
0278       ParameterSetDescription desc;
0279       desc.setUnknown();
0280       descriptions.addDefault(desc);
0281     }
0282 
0283     void EDFilterBase::prevalidate(ConfigurationDescriptions& iConfig) { edmodule_mightGet_config(iConfig); }
0284 
0285     static const std::string kBaseType("EDFilter");
0286 
0287     const std::string& EDFilterBase::baseType() { return kBaseType; }
0288 
0289   }  // namespace limited
0290 }  // namespace edm