PennMilliSlice.hh
Go to the documentation of this file.
1 #ifndef dune_artdaq_Overlays_PennMilliSlice_hh
2 #define dune_artdaq_Overlays_PennMilliSlice_hh
3 
5 #include "artdaq-core/Data/Fragment.hh"
6 
7 #include <boost/crc.hpp>
8 
9 //#define PENN_DONT_REBLOCK_USLICES
10 //#define PENN_OLD_STRUCTS
11 
12 namespace dune {
13  class PennMilliSlice;
14 }
15 
17 
18 public:
19 
20 #ifdef PENN_OLD_STRUCTS
21  struct TriggerPayload {
22  //FIXME: Change this format to something easier to debug.
23  //We'll use 32 bit atom since that is the total length of this struct
24  typedef uint32_t trigger_type_t;
25  typedef uint32_t trigger_pattern_t;
26  typedef uint16_t trigger_bits_t;
27  trigger_pattern_t trigger_pattern: 27;
28  trigger_type_t trigger_type : 5;
29 
30  static trigger_bits_t const num_bits_trigger_pattern = 27;
31  static trigger_bits_t const num_bits_trigger_type = 5;
32 
33  struct TriggerPatternBits {
34  static trigger_bits_t const bsu_rm_cl = 26;
35  static trigger_bits_t const tsu_nu_sl = 25;
36  static trigger_bits_t const tsu_sl_nu = 24;
37  static trigger_bits_t const tsu_el_wu = 23;
38  static std::string getName(trigger_bits_t trigger_bit){
39  switch(trigger_bit){
40  case bsu_rm_cl:
41  return "bsu_rm_cl";
42  break;
43  case tsu_nu_sl:
44  return "tsu_nu_sl";
45  break;
46  case tsu_sl_nu:
47  return "tsu_sl_nu";
48  break;
49  case tsu_el_wu:
50  return "tsu_el_wu";
51  break;
52  default:
53  return "unkown";
54  break;
55  }//switch(trigger_bit
56  return "";
57  }
58  };
59 
60  struct TriggerTypes {
61  static trigger_type_t const calibration = 0x00;
62  //FIXME not sure about the rce stuff!
63  static trigger_type_t const rce_a = 0x01;
64  static trigger_type_t const rce_b = 0x02;
65  static trigger_type_t const rce_c = 0x03;
66  static trigger_type_t const rce_d = 0x04;
67  static trigger_type_t const rce_e = 0x05;
68  static trigger_type_t const rce_f = 0x06;
69  static trigger_type_t const rce_g = 0x07;
70  static trigger_type_t const ssp = 0x08;
71  static trigger_type_t const muon = 0x10;
72  static std::string getName(trigger_type_t trigger_type){
73  switch(trigger_type){
74  case calibration:
75  return "calibration";
76  break;
77  case rce_a:
78  return "rce_a";
79  break;
80  case rce_b:
81  return "rce_b";
82  break;
83  case rce_c:
84  return "rce_c";
85  break;
86  case rce_d:
87  return "rce_d";
88  break;
89  case rce_e:
90  return "rce_e";
91  break;
92  case rce_f:
93  return "rce_f";
94  break;
95  case rce_g:
96  return "rce_g";
97  break;
98  case ssp :
99  return "ssp";
100  break;
101  case muon :
102  return "muon";
103  break;
104  default:
105  return "unknown";
106  break;
107  }
108  return "";
109  }//getName
110  };
111 
112  };
113 
114  struct TimestampPayload {
115  typedef uint64_t timestamp_t;
116  typedef uint16_t data_size_t;
117  timestamp_t nova_timestamp : 64;
118 
119  static data_size_t const num_bits_timestamp = 64;
120  static size_t const size_words = sizeof(uint64_t);
121 
122  static size_t const ptb_offset = sizeof(uint32_t);
123 
124  };
125 
126  struct CounterPayload {
127  //Need to be careful about choice of atom within this struct due to atom boundaries of the bitfields
128  //The 128 bits can be devided into two 64 bit atoms, so we will use that
129  typedef uint64_t counter_set_t;
130  typedef uint16_t trigger_bits_t;
131  counter_set_t tsu_wu : 10;
132  counter_set_t tsu_el : 10;
133  counter_set_t tsu_extra : 4;
134  counter_set_t tsu_nu : 6;
135  counter_set_t tsu_sl : 6;
136  counter_set_t tsu_nl : 6;
137  counter_set_t tsu_su : 6;
138  counter_set_t bsu_rm : 16;//end of first counter_set_t==uint64_t
139  counter_set_t bsu_cu : 10;
140  counter_set_t bsu_cl : 13;
141  counter_set_t bsu_rl : 10;
142  counter_set_t ts_rollover: 28;
143  counter_set_t header : 3;//end of second counter_set_t==uint64_t
144  static trigger_bits_t const num_bits_tsu_wu = 10;
145  static trigger_bits_t const num_bits_tsu_el = 10;
146  static trigger_bits_t const num_bits_tsu_extra = 4;
147  static trigger_bits_t const num_bits_tsu_nu = 6;
148  static trigger_bits_t const num_bits_tsu_sl = 6;
149  static trigger_bits_t const num_bits_tsu_nl = 6;
150  static trigger_bits_t const num_bits_tsu_su = 6;
151  static trigger_bits_t const num_bits_bsu_rm = 16;
152  static trigger_bits_t const num_bits_bsu_cu = 10;
153  static trigger_bits_t const num_bits_bsu_cl = 13;
154  static trigger_bits_t const num_bits_bsu_rl = 10;
155  static trigger_bits_t const num_bits_ts_rollover= 28;
156  static trigger_bits_t const num_bits_header = 3;
157  };
158 #endif /* PENN_OLD_STRUCTS */
159  struct Header {
160  //typedef uint32_t data_t;
161  typedef uint64_t data_t;
162 
163  typedef uint16_t sequence_id_t;
164  typedef uint16_t version_t;
165  typedef uint32_t millislice_size_t;
166  typedef uint16_t payload_count_t;
167  typedef uint64_t timestamp_t;
168  typedef uint32_t ticks_t;
169 #ifdef PENN_DONT_REBLOCK_USLICES
170  typedef uint32_t microslice_count_t;
171 #endif
172 
173  // TODO finalise millislice header
174 
175  data_t sequence_id : 16;
176  data_t version : 16;
177  data_t millislice_size : 32; // total size, data & header
178 #ifdef PENN_DONT_REBLOCK_USLICES
179  data_t microslice_count : 32;
180 #endif
181 
182  data_t payload_count : 16;
183  data_t payload_count_counter : 16;
184  data_t payload_count_trigger : 16;
185  data_t payload_count_timestamp : 16;
186 // -- There is information missing here
187 #ifdef NEW_FORMAT
188  data_t payload_count_warning : 16;
189 #endif
190  data_t end_timestamp : 64;
191  data_t width_in_ticks : 32; // neglecting overlap
192  data_t overlap_in_ticks : 32;
193  };
194 
195 
196  // This constructor accepts a memory buffer that contains an existing
197  // PennMilliSlice and allows the the data inside it to be accessed
198  PennMilliSlice(uint8_t* address);
199 
200  // Returns the size of the MilliSlice
202 
203  // Returns the sequence ID of the MilliSlice
205 
206  // Returns the version of the MilliSlice
207  Header::version_t version() const;
208 
209  // Returns the timestamp marking the end of the MilliSlice
211 
212  // Returns the number of ticks (neglecting overlaps) in the MilliSlice
213  Header::ticks_t widthTicks() const;
214 
215  // Returns the number of ticks in the overlap region of the MilliSlice
217 
218  // Returns the number of payloads in this MilliSlice
221  //, Header::payload_count_t& warning, Header::payload_count_t& checksum
222  // NFB, Jan-15-2016 : checksums should be kept out of the millislice.
223  ) const;
224 
225 
226 #ifdef PENN_DONT_REBLOCK_USLICES
227  // Returns the number of MicroSlices in this MilliSlice
228  Header::microslice_count_t microSliceCount() const;
229 
230  // Returns the requested MicroSlice if the requested slice was found,
231  // otherwise returns an empty pointer
232  std::unique_ptr<PennMicroSlice> microSlice(uint32_t index) const;
233 #endif
234 
235  // Returns the requested Payload if found,
236  // otherwise returns an empty pointer
237  uint8_t* payload(uint32_t index, dune::PennMicroSlice::Payload_Header::data_packet_type_t& data_packet_type,
239  size_t& payload_size) const;
240 
241 // // Returns a requested payload. The header is passed by reference. A pointer to the begin of the body
242 // // is returned.
243 // // if the payload is not found a null pointer is returned.
244 // uint8_t* payload(uint32_t index, dune::PennMicroSlice::Payload_Header &data_header, size_t &payload_size) const;
245 
246  // Returns a requested payload. The header is passed by reference. A pointer to the begin of the body
247  // is returned.
248  // if the payload is not found a null pointer is returned.
249  // NFB: approved
250  uint8_t* payload(uint32_t index, dune::PennMicroSlice::Payload_Header* &data_header) const;
251 
252  // Returns the next payload if found, and increments the current_payload_ buffer, current_word_id_
253  // Returns nullptr if there is a problem or we run off the end of the buffer_
254  // Can't be const since it shifts the current_payload_buffer and current_word_id_
255  uint8_t* get_next_payload(uint32_t &index,
258  size_t& payload_size);
259 
260  //NFB: My own implementation of get_next_payload
261  // return nullpltr if runs off the buffer
262  // or if there is some other unspecified problem
263  // it also updates the current_payload_buffer and current_word_id_
264  uint8_t* get_next_payload(uint32_t &index,dune::PennMicroSlice::Payload_Header*& data_header);
265 
266  // NFB: Returns the nearest timestamp payload after the current_word_id_
268 
269 #ifdef ENABLE_PENNMILLISLICE_CHECKSUM
270  typedef uint32_t checksum_t;
271 
272  // Calculate a checksum for this millslice
273  checksum_t calculateChecksum() const;
274 
275  // Returns the checksum
276  checksum_t checksum() const;
277 #endif
278 
279 protected:
280 
281  // returns a pointer to the header
282  Header const* header_() const;
283 
284  // returns a pointer to the requested MicroSlice
285  uint8_t* data_(int index) const;
286 
287  uint8_t* buffer_;
290 
291 };
292 
293 #endif /* dune_artdaq_Overlays_PennMilliSlice_hh */
Header const * header_() const
uint8_t * payload(uint32_t index, dune::PennMicroSlice::Payload_Header::data_packet_type_t &data_packet_type, dune::PennMicroSlice::Payload_Header::short_nova_timestamp_t &short_nova_timestamp, size_t &payload_size) const
uint8_t * get_next_payload(uint32_t &index, dune::PennMicroSlice::Payload_Header::data_packet_type_t &data_packet_type, dune::PennMicroSlice::Payload_Header::short_nova_timestamp_t &short_nova_timestamp, size_t &payload_size)
std::string string
Definition: nybbler.cc:12
Header::millislice_size_t size() const
uint8_t * data_(int index) const
Header::timestamp_t endTimestamp() const
Header::ticks_t overlapTicks() const
Header::version_t version() const
uint8_t * get_next_timestamp(dune::PennMicroSlice::Payload_Header *&data_header)
struct ptb::content::word::timestamp_t timestamp_t
PennMilliSlice(uint8_t *address)
Header::ticks_t widthTicks() const
Header::sequence_id_t sequenceID() const
Header::payload_count_t payloadCount() const
Frame header : Common header to everything except warning words.