artdaq_core_demo  v1_07_01
AsciiFragment.hh
1 #ifndef artdaq_demo_Overlays_AsciiFragment_hh
2 #define artdaq_demo_Overlays_AsciiFragment_hh
3 
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "cetlib_except/exception.h"
6 
7 #include <ostream>
8 #include <vector>
9 
10 // Implementation of "AsciiFragment", an artdaq::Fragment overlay class
11 // used for pedagogical purposes
12 
16 namespace demo {
17 class AsciiFragment;
18 
23 std::ostream& operator<<(std::ostream&, AsciiFragment const&);
24 } // namespace demo
25 
34 {
35 public:
43  struct Metadata
44  {
50  typedef char data_t;
54  typedef uint32_t chars_in_line_t;
55 
57 
58  static size_t const size_words = 4ul;
59  };
60 
61  static_assert(sizeof(Metadata) == Metadata::size_words * sizeof(Metadata::data_t),
62  "AsciiFragment::Metadata size changed");
63 
73  struct Header
74  {
75  typedef char data_t;
76 
77  typedef uint64_t event_size_t;
78  typedef uint64_t line_number_t;
79 
82 
84 
86  static size_t const size_words = 16ul;
87  };
88 
89  static_assert(sizeof(Header) == Header::size_words * sizeof(Header::data_t), "AsciiFragment::Header size changed");
90 
97  explicit AsciiFragment(artdaq::Fragment const& f)
98  : artdaq_Fragment_(f) {}
99 
100  // const getter functions for the data in the header
101 
116  static constexpr size_t hdr_size_words() { return Header::size_words; }
117 
120 
122  char const* dataBegin() const
123  {
124  return reinterpret_cast<char const*>(header_() + 1); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic)
125  }
126 
128  char const* dataEnd() const { return dataBegin() + total_line_characters(); } // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
129 
130 protected:
135  static constexpr size_t chars_per_word_() { return sizeof(Header::data_t) / sizeof(char); } // NOLINT(bugprone-sizeof-expression)
136 
143  Header const* header_() const
144  {
145  return reinterpret_cast<AsciiFragment::Header const*>(artdaq_Fragment_.dataBeginBytes()); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
146  }
147 
148 private:
149  artdaq::Fragment const& artdaq_Fragment_;
150 };
151 
152 #endif /* artdaq_demo_Overlays_AsciiFragment_hh */
Metadata describing the contents of the AsciiFragment.
chars_in_line_t charsInLine
How many characters are in the data payload.
char data_t
The data type of the payload.
std::ostream & operator<<(std::ostream &, AsciiFragment const &)
Dumps the AsciiFragment&#39;s data (text) to given stream.
Header const * header_() const
header_() simply takes the address of the start of this overlay&#39;s data (i.e., where the AsciiFragment...
The AsciiFragment::Header contains information about the payload size and the &quot;line number&quot; of the da...
uint32_t chars_in_line_t
Type used to represent the length in characters of the AsciiFragment data.
Header::event_size_t hdr_event_size() const
Gets the event_size from the AsciiFragment::Header.
static constexpr size_t hdr_size_words()
Gets the size_words variable from the artdaq::Header.
char const * dataBegin() const
Start of the line, returned as a pointer to the char type.
static size_t const size_words
Size of the Header object, in units of Header::data_t.
static size_t const size_words
Size of the Metadata object, in units of Metadata::data_t.
Header::line_number_t hdr_line_number() const
Gets the line_number from the AsciiFragment::Header.
uint64_t event_size_t
Type for the event_size field.
event_size_t unused_1
Unused.
event_size_t event_size
The number of characters in the contained string.
char const * dataEnd() const
End of the line, returned as a pointer to the char type.
static constexpr size_t chars_per_word_()
Translates between the size of the character type and the artda::Fragment::value_type.
An artdaq::Fragment overlay class designed to hold string data for pedagogical purposes.
uint64_t line_number_t
Type for the line_number field.
size_t total_line_characters() const
The number of characters in the line.
AsciiFragment(artdaq::Fragment const &f)
The AsciiFragment constructor.