artdaq  v3_09_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 namespace detail {
9 struct RequestPacket;
10 struct RequestHeader;
11 class RequestMessage;
12 
16 enum class RequestMessageMode : uint8_t
17 {
18  Normal = 0,
19  EndOfRun = 1,
20 };
21 
28 inline std::ostream& operator<<(std::ostream& o, RequestMessageMode m)
29 {
30  switch (m)
31  {
33  o << "Normal";
34  break;
36  o << "EndOfRun";
37  break;
38  }
39  return o;
40 }
41 
42 } // namespace detail
43 } // namespace artdaq
44 
49 {
50 public:
52  uint32_t header{0}; //TRIG, or 0x54524947
53  Fragment::sequence_id_t sequence_id{Fragment::InvalidSequenceID};
54  Fragment::timestamp_t timestamp{Fragment::InvalidTimestamp};
55 
56  RequestPacket() = default;
57 
63  RequestPacket(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& ts)
64  : header(0x54524947)
65  , sequence_id(seq)
66  , timestamp(ts)
67  {}
68 
73  bool isValid() const { return header == 0x54524947; }
74 };
75 
80 {
82  uint32_t header{0x48454452}; //HEDR, or 0x48454452
83  uint32_t packet_count{0};
84  int rank{my_rank};
85  uint32_t run_number{0};
87 
88  RequestHeader() = default;
89 
94  bool isValid() const { return header == 0x48454452; }
95 };
96 
101 {
102 public:
107  : header_()
108  , packets_()
109  {}
110 
115  std::vector<uint8_t> GetMessage()
116  {
117  auto size = sizeof(RequestHeader) + packets_.size() * sizeof(RequestPacket);
118  header_.packet_count = packets_.size();
119  assert(size < MAX_REQUEST_MESSAGE_SIZE);
120  auto output = std::vector<uint8_t>(size);
121  memcpy(&output[0], &header_, sizeof(RequestHeader));
122  memcpy(&output[sizeof(RequestHeader)], &packets_[0], packets_.size() * sizeof(RequestPacket));
123 
124  return output;
125  }
126 
132  {
133  header_.mode = mode;
134  }
135 
140  void setRank(int rank)
141  {
142  header_.rank = rank;
143  }
144 
150  void setRunNumber(int run)
151  {
152  header_.run_number = run;
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
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)
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...
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.