artdaq  v3_03_02
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 #define MAX_REQUEST_MESSAGE_SIZE 65000
6 
7 namespace artdaq
8 {
9  namespace detail
10  {
11  struct RequestPacket;
12  struct RequestHeader;
13  class RequestMessage;
14 
18  enum class RequestMessageMode : uint8_t
19  {
20  Normal = 0,
21  EndOfRun = 1,
22  };
23 
30  inline std::ostream& operator<<(std::ostream& o, RequestMessageMode m)
31  {
32  switch (m)
33  {
35  o << "Normal";
36  break;
38  o << "EndOfRun";
39  break;
40  }
41  return o;
42  }
43 
44  }
45 }
46 
51 {
52 public:
54  uint32_t header; //TRIG, or 0x54524947
55  Fragment::sequence_id_t sequence_id;
56  Fragment::timestamp_t timestamp;
57 
62  : header(0)
63  , sequence_id(Fragment::InvalidSequenceID)
64  , timestamp(Fragment::InvalidTimestamp)
65  {}
66 
72  RequestPacket(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& ts)
73  : header(0x54524947)
74  , sequence_id(seq)
75  , timestamp(ts)
76  {}
77 
82  bool isValid() const { return header == 0x54524947; }
83 };
84 
89 {
91  uint32_t header; //HEDR, or 0x48454452
92  uint32_t packet_count;
93  int rank;
95 
99  RequestHeader() : header(0x48454452)
100  , packet_count(0)
101  , rank(my_rank)
103  {}
104 
109  bool isValid() const { return header == 0x48454452; }
110 };
111 
116 {
117 public:
121  RequestMessage() : header_()
122  , packets_()
123  {}
124 
125  std::vector<uint8_t> GetMessage()
126  {
127  auto size = sizeof(RequestHeader) + packets_.size() * sizeof(RequestPacket);
128  header_.packet_count = packets_.size();
129  assert(size < MAX_REQUEST_MESSAGE_SIZE);
130  auto output = std::vector<uint8_t>(size);
131  memcpy(&output[0], &header_, sizeof(RequestHeader));
132  memcpy(&output[sizeof(RequestHeader)], &packets_[0], packets_.size() * sizeof(RequestPacket));
133 
134  return output;
135  }
136 
142  {
143  header_.mode = mode;
144  }
145 
150  void setRank(int rank)
151  {
152  header_.rank = rank;
153  }
154 
159  size_t size() const { return packets_.size(); }
160 
166  void addRequest(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& time)
167  {
168  packets_.emplace_back(RequestPacket(seq, time));
169  }
170 
171 private:
172  RequestHeader header_;
173  std::vector<RequestPacket> packets_;
174 };
175 
176 #endif // artdaq_DAQrate_detail_RequestMessage
End of Run mode (Used to end request processing on receiver)
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.
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.
void setMode(RequestMessageMode mode)
Set the Request Message Mode for this request.
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.
void setRank(int rank)
Set the rank in the header for this request. This will be the rank from which the request originates...
int rank
Rank of the sender.
The RequestPacket contains information about a single data request.
RequestMessageMode
Mode used to indicate current run conditions to the request receiver.
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.