Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-14 11:45:07

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       preallocLumis(iPrealloc.numberOfLuminosityBlocks());
0086     }
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*, ProductRegistry* reg) {
0178       if (callWhenNewProductsRegistered_) {
0179         reg->callForEachBranch(callWhenNewProductsRegistered_);
0180 
0181         Service<ConstProductRegistry> regService;
0182         regService->watchProductAdditions(callWhenNewProductsRegistered_);
0183       }
0184     }
0185 
0186   }  // namespace one
0187 }  // namespace edm