Frame14Fragment.hh
Go to the documentation of this file.
1 // Frame14Fragment.hh edited from FelixFragment.hh by Ben Land (2020)
2 
3 #ifndef artdaq_dune_Overlays_Frame14Fragment_hh
4 #define artdaq_dune_Overlays_Frame14Fragment_hh
5 
6 #include "FragmentType.hh"
7 #include "artdaq-core/Data/Fragment.hh"
10 
11 #include <iostream>
12 #include <map>
13 #include <vector>
14 #include <zlib.h>
15 
16 namespace dune {
17 
18 //============================
19 // Frame14 fragment base class
20 //============================
22  public:
23  /* Struct to hold Frame14Fragment Metadata copied directly from FelixFragment. */
24  struct Metadata {
25  typedef uint32_t data_t;
26 
27  data_t control_word : 12, version : 4, reordered : 8, compressed : 8;
28  data_t num_frames;
29  data_t offset_frames;
30  data_t window_frames;
31 
32  bool operator==(const Metadata& rhs) {
33  return (control_word == rhs.control_word) &&
34  (version == rhs.version) &&
35  (reordered == rhs.reordered) &&
36  (compressed == rhs.compressed) &&
37  (num_frames == rhs.num_frames) &&
38  (offset_frames == rhs.offset_frames) &&
39  (window_frames == rhs.window_frames);
40  }
41  };
42 
43  typedef uint16_t adc_t;
44  typedef std::vector<uint16_t> adc_v;
45 
46  /* Frame field and accessors. */
47  virtual uint8_t link_mask(const unsigned& frame_ID = 0) const = 0;
48  virtual uint8_t femb_valid(const unsigned& frame_ID = 0) const = 0;
49  virtual uint8_t fiber_no(const unsigned& frame_ID = 0) const = 0;
50  virtual uint8_t slot_no(const unsigned& frame_ID = 0) const = 0;
51  virtual uint8_t crate_no(const unsigned& frame_ID = 0) const = 0;
52  virtual uint8_t frame_version(const unsigned& frame_ID = 0) const = 0;
53 
54  virtual uint32_t wib_data(const unsigned& frame_ID = 0) const = 0;
55  virtual uint64_t timestamp(const unsigned& frame_ID = 0) const = 0;
56  virtual uint32_t crc20(const unsigned& frame_ID = 0) const = 0;
57  virtual uint32_t flex12(const unsigned& frame_ID = 0) const = 0;
58  virtual uint32_t flex24(const unsigned& frame_ID = 0) const = 0;
59 
60  // Functions to return a certain ADC value.
61  virtual adc_t get_ADC(const unsigned& frame_ID, const uint8_t block_ID,
62  const uint8_t channel_ID) const = 0;
63  virtual adc_t get_ADC(const unsigned& frame_ID,
64  const uint8_t channel_ID) const = 0;
65 
66  // Function to return all ADC values for a single channel.
67  virtual adc_v get_ADCs_by_channel(const uint8_t block_ID,
68  const uint8_t channel_ID) const = 0;
69  virtual adc_v get_ADCs_by_channel(const uint8_t channel_ID) const = 0;
70 
71  // Function to return all ADC values for all channels in a map.
72  virtual std::map<uint8_t, adc_v> get_all_ADCs() const = 0;
73 
74  Frame14Fragment(const artdaq::Fragment& fragment)
75  : meta_(*(fragment.metadata<Metadata>())),
76  artdaq_Fragment_(fragment.dataBeginBytes()),
77  sizeBytes_(fragment.dataSizeBytes()) { }
78  virtual ~Frame14Fragment() {}
79 
80  // The number of frames in the current event.
81  virtual size_t total_frames() const = 0;
82 
83 
84  protected:
86  const void* artdaq_Fragment_;
87  size_t sizeBytes_;
88 }; // class dune::FrameFragmentBase
89 
90 //==================================================
91 // Frame fragment for an array of bare Frame frames
92 //==================================================
94  public:
95  /* Frame field and accessors. */
96  uint8_t link_mask(const unsigned& frame_ID = 0) const {
97  return frame_(frame_ID)->link_mask;
98  }
99  uint8_t femb_valid(const unsigned& frame_ID = 0) const {
100  return frame_(frame_ID)->femb_valid;
101  }
102  uint8_t fiber_no(const unsigned& frame_ID = 0) const {
103  return frame_(frame_ID)->fiber_num;
104  }
105  uint8_t slot_no(const unsigned& frame_ID = 0) const {
106  return frame_(frame_ID)->slot_num;
107  }
108  uint8_t crate_no(const unsigned& frame_ID = 0) const {
109  return frame_(frame_ID)->crate_num;
110  }
111  uint8_t frame_version(const unsigned& frame_ID = 0) const {
112  return frame_(frame_ID)->frame_version;
113  }
114 
115  uint32_t wib_data(const unsigned& frame_ID = 0) const {
116  return frame_(frame_ID)->wib_data;
117  }
118  uint64_t timestamp(const unsigned& frame_ID = 0) const {
119  return frame_(frame_ID)->timestamp;
120  }
121  uint32_t crc20(const unsigned& frame_ID = 0) const {
122  return frame_(frame_ID)->crc20;
123  }
124  uint32_t flex12(const unsigned& frame_ID = 0) const {
125  return frame_(frame_ID)->flex12;
126  }
127  uint32_t flex24(const unsigned& frame_ID = 0) const {
128  return frame_(frame_ID)->flex24;
129  }
130 
131  size_t total_frames() const {
132  return meta_.num_frames;
133  }
134 
135  // Functions to return a certain ADC value.
136  adc_t get_ADC(const unsigned& frame_ID, const uint8_t block_ID,
137  const uint8_t channel_ID) const {
138  if (block_ID == 0) {
139  return frame14::unpack14(frame_(frame_ID)->femb_a_seg,channel_ID);
140  } else if (block_ID == 1) {
141  return frame14::unpack14(frame_(frame_ID)->femb_b_seg,channel_ID);
142  } else {
143  return -1;
144  //FIXME throw an exception
145  }
146  }
147  adc_t get_ADC(const unsigned& frame_ID, const uint8_t channel_ID) const {
148  return get_ADC(frame_ID,channel_ID/128,channel_ID%128);
149  }
150 
151  // Function to return all ADC values for a single channel.
152  adc_v get_ADCs_by_channel(const uint8_t block_ID,
153  const uint8_t channel_ID) const {
155  for (size_t i = 0; i < total_frames(); i++) {
156  output[i] = get_ADC(i, block_ID, channel_ID);
157  }
158  return output;
159  }
160  adc_v get_ADCs_by_channel(const uint8_t channel_ID) const {
162  for (size_t i = 0; i < total_frames(); i++) {
163  output[i] = get_ADC(i, channel_ID);
164  }
165  return output;
166  }
167  // Function to return all ADC values for all channels in a map.
168  std::map<uint8_t, adc_v> get_all_ADCs() const {
169  std::map<uint8_t, adc_v> output;
170  for (int i = 0; i < 256; i++)
171  output.insert(std::pair<uint8_t, adc_v>(i, get_ADCs_by_channel(i)));
172  return output;
173  }
174 
175 
176 
177  Frame14FragmentUnordered(artdaq::Fragment const& fragment)
178  : Frame14Fragment(fragment) {}
179 
180  protected:
181  // Allow access to individual frames according to the dune::frame14::frame14 structure.
182  frame14::frame14 const* frame_(const unsigned& frame_num = 0) const {
183  return static_cast<frame14::frame14 const*>(artdaq_Fragment_) + frame_num;
184  }
185 }; // class dune::Frame14FragmentUnordered
186 
187 const Frame14Fragment* ParseFrame14Fragment(const artdaq::Fragment& fragment) {
188  // const Frame14Fragment::Metadata *meta = fragment.metadata<Frame14Fragment::Metadata>();
189  // Check meta and potentially return a different unpacker
190  return new Frame14FragmentUnordered(fragment);
191 }
192 
193 }
194 
195 #endif /* artdaq_dune_Overlays_Frame14Fragment_hh */
adc_t get_ADC(const unsigned &frame_ID, const uint8_t block_ID, const uint8_t channel_ID) const
Frame14FragmentUnordered(artdaq::Fragment const &fragment)
uint8_t slot_no(const unsigned &frame_ID=0) const
uint8_t fiber_no(const unsigned &frame_ID=0) const
std::map< uint8_t, adc_v > get_all_ADCs() const
uint8_t femb_valid(const unsigned &frame_ID=0) const
uint32_t wib_data(const unsigned &frame_ID=0) const
adc_t get_ADC(const unsigned &frame_ID, const uint8_t channel_ID) const
uint16_t unpack14(const uint32_t *packed, size_t i)
virtual uint8_t slot_no(const unsigned &frame_ID=0) const =0
virtual std::map< uint8_t, adc_v > get_all_ADCs() const =0
virtual adc_t get_ADC(const unsigned &frame_ID, const uint8_t block_ID, const uint8_t channel_ID) const =0
virtual adc_v get_ADCs_by_channel(const uint8_t block_ID, const uint8_t channel_ID) const =0
uint32_t flex24(const unsigned &frame_ID=0) const
adc_v get_ADCs_by_channel(const uint8_t channel_ID) const
uint64_t timestamp(const unsigned &frame_ID=0) const
virtual uint32_t wib_data(const unsigned &frame_ID=0) const =0
Frame14Fragment(const artdaq::Fragment &fragment)
virtual size_t total_frames() const =0
const void * artdaq_Fragment_
virtual uint32_t flex24(const unsigned &frame_ID=0) const =0
virtual uint8_t link_mask(const unsigned &frame_ID=0) const =0
uint32_t flex12(const unsigned &frame_ID=0) const
virtual uint8_t femb_valid(const unsigned &frame_ID=0) const =0
uint8_t frame_version(const unsigned &frame_ID=0) const
uint32_t crc20(const unsigned &frame_ID=0) const
virtual uint8_t fiber_no(const unsigned &frame_ID=0) const =0
const Frame14Fragment * ParseFrame14Fragment(const artdaq::Fragment &fragment)
virtual uint64_t timestamp(const unsigned &frame_ID=0) const =0
virtual uint32_t flex12(const unsigned &frame_ID=0) const =0
bool operator==(const Metadata &rhs)
uint8_t crate_no(const unsigned &frame_ID=0) const
frame14::frame14 const * frame_(const unsigned &frame_num=0) const
virtual uint8_t frame_version(const unsigned &frame_ID=0) const =0
std::vector< uint16_t > adc_v
adc_v get_ADCs_by_channel(const uint8_t block_ID, const uint8_t channel_ID) const
virtual uint32_t crc20(const unsigned &frame_ID=0) const =0
uint8_t link_mask(const unsigned &frame_ID=0) const
virtual uint8_t crate_no(const unsigned &frame_ID=0) const =0