Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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