Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-25 02:40:53

0001 #ifndef HeterogeneousCore_SonicCore_SonicClientBase
0002 #define HeterogeneousCore_SonicCore_SonicClientBase
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 #include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "HeterogeneousCore/SonicCore/interface/SonicDispatcher.h"
0009 #include "HeterogeneousCore/SonicCore/interface/SonicDispatcherPseudoAsync.h"
0010 
0011 #include <string>
0012 #include <exception>
0013 #include <memory>
0014 #include <optional>
0015 
0016 enum class SonicMode { Sync = 1, Async = 2, PseudoAsync = 3 };
0017 
0018 class SonicClientBase {
0019 public:
0020   //constructor
0021   SonicClientBase(const edm::ParameterSet& params, const std::string& debugName, const std::string& clientName);
0022 
0023   //destructor
0024   virtual ~SonicClientBase() = default;
0025 
0026   const std::string& debugName() const { return debugName_; }
0027   const std::string& clientName() const { return clientName_; }
0028   SonicMode mode() const { return mode_; }
0029 
0030   //main operation
0031   virtual void dispatch(edm::WaitingTaskWithArenaHolder holder) { dispatcher_->dispatch(std::move(holder)); }
0032 
0033   //alternate operation when ExternalWork is not used
0034   virtual void dispatch() { dispatcher_->dispatch(); }
0035 
0036   //helper: does nothing by default
0037   virtual void reset() {}
0038 
0039   //provide base params
0040   static void fillBasePSetDescription(edm::ParameterSetDescription& desc, bool allowRetry = true);
0041 
0042 protected:
0043   void setMode(SonicMode mode);
0044 
0045   virtual void evaluate() = 0;
0046 
0047   void start(edm::WaitingTaskWithArenaHolder holder);
0048 
0049   void start();
0050 
0051   void finish(bool success, std::exception_ptr eptr = std::exception_ptr{});
0052 
0053   //members
0054   SonicMode mode_;
0055   bool verbose_;
0056   std::unique_ptr<SonicDispatcher> dispatcher_;
0057   unsigned allowedTries_, tries_;
0058   std::optional<edm::WaitingTaskWithArenaHolder> holder_;
0059 
0060   //for logging/debugging
0061   std::string debugName_, clientName_, fullDebugName_;
0062 
0063   friend class SonicDispatcher;
0064   friend class SonicDispatcherPseudoAsync;
0065 };
0066 
0067 #endif