ATLAS Offline Software
STGTPPackets.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
5 
6 #include <algorithm>
7 #include <exception>
8 #include <sstream>
9 #include <stdexcept>
10 #include <string>
11 #include <tuple>
12 #include <vector>
13 
17 
18 
20  size_t packet_size_w = 0;
21  size_t word_size = 32;
22  switch (ver) {
23  case 1:
24  packet_size_w = Muon::nsw::STGTPMMData::size_v1 / word_size;
25  break;
26  case 2:
27  packet_size_w = Muon::nsw::STGTPMMData::size_v2 / word_size;
28  break;
29  case 3:
30  packet_size_w = Muon::nsw::STGTPMMData::size_v3 / word_size;
31  break;
32  default:
33  packet_size_w = 0;
34  break;
35  }
36  return packet_size_w;
37 }
38 Muon::nsw::STGTPMMPacket::STGTPMMPacket(const std::vector<uint32_t>& payload, const int ver=1) {
39 
40  if (ver < 3){
41  // This section did not exist before v3
42  return;
43  }
44 
45  size_t packet_size_w = Size(ver);
46 
47  if (std::size(payload) != packet_size_w) {
48  throw std::runtime_error(
49  Muon::nsw::format("Packet vector has size {} instead of expected size {}", std::size(payload), packet_size_w));
50  }
51 
52  const auto packets = std::span{payload.data(), std::size(payload)};
53  auto readPointer = std::size_t{0};
54  auto decode = [&packets](std::size_t& readPointer, const std::size_t size) {
55  return decode_and_advance<std::uint64_t, std::uint32_t>(packets, readPointer, size);
56  };
57 
58 
61  for (std::size_t i = Muon::nsw::STGTPMMData::num_mm; i > 0; --i) {
62  const auto index = i - 1;
63  uint32_t segment_bit = 1 << index;
64  uint32_t valid_segment = (m_valids & segment_bit);
65  m_segmentData.at(index).monitor = decode(readPointer, Muon::nsw::STGTPMMData::size_output_mm_monitor);
66  m_segmentData.at(index).spare = decode(readPointer, Muon::nsw::STGTPMMData::size_output_mm_spare);
67  m_segmentData.at(index).lowRes = decode(readPointer, Muon::nsw::STGTPMMData::size_output_mm_lowRes);
68  m_segmentData.at(index).phiRes = decode(readPointer, Muon::nsw::STGTPMMData::size_output_mm_phiRes);
69  m_segmentData.at(index).dTheta = decode(readPointer, Muon::nsw::STGTPMMData::size_output_mm_dTheta);
70  m_segmentData.at(index).phiID = decode(readPointer, Muon::nsw::STGTPMMData::size_output_mm_phiID);
71  m_segmentData.at(index).rIndex = decode(readPointer, Muon::nsw::STGTPMMData::size_output_mm_rIndex);
72  if (!valid_segment)
73  {
74  m_segmentData.at(index).monitor = 0;
75  m_segmentData.at(index).spare = 0;
76  m_segmentData.at(index).lowRes = 0;
77  m_segmentData.at(index).phiRes = 0;
78  m_segmentData.at(index).dTheta = Muon::nsw::STGTPMMData::mm_stream_invalid_dTheta; // this is the invalid flag
79  m_segmentData.at(index).phiID = 0;
80  m_segmentData.at(index).rIndex = 0;
81  }
82  }
83  m_BCID = decode(readPointer, Muon::nsw::STGTPMMData::size_bcid);
84 
85 }
86 
88  const std::size_t segment) const {
90  throw std::out_of_range(
91  Muon::nsw::format("Requested segment {} which does not exist (max {})", segment, STGTPMMData::num_mm - 1));
92  }
93  return m_segmentData.at(segment);
94 }
95 
97  size_t packet_size_w = 0;
98  size_t word_size = 32;
99  switch (ver) {
100  case 1:
101  packet_size_w = Muon::nsw::STGTPPad::size_v1 / word_size;
102  break;
103  case 2:
104  packet_size_w = Muon::nsw::STGTPPad::size_v2 / word_size;
105  break;
106  case 3:
107  packet_size_w = Muon::nsw::STGTPPad::size_v3 / word_size;
108  break;
109  default:
110  packet_size_w = 0;
111  break;
112  }
113  return packet_size_w;
114 }
115 Muon::nsw::STGTPPadPacket::STGTPPadPacket(const std::vector<uint32_t>& payload, const int ver=1) {
116  size_t packet_size_w = Size(ver);
117  if (std::size(payload) != packet_size_w) {
118  throw std::runtime_error(
119  Muon::nsw::format("Packet vector has size {} instead of expected size {}", std::size(payload), packet_size_w));
120  }
121 
122  const auto packets = std::span{payload.data(), std::size(payload)};
123  auto readPointer = std::size_t{0};
124  auto decode = [&packets](std::size_t& readPointer, const std::size_t size) {
125  return decode_and_advance<std::uint64_t, std::uint32_t>(packets, readPointer, size);
126  };
127 
128  if (ver >= 3)
129  {
130  // in versions 3+ the padding appears first
132  }
133  m_coincWedge = decode(readPointer, Muon::nsw::STGTPPad::size_coincidence_wedge);
134  for (std::size_t i = Muon::nsw::STGTPPad::num_pads; i > 0; --i) {
135  const auto index = i - 1;
136  m_phiIDs.at(index) = decode(readPointer, Muon::nsw::STGTPPad::size_phiID);
137  }
138 
139  for (std::size_t i = Muon::nsw::STGTPPad::num_pads; i > 0; --i) {
140  const auto index = i - 1;
141  m_bandIDs.at(index) = decode(readPointer, Muon::nsw::STGTPPad::size_bandID);
142  }
143 
144  m_BCID = decode(readPointer, Muon::nsw::STGTPPad::size_BCID);
145  readPointer += Muon::nsw::STGTPPad::size_spare;
146  m_idleFlag = decode(readPointer, Muon::nsw::STGTPPad::size_idleFlag);
147 }
148 
150  size_t packet_size_w = 0;
151  size_t word_size = 32;
152  switch (ver) {
153  case 1:
154  packet_size_w = Muon::nsw::STGTPSegments::size_v1 / word_size;;
155  break;
156  case 2:
157  packet_size_w = Muon::nsw::STGTPSegments::size_v2 / word_size;;
158  break;
159  case 3:
160  packet_size_w = Muon::nsw::STGTPSegments::size_v3 / word_size;
161  break;
162  default:
163  packet_size_w = 0;
164  break;
165  }
166  return packet_size_w;
167 }
168 
169 Muon::nsw::STGTPSegmentPacket::STGTPSegmentPacket(const std::vector<uint32_t>& payload, const int ver=1) {
170  size_t packet_size_w = Size(ver);
171 
172  if (std::size(payload) != packet_size_w) {
173  throw std::runtime_error(
174  Muon::nsw::format("Packet vector has size {} instead of expected size {}", std::size(payload), packet_size_w));
175  }
176  auto readPointer = std::size_t{0};
177  const auto packets = std::span{payload.data(), std::size(payload)};
178  auto decode = [&packets](std::size_t& readPointer, const std::size_t size) {
179  return decode_and_advance<std::uint64_t, std::uint32_t>(packets, readPointer, size);
180  };
181 
182  if (ver < 3)
183  {
184  // In the versions prior to version 3, there was a LUT used to merge segments
185  // the versions following 3 use an algorithm that simplifies the merge, and hence the
186  // structure of these data changed
187  m_lut_choice = decode(readPointer, Muon::nsw::STGTPSegments::size_lut_choice_selection);
188  m_nsw_segment_selector = decode(readPointer, Muon::nsw::STGTPSegments::size_nsw_segment_selector);
189  m_valid_segment_selector = decode(readPointer, Muon::nsw::STGTPSegments::size_valid_segment_selector);
190  }
191  else
192  {
194  m_nsw_segment_selector = decode(readPointer, Muon::nsw::STGTPSegments::size_valid_segment_v3);
195  m_valid_segment_selector = decode(readPointer, Muon::nsw::STGTPSegments::size_valid_segment_selector);
196  }
197 
198  for (std::size_t i = Muon::nsw::STGTPSegments::num_segments; i > 0; --i) {
199  const auto index = i - 1;
200  m_segmentData.at(index).monitor = decode(readPointer, Muon::nsw::STGTPSegments::size_output_segment_monitor);
201  m_segmentData.at(index).spare = decode(readPointer, Muon::nsw::STGTPSegments::size_output_segment_spare);
202  m_segmentData.at(index).lowRes = decode(readPointer, Muon::nsw::STGTPSegments::size_output_segment_lowRes);
203  m_segmentData.at(index).phiRes = decode(readPointer, Muon::nsw::STGTPSegments::size_output_segment_phiRes);
204  m_segmentData.at(index).dTheta = decode(readPointer, Muon::nsw::STGTPSegments::size_output_segment_dTheta);
205  m_segmentData.at(index).phiID = decode(readPointer, Muon::nsw::STGTPSegments::size_output_segment_phiID);
206  m_segmentData.at(index).rIndex = decode(readPointer, Muon::nsw::STGTPSegments::size_output_segment_rIndex);
207 
208  }
209 
210  m_BCID = decode(readPointer, Muon::nsw::STGTPSegments::size_bcid);
211  m_sectorID = decode(readPointer, Muon::nsw::STGTPSegments::size_sectorID);
212 
213 
214 }
215 
217  const std::size_t segment) const {
219  throw std::out_of_range(
220  Muon::nsw::format("Requested segment {} which does not exist (max {})", segment, STGTPSegments::num_segments - 1));
221  }
222  return m_segmentData.at(segment);
223 }
Muon::nsw::STGTPMMData::size_v3_padding
constexpr int size_v3_padding
Definition: NSWSTGTPDecodeBitmaps.h:91
Muon::nsw::STGTPMMData::size_output_mm_monitor
constexpr int size_output_mm_monitor
Definition: NSWSTGTPDecodeBitmaps.h:82
Muon::nsw::STGTPPadPacket::STGTPPadPacket
STGTPPadPacket(const std::vector< std::uint32_t > &payload, const int ver)
Definition: STGTPPackets.cxx:115
Muon::nsw::STGTPSegments::size_valid_segment_selector
constexpr int size_valid_segment_selector
Definition: NSWSTGTPDecodeBitmaps.h:107
AtlasMcWeight::decode
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
Definition: AtlasMcWeight.cxx:32
CxxUtils::span
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
Muon::nsw::STGTPSegments::size_output_segment_spare
constexpr int size_output_segment_spare
Definition: NSWSTGTPDecodeBitmaps.h:110
Muon::nsw::STGTPSegments::size_v2
constexpr std::size_t size_v2
Definition: NSWSTGTPDecodeBitmaps.h:121
Muon::nsw::STGTPMMPacket::Segment
const MMSegmentData & Segment(std::size_t segment) const
Definition: STGTPPackets.cxx:87
Muon::nsw::STGTPMMData::size_output_mm_dTheta
constexpr int size_output_mm_dTheta
Definition: NSWSTGTPDecodeBitmaps.h:86
Muon::nsw::STGTPMMData::size_v1
constexpr std::size_t size_v1
Definition: NSWSTGTPDecodeBitmaps.h:93
Muon::nsw::STGTPSegments::size_output_segment_phiRes
constexpr int size_output_segment_phiRes
Definition: NSWSTGTPDecodeBitmaps.h:112
Muon::nsw::STGTPPad::size_idleFlag
constexpr std::size_t size_idleFlag
Definition: NSWSTGTPDecodeBitmaps.h:68
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
Muon::nsw::STGTPSegments::size_v3
constexpr std::size_t size_v3
Definition: NSWSTGTPDecodeBitmaps.h:122
index
Definition: index.py:1
TrigConf::JetWindowSize::Size
Size
Definition: TriggerThresholdValue.h:17
Muon::nsw::STGTPMMData::size_output_mm_phiRes
constexpr int size_output_mm_phiRes
Definition: NSWSTGTPDecodeBitmaps.h:85
Muon::nsw::STGTPSegments::size_output_segment_dTheta
constexpr int size_output_segment_dTheta
Definition: NSWSTGTPDecodeBitmaps.h:113
Muon::nsw::STGTPMMData::size_output_mm_spare
constexpr int size_output_mm_spare
Definition: NSWSTGTPDecodeBitmaps.h:83
NSWSTGTPDecodeBitmaps.h
Muon::nsw::STGTPPad::size_coincidence_wedge
constexpr std::size_t size_coincidence_wedge
Definition: NSWSTGTPDecodeBitmaps.h:63
Muon::nsw::STGTPMMData::size_output_mm_phiID
constexpr int size_output_mm_phiID
Definition: NSWSTGTPDecodeBitmaps.h:87
STGTPPackets.h
Muon::nsw::STGTPPad::size_BCID
constexpr std::size_t size_BCID
Definition: NSWSTGTPDecodeBitmaps.h:66
Muon::nsw::STGTPPad::size_v2
constexpr std::size_t size_v2
Definition: NSWSTGTPDecodeBitmaps.h:73
Muon::nsw::STGTPPad::num_pads
constexpr std::size_t num_pads
Definition: NSWSTGTPDecodeBitmaps.h:60
Muon::nsw::STGTPSegments::size_output_segment_phiID
constexpr int size_output_segment_phiID
Definition: NSWSTGTPDecodeBitmaps.h:114
Muon::nsw::STGTPMMData::size_v2
constexpr std::size_t size_v2
Definition: NSWSTGTPDecodeBitmaps.h:94
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Muon::nsw::STGTPPad::size_bandID
constexpr std::size_t size_bandID
Definition: NSWSTGTPDecodeBitmaps.h:65
Muon::nsw::STGTPSegments::num_segments
constexpr std::size_t num_segments
Definition: NSWSTGTPDecodeBitmaps.h:101
Pythia8_A14_NNPDF23LO_Var1Down_Common.ver
ver
Definition: Pythia8_A14_NNPDF23LO_Var1Down_Common.py:26
Muon::nsw::STGTPSegments::size_output_segment_lowRes
constexpr int size_output_segment_lowRes
Definition: NSWSTGTPDecodeBitmaps.h:111
Muon::nsw::STGTPMMData::size_output_mm_lowRes
constexpr int size_output_mm_lowRes
Definition: NSWSTGTPDecodeBitmaps.h:84
Muon::nsw::STGTPSegments::size_valid_segment_v3
constexpr std::size_t size_valid_segment_v3
Definition: NSWSTGTPDecodeBitmaps.h:123
lumiFormat.i
int i
Definition: lumiFormat.py:85
Muon::nsw::STGTPMMData::size_output_mm_valids
constexpr int size_output_mm_valids
Definition: NSWSTGTPDecodeBitmaps.h:81
Muon::nsw::STGTPPad::size_phiID
constexpr std::size_t size_phiID
Definition: NSWSTGTPDecodeBitmaps.h:64
Muon::nsw::STGTPPad::size_v3_padding
constexpr std::size_t size_v3_padding
Definition: NSWSTGTPDecodeBitmaps.h:71
Muon::nsw::STGTPSegments::size_v1
constexpr std::size_t size_v1
Definition: NSWSTGTPDecodeBitmaps.h:120
Muon::nsw::STGTPMMData::num_mm
constexpr std::size_t num_mm
Definition: NSWSTGTPDecodeBitmaps.h:79
Muon::nsw::STGTPMMPacket::MMSegmentData
Definition: STGTPPackets.h:21
Muon::nsw::STGTPMMData::mm_stream_invalid_dTheta
constexpr int mm_stream_invalid_dTheta
Definition: NSWSTGTPDecodeBitmaps.h:96
Muon::nsw::STGTPSegmentPacket::Segment
const SegmentData & Segment(std::size_t segment) const
Definition: STGTPPackets.cxx:216
Muon::nsw::STGTPSegments::size_lut_choice_selection
constexpr int size_lut_choice_selection
Definition: NSWSTGTPDecodeBitmaps.h:105
Muon::nsw::STGTPMMPacket::Size
size_t Size(const int ver)
Definition: STGTPPackets.cxx:19
Muon::nsw::STGTPSegments::size_v3_padding
constexpr int size_v3_padding
Definition: NSWSTGTPDecodeBitmaps.h:119
Muon::nsw::format
std::string format(const std::string &str, const T &arg)
Definition: NSWDecodeHelper.h:43
Muon::nsw::STGTPMMData::size_v3
constexpr std::size_t size_v3
Definition: NSWSTGTPDecodeBitmaps.h:95
NSWDecodeHelper.h
Muon::nsw::STGTPSegments::size_output_segment_monitor
constexpr int size_output_segment_monitor
Definition: NSWSTGTPDecodeBitmaps.h:109
Muon::nsw::STGTPMMPacket::STGTPMMPacket
STGTPMMPacket(const std::vector< std::uint32_t > &payload, const int ver)
Definition: STGTPPackets.cxx:38
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
NSWMMTPDecodeBitmaps.h
Muon::nsw::STGTPPad::size_spare
constexpr std::size_t size_spare
Definition: NSWSTGTPDecodeBitmaps.h:67
DeMoScan.index
string index
Definition: DeMoScan.py:364
Muon::nsw::STGTPMMData::size_bcid
constexpr int size_bcid
Definition: NSWSTGTPDecodeBitmaps.h:90
Muon::nsw::STGTPPadPacket::Size
size_t Size(const int version)
Definition: STGTPPackets.cxx:96
Muon::nsw::STGTPPad::size_v1
constexpr std::size_t size_v1
Definition: NSWSTGTPDecodeBitmaps.h:72
Muon::nsw::STGTPSegments::size_bcid
constexpr int size_bcid
Definition: NSWSTGTPDecodeBitmaps.h:117
Muon::nsw::STGTPSegmentPacket::STGTPSegmentPacket
STGTPSegmentPacket(const std::vector< std::uint32_t > &payload, const int ver)
Definition: STGTPPackets.cxx:169
Muon::nsw::STGTPPad::size_v3
constexpr std::size_t size_v3
Definition: NSWSTGTPDecodeBitmaps.h:74
Muon::nsw::STGTPSegments::size_nsw_segment_selector
constexpr int size_nsw_segment_selector
Definition: NSWSTGTPDecodeBitmaps.h:106
Muon::nsw::STGTPSegmentPacket::SegmentData
Definition: STGTPPackets.h:68
Muon::nsw::STGTPSegmentPacket::Size
size_t Size(const int ver)
Definition: STGTPPackets.cxx:149
Muon::nsw::STGTPSegments::size_sectorID
constexpr int size_sectorID
Definition: NSWSTGTPDecodeBitmaps.h:118
Muon::nsw::STGTPMMData::size_output_mm_rIndex
constexpr int size_output_mm_rIndex
Definition: NSWSTGTPDecodeBitmaps.h:88
Muon::nsw::STGTPSegments::size_output_segment_rIndex
constexpr int size_output_segment_rIndex
Definition: NSWSTGTPDecodeBitmaps.h:115
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5