otsdaq_mu2e_calorimeter  v2_04_02
DataGenFragment.hh
1 #ifndef artdaq_ots_Overlays_DataGenFragment_hh
2 #define artdaq_ots_Overlays_DataGenFragment_hh
3 
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "cetlib/exception.h"
6 
7 #include <ostream>
8 #include <vector>
9 
10 // Implementation of "DataGenFragment", an artdaq::Fragment overlay class
11 
12 namespace ots
13 {
14 class DataGenFragment;
15 
16 // Let the "<<" operator dump the DataGenFragment's data to stdout
17 std::ostream& operator<<(std::ostream&, DataGenFragment const&);
18 } // namespace ots
19 
21 {
22  public:
23  // The "Metadata" struct is used to store info primarily related to
24  // the upstream hardware environment from where the fragment came
25 
26  // "data_t" is a typedef of the fundamental unit of data the
27  // metadata structure thinks of itself as consisting of; it can give
28  // its size via the static "size_words" variable (
29  // DataGenFragment::Metadata::size_words )
30 
31  struct Metadata
32  {
33  typedef uint64_t data_t;
34 
35  data_t port : 16;
36  data_t address : 32;
37  data_t unused : 16;
38 
39  static size_t const size_words = 1ull; // Units of Metadata::data_t
40  };
41 
42  static_assert(sizeof(Metadata) == Metadata::size_words * sizeof(Metadata::data_t),
43  "DataGenFragment::Metadata size changed");
44 
45  // The "Header" struct contains "metadata" specific to the fragment
46  // which is not hardware-related
47 
48  struct Header
49  {
50  typedef uint32_t data_t;
51  // data_t type;
52  // data_t sequence;
53 
54  data_t data_bytes;
55  data_t board_id;
56  data_t channel;
57  data_t datetime1;
58  data_t datetime2;
59  data_t sequence;
60  data_t triggercount;
61  data_t triggertype;
62 
63  static size_t const size_words = 8ul; // Units of Header::data_t
64  };
65 
66  static_assert(sizeof(Header) == Header::size_words * sizeof(Header::data_t),
67  "DataGenFragment::Header size changed");
68 
69  struct DataBlob
70  {
71  float data[16000];
72  };
73 
74  // The constructor simply sets its const private member "artdaq_Fragment_"
75  // to refer to the artdaq::Fragment object
76 
77  DataGenFragment(artdaq::Fragment const& f) : artdaq_Fragment_(f) {}
78 
79  // const getter functions for the data in the header
80 
81  // Start of the data, returned as a pointer
82  DataBlob const* dataBegin() const
83  {
84  return reinterpret_cast<DataBlob const*>(header_() + 1);
85  // return reinterpret_cast<DataBlob const *>(header_());
86  }
87  // 0 - type
88  // 1 - seq
89  // 2-9 - data
90 
91  // End of the data, returned as a pointer
92  DataBlob const* dataEnd() const
93  {
94  return dataBegin() + (artdaq_Fragment_.dataSize() / sizeof(DataBlob));
95  }
96 
97  protected:
98  // header_() simply takes the address of the start of this overlay's
99  // data (i.e., where the DataGenFragment::Header object begins) and
100  // casts it as a pointer to DataGenFragment::Header
101 
102  Header const* header_() const
103  {
104  return reinterpret_cast<DataGenFragment::Header const*>(
105  artdaq_Fragment_.dataBeginBytes());
106  }
107 
108  private:
109  artdaq::Fragment const& artdaq_Fragment_;
110 };
111 
112 #endif /* artdaq_ots_core_Overlays_DataGenFragment_hh */