artdaq  v2_02_03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
RequestMessage.hh
1 #ifndef artdaq_DAQrate_detail_RequestMessage_hh
2 #define artdaq_DAQrate_detail_RequestMessage_hh
3 
4 #include "artdaq-core/Data/Fragment.hh"
5 
6 namespace artdaq
7 {
8  namespace detail
9  {
10  struct RequestPacket;
11  struct RequestHeader;
12  class RequestMessage;
13  }
14 }
15 
20 {
21 public:
23  uint32_t header; //TRIG, or 0x54524947
24  Fragment::sequence_id_t sequence_id;
25  Fragment::timestamp_t timestamp;
26 
31  : header(0)
32  , sequence_id(Fragment::InvalidSequenceID)
33  , timestamp(Fragment::InvalidTimestamp) {}
34 
40  RequestPacket(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& ts)
41  : header(0x54524947)
42  , sequence_id(seq)
43  , timestamp(ts) {}
44 
49  bool isValid() const { return header == 0x54524947; }
50 };
51 
56 {
58  uint32_t header; //HEDR, or 0x48454452
59  uint32_t packet_count;
60 
64  RequestHeader() : header(0x48454452)
65  , packet_count(0) {}
66 
71  bool isValid() const { return header == 0x48454452; }
72 };
73 
78 {
79 public:
83  RequestMessage() : header_()
84  , packets_() { }
85 
91  {
92  header_.packet_count = packets_.size();
93  return &header_;
94  }
95 
100  RequestPacket* buffer() { return &packets_[0]; }
105  size_t size() const { return packets_.size(); }
106 
112  void addRequest(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& time)
113  {
114  packets_.emplace_back(RequestPacket(seq, time));
115  }
116 
117 private:
118  RequestHeader header_;
119  std::vector<RequestPacket> packets_;
120 };
121 
122 #endif // artdaq_DAQrate_detail_RequestMessage
RequestHeader * header()
Get a pointer to the RequestHeader, filling in the current size of the message.
RequestHeader()
Default Constructor.
void addRequest(const Fragment::sequence_id_t &seq, const Fragment::timestamp_t &time)
Add a request for a sequence ID and timestamp combination.
bool isValid() const
Check the magic bytes of the packet.
Fragment::timestamp_t timestamp
The timestamp of the request.
A RequestMessage consists of a RequestHeader and zero or more RequestPackets. They will usually be se...
RequestPacket()
Default Constructor.
Header of a RequestMessage. Contains magic bytes for validation and a count of expected RequestPacket...
uint32_t packet_count
The number of RequestPackets in this Request message.
The RequestPacket contains information about a single data request.
RequestPacket * buffer()
Get a pointer to the first RequestPacket in contiguous storage.
size_t size() const
Get the number of RequestPackets in the RequestMessage.
bool isValid() const
Check the magic bytes of the packet.
RequestMessage()
Default Constructor.
RequestPacket(const Fragment::sequence_id_t &seq, const Fragment::timestamp_t &ts)
Create a RequestPacket using the given sequence ID and timestmap.
Fragment::sequence_id_t sequence_id
The sequence ID that responses to this request should use.