artdaq  v2_03_02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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 
14  enum class RequestMessageMode
15  {
16  Normal = 0,
17  EndOfRun = 1,
18  };
19  }
20 }
21 
26 {
27 public:
29  uint32_t header; //TRIG, or 0x54524947
30  Fragment::sequence_id_t sequence_id;
31  Fragment::timestamp_t timestamp;
32 
37  : header(0)
38  , sequence_id(Fragment::InvalidSequenceID)
39  , timestamp(Fragment::InvalidTimestamp) {}
40 
46  RequestPacket(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& ts)
47  : header(0x54524947)
48  , sequence_id(seq)
49  , timestamp(ts) {}
50 
55  bool isValid() const { return header == 0x54524947; }
56 };
57 
62 {
64  uint32_t header; //HEDR, or 0x48454452
65  uint32_t packet_count;
66  RequestMessageMode mode ;
67 
71  RequestHeader() : header(0x48454452)
72  , packet_count(0)
73  , mode(RequestMessageMode::Normal)
74  {}
75 
80  bool isValid() const { return header == 0x48454452; }
81 };
82 
87 {
88 public:
92  RequestMessage() : header_()
93  , packets_() { }
94 
100  {
101  header_.packet_count = packets_.size();
102  return &header_;
103  }
104 
109  RequestPacket* buffer() { return &packets_[0]; }
114  size_t size() const { return packets_.size(); }
115 
121  void addRequest(const Fragment::sequence_id_t& seq, const Fragment::timestamp_t& time)
122  {
123  packets_.emplace_back(RequestPacket(seq, time));
124  }
125 
126 private:
127  RequestHeader header_;
128  std::vector<RequestPacket> packets_;
129 };
130 
131 #endif // artdaq_DAQrate_detail_RequestMessage
RequestHeader * header()
Get a pointer to the RequestHeader, filling in the current size of the message.
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.
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.
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.