artdaq  v3_08_00
ArtdaqSharedMemoryService.h
1 #ifndef artdaq_ArtModules_ArtdaqSharedMemoryService_h
2 #define artdaq_ArtModules_ArtdaqSharedMemoryService_h
3 
4 #include "art/Framework/Services/Registry/ServiceMacros.h"
5 #include "artdaq-core/Core/SharedMemoryEventReceiver.hh"
6 #include "artdaq-core/Data/RawEvent.hh"
7 #include "fhiclcpp/types/Atom.h"
8 
13 {
14 public:
18  virtual ~ArtdaqSharedMemoryServiceInterface() = default;
19 
25  virtual std::unordered_map<artdaq::Fragment::type_t, std::unique_ptr<artdaq::Fragments>> ReceiveEvent(bool broadcast) = 0;
26 
31  virtual size_t GetQueueSize() = 0;
32 
37  virtual size_t GetQueueCapacity() = 0;
38 
43  virtual std::shared_ptr<artdaq::detail::RawEventHeader> GetEventHeader() = 0;
44 };
45 
46 DECLARE_ART_SERVICE_INTERFACE(ArtdaqSharedMemoryServiceInterface, LEGACY)
47 
48 // ----------------------------------------------------------------------
49 
50 
56 {
57 public:
61  struct Config
62  {
64  fhicl::Atom<uint32_t> shared_memory_key{fhicl::Name{"shared_memory_key"}, fhicl::Comment{"Key to use when connecting to shared memory. Will default to 0xBEE70000 + getppid()."}, 0xBEE70000};
66  fhicl::Atom<uint32_t> broadcast_shared_memory_key{fhicl::Name{"broadcast_shared_memory_key"}, fhicl::Comment{"Key to use when connecting to broadcast shared memory. Will default to 0xCEE70000 + getppid()."}, 0xCEE70000};
68  fhicl::Atom<int> rank{fhicl::Name{"rank"}, fhicl::Comment{"Rank of this artdaq application. Used for data transfers"}};
69  };
71  using Parameters = fhicl::WrappedTable<Config>;
72 
76  virtual ~ArtdaqSharedMemoryService();
77 
82  ArtdaqSharedMemoryService(fhicl::ParameterSet const& pset, art::ActivityRegistry&);
83 
89  std::unordered_map<artdaq::Fragment::type_t, std::unique_ptr<artdaq::Fragments>> ReceiveEvent(bool broadcast) override;
90 
95  size_t GetQueueSize() override { return incoming_events_->ReadReadyCount(); }
100  size_t GetQueueCapacity() override { return incoming_events_->size(); }
105  std::shared_ptr<artdaq::detail::RawEventHeader> GetEventHeader() override { return evtHeader_; }
106 
107 private:
108  std::unique_ptr<artdaq::SharedMemoryEventReceiver> incoming_events_;
109  std::shared_ptr<artdaq::detail::RawEventHeader> evtHeader_;
110  size_t read_timeout_;
111  bool resume_after_timeout_;
112 };
113 
114 DECLARE_ART_SERVICE_INTERFACE_IMPL(ArtdaqSharedMemoryService, ArtdaqSharedMemoryServiceInterface, LEGACY)
115 
116 #endif /* artdaq_ArtModules_ArtdaqSharedMemoryService_h */
117 
118 // Local Variables:
119 // mode: c++
120 // End:
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
Interface for ArtdaqSharedMemoryService. This interface is declared to art as part of the required re...
size_t GetQueueSize() override
Get the number of events which are ready to be read.
virtual std::shared_ptr< artdaq::detail::RawEventHeader > GetEventHeader()=0
Get a shared_ptr to the current event header, if any.
virtual std::unordered_map< artdaq::Fragment::type_t, std::unique_ptr< artdaq::Fragments > > ReceiveEvent(bool broadcast)=0
Receive an event from the shared memory.
size_t GetQueueCapacity() override
Get the maximum number of events which can be stored in the shared memory.
Allowed Configuration parameters of NetMonTransportService. May be used for configuration validation ...
ArtdaqSharedMemoryService extends ArtdaqSharedMemoryServiceInterface. It receives events from shared ...
virtual size_t GetQueueCapacity()=0
Get the maximum number of events which can be stored in the shared memory.
std::shared_ptr< artdaq::detail::RawEventHeader > GetEventHeader() override
Get a shared_ptr to the current event header, if any.
virtual ~ArtdaqSharedMemoryServiceInterface()=default
Default virtual destructor.
virtual size_t GetQueueSize()=0
Get the number of events which are ready to be read.