Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-04 04:34:53

0001 #ifndef FWCore_Framework_UnscheduledCallProducer_h
0002 #define FWCore_Framework_UnscheduledCallProducer_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:     FWCore/Framework
0007 // Class  :     UnscheduledCallProducer
0008 //
0009 /**\class UnscheduledCallProducer UnscheduledCallProducer.h "UnscheduledCallProducer.h"
0010 
0011  Description: Handles calling of EDProducers which are unscheduled
0012 
0013  Usage:
0014  <usage>
0015 
0016  */
0017 
0018 #include "FWCore/Concurrency/interface/WaitingTaskHolder.h"
0019 #include "FWCore/Framework/interface/maker/Worker.h"
0020 #include "FWCore/Framework/interface/UnscheduledAuxiliary.h"
0021 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0022 #include "FWCore/ServiceRegistry/interface/ServiceRegistryfwd.h"
0023 #include "FWCore/Utilities/interface/Signal.h"
0024 #include "FWCore/Utilities/interface/StreamID.h"
0025 
0026 #include <algorithm>
0027 #include <cassert>
0028 #include <functional>
0029 #include <vector>
0030 
0031 namespace edm {
0032 
0033   class EventTransitionInfo;
0034 
0035   class UnscheduledCallProducer {
0036   public:
0037     using worker_container = std::vector<Worker*>;
0038     using const_iterator = worker_container::const_iterator;
0039 
0040     UnscheduledCallProducer(ActivityRegistry& iReg) : unscheduledWorkers_() {
0041       aux_.preModuleDelayedGetSignal_.connect(std::cref(iReg.preModuleEventDelayedGetSignal_));
0042       aux_.postModuleDelayedGetSignal_.connect(std::cref(iReg.postModuleEventDelayedGetSignal_));
0043     }
0044     void addWorker(Worker* aWorker) {
0045       assert(nullptr != aWorker);
0046       unscheduledWorkers_.push_back(aWorker);
0047       if (aWorker->hasAccumulator()) {
0048         accumulatorWorkers_.push_back(aWorker);
0049       }
0050     }
0051 
0052     void removeWorker(Worker const* worker) {
0053       unscheduledWorkers_.erase(std::remove(unscheduledWorkers_.begin(), unscheduledWorkers_.end(), worker),
0054                                 unscheduledWorkers_.end());
0055       accumulatorWorkers_.erase(std::remove(accumulatorWorkers_.begin(), accumulatorWorkers_.end(), worker),
0056                                 accumulatorWorkers_.end());
0057     }
0058 
0059     void setEventTransitionInfo(EventTransitionInfo const& info) { aux_.setEventTransitionInfo(info); }
0060 
0061     UnscheduledAuxiliary const& auxiliary() const { return aux_; }
0062 
0063     const_iterator begin() const { return unscheduledWorkers_.begin(); }
0064     const_iterator end() const { return unscheduledWorkers_.end(); }
0065     worker_container const& workers() const { return unscheduledWorkers_; }
0066 
0067     template <typename T>
0068     void runAccumulatorsAsync(WaitingTaskHolder task,
0069                               typename T::TransitionInfoType const& info,
0070                               ServiceToken const& token,
0071                               StreamID streamID,
0072                               ParentContext const& parentContext,
0073                               typename T::Context const* context) noexcept {
0074       for (auto worker : accumulatorWorkers_) {
0075         worker->doWorkAsync<T>(task, info, token, streamID, parentContext, context);
0076       }
0077     }
0078 
0079   private:
0080     worker_container unscheduledWorkers_;
0081     worker_container accumulatorWorkers_;
0082     UnscheduledAuxiliary aux_;
0083   };
0084 
0085 }  // namespace edm
0086 
0087 #endif