artdaq  v3_01_00
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 
17  enum class RequestMessageMode : uint8_t
18  {
19  Normal = 0,
20  EndOfRun = 1,
21  };
22 
29  inline std::ostream& operator<<(std::ostream& o, RequestMessageMode m)
30  {
31  switch (m)
32  {
34  o << "Normal";
35  break;
37  o << "EndOfRun";
38  break;
39  }
40  return o;
41  }
42 
43  }
44 }
45 
50 {
51 public:
53  uint32_t header; //TRIG, or 0x54524947
54  Fragment::sequence_id_t sequence_id;
55  Fragment::timestamp_t timestamp;
56 
61  : header(0)
62  , sequence_id(Fragment::InvalidSequenceID)
63  , timestamp(Fragment::InvalidTimestamp)
64  {}
65 
71  RequestPacket(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& ts)
72  : header(0x54524947)
73  , sequence_id(seq)
74  , timestamp(ts)
75  {}
76 
81  bool isValid() const { return header == 0x54524947; }
82 };
83 
88 {
90  uint32_t header; //HEDR, or 0x48454452
91  uint32_t packet_count;
93 
97  RequestHeader() : header(0x48454452)
98  , packet_count(0)
100  {}
101 
106  bool isValid() const { return header == 0x48454452; }
107 };
108 
113 {
114 public:
118  RequestMessage() : header_()
119  , packets_()
120  {}
121 
127  {
128  header_.packet_count = packets_.size();
129  return &header_;
130  }
131 
136  RequestPacket* buffer() { return &packets_[0]; }
141  size_t size() const { return packets_.size(); }
142 
148  void addRequest(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& time)
149  {
150  packets_.emplace_back(RequestPacket(seq, time));
151  }
152 
153 private:
154  RequestHeader header_;
155  std::vector<RequestPacket> packets_;
156 };
157 
158 #endif // artdaq_DAQrate_detail_RequestMessage
RequestHeader * header()
Get a pointer to the RequestHeader, filling in the current size of the message.
End of Run mode (Used to end request processing on receiver)
RequestHeader()
Default Constructor.
std::ostream & operator<<(std::ostream &o, RequestMessageMode m)
Converts the RequestMessageMode to a string and sends it to the output stream.
void addRequest(const Fragment::sequence_id_t &seq, const Fragment::timestamp_t &time)
Add a request for a sequence ID and timestamp combination.
RequestMessageMode mode
Communicates additional information to the Request receiver.
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.
RequestMessageMode
Mode used to indicate current run conditions to the request receiver.
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.