ATLAS Offline Software
Loading...
Searching...
No Matches
EtaCMA.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "GaudiKernel/MsgStream.h"
7
11
12#include <cstdio>
13#include <cstdlib>
14#include <fstream>
15
16using namespace RPC_CondCabling;
17
30
40
41EtaCMA::~EtaCMA() = default;
42
44 if (this != &cma) {
49 m_inversion = cma.inversion();
51 }
52 return *this;
53}
54
56 if (pivot_station()) // Check and connect strips with Pivot matrix channels
57 {
58 for (int i = pivot_start_ch(); i <= pivot_stop_ch(); ++i) {
59 int strip_number = (m_active_pivot_chs) ? 1 : pivot_start_st();
60 RPClink::iterator found = m_pivot_RPCs.find(i);
61 RPCchamber* rpc = (*found).second;
62 int final_strip = rpc->eta_strips();
63 if (i == pivot_stop_ch()) final_strip = pivot_stop_st();
64 do {
66 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EtaCMA") << noMoreChannels("Pivot");
67 return false;
68 }
69
70 int st_effective = strip_number - 1;
71 if (!i && side == Negative) st_effective = abs(st_effective - final_strip) - 1;
72
73 if (rpc->ijk_etaReadout() == 1) {
74 m_pivot[0][0][m_active_pivot_chs] = i * 100 + st_effective;
75 m_pivot[0][1][m_active_pivot_chs] = 10000 + i * 100 + st_effective;
76 } else {
77 m_pivot[0][1][m_active_pivot_chs] = i * 100 + st_effective;
78 m_pivot[0][0][m_active_pivot_chs] = 10000 + i * 100 + st_effective;
79 }
80 rpc->add_eta_channel(st_effective);
82 } while (++strip_number <= final_strip);
83 }
84 // Set first and last connectors code
85 int code = pivot_station() * 100000 + 2 * 100000000;
86 m_first_pivot_code = code + m_pivot[0][0][0];
88 }
89 if (lowPt_station() && lowPt_number_co() != -1) {
90 for (int i = lowPt_start_ch(); i <= lowPt_stop_ch(); ++i) {
91 int strip_number = (m_active_lowPt_chs) ? 1 : lowPt_start_st();
92 RPClink::iterator found = m_lowPt_RPCs.find(i);
93 RPCchamber* rpc = (*found).second;
94 int final_strip = rpc->eta_strips();
95 if (i == lowPt_stop_ch()) final_strip = lowPt_stop_st();
96 do {
98 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EtaCMA") << noMoreChannels("Low Pt");
99 return false;
100 }
101
102 int st_effective = strip_number - 1;
103 if (!i && side == Negative) st_effective = abs(st_effective - final_strip) - 1;
104
105 if (rpc->ijk_etaReadout() == 1) {
106 m_lowPt[0][0][m_active_lowPt_chs] = i * 100 + st_effective;
107 m_lowPt[0][1][m_active_lowPt_chs] = 10000 + i * 100 + st_effective;
108 } else {
109 m_lowPt[0][1][m_active_lowPt_chs] = i * 100 + st_effective;
110 m_lowPt[0][0][m_active_lowPt_chs] = 10000 + i * 100 + st_effective;
111 }
112 rpc->add_eta_channel(st_effective);
114 } while (++strip_number <= final_strip);
115 }
116 // Set first and last connectors code
117 int code = lowPt_station() * 100000 + 2 * 100000000;
118 m_first_lowPt_code = code + m_lowPt[0][0][0];
119 m_last_lowPt_code = code + m_lowPt[0][0][m_active_lowPt_chs - 1];
120 }
121 if (highPt_station() && highPt_number_co() != -1) {
122 for (int i = highPt_start_ch(); i <= highPt_stop_ch(); ++i) {
123 int strip_number = (m_active_highPt_chs) ? 1 : highPt_start_st();
124 RPClink::iterator found = m_highPt_RPCs.find(i);
125 RPCchamber* rpc = (*found).second;
126 int final_strip = rpc->eta_strips();
127 if (i == highPt_stop_ch()) final_strip = highPt_stop_st();
128 do {
130 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EtaCMA") << noMoreChannels("High Pt");
131 return false;
132 }
133
134 int st_effective = strip_number - 1;
135 if (!i && side == Negative) st_effective = abs(st_effective - final_strip) - 1;
136
137 if (rpc->ijk_etaReadout() == 1) {
138 m_highPt[0][0][m_active_highPt_chs] = i * 100 + st_effective;
139 m_highPt[0][1][m_active_highPt_chs] = 10000 + i * 100 + st_effective;
140 } else {
141 m_highPt[0][1][m_active_highPt_chs] = i * 100 + st_effective;
142 m_highPt[0][0][m_active_highPt_chs] = 10000 + i * 100 + st_effective;
143 }
144 rpc->add_eta_channel(st_effective);
146 } while (++strip_number <= final_strip);
147 }
148 // Set first and last connectors code
149 int code = highPt_station() * 100000 + 2 * 100000000;
150 m_first_highPt_code = code + m_highPt[0][0][0];
152 }
153 return true;
154}
155
157 if (pivot_station()) // Check and connect Pivot chambers
158 {
159 for (int i = pivot_start_ch(); i <= pivot_stop_ch(); ++i) {
160 RPCchamber* rpc = setup.find_chamber(pivot_station(), i);
161 if (rpc) {
162 rpc->add_cma(this);
163 m_pivot_RPCs.insert(RPClink::value_type(i, rpc));
164 } else {
165 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EtaCMA") << no_connection_error("RPC - pivot", i);
166 return false;
167 }
168 }
169 }
170
171 if (lowPt_station() && lowPt_number_co() != -1) { // Check and connect Low Pt chambers
173 ++m_lowPt_start_st; // RPC strips starts from 1!
174 for (int i = m_lowPt_start_ch; i <= m_lowPt_stop_ch; ++i) {
175 RPCchamber* rpc = setup.find_chamber(lowPt_station(), i);
176 if (rpc) {
177 rpc->add_cma(this);
178 m_lowPt_RPCs.insert(RPClink::value_type(i, rpc));
179 } else {
180 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EtaCMA") << no_connection_error("RPC - low Pt", i);
181 return false;
182 }
184 }
185 } else {
187 return false;
188 }
189 }
190
191 if (highPt_station() && highPt_number_co() != -1) { // Check and connect High Pt chambers
193 ++m_highPt_start_st; // RPC strips starts from 1!
194 for (int i = m_highPt_start_ch; i <= m_highPt_stop_ch; ++i) {
195 RPCchamber* rpc = setup.find_chamber(highPt_station(), i);
196 if (rpc) {
197 rpc->add_cma(this);
198 m_highPt_RPCs.insert(RPClink::value_type(i, rpc));
199 } else {
200 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EtaCMA") << no_connection_error("RPC - high Pt", i);
201 return false;
202 }
204 }
205 } else {
207 return false;
208 }
209 }
210 return true;
211}
212
214 int l;
215 if (stat == lowPt_station()) {
216 bool result = setup.local_conn_add(Eta, stat, lowPt_start_co(), l, m_lowPt_start_ch, m_lowPt_start_st) &&
217 setup.local_conn_add(Eta, stat, lowPt_stop_co(), l, m_lowPt_stop_ch, m_lowPt_stop_st);
218 if ((!m_lowPt_start_ch || !m_lowPt_stop_ch) && setup.side() == NoHalf) {
219 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EvenPhiCMA") << "Sector Type must belong "
220 "to a specific side when RPC chamber is in between eta 0";
221 return false;
222 }
223 return result;
224 } else if (stat == highPt_station()) {
225 bool result = setup.local_conn_add(Eta, stat, highPt_start_co(), l, m_highPt_start_ch, m_highPt_start_st) &&
226 setup.local_conn_add(Eta, stat, highPt_stop_co(), l, m_highPt_stop_ch, m_highPt_stop_st);
227 if ((!m_highPt_start_ch || !m_highPt_stop_ch) && setup.side() == NoHalf) {
228 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EvenPhiCMA") << "Sector Type must belong "
229 "to a specific side when RPC chamber is in between eta 0";
230 return false;
231 }
232 return result;
233
234 } else {
235 REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "EvenPhiCMA") << "Station n. " << stat
236 << " don't give input to CMA confirm planes!";
237 return false;
238 }
239}
240
241bool EtaCMA::setup(SectorLogicSetup& setup, MsgStream& log) {
242 // Connect the CMA with RPC chambers
243 if (!connect(setup)) return false;
244
245 // Check boundary of CMA channels
246 EtaCMA* prev = setup.previousCMA(*this);
247 if (prev && pivot_station()) {
248 if (pivot_start_ch() == prev->pivot_stop_ch()) {
249 if (!(pivot_start_st() == prev->pivot_stop_st() + 1)) {
250 log << MSG::ERROR << two_obj_error_message("strips mismatch", prev) << endmsg;
251 return false;
252 }
253 } else if (!(pivot_start_ch() == prev->pivot_stop_ch() + 1)) {
254 log << MSG::ERROR << two_obj_error_message("chambers mismatch", prev) << endmsg;
255 return false;
256 } else {
258 log << MSG::ERROR << two_obj_error_message("boundary mismatch", prev) << endmsg;
259 return false;
260 }
261 }
262 }
263
264 // Build the cabling map
265 if (!cable_CMA_channels(setup.side())) return false;
266
267 // invert the strip cabling if needed
268 if (!doInversion(setup)) return false;
269
270 // only 1 repository allowed so far
271 std::string LVL1_configuration_repository;
272 LVL1_configuration_repository = "ATLAS.data";
273
274 // Read the program file if exist
275 SectorLogicSetup::SECTORlist sectors = setup.sectors();
276 SectorLogicSetup::SECTORlist::const_iterator it = sectors.begin();
277
278 char s_tag[4];
279 sprintf(s_tag, "s%02d", *it);
280
281 char t_tag[3];
282 sprintf(t_tag, "t%1d", id().PAD_index());
283
284 char c_tag[4] = {'_', 'c', '2', '\0'};
285 if (id().Ixx_index() == 1) c_tag[2] = '3';
286
287 std::ifstream CMAprogLow;
288 std::istringstream CMAprogLow_COOL;
289 char name[200];
290
291 // LB retrieve pointer to the map of the trigger roads
292 const std::map<std::string, std::string>* p_trigroads = setup.GetPtoTrigRoads();
293
294 // Read trigger configurations from files
295
296 if (p_trigroads == nullptr) {
297 while (!CMAprogLow.is_open() && it != sectors.end()) {
298 std::ostringstream namestr;
299
300 std::string dir;
301 dir = setup.online_database();
302 namestr << dir << "/" << s_tag << "_" << t_tag << "_pl" << c_tag << ".txt" << std::ends; // M.C. search for local files
303
304 namestr.str().copy(name, namestr.str().length(), 0);
305 name[namestr.str().length()] = 0;
306 if (log.level() <= MSG::DEBUG) {
307 log << "filename for the trigger roads " << name << endmsg;
308 }
309
310 CMAprogLow.open(name);
311 ++it;
312 namestr.clear();
313 }
314 }
315 // Trigger configuration loaded from COOL
316 else {
317 while (CMAprogLow_COOL.str().empty() && it != sectors.end()) {
318 std::ostringstream namestr;
319 namestr << s_tag << "_" << t_tag << "_pl" << c_tag << ".txt" << std::ends;
320 namestr.str().copy(name, namestr.str().length(), 0);
321 name[namestr.str().length()] = 0;
322 std::map<std::string, std::string>::const_iterator itc;
323 itc = p_trigroads->find(name);
324 if (itc != p_trigroads->end()) {
325 CMAprogLow_COOL.str(itc->second.c_str());
326
327 if (log.level() <= MSG::VERBOSE) {
328 log << MSG::VERBOSE << "EtaCMA low: key " << name << "found in the Trigger Road Map --> OK"
329 << ", EtaCMA low: key " << itc->second.c_str()
330 << ", Etacma:CMAPROGLOW " << CMAprogLow_COOL.str()
331 << endmsg;
332 }
333 }
334 ++it;
335 namestr.clear();
336 }
337 }
338 if (CMAprogLow.is_open()) {
339 std::unique_ptr<CMAprogram> program = std::make_unique<CMAprogram>(CMAprogLow, true);
340 if (program->check()) {
341 m_lowPt_program = std::move(program);
342 if (setup.cosmic()) {
343 m_lowPt_program->open_threshold(0);
344 m_lowPt_program->open_threshold(1);
345 }
346 for (unsigned int i = 0; i < 3; ++i) {
347 if (!m_lowPt_program->hasProgrammed(i)) {
348 if (log.level() <= MSG::DEBUG) {
349 log << MSG::DEBUG << s_tag << ": " << id() << ": low-pt: has threshold " << i
350 << " not programmed." << endmsg;
351 }
352 }
353 }
354 }
355 CMAprogLow.close();
356 if (log.level() <= MSG::DEBUG) {
357 log << MSG::DEBUG << "EtaCMA::setup low_pt program has been read ---- " << endmsg;
358 }
359 } else if (!CMAprogLow_COOL.str().empty()) {
360 std::unique_ptr<CMAprogram> program = std::make_unique<CMAprogram>(CMAprogLow_COOL, true);
361 if (program->check()) {
362 m_lowPt_program = std::move(program);
363 if (setup.cosmic()) {
364 m_lowPt_program->open_threshold(0);
365 m_lowPt_program->open_threshold(1);
366 }
367 for (unsigned int i = 0; i < 3; ++i) {
368 if (!m_lowPt_program->hasProgrammed(i)) {
369 if (log.level() <= MSG::DEBUG) {
370 log << MSG::DEBUG << s_tag << ": " << id() << ": low-pt: has threshold " << i
371 << " not programmed." << endmsg;
372 }
373 }
374 }
375 }
376 CMAprogLow_COOL.str("");
377 } else {
378 if (log.level() <= MSG::DEBUG) {
379 log << MSG::DEBUG << name << " not found! Putting a dummy configuration" << endmsg;
380 }
381 m_lowPt_program = std::make_unique<CMAprogram>();
382 m_lowPt_program->open_threshold(0);
383 }
384
385 it = sectors.begin();
386 std::ifstream CMAprogHigh;
387 std::istringstream CMAprogHigh_COOL;
388
389 if (p_trigroads == nullptr) {
390 while (!CMAprogHigh.is_open() && it != sectors.end()) {
391 std::ostringstream namestr;
392 std::string dir;
393 dir = setup.online_database();
394 namestr << dir << "/" << s_tag << "_" << t_tag << "_ph" << c_tag << ".txt" << std::ends;
395
396 namestr.str().copy(name, namestr.str().length(), 0);
397 name[namestr.str().length()] = 0;
398 if (log.level() <= MSG::DEBUG) {
399 log << MSG::DEBUG << "filename for the trigger roads " << name << endmsg;
400 }
401 CMAprogHigh.open(name);
402 ++it;
403 namestr.clear();
404 }
405 }
406 // Trigger configuration loaded from COOL
407 else {
408 while (CMAprogHigh_COOL.str().empty() && it != sectors.end()) {
409 std::ostringstream namestr;
410 namestr << s_tag << "_" << t_tag << "_ph" << c_tag << ".txt" << std::ends;
411 namestr.str().copy(name, namestr.str().length(), 0);
412 name[namestr.str().length()] = 0;
413 std::map<std::string, std::string>::const_iterator itc;
414 itc = p_trigroads->find(name);
415 if (itc != p_trigroads->end()) {
416 if (log.level() <= MSG::VERBOSE) {
417 log << MSG::VERBOSE << "EtaCMA high: key " << name << "found in the Trigger Road Map --> OK"
418 << ", EtaCMA high: key " << itc->second.c_str() << endmsg;
419 }
420 CMAprogHigh_COOL.str(itc->second.c_str());
421 if (log.level() <= MSG::VERBOSE) {
422 log << MSG::VERBOSE << "EtaCMA:CMAPROGHIGH " << CMAprogHigh_COOL.str() << endmsg;
423 }
424 }
425 ++it;
426 namestr.clear();
427 }
428 }
429
430 if (CMAprogHigh.is_open()) {
431 std::unique_ptr<CMAprogram> program = std::make_unique<CMAprogram>(CMAprogHigh, true);
432 if (program->check()) {
433 m_highPt_program = std::move(program);
434 if (setup.cosmic()) {
435 m_highPt_program->open_threshold(0);
436 m_highPt_program->open_threshold(1);
437 }
438 for (unsigned int i = 0; i < 3; ++i) {
439 if (!m_highPt_program->hasProgrammed(i)) {
440 if (log.level() <= MSG::DEBUG) {
441 log << MSG::DEBUG << s_tag << ": " << id() << ": high-pt: has threshold " << i
442 << " not programmed." << endmsg;
443 }
444 }
445 }
446 }
447 CMAprogHigh.close();
448 if (log.level() <= MSG::DEBUG) {
449 log << MSG::DEBUG << "EtaCMA::setup high_pt program has been read ---- " << endmsg;
450 }
451 } else if (!CMAprogHigh_COOL.str().empty()) {
452 std::unique_ptr<CMAprogram> program = std::make_unique<CMAprogram>(CMAprogHigh_COOL, true);
453 if (program->check()) {
454 m_highPt_program = std::move(program);
455 if (setup.cosmic()) {
456 m_highPt_program->open_threshold(0);
457 m_highPt_program->open_threshold(1);
458 }
459 for (unsigned int i = 0; i < 3; ++i) {
460 if (!m_highPt_program->hasProgrammed(i)) {
461 if (log.level() <= MSG::DEBUG) {
462 log << MSG::DEBUG << s_tag << ": " << id() << ": high-pt: has threshold " << i
463 << " not programmed." << endmsg;
464 }
465 }
466 }
467 }
468 CMAprogHigh_COOL.str("");
469 } else {
470 if (log.level() <= MSG::DEBUG) {
471 log << MSG::DEBUG << " not found! Putting a dummy configuration" << endmsg;
472 }
473 m_highPt_program = std::make_unique<CMAprogram>();
474 m_highPt_program->open_threshold(0);
475 }
476
477 return true;
478}
479
481 SectorLogicSetup::SECTORlist Sectors = setup.sectors();
482 SectorLogicSetup::SECTORlist::const_iterator it = Sectors.begin();
483 int sector = *it;
484
485 RPClink::const_iterator rpc;
486 if (lowPt_station() && lowPt_number_co() != -1) {
487 rpc = m_lowPt_RPCs.begin();
488 if ((*rpc).second->inversion(sector)) {
489 m_inversion = true;
492 int tmp = m_first_lowPt_code;
494 m_last_lowPt_code = tmp;
495 }
496 }
497
498 if (pivot_station()) {
499 rpc = m_pivot_RPCs.begin();
500 if ((*rpc).second->inversion(sector)) {
501 m_inversion = true;
504 int tmp = m_first_pivot_code;
506 m_last_pivot_code = tmp;
507 }
508 }
509
510 if (highPt_station() && highPt_number_co() != -1) {
511 rpc = m_highPt_RPCs.begin();
512 if ((*rpc).second->inversion(sector)) {
513 m_inversion = true;
516 int tmp = m_first_highPt_code;
518 m_last_highPt_code = tmp;
519 }
520 }
521
522 if (m_inversion) m_id->inversion();
523
524 return true;
525}
526
528 RPClink::const_iterator found = m_pivot_RPCs.find(pivot_stop_ch());
529 return (*found).second->eta_strips() == pivot_stop_st();
530}
531
533 return pivot_start_st() == 1;
534}
#define endmsg
@ LowPt
@ HighPt
@ Pivot
@ Inversion
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
HalfType
Definition RPCdef.h:9
@ NoHalf
Definition RPCdef.h:9
@ Negative
Definition RPCdef.h:9
const std::string & name() const
Definition BaseObject.h:23
int highPt_number_co() const
unsigned int last_lowPt_channel() const
int pivot_stop_st() const
int pivot_stop_ch() const
unsigned int first_lowPt_channel() const
int highPt_stop_st() const
CMAconfiguration m_conf_type
int pivot_station() const
static constexpr int confirm_channels
int(* m_lowPt)[2][confirm_channels]
int lowPt_start_co() const
bool correct(L1RPCcabCorrection type, CMAinput it, unsigned int layer, unsigned short int Ch1, unsigned short int Ch2, short int num) const
int(* m_pivot)[2][pivot_channels]
CMAparameters & operator=(const CMAparameters &)
int pivot_start_st() const
int highPt_start_st() const
unsigned int m_last_pivot_code
unsigned int m_last_lowPt_code
int highPt_stop_co() const
int lowPt_stop_st() const
const CMAidentity & id() const
int lowPt_start_st() const
int lowPt_number_co() const
unsigned int m_first_pivot_code
std::string two_obj_error_message(const std::string &, CMAparameters *)
int lowPt_stop_ch() const
int highPt_station() const
std::string noMoreChannels(const std::string &stat)
int lowPt_station() const
void create_highPt_map(int)
unsigned int m_first_highPt_code
std::unique_ptr< CMAprogram > m_lowPt_program
std::unique_ptr< CMAidentity > m_id
int highPt_stop_ch() const
int highPt_start_ch() const
unsigned int m_last_highPt_code
int lowPt_start_ch() const
void create_pivot_map(int)
void create_lowPt_map(int)
std::unique_ptr< CMAprogram > m_highPt_program
unsigned int m_first_lowPt_code
unsigned int first_highPt_channel() const
int highPt_start_co() const
int lowPt_stop_co() const
unsigned int last_pivot_channel() const
CMAparameters(const parseParams &parse)
std::string no_confirm_error(int)
int(* m_highPt)[2][confirm_channels]
int pivot_start_ch() const
static constexpr int pivot_channels
unsigned int first_pivot_channel() const
unsigned int last_highPt_channel() const
std::string no_connection_error(const std::string &, int) const
bool cable_CMA_channels(HalfType)
Definition EtaCMA.cxx:55
const RPClink & pivot_RPCs(void) const
Definition EtaCMA.h:44
EtaCMA(const parseParams &parse)
Definition EtaCMA.cxx:18
bool doInversion(SectorLogicSetup &)
Definition EtaCMA.cxx:480
EtaCMA & operator=(const EtaCMA &)
Definition EtaCMA.cxx:43
bool begin_at_RPC_Z_boundary(void) const
Definition EtaCMA.cxx:532
bool end_at_RPC_Z_boundary(void) const
Definition EtaCMA.cxx:527
bool inversion(void) const
Definition EtaCMA.h:48
const RPClink & lowPt_RPCs(void) const
Definition EtaCMA.h:45
const RPClink & highPt_RPCs(void) const
Definition EtaCMA.h:46
bool connect(SectorLogicSetup &)
Definition EtaCMA.cxx:156
bool got_confirm_cabling(SectorLogicSetup &, int)
Definition EtaCMA.cxx:213
bool setup(SectorLogicSetup &, MsgStream &)
Definition EtaCMA.cxx:241
void add_cma(const EtaCMA *)
std::map< std::string, std::string > parse(const std::string &list)