ATLAS Offline Software
Loading...
Searching...
No Matches
NSWTriggerMML1AElink.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
12#include "ers/ers.h"
13#include <exception>
14#include <sstream>
15
16Muon::nsw::NSWTriggerMML1AElink::NSWTriggerMML1AElink (const uint32_t *bs, const uint32_t remaining):
17 NSWTriggerElink (bs, remaining)
18{
19
20 std::size_t size_word{sizeof(uint32_t) * 8};
21 // 2 felix header 32b words already decoded
22 std::size_t readPointer{2 * 32};
23 std::span<const std::uint32_t> data{bs, remaining};
24 //once format finalized, checking a minimum size or at least the structure
25
34
35 ERS_DEBUG(2, Muon::nsw::format("\n TP header: \n"
36 " fradID: {}\n"
37 " sectID: {}\n"
38 " EC: {}\n"
39 " flags: {}\n"
40 " BCID: {}\n"
41 " orbit: {}\n"
42 " spare: {}\n"
43 " L1ID: {}",
45
61 //m_l1a_link_const is important! It identifies the elink! It should be ABCD1230/ABCD1231/ABCD1232
62 //not checked during decoding but must be checked at some point
63
64 //already checked in NSWTriggerElink that remaining >= m_wordCountFlx
65 while ( readPointer < (m_wordCountFlx-1) * size_word ) {
66 //later during commissioning, need to change to ( readPointer < (m_wordCountFlx-1-stream_block_size) * size_word )
67 //later during commissioning, checking if there's at least enough space for the stream header and stream content
68 //(protected for now by a generic expression in bit_slice, just want to be more specific)
69
70 uint32_t current_stream_head_nbits = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_stream_head_nbits);
71 uint32_t current_stream_head_nwords = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_stream_head_nwords);
72 uint32_t current_stream_head_fifo_size = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_stream_head_fifo_size);
73 uint32_t current_stream_head_streamID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMTPL1A::size_stream_head_streamID);
74
75 ERS_DEBUG(2, Muon::nsw::format("\n Stream header: \n"
76 " nbits: {}\n"
77 " nwords: {}\n"
78 " fifo_size: {}\n"
79 " streamID: {}",
80 current_stream_head_nbits, current_stream_head_nwords, current_stream_head_fifo_size, current_stream_head_streamID));
81
82
83 //zero padding to multiples of 16bits - TP logic - this is the real number of bits to read
84 current_stream_head_nbits = current_stream_head_nbits%16? ((current_stream_head_nbits+15)/16)*16 : current_stream_head_nbits;
85
86 m_stream_head_nbits.push_back ( current_stream_head_nbits );
87 m_stream_head_nwords.push_back ( current_stream_head_nwords );
88 m_stream_head_fifo_size.push_back ( current_stream_head_fifo_size );
89 m_stream_head_streamID.push_back ( current_stream_head_streamID );
90
91 int current_stream_head_n32b_per_word = (current_stream_head_nbits-1)/32 +1; //how many 32b words needed for a art/trigger packet
92 std::vector<std::vector<uint32_t>> current_stream_data;
93
94 //this block is very generic and agnostic of MMTP stream data format!
95 //only assumption: art/trigger packet size is multiple of 32b --- SF FIX BEFORE MR!
96 for (uint i = 0; i<current_stream_head_nwords; i++){
97 std::vector<uint32_t> current_stream_word;
98 for (int j = 0; j < current_stream_head_n32b_per_word; j++){
99 current_stream_word.push_back( Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, size_word) );
100 }
101 current_stream_data.push_back(std::move(current_stream_word));
102 }
103 m_stream_data.push_back(std::move(current_stream_data));
104
105 }
106
107 for (uint i=0; i<m_stream_data.size(); i++){
108
109 switch (m_stream_head_streamID[i]) {
110 case 0xAAA0:
111 case 0xAAA1:
112 case 0xAAA2:
113 case 0xAAA3:
114 for (uint j = 0; j < m_stream_data[i].size(); j++){
115 if ( m_stream_data[i][j].size()!=3 ){
116 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);
117 throw e;
118 }
119 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
120 }
121 break;
122 case 0xAAA4:
123 for (uint j = 0; j < m_stream_data[i].size(); j++){
124 if ( m_stream_data[i][j].size()!=2 ){
125 Muon::nsw::NSWTriggerException e ( Muon::nsw::format( "Stream ID 0xAAA4 packet length not correct: expected 2, got ({})", m_stream_data[i][j].size() ), 7);
126 throw e;
127 }
128 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
129 }
130 break;
131 default:
132 Muon::nsw::NSWTriggerException e ( Muon::nsw::format("Stream ID in MMTP L1A not recognized: {}", m_stream_head_streamID[i]), 5);
133 throw e;
134 }
135
136 }
137
138 // warning: swROD is zero padding the last word to 32b
139 // this means that there can be a leftover 16b 0x0000 after the CRC
140 // m_wordCountFlx is anyway "aware" of this
142
143 // calculate CRC by hand now - need to exclude the FEC header (2 words)
145
146}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
unsigned int uint
constexpr int size_l1a_close_BCID_offset
constexpr int size_l1a_close_BCID
constexpr int size_l1a_local_req_BCID
constexpr int size_head_orbit
constexpr int size_l1a_req_BCID
constexpr int size_head_sectID
constexpr int size_stream_head_fifo_size
constexpr int size_trailer_CRC
constexpr int size_l1a_versionID
constexpr int size_l1a_req_BCID_offset
constexpr int size_head_flags
constexpr int size_head_spare
constexpr int size_l1a_timeout
constexpr int size_stream_head_nwords
constexpr int size_head_fragID
constexpr int size_l1a_link_const
constexpr int size_l1a_engine_snapshot
constexpr int size_l1a_open_BCID
constexpr int size_l1a_padding
constexpr int size_l1a_busy_thr
constexpr int size_l1a_open_BCID_offset
constexpr int size_stream_head_streamID
constexpr int size_l1a_local_rel_BCID
constexpr int size_l1a_timeout_config
constexpr int size_stream_head_nbits
uint16_t get_16bxor_crc(const uint32_t *dataPointer, uint32_t dataSize)
std::string format(const std::string &str, const T &arg)
constexpr Target decode_and_advance(const std::span< const Source > words, std::size_t &start, const std::size_t size)
Decode bits from data of words and advance the read pointer.