Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-18 04:13:18

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