artdaq  v3_06_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 #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;
94  uint32_t run_number;
96 
100  RequestHeader() : header(0x48454452)
101  , packet_count(0)
102  , rank(my_rank)
103  , run_number(0)
105  {}
106 
111  bool isValid() const { return header == 0x48454452; }
112 };
113 
118 {
119 public:
123  RequestMessage() : header_()
124  , packets_()
125  {}
126 
131  std::vector<uint8_t> GetMessage()
132  {
133  auto size = sizeof(RequestHeader) + packets_.size() * sizeof(RequestPacket);
134  header_.packet_count = packets_.size();
135  assert(size < MAX_REQUEST_MESSAGE_SIZE);
136  auto output = std::vector<uint8_t>(size);
137  memcpy(&output[0], &header_, sizeof(RequestHeader));
138  memcpy(&output[sizeof(RequestHeader)], &packets_[0], packets_.size() * sizeof(RequestPacket));
139 
140  return output;
141  }
142 
148  {
149  header_.mode = mode;
150  }
151 
156  void setRank(int rank)
157  {
158  header_.rank = rank;
159  }
160 
166  void setRunNumber(int run)
167  {
168  header_.run_number = run;
169  }
170 
175  size_t size() const { return packets_.size(); }
176 
182  void addRequest(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& time)
183  {
184  packets_.emplace_back(RequestPacket(seq, time));
185  }
186 
187 private:
188  RequestHeader header_;
189  std::vector<RequestPacket> packets_;
190 };
191 
192 #endif // artdaq_DAQrate_detail_RequestMessage
std::vector< uint8_t > GetMessage()
Get the contents of the RequestMessage.
uint32_t run_number
The Run with which this request should be associated.
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.
void setRunNumber(int run)
Set the run number in the header for this request. This will be the Run for which the request is vali...
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.