Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*----------------------------------------------------------------------
0002   
0003 
0004 ----------------------------------------------------------------------*/
0005 
0006 #include "FWCore/Framework/interface/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/LuminosityBlock.h"
0009 #include "FWCore/Framework/interface/Run.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/src/edmodule_mightGet_config.h"
0012 #include "FWCore/Framework/interface/ConstProductRegistry.h"
0013 #include "FWCore/Framework/src/EventSignalsSentry.h"
0014 #include "FWCore/Framework/interface/TransitionInfoTypes.h"
0015 
0016 #include "FWCore/Framework/interface/SharedResourcesRegistry.h"
0017 
0018 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 
0021 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0022 
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0025 
0026 namespace edm {
0027   EDAnalyzer::~EDAnalyzer() {}
0028   EDAnalyzer::EDAnalyzer() : moduleDescription_() {
0029     SharedResourcesRegistry::instance()->registerSharedResource(SharedResourcesRegistry::kLegacyModuleResourceName);
0030   }
0031 
0032   bool EDAnalyzer::doEvent(EventTransitionInfo const& info, ActivityRegistry* act, ModuleCallingContext const* mcc) {
0033     Event e(info, moduleDescription_, mcc);
0034     e.setConsumer(this);
0035     e.setSharedResourcesAcquirer(&resourceAcquirer_);
0036     EventSignalsSentry sentry(act, mcc);
0037     ESParentContext parentC(mcc);
0038     const EventSetup c{
0039         info, static_cast<unsigned int>(Transition::Event), esGetTokenIndices(Transition::Event), parentC};
0040     this->analyze(e, c);
0041     return true;
0042   }
0043 
0044   void EDAnalyzer::doBeginJob() {
0045     std::vector<std::string> res = {SharedResourcesRegistry::kLegacyModuleResourceName};
0046     resourceAcquirer_ = SharedResourcesRegistry::instance()->createAcquirer(res);
0047 
0048     this->beginJob();
0049   }
0050 
0051   void EDAnalyzer::doEndJob() { this->endJob(); }
0052 
0053   bool EDAnalyzer::doBeginRun(RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0054     Run r(info, moduleDescription_, mcc, false);
0055     r.setConsumer(this);
0056     ESParentContext parentC(mcc);
0057     const EventSetup c{
0058         info, static_cast<unsigned int>(Transition::BeginRun), esGetTokenIndices(Transition::BeginRun), parentC};
0059     this->beginRun(r, c);
0060     return true;
0061   }
0062 
0063   bool EDAnalyzer::doEndRun(RunTransitionInfo const& info, ModuleCallingContext const* mcc) {
0064     Run r(info, moduleDescription_, mcc, true);
0065     r.setConsumer(this);
0066     ESParentContext parentC(mcc);
0067     const EventSetup c{
0068         info, static_cast<unsigned int>(Transition::EndRun), esGetTokenIndices(Transition::EndRun), parentC};
0069     this->endRun(r, c);
0070     return true;
0071   }
0072 
0073   bool EDAnalyzer::doBeginLuminosityBlock(LumiTransitionInfo const& info, ModuleCallingContext const* mcc) {
0074     LuminosityBlock lb(info, moduleDescription_, mcc, false);
0075     lb.setConsumer(this);
0076     ESParentContext parentC(mcc);
0077     const EventSetup c{info,
0078                        static_cast<unsigned int>(Transition::BeginLuminosityBlock),
0079                        esGetTokenIndices(Transition::BeginLuminosityBlock),
0080                        parentC};
0081     this->beginLuminosityBlock(lb, c);
0082     return true;
0083   }
0084 
0085   bool EDAnalyzer::doEndLuminosityBlock(LumiTransitionInfo const& info, ModuleCallingContext const* mcc) {
0086     LuminosityBlock lb(info, moduleDescription_, mcc, true);
0087     lb.setConsumer(this);
0088     ESParentContext parentC(mcc);
0089     const EventSetup c{info,
0090                        static_cast<unsigned int>(Transition::EndLuminosityBlock),
0091                        esGetTokenIndices(Transition::EndLuminosityBlock),
0092                        parentC};
0093     this->endLuminosityBlock(lb, c);
0094     return true;
0095   }
0096 
0097   void EDAnalyzer::doRespondToOpenInputFile(FileBlock const& fb) { respondToOpenInputFile(fb); }
0098 
0099   void EDAnalyzer::doRespondToCloseInputFile(FileBlock const& fb) { respondToCloseInputFile(fb); }
0100 
0101   void EDAnalyzer::callWhenNewProductsRegistered(std::function<void(BranchDescription const&)> const& func) {
0102     callWhenNewProductsRegistered_ = func;
0103   }
0104 
0105   void EDAnalyzer::fillDescriptions(ConfigurationDescriptions& descriptions) {
0106     ParameterSetDescription desc;
0107     desc.setUnknown();
0108     descriptions.addDefault(desc);
0109   }
0110 
0111   void EDAnalyzer::prevalidate(ConfigurationDescriptions& iConfig) { edmodule_mightGet_config(iConfig); }
0112 
0113   void EDAnalyzer::registerProductsAndCallbacks(EDAnalyzer const*, ProductRegistry* reg) {
0114     if (callWhenNewProductsRegistered_) {
0115       reg->callForEachBranch(callWhenNewProductsRegistered_);
0116 
0117       Service<ConstProductRegistry> regService;
0118       regService->watchProductAdditions(callWhenNewProductsRegistered_);
0119     }
0120   }
0121 
0122   static const std::string kBaseType("EDAnalyzer");
0123   const std::string& EDAnalyzer::baseType() { return kBaseType; }
0124 }  // namespace edm