artdaq  v3_09_01
RequestBuffer.hh
1 #ifndef _artdaq_DAQrate_RequestBuffer_hh_
2 #define _artdaq_DAQrate_RequestBuffer_hh_
3 
4 #include <condition_variable>
5 #include <map>
6 #include <set>
7 
8 #include "artdaq-core/Data/Fragment.hh"
9 
10 namespace artdaq {
12 {
13 public:
14  RequestBuffer(Fragment::sequence_id_t request_increment = 1);
15 
16  virtual ~RequestBuffer();
17 
18  void push(artdaq::Fragment::sequence_id_t seq, artdaq::Fragment::timestamp_t ts);
19 
20  void reset();
21 
26  std::map<artdaq::Fragment::sequence_id_t, artdaq::Fragment::timestamp_t> GetRequests() const;
27 
34  std::pair<artdaq::Fragment::sequence_id_t, artdaq::Fragment::timestamp_t> GetNextRequest();
35 
40  void RemoveRequest(artdaq::Fragment::sequence_id_t reqID);
41 
45  void ClearRequests();
50  std::map<artdaq::Fragment::sequence_id_t, artdaq::Fragment::timestamp_t> GetAndClearRequests();
51 
56  size_t size();
62  bool WaitForRequests(int timeout_ms);
63 
69  std::chrono::steady_clock::time_point GetRequestTime(artdaq::Fragment::sequence_id_t reqID);
70 
71  bool isRunning() const { return receiver_running_; }
72  void setRunning(bool running) { receiver_running_ = running; }
73 
74 private:
75  std::map<artdaq::Fragment::sequence_id_t, artdaq::Fragment::timestamp_t> requests_;
76  std::map<artdaq::Fragment::sequence_id_t, std::chrono::steady_clock::time_point> request_timing_;
77  std::atomic<artdaq::Fragment::sequence_id_t> highest_seen_request_;
78  std::atomic<artdaq::Fragment::sequence_id_t> last_next_request_; // The last request returned by GetNextRequest
79  std::set<artdaq::Fragment::sequence_id_t> out_of_order_requests_;
80  artdaq::Fragment::sequence_id_t request_increment_;
81  mutable std::mutex request_mutex_;
82  std::condition_variable request_cv_;
83 
84  std::atomic<bool> receiver_running_;
85 };
86 } // namespace artdaq
87 
88 #endif // _artdaq_DAQrate_RequestBuffer_hh_
void ClearRequests()
Clear all requests from the map
std::map< artdaq::Fragment::sequence_id_t, artdaq::Fragment::timestamp_t > GetAndClearRequests()
Get the current requests, then clear the map
std::pair< artdaq::Fragment::sequence_id_t, artdaq::Fragment::timestamp_t > GetNextRequest()
Get the &quot;next&quot; request, i.e. the first unsatisfied request that has not already been returned by GetN...
std::map< artdaq::Fragment::sequence_id_t, artdaq::Fragment::timestamp_t > GetRequests() const
Get the current requests
std::chrono::steady_clock::time_point GetRequestTime(artdaq::Fragment::sequence_id_t reqID)
Get the time a given request was received
bool WaitForRequests(int timeout_ms)
Wait for a new request message, up to the timeout given
void RemoveRequest(artdaq::Fragment::sequence_id_t reqID)
Remove the request with the given sequence ID from the request map
size_t size()
Get the number of requests currently stored in the RequestReceiver