Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:47

0001 #ifndef HeterogeneousCore_SonicTriton_TritonEDProducer
0002 #define HeterogeneousCore_SonicTriton_TritonEDProducer
0003 
0004 //TritonDummyCache include comes first for overload resolution
0005 #include "HeterogeneousCore/SonicTriton/interface/TritonDummyCache.h"
0006 #include "HeterogeneousCore/SonicCore/interface/SonicEDProducer.h"
0007 #include "HeterogeneousCore/SonicTriton/interface/TritonClient.h"
0008 #include "FWCore/ServiceRegistry/interface/Service.h"
0009 #include "HeterogeneousCore/SonicTriton/interface/TritonService.h"
0010 
0011 //inherited classes that use a non-default GlobalCache should be sure to call the parent initializeGlobalCache()
0012 template <typename G, typename... Capabilities>
0013 class TritonEDProducerT : public SonicEDProducer<TritonClient, edm::GlobalCache<G>, Capabilities...> {
0014 public:
0015   TritonEDProducerT(edm::ParameterSet const& cfg)
0016       : SonicEDProducer<TritonClient, edm::GlobalCache<G>, Capabilities...>(cfg) {}
0017 
0018   //use this function to avoid calling TritonService functions Nstreams times
0019   static std::unique_ptr<G> initializeGlobalCache(edm::ParameterSet const& pset) {
0020     edm::Service<TritonService> ts;
0021     const auto& clientPset = pset.getParameterSet("Client");
0022     ts->addModel(clientPset.getParameter<std::string>("modelName"),
0023                  clientPset.getParameter<edm::FileInPath>("modelConfigPath").fullPath());
0024     return nullptr;
0025   }
0026 
0027   static void globalEndJob(G*) {}
0028 
0029   //destroy client before destructor called to unregister any shared memory before TritonService shuts down fallback server
0030   virtual void tritonEndStream() {}
0031   void endStream() final {
0032     tritonEndStream();
0033     this->client_.reset();
0034   }
0035 };
0036 
0037 template <typename... Capabilities>
0038 using TritonEDProducer = TritonEDProducerT<TritonDummyCache, Capabilities...>;
0039 
0040 #endif