artdaq  v3_04_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 
127  std::vector<uint8_t> GetMessage()
128  {
129  auto size = sizeof(RequestHeader) + packets_.size() * sizeof(RequestPacket);
130  header_.packet_count = packets_.size();
131  assert(size < MAX_REQUEST_MESSAGE_SIZE);
132  auto output = std::vector<uint8_t>(size);
133  memcpy(&output[0], &header_, sizeof(RequestHeader));
134  memcpy(&output[sizeof(RequestHeader)], &packets_[0], packets_.size() * sizeof(RequestPacket));
135 
136  return output;
137  }
138 
144  {
145  header_.mode = mode;
146  }
147 
152  void setRank(int rank)
153  {
154  header_.rank = rank;
155  }
156 
162  void setRunNumber(int run)
163  {
164  header_.run_number = run;
165  }
166 
171  size_t size() const { return packets_.size(); }
172 
178  void addRequest(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& time)
179  {
180  packets_.emplace_back(RequestPacket(seq, time));
181  }
182 
183 private:
184  RequestHeader header_;
185  std::vector<RequestPacket> packets_;
186 };
187 
188 #endif // artdaq_DAQrate_detail_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.