Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-13 02:31:50

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Framework
0004 // Class  :     one::EDAnalyzerBase
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 "FWCore/Framework/interface/one/EDAnalyzerBase.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/LuminosityBlock.h"
0019 #include "FWCore/Framework/interface/ProcessBlock.h"
0020 #include "FWCore/Framework/interface/Run.h"
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/Framework/src/edmodule_mightGet_config.h"
0023 #include "FWCore/Framework/src/EventSignalsSentry.h"
0024 #include "FWCore/Framework/interface/PreallocationConfiguration.h"
0025 #include "FWCore/Framework/interface/TransitionInfoTypes.h"
0026 #include "FWCore/Framework/interface/SignallingProductRegistryFiller.h"
0027 
0028 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0030 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0031 //
0032 // constants, enums and typedefs
0033 //
0034 namespace edm {
0035   namespace one {
0036     //
0037     // static data member definitions
0038     //
0039 
0040     //
0041     // constructors and destructor
0042     //
0043     EDAnalyzerBase::EDAnalyzerBase() : moduleDescription_() {}
0044 
0045     EDAnalyzerBase::~EDAnalyzerBase() {}
0046 
0047     void EDAnalyzerBase::callWhenNewProductsRegistered(std::function<void(ProductDescription const&)> const& func) {
0048       callWhenNewProductsRegistered_ = func;
0049     }
0050 
0051     bool EDAnalyzerBase::doEvent(EventTransitionInfo const& info,
0052                                  ActivityRegistry* act,
0053                                  ModuleCallingContext const* mcc) {
0054       EventSignalsSentry sentry(act, mcc);
0055       Event e(info, moduleDescription_, mcc);
0056       e.setConsumer(this);
0057       e.setSharedResourcesAcquirer(&resourcesAcquirer_);
0058       ESParentContext parentC(mcc);
0059       const EventSetup c{
0060           info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC};
0061       this->analyze(e, c);
0062       return true;
0063     }
0064 
0065     SharedResourcesAcquirer EDAnalyzerBase::createAcquirer() {
0066       return SharedResourcesAcquirer{
0067           std::vector<std::shared_ptr<SerialTaskQueue>>(1, std::make_shared<SerialTaskQueue>())};
0068     }
0069 
0070     SerialTaskQueue* EDAnalyzerBase::globalRunsQueue() { return nullptr; }
0071     SerialTaskQueue* EDAnalyzerBase::globalLuminosityBlocksQueue() { return nullptr; };
0072 
0073     void EDAnalyzerBase::doBeginJob() {
0074       resourcesAcquirer_ = createAcquirer();
0075 
0076       this->beginJob();
0077     }
0078 
0079     void EDAnalyzerBase::doEndJob() { this->endJob(); }
0080 
0081     void EDAnalyzerBase::doPreallocate(PreallocationConfiguration const& iPrealloc) {
0082       preallocRuns(iPrealloc.numberOfRuns());
0083       preallocLumis(iPrealloc.numberOfLuminosityBlocks());
0084     }
0085 
0086     void EDAnalyzerBase::preallocRuns(unsigned int) {}
0087     void EDAnalyzerBase::preallocLumis(unsigned int) {}
0088 
0089     void EDAnalyzerBase::doBeginProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0090       ProcessBlock processBlock(pbp, moduleDescription_, mcc, false);
0091       processBlock.setConsumer(this);
0092       ProcessBlock const& constProcessBlock = processBlock;
0093       this->doBeginProcessBlock_(constProcessBlock);
0094     }
0095 
0096     void EDAnalyzerBase::doAccessInputProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0097       ProcessBlock processBlock(pbp, moduleDescription_, mcc, false);
0098       processBlock.setConsumer(this);
0099       ProcessBlock const& constProcessBlock = processBlock;
0100       this->doAccessInputProcessBlock_(constProcessBlock);
0101     }
0102 
0103     void EDAnalyzerBase::doEndProcessBlock(ProcessBlockPrincipal const& pbp, ModuleCallingContext const* mcc) {
0104       ProcessBlock processBlock(pbp, moduleDescription_, mcc, true);
0105       processBlock.setConsumer(this);
0106       ProcessBlock const& constProcessBlock = processBlock;
0107       this->doEndProcessBlock_(constProcessBlock);
0108     }
0109 
0110     void EDAnalyzerBase::doBeginRun(RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0111       Run r(info, moduleDescription_, mcc, false);
0112       r.setConsumer(this);
0113       Run const& cnstR = r;
0114       ESParentContext parentC(mcc);
0115       const EventSetup c{
0116           info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC};
0117       this->doBeginRun_(cnstR, c);
0118     }
0119 
0120     void EDAnalyzerBase::doEndRun(RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0121       Run r(info, moduleDescription_, mcc, true);
0122       r.setConsumer(this);
0123       Run const& cnstR = r;
0124       ESParentContext parentC(mcc);
0125       const EventSetup c{
0126           info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
0127       this->doEndRun_(cnstR, c);
0128     }
0129 
0130     void EDAnalyzerBase::doBeginLuminosityBlock(LumiTransitionInfo const& info, ModuleCallingContext const* mcc) {
0131       LuminosityBlock lb(info, moduleDescription_, mcc, false);
0132       lb.setConsumer(this);
0133       LuminosityBlock const& cnstLb = lb;
0134       ESParentContext parentC(mcc);
0135       const EventSetup c{info,
0136                          static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0137                          esGetTokenIndices(Transition::BeginLuminosityBlock),
0138                          parentC};
0139       this->doBeginLuminosityBlock_(cnstLb, c);
0140     }
0141 
0142     void EDAnalyzerBase::doEndLuminosityBlock(LumiTransitionInfo const& info, ModuleCallingContext const* mcc) {
0143       LuminosityBlock lb(info, moduleDescription_, mcc, true);
0144       lb.setConsumer(this);
0145       LuminosityBlock const& cnstLb = lb;
0146       ESParentContext parentC(mcc);
0147       const EventSetup c{info,
0148                          static_cast<unsigned int>(Transition::EndLuminosityBlock),
0149                          esGetTokenIndices(Transition::EndLuminosityBlock),
0150                          parentC};
0151       this->doEndLuminosityBlock_(cnstLb, c);
0152     }
0153 
0154     void EDAnalyzerBase::doBeginProcessBlock_(ProcessBlock const&) {}
0155     void EDAnalyzerBase::doAccessInputProcessBlock_(ProcessBlock const&) {}
0156     void EDAnalyzerBase::doEndProcessBlock_(ProcessBlock const&) {}
0157 
0158     void EDAnalyzerBase::doBeginRun_(Run const& rp, EventSetup const& c) {}
0159     void EDAnalyzerBase::doEndRun_(Run const& rp, EventSetup const& c) {}
0160     void EDAnalyzerBase::doBeginLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c) {}
0161     void EDAnalyzerBase::doEndLuminosityBlock_(LuminosityBlock const& lbp, EventSetup const& c) {}
0162 
0163     void EDAnalyzerBase::clearInputProcessBlockCaches() {}
0164 
0165     void EDAnalyzerBase::fillDescriptions(ConfigurationDescriptions& descriptions) {
0166       ParameterSetDescription desc;
0167       desc.setUnknown();
0168       descriptions.addDefault(desc);
0169     }
0170 
0171     void EDAnalyzerBase::prevalidate(ConfigurationDescriptions& iConfig) { edmodule_mightGet_config(iConfig); }
0172 
0173     static const std::string kBaseType("EDAnalyzer");
0174 
0175     const std::string& EDAnalyzerBase::baseType() { return kBaseType; }
0176 
0177     void EDAnalyzerBase::registerProductsAndCallbacks(EDAnalyzerBase const*, SignallingProductRegistryFiller* reg) {
0178       if (callWhenNewProductsRegistered_) {
0179         reg->callForEachBranch(callWhenNewProductsRegistered_);
0180         reg->watchProductAdditions(callWhenNewProductsRegistered_);
0181       }
0182     }
0183 
0184   }  // namespace one
0185 }  // namespace edm