diff --git a/FWCore/Framework/interface/GlobalSchedule.h b/FWCore/Framework/interface/GlobalSchedule.h index a50ec541d07e8..09f3db6d57cfd 100644 --- a/FWCore/Framework/interface/GlobalSchedule.h +++ b/FWCore/Framework/interface/GlobalSchedule.h @@ -19,6 +19,8 @@ #include "FWCore/Framework/interface/WorkerRegistry.h" #include "FWCore/MessageLogger/interface/ExceptionMessages.h" #include "FWCore/ServiceRegistry/interface/GlobalContext.h" +#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h" +#include "FWCore/ServiceRegistry/interface/ServiceToken.h" #include "FWCore/Utilities/interface/Algorithms.h" #include "FWCore/Utilities/interface/BranchType.h" #include "FWCore/Utilities/interface/ConvertException.h" @@ -28,6 +30,7 @@ #include "FWCore/Concurrency/interface/WaitingTaskHolder.h" #include "FWCore/Utilities/interface/thread_safety_macros.h" +#include #include #include #include @@ -38,37 +41,6 @@ namespace edm { - namespace { - template - class GlobalScheduleSignalSentry { - public: - GlobalScheduleSignalSentry(ActivityRegistry* a, typename T::Context const* context) - : a_(a), context_(context), allowThrow_(false) { - if (a_) - T::preScheduleSignal(a_, context_); - } - ~GlobalScheduleSignalSentry() noexcept(false) { - // Caught exception is rethrown - CMS_SA_ALLOW try { - if (a_) - T::postScheduleSignal(a_, context_); - } catch (...) { - if (allowThrow_) { - throw; - } - } - } - - void allowThrow() { allowThrow_ = true; } - - private: - // We own none of these resources. - ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable. - typename T::Context const* context_; - bool allowThrow_; - }; - } // namespace - class ActivityRegistry; class ExceptionCollector; class ProcessContext; @@ -131,25 +103,16 @@ namespace edm { AllWorkers const& allWorkers() const { return workerManagers_[0].allWorkers(); } private: - //Sentry class to only send a signal if an - // exception occurs. An exception is identified - // by the destructor being called without first - // calling completedSuccessfully(). - class SendTerminationSignalIfException { - public: - SendTerminationSignalIfException(edm::ActivityRegistry* iReg, edm::GlobalContext const* iContext) - : reg_(iReg), context_(iContext) {} - ~SendTerminationSignalIfException() { - if (reg_) { - reg_->preGlobalEarlyTerminationSignal_(*context_, TerminationOrigin::ExceptionFromThisContext); - } - } - void completedSuccessfully() { reg_ = nullptr; } + template + void preScheduleSignal(GlobalContext const*, ServiceToken const&); + + template + void postScheduleSignal(GlobalContext const*, ServiceWeakToken const&, std::exception_ptr&); - private: - edm::ActivityRegistry* reg_; // We do not use propagate_const because the registry itself is mutable. - GlobalContext const* context_; - }; + void handleException(GlobalContext const*, + ServiceWeakToken const&, + bool cleaningUpAfterException, + std::exception_ptr&); /// returns the action table ExceptionToActionTable const& actionTable() const { return workerManagers_[0].actionTable(); } @@ -173,72 +136,88 @@ namespace edm { //need the doneTask to own the memory auto globalContext = std::make_shared(T::makeGlobalContext(principal, processContext_)); - if (actReg_) { - //Services may depend upon each other - ServiceRegistry::Operate op(token); - T::preScheduleSignal(actReg_.get(), globalContext.get()); - } - ServiceWeakToken weakToken = token; auto doneTask = make_waiting_task( [this, iHolder, cleaningUpAfterException, globalContext, weakToken](std::exception_ptr const* iPtr) mutable { std::exception_ptr excpt; if (iPtr) { excpt = *iPtr; - //add context information to the exception and print message - try { - convertException::wrap([&]() { std::rethrow_exception(excpt); }); - } catch (cms::Exception& ex) { - //TODO: should add the transition type info - std::ostringstream ost; - if (ex.context().empty()) { - ost << "Processing " << T::transitionName() << " "; - } - ServiceRegistry::Operate op(weakToken.lock()); - addContextAndPrintException(ost.str().c_str(), ex, cleaningUpAfterException); - excpt = std::current_exception(); - } - if (actReg_) { - ServiceRegistry::Operate op(weakToken.lock()); - actReg_->preGlobalEarlyTerminationSignal_(*globalContext, TerminationOrigin::ExceptionFromThisContext); - } - } - if (actReg_) { - // Caught exception is propagated via WaitingTaskHolder - CMS_SA_ALLOW try { - ServiceRegistry::Operate op(weakToken.lock()); - T::postScheduleSignal(actReg_.get(), globalContext.get()); - } catch (...) { - if (not excpt) { - excpt = std::current_exception(); - } - } + // add context information to the exception and print message + handleException(globalContext.get(), weakToken, cleaningUpAfterException, excpt); } + postScheduleSignal(globalContext.get(), weakToken, excpt); iHolder.doneWaiting(excpt); }); - unsigned int managerIndex = principal.index(); - if constexpr (T::branchType_ == InRun) { - managerIndex += numberOfConcurrentLumis_; - } - WorkerManager& workerManager = workerManagers_[managerIndex]; - workerManager.resetAll(); - - ParentContext parentContext(globalContext.get()); - //make sure the ProductResolvers know about their - // workers to allow proper data dependency handling - workerManager.setupResolvers(transitionInfo.principal()); //make sure the task doesn't get run until all workers have beens started WaitingTaskHolder holdForLoop(*iHolder.group(), doneTask); - auto& aw = workerManager.allWorkers(); - for (Worker* worker : boost::adaptors::reverse(aw)) { - worker->doWorkAsync( - holdForLoop, transitionInfo, token, StreamID::invalidStreamID(), parentContext, globalContext.get()); + + CMS_SA_ALLOW try { + preScheduleSignal(globalContext.get(), token); + + unsigned int managerIndex = principal.index(); + if constexpr (T::branchType_ == InRun) { + managerIndex += numberOfConcurrentLumis_; + } + WorkerManager& workerManager = workerManagers_[managerIndex]; + workerManager.resetAll(); + + ParentContext parentContext(globalContext.get()); + // make sure the ProductResolvers know about their + // workers to allow proper data dependency handling + workerManager.setupResolvers(transitionInfo.principal()); + + auto& aw = workerManager.allWorkers(); + for (Worker* worker : boost::adaptors::reverse(aw)) { + worker->doWorkAsync( + holdForLoop, transitionInfo, token, StreamID::invalidStreamID(), parentContext, globalContext.get()); + } + } catch (...) { + holdForLoop.doneWaiting(std::current_exception()); } } catch (...) { iHolder.doneWaiting(std::current_exception()); } } + + template + void GlobalSchedule::preScheduleSignal(GlobalContext const* globalContext, ServiceToken const& token) { + if (actReg_) { + try { + ServiceRegistry::Operate op(token); + convertException::wrap([this, globalContext]() { T::preScheduleSignal(actReg_.get(), globalContext); }); + } catch (cms::Exception& ex) { + std::ostringstream ost; + ex.addContext("Handling pre signal, likely in a service function"); + exceptionContext(ost, *globalContext); + ex.addContext(ost.str()); + throw; + } + } + } + + template + void GlobalSchedule::postScheduleSignal(GlobalContext const* globalContext, + ServiceWeakToken const& weakToken, + std::exception_ptr& excpt) { + if (actReg_) { + try { + convertException::wrap([this, &weakToken, globalContext]() { + ServiceRegistry::Operate op(weakToken.lock()); + T::postScheduleSignal(actReg_.get(), globalContext); + }); + } catch (cms::Exception& ex) { + if (not excpt) { + std::ostringstream ost; + ex.addContext("Handling post signal, likely in a service function"); + exceptionContext(ost, *globalContext); + ex.addContext(ost.str()); + excpt = std::current_exception(); + } + } + } + } + } // namespace edm #endif diff --git a/FWCore/Framework/interface/maker/Worker.h b/FWCore/Framework/interface/maker/Worker.h index 3fac575013d05..0d3cb321798ea 100644 --- a/FWCore/Framework/interface/maker/Worker.h +++ b/FWCore/Framework/interface/maker/Worker.h @@ -650,7 +650,12 @@ namespace edm { } void preModuleSignal() { if (a_) { - T::preModuleSignal(a_, context_, moduleCallingContext_); + try { + convertException::wrap([this]() { T::preModuleSignal(a_, context_, moduleCallingContext_); }); + } catch (cms::Exception& ex) { + ex.addContext("Handling pre module signal, likely in a service function immediately before module method"); + throw; + } } } void postModuleSignal() { @@ -659,7 +664,12 @@ namespace edm { // Setting a_ to null informs the destructor that the signal // was already run and that it should do nothing. a_ = nullptr; - T::postModuleSignal(temp, context_, moduleCallingContext_); + try { + convertException::wrap([this, temp]() { T::postModuleSignal(temp, context_, moduleCallingContext_); }); + } catch (cms::Exception& ex) { + ex.addContext("Handling post module signal, likely in a service function immediately after module method"); + throw; + } } } @@ -831,6 +841,7 @@ namespace edm { cpp.preModuleSignal(); auto returnValue = iWorker->implDoBegin(info, mcc); cpp.postModuleSignal(); + iWorker->beginSucceeded_ = true; return returnValue; } static void esPrefetchAsync(Worker* worker, @@ -885,11 +896,16 @@ namespace edm { ActivityRegistry* actReg, ModuleCallingContext const* mcc, Arg::Context const* context) { - ModuleSignalSentry cpp(actReg, context, mcc); - cpp.preModuleSignal(); - auto returnValue = iWorker->implDoEnd(info, mcc); - cpp.postModuleSignal(); - return returnValue; + if (iWorker->beginSucceeded_) { + iWorker->beginSucceeded_ = false; + + ModuleSignalSentry cpp(actReg, context, mcc); + cpp.preModuleSignal(); + auto returnValue = iWorker->implDoEnd(info, mcc); + cpp.postModuleSignal(); + return returnValue; + } + return true; } static void esPrefetchAsync(Worker* worker, WaitingTaskHolder waitingTask, diff --git a/FWCore/Framework/src/EventProcessor.cc b/FWCore/Framework/src/EventProcessor.cc index 305d17783180c..0b4e1b93895f6 100644 --- a/FWCore/Framework/src/EventProcessor.cc +++ b/FWCore/Framework/src/EventProcessor.cc @@ -1744,22 +1744,18 @@ namespace edm { looper_->prefetchAsync( nextTask, serviceToken_, Transition::BeginLuminosityBlock, *(status->lumiPrincipal()), es); }) | ifThen(looper_, [this, status, &es](auto nextTask) { - status->globalBeginDidSucceed(); ServiceRegistry::Operate operateLooper(serviceToken_); looper_->doBeginLuminosityBlock(*(status->lumiPrincipal()), es, &processContext_); }) | then([this, status, iRunStatus](std::exception_ptr const* iException, auto holder) mutable { + status->setGlobalEndRunHolder(iRunStatus->globalEndRunHolder()); + if (iException) { - status->resetResources(); - queueWhichWaitsForIOVsToFinish_.resume(); WaitingTaskHolder copyHolder(holder); copyHolder.doneWaiting(*iException); + globalEndLumiAsync(holder, status); endRunAsync(iRunStatus, holder); } else { - if (not looper_) { - status->globalBeginDidSucceed(); - } - - status->setGlobalEndRunHolder(iRunStatus->globalEndRunHolder()); + status->globalBeginDidSucceed(); EventSetupImpl const& es = status->eventSetupImpl(esp_->subProcessIndex()); using Traits = OccurrenceTraits; @@ -1957,18 +1953,16 @@ namespace edm { auto eventSetupImpls = &lumiStatus->eventSetupImpls(); bool cleaningUpAfterException = lumiStatus->cleaningUpAfterException() || iTask.taskHasFailed(); - if (lumiStatus->didGlobalBeginSucceed()) { - auto& lumiPrincipal = *lumiStatus->lumiPrincipal(); - using Traits = OccurrenceTraits; - LumiTransitionInfo transitionInfo(lumiPrincipal, es, eventSetupImpls); - endStreamTransitionAsync(std::move(lumiDoneTask), - *schedule_, - iStreamIndex, - transitionInfo, - serviceToken_, - subProcesses_, - cleaningUpAfterException); - } + auto& lumiPrincipal = *lumiStatus->lumiPrincipal(); + using Traits = OccurrenceTraits; + LumiTransitionInfo transitionInfo(lumiPrincipal, es, eventSetupImpls); + endStreamTransitionAsync(std::move(lumiDoneTask), + *schedule_, + iStreamIndex, + transitionInfo, + serviceToken_, + subProcesses_, + cleaningUpAfterException); } void EventProcessor::endUnfinishedLumi(bool cleaningUpAfterException) { diff --git a/FWCore/Framework/src/GlobalSchedule.cc b/FWCore/Framework/src/GlobalSchedule.cc index 2fc16e6486b2c..edce7d10794de 100644 --- a/FWCore/Framework/src/GlobalSchedule.cc +++ b/FWCore/Framework/src/GlobalSchedule.cc @@ -131,4 +131,32 @@ namespace edm { } return result; } + + void GlobalSchedule::handleException(GlobalContext const* globalContext, + ServiceWeakToken const& weakToken, + bool cleaningUpAfterException, + std::exception_ptr& excpt) { + //add context information to the exception and print message + try { + convertException::wrap([&excpt]() { std::rethrow_exception(excpt); }); + } catch (cms::Exception& ex) { + std::ostringstream ost; + // In most cases the exception will already have context at this point, + // but add some context here in those rare cases where it does not. + if (ex.context().empty()) { + exceptionContext(ost, *globalContext); + } + ServiceRegistry::Operate op(weakToken.lock()); + addContextAndPrintException(ost.str().c_str(), ex, cleaningUpAfterException); + excpt = std::current_exception(); + } + CMS_SA_ALLOW try { + if (actReg_) { + ServiceRegistry::Operate op(weakToken.lock()); + actReg_->preGlobalEarlyTerminationSignal_(*globalContext, TerminationOrigin::ExceptionFromThisContext); + } + } catch (...) { + } + } + } // namespace edm diff --git a/FWCore/Framework/test/global_filter_t.cppunit.cc b/FWCore/Framework/test/global_filter_t.cppunit.cc index 3e4508a6f4e5b..a92eed50adecf 100644 --- a/FWCore/Framework/test/global_filter_t.cppunit.cc +++ b/FWCore/Framework/test/global_filter_t.cppunit.cc @@ -540,9 +540,18 @@ void testGlobalFilter::testTransitions(std::shared_ptr iMod, Expectations con edm::maker::ModuleHolderT h(iMod, nullptr); h.preallocate(edm::PreallocationConfiguration{}); - edm::WorkerT w{iMod, m_desc, nullptr}; + edm::WorkerT wOther{iMod, m_desc, nullptr}; + edm::WorkerT wGlobalLumi{iMod, m_desc, nullptr}; + edm::WorkerT wStreamLumi{iMod, m_desc, nullptr}; for (auto& keyVal : m_transToFunc) { - testTransition(iMod, &w, keyVal.first, iExpect, keyVal.second); + edm::Worker* worker = &wOther; + if (keyVal.first == Trans::kStreamBeginLuminosityBlock || keyVal.first == Trans::kStreamEndLuminosityBlock) { + worker = &wStreamLumi; + } else if (keyVal.first == Trans::kGlobalBeginLuminosityBlock || + keyVal.first == Trans::kGlobalEndLuminosityBlock) { + worker = &wGlobalLumi; + } + testTransition(iMod, worker, keyVal.first, iExpect, keyVal.second); } }); } diff --git a/FWCore/Framework/test/global_producer_t.cppunit.cc b/FWCore/Framework/test/global_producer_t.cppunit.cc index 27deb641b6900..2ed6c5680cbf2 100644 --- a/FWCore/Framework/test/global_producer_t.cppunit.cc +++ b/FWCore/Framework/test/global_producer_t.cppunit.cc @@ -506,9 +506,18 @@ void testGlobalProducer::testTransitions(std::shared_ptr iMod, Expectations c edm::maker::ModuleHolderT h(iMod, nullptr); h.preallocate(edm::PreallocationConfiguration{}); - edm::WorkerT w{iMod, m_desc, nullptr}; + edm::WorkerT wOther{iMod, m_desc, nullptr}; + edm::WorkerT wGlobalLumi{iMod, m_desc, nullptr}; + edm::WorkerT wStreamLumi{iMod, m_desc, nullptr}; for (auto& keyVal : m_transToFunc) { - testTransition(iMod, &w, keyVal.first, iExpect, keyVal.second); + edm::Worker* worker = &wOther; + if (keyVal.first == Trans::kStreamBeginLuminosityBlock || keyVal.first == Trans::kStreamEndLuminosityBlock) { + worker = &wStreamLumi; + } else if (keyVal.first == Trans::kGlobalBeginLuminosityBlock || + keyVal.first == Trans::kGlobalEndLuminosityBlock) { + worker = &wGlobalLumi; + } + testTransition(iMod, worker, keyVal.first, iExpect, keyVal.second); } }); } diff --git a/FWCore/Framework/test/limited_filter_t.cppunit.cc b/FWCore/Framework/test/limited_filter_t.cppunit.cc index 4d945c796d1b9..2bdf1b7aab141 100644 --- a/FWCore/Framework/test/limited_filter_t.cppunit.cc +++ b/FWCore/Framework/test/limited_filter_t.cppunit.cc @@ -547,9 +547,17 @@ void testLimitedFilter::testTransitions(std::shared_ptr iMod, Expectations co edm::maker::ModuleHolderT h(iMod, nullptr); h.preallocate(edm::PreallocationConfiguration{}); - edm::WorkerT w{iMod, m_desc, nullptr}; + edm::WorkerT wOther{iMod, m_desc, nullptr}; + edm::WorkerT wGlobalLumi{iMod, m_desc, nullptr}; + edm::WorkerT wStreamLumi{iMod, m_desc, nullptr}; for (auto& keyVal : m_transToFunc) { - testTransition(iMod, &w, keyVal.first, iExpect, keyVal.second); + edm::Worker* worker = &wOther; + if (keyVal.first == Trans::kStreamBeginLuminosityBlock || keyVal.first == Trans::kStreamEndLuminosityBlock) { + worker = &wStreamLumi; + } else if (keyVal.first == Trans::kGlobalBeginLuminosityBlock || keyVal.first == Trans::kGlobalEndLuminosityBlock) { + worker = &wGlobalLumi; + } + testTransition(iMod, worker, keyVal.first, iExpect, keyVal.second); } } diff --git a/FWCore/Framework/test/limited_producer_t.cppunit.cc b/FWCore/Framework/test/limited_producer_t.cppunit.cc index b5383f0e14285..be294560854a7 100644 --- a/FWCore/Framework/test/limited_producer_t.cppunit.cc +++ b/FWCore/Framework/test/limited_producer_t.cppunit.cc @@ -512,9 +512,17 @@ void testLimitedProducer::testTransitions(std::shared_ptr iMod, Expectations edm::maker::ModuleHolderT h(iMod, nullptr); h.preallocate(edm::PreallocationConfiguration{}); - edm::WorkerT w{iMod, m_desc, nullptr}; + edm::WorkerT wOther{iMod, m_desc, nullptr}; + edm::WorkerT wGlobalLumi{iMod, m_desc, nullptr}; + edm::WorkerT wStreamLumi{iMod, m_desc, nullptr}; for (auto& keyVal : m_transToFunc) { - testTransition(iMod, &w, keyVal.first, iExpect, keyVal.second); + edm::Worker* worker = &wOther; + if (keyVal.first == Trans::kStreamBeginLuminosityBlock || keyVal.first == Trans::kStreamEndLuminosityBlock) { + worker = &wStreamLumi; + } else if (keyVal.first == Trans::kGlobalBeginLuminosityBlock || keyVal.first == Trans::kGlobalEndLuminosityBlock) { + worker = &wGlobalLumi; + } + testTransition(iMod, worker, keyVal.first, iExpect, keyVal.second); } } diff --git a/FWCore/Framework/test/stream_filter_t.cppunit.cc b/FWCore/Framework/test/stream_filter_t.cppunit.cc index c754f99a44249..af6db9462c1a9 100644 --- a/FWCore/Framework/test/stream_filter_t.cppunit.cc +++ b/FWCore/Framework/test/stream_filter_t.cppunit.cc @@ -587,9 +587,17 @@ template void testStreamFilter::testTransitions(std::shared_ptr iMod, Expectations const& iExpect) { oneapi::tbb::global_control control(oneapi::tbb::global_control::max_allowed_parallelism, 1); - edm::WorkerT w{iMod, m_desc, nullptr}; + edm::WorkerT wOther{iMod, m_desc, nullptr}; + edm::WorkerT wGlobalLumi{iMod, m_desc, nullptr}; + edm::WorkerT wStreamLumi{iMod, m_desc, nullptr}; for (auto& keyVal : m_transToFunc) { - testTransition(&w, keyVal.first, iExpect, keyVal.second); + edm::Worker* worker = &wOther; + if (keyVal.first == Trans::kStreamBeginLuminosityBlock || keyVal.first == Trans::kStreamEndLuminosityBlock) { + worker = &wStreamLumi; + } else if (keyVal.first == Trans::kGlobalBeginLuminosityBlock || keyVal.first == Trans::kGlobalEndLuminosityBlock) { + worker = &wGlobalLumi; + } + testTransition(worker, keyVal.first, iExpect, keyVal.second); } } template diff --git a/FWCore/Framework/test/stream_producer_t.cppunit.cc b/FWCore/Framework/test/stream_producer_t.cppunit.cc index 0fce50c7cc30c..76301b23e6da8 100644 --- a/FWCore/Framework/test/stream_producer_t.cppunit.cc +++ b/FWCore/Framework/test/stream_producer_t.cppunit.cc @@ -548,11 +548,20 @@ template void testStreamProducer::testTransitions(std::shared_ptr iMod, Expectations const& iExpect) { oneapi::tbb::global_control control(oneapi::tbb::global_control::max_allowed_parallelism, 1); - edm::WorkerT w{iMod, m_desc, nullptr}; + edm::WorkerT wOther{iMod, m_desc, nullptr}; + edm::WorkerT wGlobalLumi{iMod, m_desc, nullptr}; + edm::WorkerT wStreamLumi{iMod, m_desc, nullptr}; for (auto& keyVal : m_transToFunc) { - testTransition(&w, keyVal.first, iExpect, keyVal.second); + edm::Worker* worker = &wOther; + if (keyVal.first == Trans::kStreamBeginLuminosityBlock || keyVal.first == Trans::kStreamEndLuminosityBlock) { + worker = &wStreamLumi; + } else if (keyVal.first == Trans::kGlobalBeginLuminosityBlock || keyVal.first == Trans::kGlobalEndLuminosityBlock) { + worker = &wGlobalLumi; + } + testTransition(worker, keyVal.first, iExpect, keyVal.second); } } + template void testStreamProducer::runTest(Expectations const& iExpect) { auto mod = createModule(); diff --git a/FWCore/Integration/plugins/ExceptionThrowingProducer.cc b/FWCore/Integration/plugins/ExceptionThrowingProducer.cc index 18707db58f058..d12559e1e5d8b 100644 --- a/FWCore/Integration/plugins/ExceptionThrowingProducer.cc +++ b/FWCore/Integration/plugins/ExceptionThrowingProducer.cc @@ -51,6 +51,8 @@ namespace edmtest { static void fillDescriptions(edm::ConfigurationDescriptions&); private: + bool verbose_; + edm::EventID eventIDThrowOnEvent_; edm::EventID eventIDThrowOnGlobalBeginRun_; edm::EventID eventIDThrowOnGlobalBeginLumi_; @@ -63,17 +65,24 @@ namespace edmtest { mutable std::vector nStreamBeginLumi_; mutable std::vector nStreamEndLumi_; + mutable std::atomic nGlobalBeginLumi_{0}; + mutable std::atomic nGlobalEndLumi_{0}; unsigned int expectedStreamBeginLumi_; unsigned int expectedOffsetNoStreamEndLumi_; mutable unsigned int streamWithBeginLumiException_ = kUnset; + unsigned int expectedGlobalBeginLumi_; + unsigned int expectedOffsetNoGlobalEndLumi_; + unsigned int expectedOffsetNoWriteLumi_; mutable std::atomic streamBeginLumiExceptionOccurred_ = false; mutable std::atomic streamEndLumiExceptionOccurred_ = false; + mutable std::atomic globalBeginLumiExceptionOccurred_ = false; }; ExceptionThrowingProducer::ExceptionThrowingProducer(edm::ParameterSet const& pset) - : eventIDThrowOnEvent_(pset.getUntrackedParameter("eventIDThrowOnEvent")), + : verbose_(pset.getUntrackedParameter("verbose")), + eventIDThrowOnEvent_(pset.getUntrackedParameter("eventIDThrowOnEvent")), eventIDThrowOnGlobalBeginRun_(pset.getUntrackedParameter("eventIDThrowOnGlobalBeginRun")), eventIDThrowOnGlobalBeginLumi_(pset.getUntrackedParameter("eventIDThrowOnGlobalBeginLumi")), eventIDThrowOnGlobalEndRun_(pset.getUntrackedParameter("eventIDThrowOnGlobalEndRun")), @@ -85,7 +94,10 @@ namespace edmtest { nStreamBeginLumi_(kTestStreams, 0), nStreamEndLumi_(kTestStreams, 0), expectedStreamBeginLumi_(pset.getUntrackedParameter("expectedStreamBeginLumi")), - expectedOffsetNoStreamEndLumi_(pset.getUntrackedParameter("expectedOffsetNoStreamEndLumi")) {} + expectedOffsetNoStreamEndLumi_(pset.getUntrackedParameter("expectedOffsetNoStreamEndLumi")), + expectedGlobalBeginLumi_(pset.getUntrackedParameter("expectedGlobalBeginLumi")), + expectedOffsetNoGlobalEndLumi_(pset.getUntrackedParameter("expectedOffsetNoGlobalEndLumi")), + expectedOffsetNoWriteLumi_(pset.getUntrackedParameter("expectedOffsetNoWriteLumi")) {} void ExceptionThrowingProducer::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const { if (event.id() == eventIDThrowOnEvent_) { @@ -114,8 +126,10 @@ namespace edmtest { std::shared_ptr ExceptionThrowingProducer::globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) const { + ++nGlobalBeginLumi_; if (edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) == eventIDThrowOnGlobalBeginLumi_) { + globalBeginLumiExceptionOccurred_.store(true); throw cms::Exception("IntentionalTestException") << "ExceptionThrowingProducer::globalBeginLuminosityBlock, module configured to throw on: " << eventIDThrowOnGlobalBeginLumi_; @@ -125,6 +139,7 @@ namespace edmtest { void ExceptionThrowingProducer::globalEndLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) const { + ++nGlobalEndLumi_; if (edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) == eventIDThrowOnGlobalEndLumi_) { throw cms::Exception("IntentionalTestException") @@ -228,6 +243,25 @@ namespace edmtest { ++i; } + // There has to be at least as many global begin lumi transitions + // as expected. Because of concurrency, the Framework might already have + // started other lumis ahead of the one where an exception occurs. + if (expectedGlobalBeginLumi_ > 0 && nGlobalBeginLumi_.load() < expectedGlobalBeginLumi_) { + edm::LogAbsolute("ExceptionThrowingProducer") + << "FAILED: Less than the expected number of globalBeginLumi transitions, expected at least " + << expectedGlobalBeginLumi_ << " saw " << nGlobalBeginLumi_.load(); + testsPass = false; + } + + unsigned int expectedGlobalEndLumi = + globalBeginLumiExceptionOccurred_.load() ? nGlobalBeginLumi_.load() - 1 : nGlobalBeginLumi_.load(); + if (nGlobalEndLumi_.load() != expectedGlobalEndLumi) { + edm::LogAbsolute("ExceptionThrowingProducer") + << "FAILED: number of global end lumi transitions not equal to expected value, expected " + << expectedGlobalEndLumi << " saw " << nGlobalEndLumi_.load(); + testsPass = false; + } + edm::Service serviceOne; if (serviceOne->nPreStreamBeginLumi() != totalStreamBeginLumi || serviceOne->nPostStreamBeginLumi() != totalStreamBeginLumi || @@ -240,7 +274,7 @@ namespace edmtest { serviceOne->nPostModuleStreamEndLumi() != totalStreamBeginLumi * kNumberOfTestModules - expectedOffsetNoStreamEndLumi_) { edm::LogAbsolute("ExceptionThrowingProducer") - << "FAILED: Unexpected number of service transitions in TestServiceOne, stream "; + << "FAILED: Unexpected number of service transitions in TestServiceOne, stream lumi"; testsPass = false; } @@ -256,10 +290,86 @@ namespace edmtest { serviceTwo->nPostModuleStreamEndLumi() != totalStreamBeginLumi * kNumberOfTestModules - expectedOffsetNoStreamEndLumi_) { edm::LogAbsolute("ExceptionThrowingProducer") - << "FAILED: Unexpected number of service transitions in TestServiceTwo, stream "; + << "FAILED: Unexpected number of service transitions in TestServiceTwo, stream lumi"; testsPass = false; } + unsigned int nGlobalBeginLumi = nGlobalBeginLumi_.load(); + + if (serviceOne->nPreGlobalBeginLumi() != nGlobalBeginLumi || + serviceOne->nPostGlobalBeginLumi() != nGlobalBeginLumi || serviceOne->nPreGlobalEndLumi() != nGlobalBeginLumi || + serviceOne->nPostGlobalEndLumi() != nGlobalBeginLumi || + serviceOne->nPreModuleGlobalBeginLumi() != nGlobalBeginLumi * kNumberOfTestModules || + serviceOne->nPostModuleGlobalBeginLumi() != nGlobalBeginLumi * kNumberOfTestModules || + serviceOne->nPreModuleGlobalEndLumi() != + nGlobalBeginLumi * kNumberOfTestModules - expectedOffsetNoGlobalEndLumi_ || + serviceOne->nPostModuleGlobalEndLumi() != + nGlobalBeginLumi * kNumberOfTestModules - expectedOffsetNoGlobalEndLumi_ || + serviceOne->nPreGlobalWriteLumi() != nGlobalBeginLumi - expectedOffsetNoWriteLumi_ || + serviceOne->nPostGlobalWriteLumi() != nGlobalBeginLumi - expectedOffsetNoWriteLumi_) { + edm::LogAbsolute("ExceptionThrowingProducer") + << "FAILED: Unexpected number of service transitions in TestServiceOne, global lumi"; + testsPass = false; + } + + if (serviceTwo->nPreGlobalBeginLumi() != nGlobalBeginLumi || + serviceTwo->nPostGlobalBeginLumi() != nGlobalBeginLumi || serviceTwo->nPreGlobalEndLumi() != nGlobalBeginLumi || + serviceTwo->nPostGlobalEndLumi() != nGlobalBeginLumi || + serviceTwo->nPreModuleGlobalBeginLumi() != nGlobalBeginLumi * kNumberOfTestModules || + serviceTwo->nPostModuleGlobalBeginLumi() != nGlobalBeginLumi * kNumberOfTestModules || + serviceTwo->nPreModuleGlobalEndLumi() != + nGlobalBeginLumi * kNumberOfTestModules - expectedOffsetNoGlobalEndLumi_ || + serviceTwo->nPostModuleGlobalEndLumi() != + nGlobalBeginLumi * kNumberOfTestModules - expectedOffsetNoGlobalEndLumi_ || + serviceTwo->nPreGlobalWriteLumi() != nGlobalBeginLumi - expectedOffsetNoWriteLumi_ || + serviceTwo->nPostGlobalWriteLumi() != nGlobalBeginLumi - expectedOffsetNoWriteLumi_) { + edm::LogAbsolute("ExceptionThrowingProducer") + << "FAILED: Unexpected number of service transitions in TestServiceTwo, global lumi"; + testsPass = false; + } + if (verbose_) { + edm::LogAbsolute("ExceptionThrowingProducer") << "nGlobalBeginLumi_ = " << nGlobalBeginLumi_; + edm::LogAbsolute("ExceptionThrowingProducer") << "nGlobalEndLumi_ = " << nGlobalEndLumi_; + + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreStreamBeginLumi = " << serviceOne->nPreStreamBeginLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostStreamBeginLumi = " << serviceOne->nPostStreamBeginLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreStreamEndLumi = " << serviceOne->nPreStreamEndLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostStreamEndLumi = " << serviceOne->nPostStreamEndLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreModuleStreamBeginLumi = " << serviceOne->nPreModuleStreamBeginLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostModuleStreamBeginLumi = " << serviceOne->nPostModuleStreamBeginLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreModuleStreamEndLumi = " << serviceOne->nPreModuleStreamEndLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostModuleStreamEndLumi = " << serviceOne->nPostModuleStreamEndLumi() << "\n"; + + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreGlobalBeginLumi = " << serviceOne->nPreGlobalBeginLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostGlobalBeginLumi = " << serviceOne->nPostGlobalBeginLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreGlobalEndLumi = " << serviceOne->nPreGlobalEndLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostGlobalEndLumi = " << serviceOne->nPostGlobalEndLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreModuleGlobalBeginLumi = " << serviceOne->nPreModuleGlobalBeginLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostModuleGlobalBeginLumi = " << serviceOne->nPostModuleGlobalBeginLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreModuleGlobalEndLumi = " << serviceOne->nPreModuleGlobalEndLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostModuleGlobalEndLumi = " << serviceOne->nPostModuleGlobalEndLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPreGlobalWriteLumi = " << serviceOne->nPreGlobalWriteLumi(); + edm::LogAbsolute("ExceptionThrowingProducer") + << "serviceOne->nPostGlobalWriteLumi = " << serviceOne->nPostGlobalWriteLumi() << "\n"; + } + if (testsPass) { edm::LogAbsolute("ExceptionThrowingProducer") << "All tests in ExceptionThrowingProducer PASSED"; } else { @@ -270,6 +380,7 @@ namespace edmtest { void ExceptionThrowingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; edm::EventID invalidEventID; + desc.addUntracked("verbose", false); desc.addUntracked("eventIDThrowOnEvent", invalidEventID); desc.addUntracked("eventIDThrowOnGlobalBeginRun", invalidEventID); desc.addUntracked("eventIDThrowOnGlobalBeginLumi", invalidEventID); @@ -282,6 +393,9 @@ namespace edmtest { desc.addUntracked("expectedStreamBeginLumi", kUnset); desc.addUntracked("expectedOffsetNoStreamEndLumi", 0); + desc.addUntracked("expectedGlobalBeginLumi", 0); + desc.addUntracked("expectedOffsetNoGlobalEndLumi", 0); + desc.addUntracked("expectedOffsetNoWriteLumi", 0); descriptions.addDefault(desc); } diff --git a/FWCore/Integration/plugins/TestServiceOne.cc b/FWCore/Integration/plugins/TestServiceOne.cc index 69be6f24e2b8a..60d861dad1716 100644 --- a/FWCore/Integration/plugins/TestServiceOne.cc +++ b/FWCore/Integration/plugins/TestServiceOne.cc @@ -14,22 +14,54 @@ #include "FWCore/Integration/plugins/TestServiceOne.h" +#include "DataFormats/Provenance/interface/ModuleDescription.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h" +#include "FWCore/ServiceRegistry/interface/GlobalContext.h" +#include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h" #include "FWCore/ServiceRegistry/interface/ServiceMaker.h" +#include "FWCore/ServiceRegistry/interface/StreamContext.h" +#include "FWCore/Utilities/interface/TimeOfDay.h" + +#include + +using edm::GlobalContext; +using edm::ModuleCallingContext; +using edm::StreamContext; + +namespace { + + class TimeStamper { + public: + TimeStamper(bool enable) : enabled_(enable) {} + + friend std::ostream& operator<<(std::ostream& out, TimeStamper const& timestamp) { + if (timestamp.enabled_) + out << std::setprecision(2) << edm::TimeOfDay() << " "; + return out; + } + + private: + bool enabled_; + }; + + const char* globalIndent = " "; + const char* globalModuleIndent = " "; + const char* streamIndent = " "; + const char* streamModuleIndent = " "; +} // namespace namespace edmtest { TestServiceOne::TestServiceOne(edm::ParameterSet const& iPS, edm::ActivityRegistry& iRegistry) - : verbose_(iPS.getUntrackedParameter("verbose")) { + : verbose_(iPS.getUntrackedParameter("verbose")), + printTimestamps_(iPS.getUntrackedParameter("printTimestamps")) { iRegistry.watchPreBeginProcessBlock(this, &TestServiceOne::preBeginProcessBlock); iRegistry.watchPreEndProcessBlock(this, &TestServiceOne::preEndProcessBlock); iRegistry.watchPreGlobalBeginRun(this, &TestServiceOne::preGlobalBeginRun); iRegistry.watchPreGlobalEndRun(this, &TestServiceOne::preGlobalEndRun); - iRegistry.watchPreGlobalBeginLumi(this, &TestServiceOne::preGlobalBeginLumi); - iRegistry.watchPreGlobalEndLumi(this, &TestServiceOne::preGlobalEndLumi); iRegistry.watchPreStreamBeginLumi(this, &TestServiceOne::preStreamBeginLumi); iRegistry.watchPostStreamBeginLumi(this, &TestServiceOne::postStreamBeginLumi); @@ -40,103 +72,224 @@ namespace edmtest { iRegistry.watchPostModuleStreamBeginLumi(this, &TestServiceOne::postModuleStreamBeginLumi); iRegistry.watchPreModuleStreamEndLumi(this, &TestServiceOne::preModuleStreamEndLumi); iRegistry.watchPostModuleStreamEndLumi(this, &TestServiceOne::postModuleStreamEndLumi); + + iRegistry.watchPreGlobalBeginLumi(this, &TestServiceOne::preGlobalBeginLumi); + iRegistry.watchPostGlobalBeginLumi(this, &TestServiceOne::postGlobalBeginLumi); + iRegistry.watchPreGlobalEndLumi(this, &TestServiceOne::preGlobalEndLumi); + iRegistry.watchPostGlobalEndLumi(this, &TestServiceOne::postGlobalEndLumi); + + iRegistry.watchPreModuleGlobalBeginLumi(this, &TestServiceOne::preModuleGlobalBeginLumi); + iRegistry.watchPostModuleGlobalBeginLumi(this, &TestServiceOne::postModuleGlobalBeginLumi); + iRegistry.watchPreModuleGlobalEndLumi(this, &TestServiceOne::preModuleGlobalEndLumi); + iRegistry.watchPostModuleGlobalEndLumi(this, &TestServiceOne::postModuleGlobalEndLumi); + + iRegistry.watchPreGlobalWriteLumi(this, &TestServiceOne::preGlobalWriteLumi); + iRegistry.watchPostGlobalWriteLumi(this, &TestServiceOne::postGlobalWriteLumi); } void TestServiceOne::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.addUntracked("verbose", false)->setComment("Prints LogAbsolute messages if true"); + desc.addUntracked("verbose", false)->setComment("Prints LogAbsolute messages for every transition"); + desc.addUntracked("printTimestamps", false) + ->setComment("Include a time stamp in message printed for every transition"); descriptions.add("TestServiceOne", desc); } - void TestServiceOne::preBeginProcessBlock(edm::GlobalContext const&) { + void TestServiceOne::preBeginProcessBlock(GlobalContext const&) { if (verbose_) { edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preBeginProcessBlock"; } } - void TestServiceOne::preEndProcessBlock(edm::GlobalContext const&) { + void TestServiceOne::preEndProcessBlock(GlobalContext const&) { if (verbose_) { edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preEndProcessBlock"; } } - void TestServiceOne::preGlobalBeginRun(edm::GlobalContext const&) { + void TestServiceOne::preGlobalBeginRun(GlobalContext const&) { if (verbose_) { edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preGlobalBeginRun"; } } - void TestServiceOne::preGlobalEndRun(edm::GlobalContext const&) { + void TestServiceOne::preGlobalEndRun(GlobalContext const&) { if (verbose_) { edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preGlobalEndRun"; } } - void TestServiceOne::preGlobalBeginLumi(edm::GlobalContext const&) { - if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preGlobalBeginLumi"; - } - } - - void TestServiceOne::preGlobalEndLumi(edm::GlobalContext const&) { - if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preGlobalEndLumi"; - } - } - - void TestServiceOne::preStreamBeginLumi(edm::StreamContext const&) { + void TestServiceOne::preStreamBeginLumi(StreamContext const& sc) { ++nPreStreamBeginLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preStreamBeginLumi"; + edm::LogAbsolute out("TestServiceOne"); + out << streamIndent << "TestServiceOne::preStreamBeginLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " run = " << sc.eventID().run() + << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceOne::postStreamBeginLumi(edm::StreamContext const&) { + void TestServiceOne::postStreamBeginLumi(StreamContext const& sc) { ++nPostStreamBeginLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::postStreamBeginLumi"; + edm::LogAbsolute out("TestServiceOne"); + out << streamIndent << "TestServiceOne::postStreamBeginLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " run = " << sc.eventID().run() + << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceOne::preStreamEndLumi(edm::StreamContext const&) { + void TestServiceOne::preStreamEndLumi(StreamContext const& sc) { ++nPreStreamEndLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preStreamEndLumi"; + edm::LogAbsolute out("TestServiceOne"); + out << streamIndent << "TestServiceOne::preStreamEndLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " run = " << sc.eventID().run() + << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceOne::postStreamEndLumi(edm::StreamContext const&) { + void TestServiceOne::postStreamEndLumi(StreamContext const& sc) { ++nPostStreamEndLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::postStreamEndLumi"; + edm::LogAbsolute out("TestServiceOne"); + out << streamIndent << "TestServiceOne::postStreamEndLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " run = " << sc.eventID().run() + << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceOne::preModuleStreamBeginLumi(edm::StreamContext const&, edm::ModuleCallingContext const&) { + void TestServiceOne::preModuleStreamBeginLumi(StreamContext const& sc, ModuleCallingContext const& mcc) { ++nPreModuleStreamBeginLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preModuleStreamBeginLumi"; + edm::LogAbsolute out("TestServiceOne"); + out << streamModuleIndent << "TestServiceOne::preModuleStreamBeginLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " label = " << mcc.moduleDescription()->moduleLabel() + << " run = " << sc.eventID().run() << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceOne::postModuleStreamBeginLumi(edm::StreamContext const&, edm::ModuleCallingContext const&) { + void TestServiceOne::postModuleStreamBeginLumi(StreamContext const& sc, ModuleCallingContext const& mcc) { ++nPostModuleStreamBeginLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::postModuleStreamBeginLumi"; + edm::LogAbsolute out("TestServiceOne"); + out << streamModuleIndent << "TestServiceOne::postModuleStreamBeginLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " label = " << mcc.moduleDescription()->moduleLabel() + << " run = " << sc.eventID().run() << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceOne::preModuleStreamEndLumi(edm::StreamContext const&, edm::ModuleCallingContext const&) { + void TestServiceOne::preModuleStreamEndLumi(StreamContext const& sc, ModuleCallingContext const& mcc) { ++nPreModuleStreamEndLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::preModuleStreamEndLumi"; + edm::LogAbsolute out("TestServiceOne"); + out << streamModuleIndent << "TestServiceOne::preModuleStreamEndLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " label = " << mcc.moduleDescription()->moduleLabel() + << " run = " << sc.eventID().run() << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceOne::postModuleStreamEndLumi(edm::StreamContext const&, edm::ModuleCallingContext const&) { + void TestServiceOne::postModuleStreamEndLumi(StreamContext const& sc, ModuleCallingContext const& mcc) { ++nPostModuleStreamEndLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceOne") << "test message from TestServiceOne::postModuleStreamEndLumi"; + edm::LogAbsolute out("TestServiceOne"); + out << streamModuleIndent << "TestServiceOne::postModuleStreamEndLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " label = " << mcc.moduleDescription()->moduleLabel() + << " run = " << sc.eventID().run() << " lumi = " << sc.eventID().luminosityBlock(); + } + } + + void TestServiceOne::preGlobalBeginLumi(GlobalContext const& gc) { + ++nPreGlobalBeginLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalIndent << "TestServiceOne::preGlobalBeginLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::postGlobalBeginLumi(GlobalContext const& gc) { + ++nPostGlobalBeginLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalIndent << "TestServiceOne::postGlobalBeginLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::preGlobalEndLumi(GlobalContext const& gc) { + ++nPreGlobalEndLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalIndent << "TestServiceOne::preGlobalEndLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::postGlobalEndLumi(GlobalContext const& gc) { + ++nPostGlobalEndLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalIndent << "TestServiceOne::postGlobalEndLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::preModuleGlobalBeginLumi(GlobalContext const& gc, ModuleCallingContext const& mcc) { + ++nPreModuleGlobalBeginLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalModuleIndent << "TestServiceOne::preModuleGlobalBeginLumi " << TimeStamper(printTimestamps_) + << " label = " << mcc.moduleDescription()->moduleLabel() << " run = " << gc.luminosityBlockID().run() + << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::postModuleGlobalBeginLumi(GlobalContext const& gc, ModuleCallingContext const& mcc) { + ++nPostModuleGlobalBeginLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalModuleIndent << "TestServiceOne::postModuleGlobalBeginLumi " << TimeStamper(printTimestamps_) + << " label = " << mcc.moduleDescription()->moduleLabel() << " run = " << gc.luminosityBlockID().run() + << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::preModuleGlobalEndLumi(GlobalContext const& gc, ModuleCallingContext const& mcc) { + ++nPreModuleGlobalEndLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalModuleIndent << "TestServiceOne::preModuleGlobalEndLumi " << TimeStamper(printTimestamps_) + << " label = " << mcc.moduleDescription()->moduleLabel() << " run = " << gc.luminosityBlockID().run() + << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::postModuleGlobalEndLumi(GlobalContext const& gc, ModuleCallingContext const& mcc) { + ++nPostModuleGlobalEndLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalModuleIndent << "TestServiceOne::postModuleGlobalEndLumi " << TimeStamper(printTimestamps_) + << " label = " << mcc.moduleDescription()->moduleLabel() << " run = " << gc.luminosityBlockID().run() + << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::preGlobalWriteLumi(GlobalContext const& gc) { + ++nPreGlobalWriteLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalIndent << "TestServiceOne::preGlobalWriteLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceOne::postGlobalWriteLumi(GlobalContext const& gc) { + ++nPostGlobalWriteLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceOne"); + out << globalIndent << "TestServiceOne::postGlobalWriteLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); } } @@ -149,6 +302,19 @@ namespace edmtest { unsigned int TestServiceOne::nPostModuleStreamBeginLumi() const { return nPostModuleStreamBeginLumi_.load(); } unsigned int TestServiceOne::nPreModuleStreamEndLumi() const { return nPreModuleStreamEndLumi_.load(); } unsigned int TestServiceOne::nPostModuleStreamEndLumi() const { return nPostModuleStreamEndLumi_.load(); } + + unsigned int TestServiceOne::nPreGlobalBeginLumi() const { return nPreGlobalBeginLumi_.load(); } + unsigned int TestServiceOne::nPostGlobalBeginLumi() const { return nPostGlobalBeginLumi_.load(); } + unsigned int TestServiceOne::nPreGlobalEndLumi() const { return nPreGlobalEndLumi_.load(); } + unsigned int TestServiceOne::nPostGlobalEndLumi() const { return nPostGlobalEndLumi_.load(); } + + unsigned int TestServiceOne::nPreModuleGlobalBeginLumi() const { return nPreModuleGlobalBeginLumi_.load(); } + unsigned int TestServiceOne::nPostModuleGlobalBeginLumi() const { return nPostModuleGlobalBeginLumi_.load(); } + unsigned int TestServiceOne::nPreModuleGlobalEndLumi() const { return nPreModuleGlobalEndLumi_.load(); } + unsigned int TestServiceOne::nPostModuleGlobalEndLumi() const { return nPostModuleGlobalEndLumi_.load(); } + + unsigned int TestServiceOne::nPreGlobalWriteLumi() const { return nPreGlobalWriteLumi_.load(); } + unsigned int TestServiceOne::nPostGlobalWriteLumi() const { return nPostGlobalWriteLumi_.load(); } } // namespace edmtest using edmtest::TestServiceOne; diff --git a/FWCore/Integration/plugins/TestServiceOne.h b/FWCore/Integration/plugins/TestServiceOne.h index d438a7b0be196..0d6e251ad41fc 100644 --- a/FWCore/Integration/plugins/TestServiceOne.h +++ b/FWCore/Integration/plugins/TestServiceOne.h @@ -33,8 +33,6 @@ namespace edmtest { void preGlobalBeginRun(edm::GlobalContext const&); void preGlobalEndRun(edm::GlobalContext const&); - void preGlobalBeginLumi(edm::GlobalContext const&); - void preGlobalEndLumi(edm::GlobalContext const&); void preStreamBeginLumi(edm::StreamContext const&); void postStreamBeginLumi(edm::StreamContext const&); @@ -46,6 +44,19 @@ namespace edmtest { void preModuleStreamEndLumi(edm::StreamContext const&, edm::ModuleCallingContext const&); void postModuleStreamEndLumi(edm::StreamContext const&, edm::ModuleCallingContext const&); + void preGlobalBeginLumi(edm::GlobalContext const&); + void postGlobalBeginLumi(edm::GlobalContext const&); + void preGlobalEndLumi(edm::GlobalContext const&); + void postGlobalEndLumi(edm::GlobalContext const&); + + void preModuleGlobalBeginLumi(edm::GlobalContext const&, edm::ModuleCallingContext const&); + void postModuleGlobalBeginLumi(edm::GlobalContext const&, edm::ModuleCallingContext const&); + void preModuleGlobalEndLumi(edm::GlobalContext const&, edm::ModuleCallingContext const&); + void postModuleGlobalEndLumi(edm::GlobalContext const&, edm::ModuleCallingContext const&); + + void preGlobalWriteLumi(edm::GlobalContext const&); + void postGlobalWriteLumi(edm::GlobalContext const&); + unsigned int nPreStreamBeginLumi() const; unsigned int nPostStreamBeginLumi() const; unsigned int nPreStreamEndLumi() const; @@ -56,8 +67,22 @@ namespace edmtest { unsigned int nPreModuleStreamEndLumi() const; unsigned int nPostModuleStreamEndLumi() const; + unsigned int nPreGlobalBeginLumi() const; + unsigned int nPostGlobalBeginLumi() const; + unsigned int nPreGlobalEndLumi() const; + unsigned int nPostGlobalEndLumi() const; + + unsigned int nPreModuleGlobalBeginLumi() const; + unsigned int nPostModuleGlobalBeginLumi() const; + unsigned int nPreModuleGlobalEndLumi() const; + unsigned int nPostModuleGlobalEndLumi() const; + + unsigned int nPreGlobalWriteLumi() const; + unsigned int nPostGlobalWriteLumi() const; + private: bool verbose_; + bool printTimestamps_; std::atomic nPreStreamBeginLumi_ = 0; std::atomic nPostStreamBeginLumi_ = 0; @@ -68,6 +93,19 @@ namespace edmtest { std::atomic nPostModuleStreamBeginLumi_ = 0; std::atomic nPreModuleStreamEndLumi_ = 0; std::atomic nPostModuleStreamEndLumi_ = 0; + + std::atomic nPreGlobalBeginLumi_ = 0; + std::atomic nPostGlobalBeginLumi_ = 0; + std::atomic nPreGlobalEndLumi_ = 0; + std::atomic nPostGlobalEndLumi_ = 0; + + std::atomic nPreModuleGlobalBeginLumi_ = 0; + std::atomic nPostModuleGlobalBeginLumi_ = 0; + std::atomic nPreModuleGlobalEndLumi_ = 0; + std::atomic nPostModuleGlobalEndLumi_ = 0; + + std::atomic nPreGlobalWriteLumi_ = 0; + std::atomic nPostGlobalWriteLumi_ = 0; }; } // namespace edmtest #endif diff --git a/FWCore/Integration/plugins/TestServiceTwo.cc b/FWCore/Integration/plugins/TestServiceTwo.cc index 69676c5584624..9ff18a059b66f 100644 --- a/FWCore/Integration/plugins/TestServiceTwo.cc +++ b/FWCore/Integration/plugins/TestServiceTwo.cc @@ -14,22 +14,54 @@ #include "FWCore/Integration/plugins/TestServiceTwo.h" +#include "DataFormats/Provenance/interface/ModuleDescription.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h" +#include "FWCore/ServiceRegistry/interface/GlobalContext.h" +#include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h" #include "FWCore/ServiceRegistry/interface/ServiceMaker.h" +#include "FWCore/ServiceRegistry/interface/StreamContext.h" +#include "FWCore/Utilities/interface/TimeOfDay.h" + +#include + +using edm::GlobalContext; +using edm::ModuleCallingContext; +using edm::StreamContext; + +namespace { + + class TimeStamper { + public: + TimeStamper(bool enable) : enabled_(enable) {} + + friend std::ostream& operator<<(std::ostream& out, TimeStamper const& timestamp) { + if (timestamp.enabled_) + out << std::setprecision(2) << edm::TimeOfDay() << " "; + return out; + } + + private: + bool enabled_; + }; + + const char* globalIndent = " "; + const char* globalModuleIndent = " "; + const char* streamIndent = " "; + const char* streamModuleIndent = " "; +} // namespace namespace edmtest { TestServiceTwo::TestServiceTwo(edm::ParameterSet const& iPS, edm::ActivityRegistry& iRegistry) - : verbose_(iPS.getUntrackedParameter("verbose")) { + : verbose_(iPS.getUntrackedParameter("verbose")), + printTimestamps_(iPS.getUntrackedParameter("printTimestamps")) { iRegistry.watchPreBeginProcessBlock(this, &TestServiceTwo::preBeginProcessBlock); iRegistry.watchPreEndProcessBlock(this, &TestServiceTwo::preEndProcessBlock); iRegistry.watchPreGlobalBeginRun(this, &TestServiceTwo::preGlobalBeginRun); iRegistry.watchPreGlobalEndRun(this, &TestServiceTwo::preGlobalEndRun); - iRegistry.watchPreGlobalBeginLumi(this, &TestServiceTwo::preGlobalBeginLumi); - iRegistry.watchPreGlobalEndLumi(this, &TestServiceTwo::preGlobalEndLumi); iRegistry.watchPreStreamBeginLumi(this, &TestServiceTwo::preStreamBeginLumi); iRegistry.watchPostStreamBeginLumi(this, &TestServiceTwo::postStreamBeginLumi); @@ -40,103 +72,224 @@ namespace edmtest { iRegistry.watchPostModuleStreamBeginLumi(this, &TestServiceTwo::postModuleStreamBeginLumi); iRegistry.watchPreModuleStreamEndLumi(this, &TestServiceTwo::preModuleStreamEndLumi); iRegistry.watchPostModuleStreamEndLumi(this, &TestServiceTwo::postModuleStreamEndLumi); + + iRegistry.watchPreGlobalBeginLumi(this, &TestServiceTwo::preGlobalBeginLumi); + iRegistry.watchPostGlobalBeginLumi(this, &TestServiceTwo::postGlobalBeginLumi); + iRegistry.watchPreGlobalEndLumi(this, &TestServiceTwo::preGlobalEndLumi); + iRegistry.watchPostGlobalEndLumi(this, &TestServiceTwo::postGlobalEndLumi); + + iRegistry.watchPreModuleGlobalBeginLumi(this, &TestServiceTwo::preModuleGlobalBeginLumi); + iRegistry.watchPostModuleGlobalBeginLumi(this, &TestServiceTwo::postModuleGlobalBeginLumi); + iRegistry.watchPreModuleGlobalEndLumi(this, &TestServiceTwo::preModuleGlobalEndLumi); + iRegistry.watchPostModuleGlobalEndLumi(this, &TestServiceTwo::postModuleGlobalEndLumi); + + iRegistry.watchPreGlobalWriteLumi(this, &TestServiceTwo::preGlobalWriteLumi); + iRegistry.watchPostGlobalWriteLumi(this, &TestServiceTwo::postGlobalWriteLumi); } void TestServiceTwo::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.addUntracked("verbose", false)->setComment("Prints LogAbsolute messages if true"); + desc.addUntracked("verbose", false)->setComment("Prints LogAbsolute messages for every transition"); + desc.addUntracked("printTimestamps", false) + ->setComment("Include a time stamp in message printed for every transition"); descriptions.add("TestServiceTwo", desc); } - void TestServiceTwo::preBeginProcessBlock(edm::GlobalContext const&) { + void TestServiceTwo::preBeginProcessBlock(GlobalContext const&) { if (verbose_) { edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preBeginProcessBlock"; } } - void TestServiceTwo::preEndProcessBlock(edm::GlobalContext const&) { + void TestServiceTwo::preEndProcessBlock(GlobalContext const&) { if (verbose_) { edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preEndProcessBlock"; } } - void TestServiceTwo::preGlobalBeginRun(edm::GlobalContext const&) { + void TestServiceTwo::preGlobalBeginRun(GlobalContext const&) { if (verbose_) { edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preGlobalBeginRun"; } } - void TestServiceTwo::preGlobalEndRun(edm::GlobalContext const&) { + void TestServiceTwo::preGlobalEndRun(GlobalContext const&) { if (verbose_) { edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preGlobalEndRun"; } } - void TestServiceTwo::preGlobalBeginLumi(edm::GlobalContext const&) { - if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preGlobalBeginLumi"; - } - } - - void TestServiceTwo::preGlobalEndLumi(edm::GlobalContext const&) { - if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preGlobalEndLumi"; - } - } - - void TestServiceTwo::preStreamBeginLumi(edm::StreamContext const&) { + void TestServiceTwo::preStreamBeginLumi(StreamContext const& sc) { ++nPreStreamBeginLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preStreamBeginLumi"; + edm::LogAbsolute out("TestServiceTwo"); + out << streamIndent << "TestServiceTwo::preStreamBeginLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " run = " << sc.eventID().run() + << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceTwo::postStreamBeginLumi(edm::StreamContext const&) { + void TestServiceTwo::postStreamBeginLumi(StreamContext const& sc) { ++nPostStreamBeginLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::postStreamBeginLumi"; + edm::LogAbsolute out("TestServiceTwo"); + out << streamIndent << "TestServiceTwo::postStreamBeginLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " run = " << sc.eventID().run() + << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceTwo::preStreamEndLumi(edm::StreamContext const&) { + void TestServiceTwo::preStreamEndLumi(StreamContext const& sc) { ++nPreStreamEndLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preStreamEndLumi"; + edm::LogAbsolute out("TestServiceTwo"); + out << streamIndent << "TestServiceTwo::preStreamEndLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " run = " << sc.eventID().run() + << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceTwo::postStreamEndLumi(edm::StreamContext const&) { + void TestServiceTwo::postStreamEndLumi(StreamContext const& sc) { ++nPostStreamEndLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::postStreamEndLumi"; + edm::LogAbsolute out("TestServiceTwo"); + out << streamIndent << "TestServiceTwo::postStreamEndLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " run = " << sc.eventID().run() + << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceTwo::preModuleStreamBeginLumi(edm::StreamContext const&, edm::ModuleCallingContext const&) { + void TestServiceTwo::preModuleStreamBeginLumi(StreamContext const& sc, ModuleCallingContext const& mcc) { ++nPreModuleStreamBeginLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preModuleStreamBeginLumi"; + edm::LogAbsolute out("TestServiceTwo"); + out << streamModuleIndent << "TestServiceTwo::preModuleStreamBeginLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " label = " << mcc.moduleDescription()->moduleLabel() + << " run = " << sc.eventID().run() << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceTwo::postModuleStreamBeginLumi(edm::StreamContext const&, edm::ModuleCallingContext const&) { + void TestServiceTwo::postModuleStreamBeginLumi(StreamContext const& sc, ModuleCallingContext const& mcc) { ++nPostModuleStreamBeginLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::postModuleStreamBeginLumi"; + edm::LogAbsolute out("TestServiceTwo"); + out << streamModuleIndent << "TestServiceTwo::postModuleStreamBeginLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " label = " << mcc.moduleDescription()->moduleLabel() + << " run = " << sc.eventID().run() << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceTwo::preModuleStreamEndLumi(edm::StreamContext const&, edm::ModuleCallingContext const&) { + void TestServiceTwo::preModuleStreamEndLumi(StreamContext const& sc, ModuleCallingContext const& mcc) { ++nPreModuleStreamEndLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::preModuleStreamEndLumi"; + edm::LogAbsolute out("TestServiceTwo"); + out << streamModuleIndent << "TestServiceTwo::preModuleStreamEndLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " label = " << mcc.moduleDescription()->moduleLabel() + << " run = " << sc.eventID().run() << " lumi = " << sc.eventID().luminosityBlock(); } } - void TestServiceTwo::postModuleStreamEndLumi(edm::StreamContext const&, edm::ModuleCallingContext const&) { + void TestServiceTwo::postModuleStreamEndLumi(StreamContext const& sc, ModuleCallingContext const& mcc) { ++nPostModuleStreamEndLumi_; if (verbose_) { - edm::LogAbsolute("TestServiceTwo") << "test message from TestServiceTwo::postModuleStreamEndLumi"; + edm::LogAbsolute out("TestServiceTwo"); + out << streamModuleIndent << "TestServiceTwo::postModuleStreamEndLumi " << TimeStamper(printTimestamps_) + << " stream = " << sc.streamID() << " label = " << mcc.moduleDescription()->moduleLabel() + << " run = " << sc.eventID().run() << " lumi = " << sc.eventID().luminosityBlock(); + } + } + + void TestServiceTwo::preGlobalBeginLumi(GlobalContext const& gc) { + ++nPreGlobalBeginLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalIndent << "TestServiceTwo::preGlobalBeginLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::postGlobalBeginLumi(GlobalContext const& gc) { + ++nPostGlobalBeginLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalIndent << "TestServiceTwo::postGlobalBeginLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::preGlobalEndLumi(GlobalContext const& gc) { + ++nPreGlobalEndLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalIndent << "TestServiceTwo::preGlobalEndLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::postGlobalEndLumi(GlobalContext const& gc) { + ++nPostGlobalEndLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalIndent << "TestServiceTwo::postGlobalEndLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::preModuleGlobalBeginLumi(GlobalContext const& gc, ModuleCallingContext const& mcc) { + ++nPreModuleGlobalBeginLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalModuleIndent << "TestServiceTwo::preModuleGlobalBeginLumi " << TimeStamper(printTimestamps_) + << " label = " << mcc.moduleDescription()->moduleLabel() << " run = " << gc.luminosityBlockID().run() + << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::postModuleGlobalBeginLumi(GlobalContext const& gc, ModuleCallingContext const& mcc) { + ++nPostModuleGlobalBeginLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalModuleIndent << "TestServiceTwo::postModuleGlobalBeginLumi " << TimeStamper(printTimestamps_) + << " label = " << mcc.moduleDescription()->moduleLabel() << " run = " << gc.luminosityBlockID().run() + << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::preModuleGlobalEndLumi(GlobalContext const& gc, ModuleCallingContext const& mcc) { + ++nPreModuleGlobalEndLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalModuleIndent << "TestServiceTwo::preModuleGlobalEndLumi " << TimeStamper(printTimestamps_) + << " label = " << mcc.moduleDescription()->moduleLabel() << " run = " << gc.luminosityBlockID().run() + << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::postModuleGlobalEndLumi(GlobalContext const& gc, ModuleCallingContext const& mcc) { + ++nPostModuleGlobalEndLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalModuleIndent << "TestServiceTwo::postModuleGlobalEndLumi " << TimeStamper(printTimestamps_) + << " label = " << mcc.moduleDescription()->moduleLabel() << " run = " << gc.luminosityBlockID().run() + << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::preGlobalWriteLumi(GlobalContext const& gc) { + ++nPreGlobalWriteLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalIndent << "TestServiceTwo::preGlobalWriteLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); + } + } + + void TestServiceTwo::postGlobalWriteLumi(GlobalContext const& gc) { + ++nPostGlobalWriteLumi_; + if (verbose_) { + edm::LogAbsolute out("TestServiceTwo"); + out << globalIndent << "TestServiceTwo::postGlobalWriteLumi " << TimeStamper(printTimestamps_) + << " run = " << gc.luminosityBlockID().run() << " lumi = " << gc.luminosityBlockID().luminosityBlock(); } } @@ -149,6 +302,19 @@ namespace edmtest { unsigned int TestServiceTwo::nPostModuleStreamBeginLumi() const { return nPostModuleStreamBeginLumi_.load(); } unsigned int TestServiceTwo::nPreModuleStreamEndLumi() const { return nPreModuleStreamEndLumi_.load(); } unsigned int TestServiceTwo::nPostModuleStreamEndLumi() const { return nPostModuleStreamEndLumi_.load(); } + + unsigned int TestServiceTwo::nPreGlobalBeginLumi() const { return nPreGlobalBeginLumi_.load(); } + unsigned int TestServiceTwo::nPostGlobalBeginLumi() const { return nPostGlobalBeginLumi_.load(); } + unsigned int TestServiceTwo::nPreGlobalEndLumi() const { return nPreGlobalEndLumi_.load(); } + unsigned int TestServiceTwo::nPostGlobalEndLumi() const { return nPostGlobalEndLumi_.load(); } + + unsigned int TestServiceTwo::nPreModuleGlobalBeginLumi() const { return nPreModuleGlobalBeginLumi_.load(); } + unsigned int TestServiceTwo::nPostModuleGlobalBeginLumi() const { return nPostModuleGlobalBeginLumi_.load(); } + unsigned int TestServiceTwo::nPreModuleGlobalEndLumi() const { return nPreModuleGlobalEndLumi_.load(); } + unsigned int TestServiceTwo::nPostModuleGlobalEndLumi() const { return nPostModuleGlobalEndLumi_.load(); } + + unsigned int TestServiceTwo::nPreGlobalWriteLumi() const { return nPreGlobalWriteLumi_.load(); } + unsigned int TestServiceTwo::nPostGlobalWriteLumi() const { return nPostGlobalWriteLumi_.load(); } } // namespace edmtest using edmtest::TestServiceTwo; diff --git a/FWCore/Integration/plugins/TestServiceTwo.h b/FWCore/Integration/plugins/TestServiceTwo.h index ecd3be18967d5..03841e1ce5014 100644 --- a/FWCore/Integration/plugins/TestServiceTwo.h +++ b/FWCore/Integration/plugins/TestServiceTwo.h @@ -11,6 +11,11 @@ // library and could be used to access the service if it was ever useful // for debugging issues related to begin/end transitions. // +// This is almost identical to TestServiceOne. It was initially used to +// test that after a signal all services get executed even if one of the +// service functions throws. +// +// // Original Author: W. David Dagenhart // Created: 13 March 2024 @@ -33,8 +38,6 @@ namespace edmtest { void preGlobalBeginRun(edm::GlobalContext const&); void preGlobalEndRun(edm::GlobalContext const&); - void preGlobalBeginLumi(edm::GlobalContext const&); - void preGlobalEndLumi(edm::GlobalContext const&); void preStreamBeginLumi(edm::StreamContext const&); void postStreamBeginLumi(edm::StreamContext const&); @@ -46,6 +49,19 @@ namespace edmtest { void preModuleStreamEndLumi(edm::StreamContext const&, edm::ModuleCallingContext const&); void postModuleStreamEndLumi(edm::StreamContext const&, edm::ModuleCallingContext const&); + void preGlobalBeginLumi(edm::GlobalContext const&); + void postGlobalBeginLumi(edm::GlobalContext const&); + void preGlobalEndLumi(edm::GlobalContext const&); + void postGlobalEndLumi(edm::GlobalContext const&); + + void preModuleGlobalBeginLumi(edm::GlobalContext const&, edm::ModuleCallingContext const&); + void postModuleGlobalBeginLumi(edm::GlobalContext const&, edm::ModuleCallingContext const&); + void preModuleGlobalEndLumi(edm::GlobalContext const&, edm::ModuleCallingContext const&); + void postModuleGlobalEndLumi(edm::GlobalContext const&, edm::ModuleCallingContext const&); + + void preGlobalWriteLumi(edm::GlobalContext const&); + void postGlobalWriteLumi(edm::GlobalContext const&); + unsigned int nPreStreamBeginLumi() const; unsigned int nPostStreamBeginLumi() const; unsigned int nPreStreamEndLumi() const; @@ -56,8 +72,22 @@ namespace edmtest { unsigned int nPreModuleStreamEndLumi() const; unsigned int nPostModuleStreamEndLumi() const; + unsigned int nPreGlobalBeginLumi() const; + unsigned int nPostGlobalBeginLumi() const; + unsigned int nPreGlobalEndLumi() const; + unsigned int nPostGlobalEndLumi() const; + + unsigned int nPreModuleGlobalBeginLumi() const; + unsigned int nPostModuleGlobalBeginLumi() const; + unsigned int nPreModuleGlobalEndLumi() const; + unsigned int nPostModuleGlobalEndLumi() const; + + unsigned int nPreGlobalWriteLumi() const; + unsigned int nPostGlobalWriteLumi() const; + private: bool verbose_; + bool printTimestamps_; std::atomic nPreStreamBeginLumi_ = 0; std::atomic nPostStreamBeginLumi_ = 0; @@ -68,6 +98,19 @@ namespace edmtest { std::atomic nPostModuleStreamBeginLumi_ = 0; std::atomic nPreModuleStreamEndLumi_ = 0; std::atomic nPostModuleStreamEndLumi_ = 0; + + std::atomic nPreGlobalBeginLumi_ = 0; + std::atomic nPostGlobalBeginLumi_ = 0; + std::atomic nPreGlobalEndLumi_ = 0; + std::atomic nPostGlobalEndLumi_ = 0; + + std::atomic nPreModuleGlobalBeginLumi_ = 0; + std::atomic nPostModuleGlobalBeginLumi_ = 0; + std::atomic nPreModuleGlobalEndLumi_ = 0; + std::atomic nPostModuleGlobalEndLumi_ = 0; + + std::atomic nPreGlobalWriteLumi_ = 0; + std::atomic nPostGlobalWriteLumi_ = 0; }; } // namespace edmtest #endif diff --git a/FWCore/Integration/test/testFrameworkExceptionHandling_cfg.py b/FWCore/Integration/test/testFrameworkExceptionHandling_cfg.py index ffc16617d670b..8e4bc1847c0f8 100644 --- a/FWCore/Integration/test/testFrameworkExceptionHandling_cfg.py +++ b/FWCore/Integration/test/testFrameworkExceptionHandling_cfg.py @@ -23,11 +23,13 @@ from FWCore.ParameterSet.VarParsing import VarParsing process.TestServiceOne = cms.Service("TestServiceOne", - verbose = cms.untracked.bool(False) + verbose = cms.untracked.bool(False), + printTimestamps = cms.untracked.bool(True) ) process.TestServiceTwo = cms.Service("TestServiceTwo", - verbose = cms.untracked.bool(False) + verbose = cms.untracked.bool(False), + printTimestamps = cms.untracked.bool(True) ) options = VarParsing() @@ -75,10 +77,18 @@ process.throwException.eventIDThrowOnGlobalBeginRun = cms.untracked.EventID(4, 0, 0) elif options.testNumber == 3: process.throwException.eventIDThrowOnGlobalBeginLumi = cms.untracked.EventID(4, 1, 0) + process.throwException.expectedGlobalBeginLumi = cms.untracked.uint32(4) + process.throwException.expectedOffsetNoGlobalEndLumi = cms.untracked.uint32(1) + process.throwException.expectedOffsetNoWriteLumi = cms.untracked.uint32(1) + process.doNotThrowException.expectedOffsetNoGlobalEndLumi = cms.untracked.uint32(1) + process.doNotThrowException.expectedOffsetNoWriteLumi = cms.untracked.uint32(1) elif options.testNumber == 4: process.throwException.eventIDThrowOnGlobalEndRun = cms.untracked.EventID(3, 0, 0) elif options.testNumber == 5: process.throwException.eventIDThrowOnGlobalEndLumi = cms.untracked.EventID(3, 1, 0) + process.throwException.expectedGlobalBeginLumi = cms.untracked.uint32(3) + process.throwException.expectedOffsetNoWriteLumi = cms.untracked.uint32(1) + process.doNotThrowException.expectedOffsetNoWriteLumi = cms.untracked.uint32(1) elif options.testNumber == 6: process.throwException.eventIDThrowOnStreamBeginRun = cms.untracked.EventID(4, 0, 0) elif options.testNumber == 7: