Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-13 03:37:58

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