ATLAS Offline Software
Loading...
Searching...
No Matches
CMAprogram.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <string>
9#include <algorithm>
10#include <iostream>
11#include <fstream>
12#include <sstream>
13
14namespace {
15 void
16 storeThresholdWords(uint64_t twoWords,
17 uint32_t (&programBytes)[CMAparameters::pivot_channels][2],
18 bool (&thresholdRegisters)[CMAparameters::pivot_channels]
20 int channel)
21 {
22 const uint32_t lowWord = static_cast<uint32_t>(twoWords);
23 const uint32_t highWord = static_cast<uint32_t>(twoWords >> 32);
24
25 programBytes[channel][0] = lowWord;
26 programBytes[channel][1] = highWord;
27
28 for (int bit = 0; bit < 32; ++bit) {
29 thresholdRegisters[channel][bit] = ((lowWord >> bit) & 1U) != 0U;
30 thresholdRegisters[channel][bit + 32] = ((highWord >> bit) & 1U) != 0U;
31 }
32 }
33}
34
36
37 // initialize multi-dimensional arrays:
38 std::fill_n(reinterpret_cast<uint32_t*>(m_program_bytes),
40 0xffffffff);
41
42 std::fill_n(reinterpret_cast<bool*>(m_threshold_registers),
44 true);
45}
46
47CMAprogram::CMAprogram(std::ifstream& file, bool NewCab) :
48 CMAprogram() {
49
50 m_isnewcab = NewCab;
53}
54
55CMAprogram::CMAprogram(std::istringstream& filestr, bool NewCab) :
56 CMAprogram() {
57
58 m_isnewcab = NewCab;
59 DBline data(filestr);
61}
62
64 uint32_t right_bit = 0x1;
65 std::string ignore;
66
67 ++data;
68
69 while (data) {
70 data("set_main_control") >> data.dbhex() >> m_main_control >> data.dbdec();
71 data("set_main_count") >> data.dbhex() >> m_main_count >> data.dbdec();
72 data("set_main_status") >> data.dbhex() >> m_main_status >> data.dbdec();
73
74 data("set_pipe_i0_mask0_in") >> data.dbhex() >> m_pipe_i0_mask0_in >> data.dbdec();
75 data("set_pipe_i0_edge") >> data.dbhex() >> m_pipe_i0_edge >> data.dbdec();
76 data("set_pipe_i0_ipb_regdepth") >> data.dbhex() >> m_pipe_i0_ipb_regdepth >> data.dbdec();
77 data("set_pipe_i0_shape") >> data.dbhex() >> m_pipe_i0_shape >> data.dbdec();
78 data("set_pipe_i0_mask0_readout") >> data.dbhex() >> m_pipe_i0_mask0_readout >> data.dbdec();
79 data("set_pipe_i0_mask0_trig") >> data.dbhex() >> m_pipe_i0_mask0_trig >> data.dbdec();
80
81 data("set_pipe_i1_mask0_in") >> data.dbhex() >> m_pipe_i1_mask0_in >> data.dbdec();
82 data("set_pipe_i1_edge") >> data.dbhex() >> m_pipe_i1_edge >> data.dbdec();
83 data("set_pipe_i1_ipb_regdepth") >> data.dbhex() >> m_pipe_i1_ipb_regdepth >> data.dbdec();
84 data("set_pipe_i1_shape") >> data.dbhex() >> m_pipe_i1_shape >> data.dbdec();
85 data("set_pipe_i1_mask0_readout") >> data.dbhex() >> m_pipe_i1_mask0_readout >> data.dbdec();
86 data("set_pipe_i1_mask0_trig") >> data.dbhex() >> m_pipe_i1_mask0_trig >> data.dbdec();
87
88 data("set_pipe_j0_mask0_in") >> data.dbhex() >> m_pipe_j0_mask0_in >> data.dbdec();
89 data("set_pipe_j0_edge") >> data.dbhex() >> m_pipe_j0_edge >> data.dbdec();
90 data("set_pipe_j0_ipb_regdepth") >> data.dbhex() >> m_pipe_j0_ipb_regdepth >> data.dbdec();
91 data("set_pipe_j0_shape") >> data.dbhex() >> m_pipe_j0_shape >> data.dbdec();
92 data("set_pipe_j0_mask0_readout") >> data.dbhex() >> m_pipe_j0_mask0_readout >> data.dbdec();
93 data("set_pipe_j0_mask0_trig") >> data.dbhex() >> m_pipe_j0_mask0_trig >> data.dbdec();
94
95 data("set_pipe_j1_mask0_in") >> data.dbhex() >> m_pipe_j1_mask0_in >> data.dbdec();
96 data("set_pipe_j1_edge") >> data.dbhex() >> m_pipe_j1_edge >> data.dbdec();
97 data("set_pipe_j1_ipb_regdepth") >> data.dbhex() >> m_pipe_j1_ipb_regdepth >> data.dbdec();
98 data("set_pipe_j1_shape") >> data.dbhex() >> m_pipe_j1_shape >> data.dbdec();
99 data("set_pipe_j1_mask0_readout") >> data.dbhex() >> m_pipe_j1_mask0_readout >> data.dbdec();
100 data("set_pipe_j1_mask0_trig") >> data.dbhex() >> m_pipe_j1_mask0_trig >> data.dbdec();
101
102 data("set_trig_thr0_maj_reg") >> data.dbhex() >> m_trig_thr0_maj_reg >> data.dbdec();
103 data("set_trig_thr0_mask_1_i_ge1_reg") >> data.dbhex() >> m_trig_thr0_mask_1_i_ge1_reg >> data.dbdec();
104 data("set_trig_thr0_mask_1_i_eq2_reg") >> data.dbhex() >> m_trig_thr0_mask_1_i_eq2_reg >> data.dbdec();
105 data("set_trig_thr0_mask_1_j_ge1_reg") >> data.dbhex() >> m_trig_thr0_mask_1_j_ge1_reg >> data.dbdec();
106 data("set_trig_thr0_mask_1_j_eq2_reg") >> data.dbhex() >> m_trig_thr0_mask_1_j_eq2_reg >> data.dbdec();
107
108 data("set_trig_thr1_maj_reg") >> data.dbhex() >> m_trig_thr1_maj_reg >> data.dbdec();
109 data("set_trig_thr1_mask_1_i_ge1_reg") >> data.dbhex() >> m_trig_thr1_mask_1_i_ge1_reg >> data.dbdec();
110 data("set_trig_thr1_mask_1_i_eq2_reg") >> data.dbhex() >> m_trig_thr1_mask_1_i_eq2_reg >> data.dbdec();
111 data("set_trig_thr1_mask_1_j_ge1_reg") >> data.dbhex() >> m_trig_thr1_mask_1_j_ge1_reg >> data.dbdec();
112 data("set_trig_thr1_mask_1_j_eq2_reg") >> data.dbhex() >> m_trig_thr1_mask_1_j_eq2_reg >> data.dbdec();
113
114 data("set_trig_thr2_maj_reg") >> data.dbhex() >> m_trig_thr2_maj_reg >> data.dbdec();
115 data("set_trig_thr2_mask_1_i_ge1_reg") >> data.dbhex() >> m_trig_thr2_mask_1_i_ge1_reg >> data.dbdec();
116 data("set_trig_thr2_mask_1_i_eq2_reg") >> data.dbhex() >> m_trig_thr2_mask_1_i_eq2_reg >> data.dbdec();
117 data("set_trig_thr2_mask_1_j_ge1_reg") >> data.dbhex() >> m_trig_thr2_mask_1_j_ge1_reg >> data.dbdec();
118 data("set_trig_thr2_mask_1_j_eq2_reg") >> data.dbhex() >> m_trig_thr2_mask_1_j_eq2_reg >> data.dbdec();
119
120 data("set_trig_declu_i0_clsize") >> data.dbhex() >> m_trig_declu_i0_clsize >> data.dbdec();
121 data("set_trig_declu_i1_clsize") >> data.dbhex() >> m_trig_declu_i1_clsize >> data.dbdec();
122 data("set_trig_declu_j0_clsize") >> data.dbhex() >> m_trig_declu_j0_clsize >> data.dbdec();
123 data("set_trig_declu_j1_clsize") >> data.dbhex() >> m_trig_declu_j1_clsize >> data.dbdec();
124
125 data("set_trig_prp_i_eta_reg") >> data.dbhex() >> m_trig_local_direc_i >> data.dbdec();
126 data("set_trig_prp_j_eta_reg") >> data.dbhex() >> m_trig_local_direc_j >> data.dbdec();
127 data("set_trig_shape_k_reg") >> data.dbhex() >> m_trig_shape_k_reg >> data.dbdec();
128 data("set_trig_ovl_sx_reg") >> data.dbhex() >> m_overlap2 >> data.dbdec();
129 data("set_trig_ovl_dx_reg") >> data.dbhex() >> m_overlap1 >> data.dbdec();
130 data("set_trig_edge_reg") >> data.dbhex() >> m_trig_edge_reg >> data.dbdec();
131
132 data("set_readout_buffer_empty") >> data.dbhex() >> m_readout_buffer_empty >> data.dbdec();
133 data("set_readout_buffer_almost_empty") >> data.dbhex() >> m_readout_buffer_almost_empty >> data.dbdec();
134 data("set_readout_buffer_half_full") >> data.dbhex() >> m_readout_buffer_half_full >> data.dbdec();
135 data("set_readout_buffer_almost_full") >> data.dbhex() >> m_readout_buffer_almost_full >> data.dbdec();
136 data("set_readout_buffer_full") >> data.dbhex() >> m_readout_buffer_full >> data.dbdec();
137 data("set_readout_buffer_latreg") >> data.dbhex() >> m_readout_buffer_latreg >> data.dbdec();
138 data("set_readout_buffer_hireg") >> data.dbhex() >> m_readout_buffer_hireg >> data.dbdec();
139 data("set_readout_buffer_lowreg") >> data.dbhex() >> m_readout_buffer_lowreg >> data.dbdec();
140 data("set_readout_serializer_dslink") >> data.dbhex() >> m_readout_serializer_dslink >> data.dbdec();
141
142 data("set_l1c_pre") >> data.dbhex() >> m_l1c_pre >> data.dbdec();
143 data("set_bcc_pre") >> data.dbhex() >> m_bcc_pre >> data.dbdec();
144
145 // start reading the threshold registers
146
147 uint64_t twowords;
148
149 if (m_isnewcab) {
150 if (data("set_trig_thr0_thr_reg_00")) {
151 for (int i = 0; i < 32; ++i) {
152 ignore.clear();
153 if (i == 0) {
154 data >> data.dbhex() >> twowords >> data.dbdec();
155 } else {
156 data >> ignore >> data.dbhex() >> twowords >> data.dbdec();
157 }
158 storeThresholdWords(twowords, m_program_bytes[0], m_threshold_registers[0], i);
159 if (i < 31) {
160 ++data;
161 }
162 }
163 }
164 if (data("set_trig_thr1_thr_reg_00")) {
165 ignore.clear();
166 for (int i = 0; i < 32; ++i) {
167 if (i == 0) {
168 data >> data.dbhex() >> twowords >> data.dbdec();
169 } else {
170 data >> ignore >> data.dbhex() >> twowords >> data.dbdec();
171 }
172 storeThresholdWords(twowords, m_program_bytes[1], m_threshold_registers[1], i);
173 if (i < 31) {
174 ++data;
175 }
176 }
177 }
178
179 if (data("set_trig_thr2_thr_reg_00")) {
180 ignore.clear();
181 for (int i = 0; i < 32; ++i) {
182 if (i == 0) {
183 data >> data.dbhex() >> twowords >> data.dbdec();
184 } else {
185 data >> ignore >> data.dbhex() >> twowords >> data.dbdec();
186 }
187 storeThresholdWords(twowords, m_program_bytes[2], m_threshold_registers[2], i);
188 if (i < 31) {
189 ++data;
190 }
191 }
192 }
193 ++data;
194 } else {
195 // case RPCcablingSim
196 // old format ///////////////////////////////////////////////////////
197 for (int i = 1; i <= 3; ++i) {
198 int majority;
199
200 if (data("th #", i) && data("maj_reg") >> majority) {
201 int th = 0;
202 int ch = 0;
203 uint32_t first_word = 0;
204 uint32_t second_word = 0;
205
206 ++data;
207
208 while (data("th") >> th >> "thr_reg" >> ch >> data.dbhex() >> first_word >> second_word >> data.dbdec()) {
209 if (th < 1) return false;
210 m_program_bytes[th - 1][ch][1] = first_word;
211 m_program_bytes[th - 1][ch][0] = second_word;
212
213 for (int bit = 0; bit < 32; ++bit) {
214 m_threshold_registers[th - 1][ch][bit] = ((second_word >> bit) & right_bit) != 0;
215 m_threshold_registers[th - 1][ch][bit + 32] = ((first_word >> bit) & right_bit) != 0;
216 }
217
218 ++data;
219 }
220 }
221 }
222
223 data("overlap1") >> data.dbhex() >> m_overlap1 >> data.dbdec();
224 data("overlap2") >> data.dbhex() >> m_overlap2 >> data.dbdec();
225 data("trig_local_direc_i") >> m_trig_local_direc_i;
226 data("trig_local_direc_j") >> m_trig_local_direc_j;
227 data("trig_k_readout") >> m_trig_k_readout;
228
229 ++data;
230 }
231 }
232
233 return true;
234}
235
237 if (th >= 3) return;
238 for (int ch = 0; ch < CMAparameters::pivot_channels; ++ch) {
239 m_program_bytes[th][ch][1] = 0xffffffff;
240 m_program_bytes[th][ch][0] = 0xffffffff;
241
242 for (int bit = 0; bit < 32; ++bit) {
243 m_threshold_registers[th][ch][bit] = true;
244 m_threshold_registers[th][ch][bit + 32] = true;
245 }
246 }
247}
248
249void CMAprogram::copy_over(int source, int dest) {
250 if (source >= 3 || dest >= 3) return;
251 if (source == dest) return;
252
253 for (int ch = 0; ch < CMAparameters::pivot_channels; ++ch) {
254 m_program_bytes[dest][ch][1] = m_program_bytes[source][ch][1];
255 m_program_bytes[dest][ch][0] = m_program_bytes[source][ch][0];
256
257 for (int bit = 0; bit < 32; ++bit) {
258 m_threshold_registers[dest][ch][bit] = m_threshold_registers[source][ch][bit];
259 m_threshold_registers[dest][ch][bit + 32] = m_threshold_registers[source][ch][bit + 32];
260 }
261 }
262}
263
264bool CMAprogram::hasProgrammed(unsigned int th) const {
265 if (th >= 3) return false;
266 for (int ch = 0; ch < CMAparameters::pivot_channels; ++ch) {
267 if (m_program_bytes[th][ch][1] != 0x0) return true;
268 if (m_program_bytes[th][ch][0] != 0x0) return true;
269 }
270 return false;
271}
272
273std::ostream& operator<<(std::ostream& stream, const CMAprogram& program) {
274 unsigned int no_coincidence = 183;
275
276 for (int piv = CMAparameters::pivot_channels - 1; piv >= 0; --piv) {
277 for (int con = 0; con < CMAparameters::confirm_channels; ++con) {
278 for (int th = 2; th >= 0; --th) {
279 if (program.m_threshold_registers[th][piv][con]) {
280 stream << th + 1;
281 break;
282 }
283 if (th == 0) stream << (char)no_coincidence;
284 }
285 }
286 stream << std::endl;
287 }
288 return stream;
289}
std::ostream & operator<<(std::ostream &stream, const CMAprogram &program)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static constexpr int confirm_channels
static constexpr int pivot_channels
uint64_t m_pipe_j0_shape
Definition CMAprogram.h:54
uint64_t m_trig_thr2_mask_1_j_ge1_reg
Definition CMAprogram.h:76
bool m_threshold_registers[3][CMAparameters::pivot_channels][CMAparameters::confirm_channels]
Definition CMAprogram.h:110
uint32_t m_pipe_i1_shape
Definition CMAprogram.h:45
uint64_t m_trig_thr1_mask_1_j_eq2_reg
Definition CMAprogram.h:72
uint32_t m_pipe_i0_mask0_trig
Definition CMAprogram.h:41
uint8_t m_main_count
Definition CMAprogram.h:22
uint32_t m_pipe_i0_mask0_in
Definition CMAprogram.h:37
uint32_t m_trig_local_direc_j
Definition CMAprogram.h:31
uint32_t m_trig_shape_k_reg
Definition CMAprogram.h:80
uint32_t m_pipe_i0_shape
Definition CMAprogram.h:39
uint64_t m_pipe_j1_mask0_readout
Definition CMAprogram.h:61
uint32_t m_pipe_i1_mask0_in
Definition CMAprogram.h:43
uint32_t m_trig_thr0_mask_1_i_ge1_reg
Definition CMAprogram.h:64
uint64_t m_pipe_j1_edge
Definition CMAprogram.h:59
uint32_t m_pipe_i0_mask0_readout
Definition CMAprogram.h:40
void copy_over(int, int)
uint8_t m_trig_declu_i1_clsize
Definition CMAprogram.h:91
uint16_t m_bcc_pre
Definition CMAprogram.h:108
uint64_t m_pipe_j0_mask0_in
Definition CMAprogram.h:52
uint8_t m_readout_buffer_hireg
Definition CMAprogram.h:103
uint32_t m_main_control
Definition CMAprogram.h:25
uint32_t m_pipe_i1_mask0_readout
Definition CMAprogram.h:46
uint8_t m_trig_declu_j1_clsize
Definition CMAprogram.h:93
uint64_t m_trig_thr0_mask_1_j_eq2_reg
Definition CMAprogram.h:67
uint8_t m_trig_thr0_maj_reg
Definition CMAprogram.h:98
uint16_t m_readout_buffer_empty
Definition CMAprogram.h:84
uint32_t m_trig_k_readout
Definition CMAprogram.h:32
uint32_t m_pipe_j1_ipb_regdepth
Definition CMAprogram.h:50
uint8_t m_trig_declu_j0_clsize
Definition CMAprogram.h:92
uint32_t m_overlap1
Definition CMAprogram.h:27
uint16_t m_pipe_i1_ipb_regdepth
Definition CMAprogram.h:35
uint8_t m_readout_buffer_lowreg
Definition CMAprogram.h:104
uint64_t m_pipe_j0_edge
Definition CMAprogram.h:53
uint32_t m_pipe_i1_edge
Definition CMAprogram.h:44
uint8_t m_trig_declu_i0_clsize
Definition CMAprogram.h:90
uint16_t m_l1c_pre
Definition CMAprogram.h:107
uint8_t m_trig_thr2_maj_reg
Definition CMAprogram.h:100
bool m_status
Definition CMAprogram.h:20
uint16_t m_readout_buffer_full
Definition CMAprogram.h:88
void open_threshold(int th)
uint32_t m_pipe_j0_ipb_regdepth
Definition CMAprogram.h:49
uint16_t m_readout_buffer_almost_empty
Definition CMAprogram.h:85
uint16_t m_readout_buffer_almost_full
Definition CMAprogram.h:87
bool hasProgrammed(unsigned int th) const
uint64_t m_trig_thr1_mask_1_j_ge1_reg
Definition CMAprogram.h:71
bool read_v02(DBline &)
uint8_t m_main_status
Definition CMAprogram.h:23
uint64_t m_pipe_j1_mask0_trig
Definition CMAprogram.h:62
uint32_t m_overlap2
Definition CMAprogram.h:28
uint32_t m_trig_thr1_mask_1_i_eq2_reg
Definition CMAprogram.h:70
uint32_t m_trig_thr2_mask_1_i_eq2_reg
Definition CMAprogram.h:75
uint32_t m_pipe_i1_mask0_trig
Definition CMAprogram.h:47
uint32_t m_pipe_i0_edge
Definition CMAprogram.h:38
uint64_t m_pipe_j0_mask0_readout
Definition CMAprogram.h:55
uint64_t m_trig_thr0_mask_1_j_ge1_reg
Definition CMAprogram.h:66
uint64_t m_trig_edge_reg
Definition CMAprogram.h:79
uint32_t m_trig_local_direc_i
Definition CMAprogram.h:30
uint32_t m_trig_thr2_mask_1_i_ge1_reg
Definition CMAprogram.h:74
uint64_t m_pipe_j1_shape
Definition CMAprogram.h:60
bool m_isnewcab
Definition CMAprogram.h:19
uint64_t m_trig_thr2_mask_1_j_eq2_reg
Definition CMAprogram.h:77
uint32_t m_trig_thr1_mask_1_i_ge1_reg
Definition CMAprogram.h:69
uint8_t m_readout_buffer_latreg
Definition CMAprogram.h:102
uint64_t m_pipe_j1_mask0_in
Definition CMAprogram.h:58
uint16_t m_pipe_i0_ipb_regdepth
Definition CMAprogram.h:34
uint16_t m_readout_buffer_half_full
Definition CMAprogram.h:86
uint8_t m_trig_thr1_maj_reg
Definition CMAprogram.h:99
uint32_t m_trig_thr0_mask_1_i_eq2_reg
Definition CMAprogram.h:65
uint8_t m_readout_serializer_dslink
Definition CMAprogram.h:105
uint64_t m_pipe_j0_mask0_trig
Definition CMAprogram.h:56
uint32_t m_program_bytes[3][CMAparameters::pivot_channels][2]
Definition CMAprogram.h:111
constexpr unsigned int bit(int n)
setEventNumber uint32_t
TFile * file