artdaq  v3_07_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:
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 };
39 
40 DECLARE_ART_SERVICE_INTERFACE(ArtdaqSharedMemoryServiceInterface, LEGACY)
41 
42 // ----------------------------------------------------------------------
43 
44 
50 {
51 public:
55  struct Config
56  {
58  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};
60  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};
62  fhicl::Atom<int> rank{fhicl::Name{"rank"}, fhicl::Comment{"Rank of this artdaq application. Used for data transfers"}};
63  };
65  using Parameters = fhicl::WrappedTable<Config>;
66 
70  virtual ~ArtdaqSharedMemoryService();
71 
76  ArtdaqSharedMemoryService(fhicl::ParameterSet const& pset, art::ActivityRegistry&);
77 
83  std::unordered_map<artdaq::Fragment::type_t, std::unique_ptr<artdaq::Fragments>> ReceiveEvent(bool broadcast) override;
84 
89  size_t GetQueueSize() override { return incoming_events_->ReadReadyCount(); }
94  size_t GetQueueCapacity() override { return incoming_events_->size(); }
99  std::shared_ptr<artdaq::detail::RawEventHeader> GetEventHeader() { return evtHeader_; }
100 
101 private:
102  std::unique_ptr<artdaq::SharedMemoryEventReceiver> incoming_events_;
103  std::shared_ptr<artdaq::detail::RawEventHeader> evtHeader_;
104  size_t read_timeout_;
105 };
106 
107 DECLARE_ART_SERVICE_INTERFACE_IMPL(ArtdaqSharedMemoryService, ArtdaqSharedMemoryServiceInterface, LEGACY)
108 
109 #endif /* artdaq_ArtModules_ArtdaqSharedMemoryService_h */
110 
111 // Local Variables:
112 // mode: c++
113 // 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::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.
virtual ~ArtdaqSharedMemoryServiceInterface()=default
Default virtual destructor.
virtual size_t GetQueueSize()=0
Get the number of events which are ready to be read.
std::shared_ptr< artdaq::detail::RawEventHeader > GetEventHeader()
Get a shared_ptr to the current event header, if any.