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