ATLAS Offline Software
NSWTriggerMML1AElink.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 #include <vector>
5 #include <exception>
6 #include <sstream>
7 #include <string>
8 
10 
16 #include "ers/ers.h"
17 
19  NSWTriggerElink (bs, remaining)
20 {
21 
22  std::size_t size_word{sizeof(uint32_t) * 8};
23  // 2 felix header 32b words already decoded
24  std::size_t readPointer{2 * 32};
25  std::span<const std::uint32_t> data{bs, remaining};
26  //once format finalized, checking a minimum size or at least the structure
27 
28  m_head_fragID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_head_fragID);
29  m_head_sectID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_head_sectID);
30  m_head_EC = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_head_EC);
31  m_head_flags = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_head_flags);
32  m_head_BCID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_head_BCID);
33  m_head_orbit = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_head_orbit);
34  m_head_spare = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_head_spare);
35  m_L1ID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_L1ID);
36 
37  ERS_DEBUG(2, Muon::nsw::format("\n TP header: \n"
38  " fradID: {}\n"
39  " sectID: {}\n"
40  " EC: {}\n"
41  " flags: {}\n"
42  " BCID: {}\n"
43  " orbit: {}\n"
44  " spare: {}\n"
45  " L1ID: {}",
47 
48  m_l1a_versionID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_versionID);
49  m_l1a_local_req_BCID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_local_req_BCID);
50  m_l1a_local_rel_BCID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_local_rel_BCID);
51  m_l1a_open_BCID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_open_BCID);
52  m_l1a_req_BCID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_req_BCID);
53  m_l1a_close_BCID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_close_BCID);
54  m_l1a_timeout = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_timeout);
55  m_l1a_open_BCID_offset = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_open_BCID_offset);
56  m_l1a_req_BCID_offset = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_req_BCID_offset);
57  m_l1a_close_BCID_offset = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_close_BCID_offset);
58  m_l1a_timeout_config = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_timeout_config);
59  m_l1a_busy_thr = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_busy_thr);
60  m_l1a_engine_snapshot = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_engine_snapshot);
61  m_l1a_link_const = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_link_const);
62  m_l1a_padding = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_l1a_padding);
63  //m_l1a_link_const is important! It identifies the elink! It should be ABCD1230/ABCD1231/ABCD1232
64  //not checked during decoding but must be checked at some point
65 
66  //already checked in NSWTriggerElink that remaining >= m_wordCountFlx
67  while ( readPointer < (m_wordCountFlx-1) * size_word ) {
68  //later during commissioning, need to change to ( readPointer < (m_wordCountFlx-1-stream_block_size) * size_word )
69  //later during commissioning, checking if there's at least enough space for the stream header and stream content
70  //(protected for now by a generic expression in bit_slice, just want to be more specific)
71 
72  uint32_t current_stream_head_nbits = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_stream_head_nbits);
73  uint32_t current_stream_head_nwords = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_stream_head_nwords);
74  uint32_t current_stream_head_fifo_size = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_stream_head_fifo_size);
75  uint32_t current_stream_head_streamID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_stream_head_streamID);
76 
77  ERS_DEBUG(2, Muon::nsw::format("\n Stream header: \n"
78  " nbits: {}\n"
79  " nwords: {}\n"
80  " fifo_size: {}\n"
81  " streamID: {}",
82  current_stream_head_nbits, current_stream_head_nwords, current_stream_head_fifo_size, current_stream_head_streamID));
83 
84 
85  //zero padding to multiples of 16bits - TP logic - this is the real number of bits to read
86  current_stream_head_nbits = current_stream_head_nbits%16? ((current_stream_head_nbits+15)/16)*16 : current_stream_head_nbits;
87 
88  m_stream_head_nbits.push_back ( current_stream_head_nbits );
89  m_stream_head_nwords.push_back ( current_stream_head_nwords );
90  m_stream_head_fifo_size.push_back ( current_stream_head_fifo_size );
91  m_stream_head_streamID.push_back ( current_stream_head_streamID );
92 
93  int current_stream_head_n32b_per_word = (current_stream_head_nbits-1)/32 +1; //how many 32b words needed for a art/trigger packet
94  std::vector<std::vector<uint32_t>> current_stream_data;
95 
96  //this block is very generic and agnostic of MMTP stream data format!
97  //only assumption: art/trigger packet size is multiple of 32b --- SF FIX BEFORE MR!
98  for (uint i = 0; i<current_stream_head_nwords; i++){
99  std::vector<uint32_t> current_stream_word;
100  for (int j = 0; j < current_stream_head_n32b_per_word; j++){
101  current_stream_word.push_back( Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, size_word) );
102  }
103  current_stream_data.push_back(current_stream_word);
104  }
105  m_stream_data.push_back(current_stream_data);
106 
107  }
108 
109  for (uint i=0; i<m_stream_data.size(); i++){
110 
111  switch (m_stream_head_streamID[i]) {
112  case 0xAAA0:
113  case 0xAAA1:
114  case 0xAAA2:
115  case 0xAAA3:
116  for (uint j = 0; j < m_stream_data[i].size(); j++){
117  if ( m_stream_data[i][j].size()!=3 ){
118  Muon::nsw::NSWTriggerException e ( Muon::nsw::format( "Stream ID 0xAAA[0-3] packet length not correct: expected 3, got ({})", m_stream_data[i][j].size() ), 6);
119  throw e;
120  }
121  m_art_packets.push_back( std::make_shared<Muon::nsw::MMARTPacket>(m_stream_data[i][j]) ); //arg will be a vector<uint32_t> of size 3
122  }
123  break;
124  case 0xAAA4:
125  for (uint j = 0; j < m_stream_data[i].size(); j++){
126  if ( m_stream_data[i][j].size()!=2 ){
127  Muon::nsw::NSWTriggerException e ( Muon::nsw::format( "Stream ID 0xAAA4 packet length not correct: expected 2, got ({})", m_stream_data[i][j].size() ), 7);
128  throw e;
129  }
130  m_trig_packets.push_back( std::make_shared<Muon::nsw::MMTrigPacket>(m_stream_data[i][j]) ); //arg will be a vector<uint32_t> of size 2
131  }
132  break;
133  default:
134  Muon::nsw::NSWTriggerException e ( Muon::nsw::format("Stream ID in MMTP L1A not recognized: {}", m_stream_head_streamID[i]), 5);
135  throw e;
136  }
137 
138  }
139 
140  //warning: how the swROD is behaving if the last work is a uint16 only? Just 0-padding?
141  m_trailer_CRC = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_trailer_CRC);
142 
143 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
MMARTPacket.h
Muon::nsw::MMTPL1A::size_l1a_req_BCID
constexpr int size_l1a_req_BCID
Definition: NSWMMTPDecodeBitmaps.h:28
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
Muon::nsw::MMTPL1A::size_head_orbit
constexpr int size_head_orbit
Definition: NSWMMTPDecodeBitmaps.h:21
Muon::nsw::MMTPL1A::size_l1a_close_BCID_offset
constexpr int size_l1a_close_BCID_offset
Definition: NSWMMTPDecodeBitmaps.h:33
Muon::nsw::MMTPL1A::size_l1a_engine_snapshot
constexpr int size_l1a_engine_snapshot
Definition: NSWMMTPDecodeBitmaps.h:36
Muon::nsw::MMTPL1A::size_head_sectID
constexpr int size_head_sectID
Definition: NSWMMTPDecodeBitmaps.h:17
Muon::nsw::MMTPL1A::size_l1a_local_req_BCID
constexpr int size_l1a_local_req_BCID
Definition: NSWMMTPDecodeBitmaps.h:25
Muon::nsw::MMTPL1A::size_l1a_timeout_config
constexpr int size_l1a_timeout_config
Definition: NSWMMTPDecodeBitmaps.h:34
Muon::nsw::MMTPL1A::size_l1a_local_rel_BCID
constexpr int size_l1a_local_rel_BCID
Definition: NSWMMTPDecodeBitmaps.h:26
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
Muon::nsw::MMTPL1A::size_stream_head_nwords
constexpr int size_stream_head_nwords
Definition: NSWMMTPDecodeBitmaps.h:40
lumiFormat.i
int i
Definition: lumiFormat.py:85
Muon::nsw::MMTPL1A::size_l1a_versionID
constexpr int size_l1a_versionID
Definition: NSWMMTPDecodeBitmaps.h:24
Muon::nsw::MMTPL1A::size_head_EC
constexpr int size_head_EC
Definition: NSWMMTPDecodeBitmaps.h:18
Muon::nsw::MMTPL1A::size_head_spare
constexpr int size_head_spare
Definition: NSWMMTPDecodeBitmaps.h:22
Muon::nsw::MMTPL1A::size_l1a_timeout
constexpr int size_l1a_timeout
Definition: NSWMMTPDecodeBitmaps.h:30
Muon::nsw::MMTPL1A::size_head_fragID
constexpr int size_head_fragID
Definition: NSWMMTPDecodeBitmaps.h:16
Muon::nsw::MMTPL1A::size_l1a_close_BCID
constexpr int size_l1a_close_BCID
Definition: NSWMMTPDecodeBitmaps.h:29
Muon::nsw::MMTPL1A::size_stream_head_streamID
constexpr int size_stream_head_streamID
Definition: NSWMMTPDecodeBitmaps.h:42
Muon::nsw::MMTPL1A::size_l1a_padding
constexpr int size_l1a_padding
Definition: NSWMMTPDecodeBitmaps.h:38
Muon::nsw::MMTPL1A::size_l1a_link_const
constexpr int size_l1a_link_const
Definition: NSWMMTPDecodeBitmaps.h:37
Muon::nsw::format
std::string format(const std::string &str, const T &arg)
Definition: NSWDecodeHelper.h:43
Muon::nsw::MMTPL1A::size_trailer_CRC
constexpr int size_trailer_CRC
Definition: NSWMMTPDecodeBitmaps.h:43
NSWMMTPDecodeBitmaps.h
NSWResourceId.h
Muon::nsw::MMTPL1A::size_stream_head_fifo_size
constexpr int size_stream_head_fifo_size
Definition: NSWMMTPDecodeBitmaps.h:41
Muon::nsw::MMTPL1A::size_l1a_open_BCID
constexpr int size_l1a_open_BCID
Definition: NSWMMTPDecodeBitmaps.h:27
Muon::nsw::MMTPL1A::size_L1ID
constexpr int size_L1ID
Definition: NSWMMTPDecodeBitmaps.h:23
Muon::nsw::MMTPL1A::size_l1a_busy_thr
constexpr int size_l1a_busy_thr
Definition: NSWMMTPDecodeBitmaps.h:35
Muon::nsw::MMTPL1A::size_head_BCID
constexpr int size_head_BCID
Definition: NSWMMTPDecodeBitmaps.h:20
Muon::nsw::MMTPL1A::size_stream_head_nbits
constexpr int size_stream_head_nbits
Definition: NSWMMTPDecodeBitmaps.h:39
MMTrigPacket.h
Muon::nsw::MMTPL1A::size_head_flags
constexpr int size_head_flags
Definition: NSWMMTPDecodeBitmaps.h:19
Muon::nsw::MMTPL1A::size_l1a_open_BCID_offset
constexpr int size_l1a_open_BCID_offset
Definition: NSWMMTPDecodeBitmaps.h:31
Muon::nsw::MMTPL1A::size_l1a_req_BCID_offset
constexpr int size_l1a_req_BCID_offset
Definition: NSWMMTPDecodeBitmaps.h:32
Muon::nsw::NSWTriggerException
Definition: NSWTriggerElink.h:20