TestService

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
// -*- C++ -*-
//
// Package:     Services
// Class  :     TestService
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  W. David Dagenhart
//         Created:  14 July 2021

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
#include "FWCore/ServiceRegistry/interface/GlobalContext.h"
#include "FWCore/ServiceRegistry/interface/ServiceMaker.h"

namespace edm {
  namespace service {

    class TestService {
    public:
      TestService(const ParameterSet&, ActivityRegistry&);

      static void fillDescriptions(edm::ConfigurationDescriptions&);

      void preBeginProcessBlock(GlobalContext const&);

      void preEndProcessBlock(GlobalContext const&);

      void preGlobalBeginRun(GlobalContext const&);

      void preGlobalEndRun(GlobalContext const&);

      void preGlobalBeginLumi(GlobalContext const&);

      void preGlobalEndLumi(GlobalContext const&);

    private:
      bool printTestMessageLoggerErrors_;
    };
  }  // namespace service
}  // namespace edm

using namespace edm::service;

TestService::TestService(ParameterSet const& iPS, ActivityRegistry& iRegistry)
    : printTestMessageLoggerErrors_(iPS.getUntrackedParameter<bool>("printTestMessageLoggerErrors")) {
  iRegistry.watchPreBeginProcessBlock(this, &TestService::preBeginProcessBlock);

  iRegistry.watchPreEndProcessBlock(this, &TestService::preEndProcessBlock);

  iRegistry.watchPreGlobalBeginRun(this, &TestService::preGlobalBeginRun);

  iRegistry.watchPreGlobalEndRun(this, &TestService::preGlobalEndRun);

  iRegistry.watchPreGlobalBeginLumi(this, &TestService::preGlobalBeginLumi);

  iRegistry.watchPreGlobalEndLumi(this, &TestService::preGlobalEndLumi);
}

void TestService::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
  edm::ParameterSetDescription desc;
  desc.addUntracked<bool>("printTestMessageLoggerErrors", false)
      ->setComment("Prints MessageLogger errors to test formatting of such messages when printed from Services");
  descriptions.add("TestService", desc);
}

void TestService::preBeginProcessBlock(GlobalContext const&) {
  if (printTestMessageLoggerErrors_) {
    edm::LogError("TestMessageLogger") << "test message from TestService::preBeginProcessBlock";
  }
}

void TestService::preEndProcessBlock(GlobalContext const&) {
  if (printTestMessageLoggerErrors_) {
    edm::LogError("TestMessageLogger") << "test message from TestService::preEndProcessBlock";
  }
}

void TestService::preGlobalBeginRun(GlobalContext const&) {
  if (printTestMessageLoggerErrors_) {
    edm::LogError("TestMessageLogger") << "test message from TestService::preGlobalBeginRun";
  }
}

void TestService::preGlobalEndRun(GlobalContext const&) {
  if (printTestMessageLoggerErrors_) {
    edm::LogError("TestMessageLogger") << "test message from TestService::preGlobalEndRun";
  }
}

void TestService::preGlobalBeginLumi(GlobalContext const& gc) {
  if (printTestMessageLoggerErrors_) {
    edm::LogError("TestMessageLogger") << "test message from TestService::preGlobalBeginLumi";
  }
}

void TestService::preGlobalEndLumi(GlobalContext const& gc) {
  if (printTestMessageLoggerErrors_) {
    edm::LogError("TestMessageLogger") << "test message from TestService::preGlobalEndLumi";
  }
}

using edm::service::TestService;
DEFINE_FWK_SERVICE(TestService);