SSPFragment.hh
Go to the documentation of this file.
1 #ifndef artdaq_dune_Overlays_SSPFragment_hh
2 #define artdaq_dune_Overlays_SSPFragment_hh
3 
4 #include "artdaq-core/Data/Fragment.hh"
5 //#include "artdaq/DAQdata/features.hh"
6 #include "cetlib_except/exception.h"
7 //#include "dune-artdaq/Generators/anlBoard/anlTypes.h"
9 
10 #include <ostream>
11 #include <vector>
12 
13 // Implementation of "SSPFragment", an artdaq::Fragment overlay class
14 // used for pedagogical purposes
15 
16 namespace dune {
17  class SSPFragment;
18 
19  // Let the "<<" operator dump the SSPFragment's data to stdout
20  std::ostream & operator << (std::ostream &, SSPFragment const &);
21 }
22 
24  public:
25 
26  // The SSPFragment represents its data through the adc_t type, which
27  // is a typedef of an unsigned 32-bit integer.
28  typedef unsigned int adc_t;
29 
30  // The "Metadata" struct is used to store info primarily related to
31  // the upstream hardware environment from where the fragment came
32 
33  // "data_t" is a typedef of the fundamental unit of data the
34  // metadata structure thinks of itself as consisting of; it can give
35  // its size via the static "size_words" variable (
36  // SSPFragment::Metadata::size_words )
37 
38  struct Metadata {
39  //MillisliceHeader defined in anlTypes.hh
41  data_t sliceHeader;
42 
43  static size_t const size_words = 1ul; // Units of Metadata::data_t
44  };
45 
46  static_assert (sizeof (Metadata) == Metadata::size_words * sizeof (Metadata::data_t), "SSPFragment::Metadata size changed");
47 
48 
49  // The "Header" struct contains "metadata" specific to the fragment
50  // which is not hardware-related
51 
52  // Header::data_t -- not to be confused with Metadata::data_t ! --
53  // describes the standard size of a data type not just for the
54  // header data, but ALSO the physics data beyond it; the size of the
55  // header in units of Header::data_t is given by "size_words", and
56  // the size of the fragment beyond the header in units of
57  // Header::data_t is given by "event_size"
58 
59  // Notice only the first 28 bits of the first 32-bit unsigned
60  // integer in the Header is used to hold the event_size ; this means
61  // that you can't represent a fragment larger than 2**28 units of
62  // data_t, or 1,073,741,824 bytes
63 
64  struct Header {
65  typedef uint32_t data_t;
66 
67  typedef uint32_t event_size_t;
68  typedef uint32_t run_number_t;
69 
70  event_size_t event_size : 28;
71  event_size_t unused_1 : 4;
72 
73  run_number_t run_number : 32;
74 
75  static size_t const size_words = 2ul; // Units of Header::data_t
76  };
77 
78  static_assert (sizeof (Header) == Header::size_words * sizeof (Header::data_t), "SSPFragment::Header size changed");
79 
80  // The constructor simply sets its const private member "artdaq_Fragment_"
81  // to refer to the artdaq::Fragment object
82 
83  SSPFragment(artdaq::Fragment const & f ) : artdaq_Fragment_(f) {}
84 
85  // const getter functions for the data in the header
86 
89  static constexpr size_t hdr_size_words() { return Header::size_words; }
90 
91  // The number of ADC values describing data beyond the header
92  size_t total_adc_values() const {
93  return (hdr_event_size() - hdr_size_words()) * adcs_per_word_();
94  }
95 
96  // Start of the ADC values, returned as a pointer to the ADC type
97  adc_t const * dataBegin() const {
98  return reinterpret_cast<adc_t const *>(header_() + 1);
99  }
100 
101  // End of the ADC values, returned as a pointer to the ADC type
102  adc_t const * dataEnd() const {
103  return dataBegin() + total_adc_values();
104  }
105 
106  protected:
107 
108  // Functions to translate between size (in bytes) of an ADC, size of
109  // this fragment overlay's concept of a unit of data (i.e.,
110  // Header::data_t) and size of an artdaq::Fragment's concept of a
111  // unit of data (the artdaq::Fragment::value_type).
112 
113  static constexpr size_t adcs_per_word_() {
114  return sizeof(Header::data_t) / sizeof(adc_t);
115  }
116 
117  // header_() simply takes the address of the start of this overlay's
118  // data (i.e., where the SSPFragment::Header object begins) and
119  // casts it as a pointer to SSPFragment::Header
120 
121  Header const * header_() const {
122  return reinterpret_cast<SSPFragment::Header const *>(artdaq_Fragment_.dataBeginBytes());
123  }
124 
125 private:
126 
127  artdaq::Fragment const & artdaq_Fragment_;
128 };
129 
130 #endif /* artdaq_dune_Overlays_SSPFragment_hh */
std::ostream & operator<<(std::ostream &out, CTBFragment const &f)
Definition: CTBFragment.cc:6
adc_t const * dataEnd() const
Definition: SSPFragment.hh:102
adc_t const * dataBegin() const
Definition: SSPFragment.hh:97
size_t total_adc_values() const
Definition: SSPFragment.hh:92
static constexpr size_t hdr_size_words()
Definition: SSPFragment.hh:89
Header::run_number_t hdr_run_number() const
Definition: SSPFragment.hh:88
unsigned int adc_t
Definition: SSPFragment.hh:28
static size_t const size_words
Definition: SSPFragment.hh:75
Header const * header_() const
Definition: SSPFragment.hh:121
Header::event_size_t hdr_event_size() const
Definition: SSPFragment.hh:87
artdaq::Fragment const & artdaq_Fragment_
Definition: SSPFragment.hh:127
static size_t const size_words
Definition: SSPFragment.hh:43
static constexpr size_t adcs_per_word_()
Definition: SSPFragment.hh:113
SSPDAQ::MillisliceHeader data_t
Definition: SSPFragment.hh:40
SSPFragment(artdaq::Fragment const &f)
Definition: SSPFragment.hh:83