Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-05 02:13:11

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(unsigned int iNStreams) : nStreamsStillProcessingLumi_(iNStreams) {}
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 streamFinishedLumi() { return 0 == (--nStreamsStillProcessingLumi_); }
0074 
0075     //These should only be called while in the InputSource's task queue
0076     void updateLastTimestamp(edm::Timestamp const& iTime) {
0077       if (iTime > endTime_) {
0078         endTime_ = iTime;
0079       }
0080     }
0081     edm::Timestamp const& lastTimestamp() const { return endTime_; }
0082 
0083     //Called once all events in Lumi have been processed
0084     void setEndTime();
0085 
0086     enum class EventProcessingState { kProcessing, kPauseForFileTransition, kStopLumi };
0087     EventProcessingState eventProcessingState() const { return eventProcessingState_; }
0088     void setEventProcessingState(EventProcessingState val) { eventProcessingState_ = val; }
0089 
0090     bool haveStartedNextLumiOrEndedRun() const { return startedNextLumiOrEndedRun_; }
0091     void startNextLumiOrEndRun() { startedNextLumiOrEndedRun_ = true; }
0092 
0093     bool didGlobalBeginSucceed() const { return globalBeginSucceeded_; }
0094     void globalBeginDidSucceed() { globalBeginSucceeded_ = true; }
0095 
0096     bool cleaningUpAfterException() const { return cleaningUpAfterException_; }
0097     void setCleaningUpAfterException(bool value) { cleaningUpAfterException_ = value; }
0098 
0099   private:
0100     // ---------- member data --------------------------------
0101     LimitedTaskQueue::Resumer globalLumiQueueResumer_;
0102     std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
0103     std::vector<std::shared_ptr<const EventSetupImpl>> eventSetupImpls_;
0104     WaitingTaskList endIOVWaitingTasks_;
0105     edm::WaitingTaskHolder globalEndRunHolder_;
0106     std::atomic<unsigned int> nStreamsStillProcessingLumi_{0};  //read/write as streams finish lumi so must be atomic
0107     edm::Timestamp endTime_{};
0108     std::atomic<char> endTimeSetStatus_{0};
0109     EventProcessingState eventProcessingState_{EventProcessingState::kProcessing};
0110     bool startedNextLumiOrEndedRun_{false};  //read/write in m_sourceQueue
0111     bool globalBeginSucceeded_{false};
0112     bool cleaningUpAfterException_{false};
0113   };
0114 }  // namespace edm
0115 
0116 #endif