Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:23

0001 #ifndef FWCore_Framework_LuminosityBlockProcessingStatus_h
0002 #define FWCore_Framework_LuminosityBlockProcessingStatus_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     LuminosityBlockProcessingStatus
0007 //
0008 /**\class edm::LuminosityBlockProcessingStatus
0009 
0010  Description: Keep status information about one LuminosityBlock transition
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  root
0018 //         Created:  Tue, 19 Dec 2017 14:24:57 GMT
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include <atomic>
0024 #include <vector>
0025 
0026 // user include files
0027 #include "DataFormats/Provenance/interface/Timestamp.h"
0028 #include "FWCore/Concurrency/interface/LimitedTaskQueue.h"
0029 #include "FWCore/Concurrency/interface/WaitingTaskList.h"
0030 #include "FWCore/Framework/interface/EventSetup.h"
0031 #include "FWCore/Framework/interface/IOVSyncValue.h"
0032 
0033 // forward declarations
0034 namespace edm {
0035 #if !defined(TEST_NO_FWD_DECL)
0036   class LuminosityBlockPrincipal;
0037   class LuminosityBlockProcessingStatus;
0038 #endif
0039 
0040   class LuminosityBlockProcessingStatus {
0041   public:
0042     LuminosityBlockProcessingStatus() = default;
0043 
0044     LuminosityBlockProcessingStatus(LuminosityBlockProcessingStatus const&) = delete;
0045     LuminosityBlockProcessingStatus const& operator=(LuminosityBlockProcessingStatus const&) = delete;
0046 
0047     ~LuminosityBlockProcessingStatus() { endIOVWaitingTasks_.doneWaiting(std::exception_ptr{}); }
0048 
0049     void setResumer(LimitedTaskQueue::Resumer iResumer) { globalLumiQueueResumer_ = std::move(iResumer); }
0050     void resumeGlobalLumiQueue() {
0051       //free lumi for next usage
0052       lumiPrincipal_.reset();
0053       globalLumiQueueResumer_.resume();
0054     }
0055 
0056     void resetResources();
0057 
0058     std::shared_ptr<LuminosityBlockPrincipal>& lumiPrincipal() { return lumiPrincipal_; }
0059     void setLumiPrincipal(std::shared_ptr<LuminosityBlockPrincipal> val) { lumiPrincipal_ = std::move(val); }
0060 
0061     EventSetupImpl const& eventSetupImpl(unsigned subProcessIndex) const {
0062       return *eventSetupImpls_.at(subProcessIndex);
0063     }
0064 
0065     std::vector<std::shared_ptr<const EventSetupImpl>>& eventSetupImpls() { return eventSetupImpls_; }
0066     std::vector<std::shared_ptr<const EventSetupImpl>> const& eventSetupImpls() const { return eventSetupImpls_; }
0067 
0068     WaitingTaskList& endIOVWaitingTasks() { return endIOVWaitingTasks_; }
0069 
0070     void setGlobalEndRunHolder(WaitingTaskHolder);
0071     void globalEndRunHolderDoneWaiting() { globalEndRunHolder_.doneWaiting(std::exception_ptr{}); }
0072 
0073     bool shouldStreamStartLumi();
0074     void noMoreEventsInLumi();
0075     bool streamFinishedLumi() { return 0 == (--nStreamsStillProcessingLumi_); }
0076 
0077     //These should only be called while in the InputSource's task queue
0078     void updateLastTimestamp(edm::Timestamp const& iTime) {
0079       if (iTime > endTime_) {
0080         endTime_ = iTime;
0081       }
0082     }
0083     edm::Timestamp const& lastTimestamp() const { return endTime_; }
0084 
0085     //Called once all events in Lumi have been processed
0086     void setEndTime();
0087 
0088     enum class EventProcessingState { kProcessing, kPauseForFileTransition, kStopLumi };
0089     EventProcessingState eventProcessingState() const { return eventProcessingState_; }
0090     void setEventProcessingState(EventProcessingState val) { eventProcessingState_ = val; }
0091 
0092     bool haveStartedNextLumiOrEndedRun() const { return startedNextLumiOrEndedRun_.load(); }
0093     void startNextLumiOrEndRun() { startedNextLumiOrEndedRun_.store(true); }
0094 
0095     bool didGlobalBeginSucceed() const { return globalBeginSucceeded_; }
0096     void globalBeginDidSucceed() { globalBeginSucceeded_ = true; }
0097 
0098     bool cleaningUpAfterException() const { return cleaningUpAfterException_; }
0099     void setCleaningUpAfterException(bool value) { cleaningUpAfterException_ = value; }
0100 
0101   private:
0102     // ---------- member data --------------------------------
0103     LimitedTaskQueue::Resumer globalLumiQueueResumer_;
0104     std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
0105     std::vector<std::shared_ptr<const EventSetupImpl>> eventSetupImpls_;
0106     WaitingTaskList endIOVWaitingTasks_;
0107     edm::WaitingTaskHolder globalEndRunHolder_;
0108     edm::Timestamp endTime_{};
0109     CMS_THREAD_GUARD(state_) unsigned int nStreamsProcessingLumi_ { 0 };
0110     std::atomic<unsigned int> nStreamsStillProcessingLumi_{0};
0111     enum class State { kRunning, kUpdating, kNoMoreEvents };
0112     std::atomic<State> state_{State::kRunning};
0113     EventProcessingState eventProcessingState_{EventProcessingState::kProcessing};
0114     std::atomic<char> endTimeSetStatus_{0};
0115     std::atomic<bool> startedNextLumiOrEndedRun_{false};
0116     bool globalBeginSucceeded_{false};
0117     bool cleaningUpAfterException_{false};
0118   };
0119 }  // namespace edm
0120 
0121 #endif