artdaq  v3_09_01
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:
16 
20  virtual ~ArtdaqSharedMemoryServiceInterface() = default;
21 
27  virtual std::unordered_map<artdaq::Fragment::type_t, std::unique_ptr<artdaq::Fragments>> ReceiveEvent(bool broadcast) = 0;
28 
33  virtual size_t GetQueueSize() = 0;
34 
39  virtual size_t GetQueueCapacity() = 0;
40 
45  virtual std::shared_ptr<artdaq::detail::RawEventHeader> GetEventHeader() = 0;
46 
47 private:
52 };
53 
54 DECLARE_ART_SERVICE_INTERFACE(ArtdaqSharedMemoryServiceInterface, LEGACY)
55 
56 // ----------------------------------------------------------------------
57 
58 
64 {
65 public:
69  struct Config
70  {
72  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};
74  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};
76  fhicl::Atom<int> rank{fhicl::Name{"rank"}, fhicl::Comment{"Rank of this artdaq application. Used for data transfers"}};
77  };
79  using Parameters = fhicl::WrappedTable<Config>;
80 
84  virtual ~ArtdaqSharedMemoryService();
85 
90  ArtdaqSharedMemoryService(fhicl::ParameterSet const& pset, art::ActivityRegistry&);
91 
97  std::unordered_map<artdaq::Fragment::type_t, std::unique_ptr<artdaq::Fragments>> ReceiveEvent(bool broadcast) override;
98 
103  size_t GetQueueSize() override { return incoming_events_->ReadReadyCount(); }
108  size_t GetQueueCapacity() override { return incoming_events_->size(); }
113  std::shared_ptr<artdaq::detail::RawEventHeader> GetEventHeader() override { return evtHeader_; }
114 
115 private:
118  ArtdaqSharedMemoryService& operator=(ArtdaqSharedMemoryService const&) = delete;
120 
121 private:
122  std::unique_ptr<artdaq::SharedMemoryEventReceiver> incoming_events_;
123  std::shared_ptr<artdaq::detail::RawEventHeader> evtHeader_;
124  size_t read_timeout_;
125  bool resume_after_timeout_;
126 };
127 
128 DECLARE_ART_SERVICE_INTERFACE_IMPL(ArtdaqSharedMemoryService, ArtdaqSharedMemoryServiceInterface, LEGACY)
129 
130 #endif /* artdaq_ArtModules_ArtdaqSharedMemoryService_h */
131 
132 // Local Variables:
133 // mode: c++
134 // 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.