ATLAS Offline Software
Loading...
Searching...
No Matches
RpcCablingCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
8
9#include <sstream>
10
12
14
15RpcCablingCondAlg::RpcCablingCondAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthCondAlgorithm(name, pSvcLocator) {}
16
18 ATH_MSG_DEBUG("initializing" << name());
19 ATH_CHECK(m_readKey_map_schema.initialize());
21 ATH_CHECK(m_readKey_cm_thr_eta.initialize());
22 ATH_CHECK(m_readKey_cm_thr_phi.initialize());
23 ATH_CHECK(m_writeKey.initialize());
24 ATH_CHECK(m_idHelperSvc.retrieve());
25 return StatusCode::SUCCESS;
26}
27
28StatusCode RpcCablingCondAlg::execute(const EventContext& ctx) const {
29
30 ATH_MSG_DEBUG("executing" << name());
31
33 if (writeHandle.isValid()) {
34 ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
35 << ". In theory this should not be called, but may happen"
36 << " if multiple concurrent events are being processed out of order.");
37 return StatusCode::SUCCESS;
38 }
39
40 // read in the 4 different cond objects:
41 // map
43 const CondAttrListCollection* readCdoMap{*readHandle_map_schema};
44 if (!readCdoMap) {
45 ATH_MSG_FATAL("Null pointer to the read conditions object");
46 return StatusCode::FAILURE;
47 }
48 writeHandle.addDependency(readHandle_map_schema);
49 ATH_MSG_DEBUG("Size of CondAttrListCollection readCdoMap->size()= " << readCdoMap->size());
50
51 // corr
53 const CondAttrListCollection* readCdoCorr{*readHandle_map_schema_corr};
54 if (!readCdoCorr) {
55 ATH_MSG_FATAL("Null pointer to the read conditions object");
56 return StatusCode::FAILURE;
57 }
58 ATH_MSG_DEBUG("Size of CondAttrListCollection readCdoMap_corr->size()= " << readCdoCorr->size());
59 writeHandle.addDependency(readHandle_map_schema_corr);
60
61 // EtaTable
63 const CondAttrListCollection* readCdoEta{*readHandle_cm_thr_eta};
64 if (!readCdoEta) {
65 ATH_MSG_FATAL("Null pointer to the read conditions object");
66 return StatusCode::FAILURE;
67 }
68 ATH_MSG_DEBUG("Size of CondAttrListCollection readCdo_cm_thr_eta->size()= " << readCdoEta->size());
69 writeHandle.addDependency(readHandle_cm_thr_eta);
70
71 // phiTable
73 const CondAttrListCollection* readCdoPhi{*readHandle_cm_thr_phi};
74 if (!readCdoPhi) {
75 ATH_MSG_FATAL("Null pointer to the read conditions object");
76 return StatusCode::FAILURE;
77 }
78 ATH_MSG_DEBUG("Size of CondAttrListCollection readCdo_cm_thr_phi->size()= " << readCdoPhi->size());
79 writeHandle.addDependency(readHandle_cm_thr_phi);
80
81 std::unique_ptr<RpcCablingCondData> writeCdo{std::make_unique<RpcCablingCondData>()};
82 ATH_CHECK(setup(readCdoMap, readCdoCorr, readCdoEta, readCdoPhi, writeCdo.get()));
83
84 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
85 ATH_MSG_FATAL("Could not record RpcCondCablingData " << writeHandle.key() << " with EventRange " << writeHandle.getRange()
86 << " into Conditions Store");
87 return StatusCode::SUCCESS;
88 }
89
90 ATH_MSG_INFO("recorded new " << writeHandle.key() << " with range " << writeHandle.getRange());
91 return StatusCode::SUCCESS;
92}
93
94StatusCode RpcCablingCondAlg::setup(const CondAttrListCollection* readCdoMap, const CondAttrListCollection* readCdoCorr,
95 const CondAttrListCollection* readCdoEta, const CondAttrListCollection* readCdoPhi,
96 RpcCablingCondData* writeCdo) const {
97 ATH_MSG_DEBUG("starting setup()");
98
99 int maxType = 0;
100 sectorMap_t sectorMap;
101 RpcCablingCondData::STvec sectorType;
102 std::vector<unsigned short int> feedPadThresholds;
103 TrigRoadsMap trigroads;
104 SLmap_t sectorLogic;
105
106 // ------------------------------
107 // readCdoMap
108 // ------------------------------
109 ATH_MSG_INFO("setup() - Reading " << m_readKey_map_schema.key());
110 const coral::AttributeList& atr_map = readCdoMap->attributeList(1); // All data sits in cool channel 1
111 std::stringstream MAP(atr_map["Map"].data<std::string>());
112
113 // ------------------------------
114 // readCdoCorr
115 // ------------------------------
116 ATH_MSG_INFO("setup() - Reading " << m_readKey_map_schema_corr.key());
117 const coral::AttributeList& atr_map_corr = readCdoCorr->attributeList(1); // All data sits in cool channel 1
118 std::stringstream MAP_corr(atr_map_corr["Map"].data<std::string>());
119
120 // ------------------------------
121 // readCdoEta
122 // ------------------------------
123 ATH_MSG_INFO("setup() - Reading " << m_readKey_cm_thr_eta.key());
124 std::string etaCM_File;
125 std::string etaTh0;
127 for (itr_eta = readCdoEta->begin(); itr_eta != readCdoEta->end(); ++itr_eta) {
128 const coral::AttributeList& atr = itr_eta->second;
129 etaCM_File = *(static_cast<const std::string*>((atr["CM_File"]).addressOfData()));
130 etaTh0 = *(static_cast<const std::string*>((atr["Th0"]).addressOfData()));
131 trigroads[etaCM_File] = etaTh0;
132 }
133
134 // ------------------------------
135 // readCdoPhi
136 // ------------------------------
137 ATH_MSG_INFO("setup() - Reading " << m_readKey_cm_thr_phi.key());
138 std::string phiCM_File;
139 std::string phiTh0;
141 for (itr = readCdoPhi->begin(); itr != readCdoPhi->end(); ++itr) {
142 const coral::AttributeList& atr = itr->second;
143 phiCM_File = *(static_cast<const std::string*>((atr["CM_File"]).addressOfData()));
144 phiTh0 = *(static_cast<const std::string*>((atr["Th0"]).addressOfData()));
145 trigroads[phiCM_File] = phiTh0;
146 }
147 // ------------------------------
148
149 DBline data(MAP);
150 // store the setup environment
151 std::string version, setup, layout;
152
153 // Start reading routine
154 unsigned int nlines = 0;
155
156 std::string dataName = PathResolver::find_directory(m_database_repository, "DATAPATH");
157
158 // Start reading routine
159 while (++data) {
160 ATH_MSG_DEBUG("setup() - Reading routine. nlines = " << nlines);
161 ++nlines;
162 data("Version") >> version >> setup >> layout;
163
164 // Read the Sector Type enumeration
165 int start = 0;
166 int stop = 0;
167 if (data("SECTOR TYPES (") >> start >> "-" >> stop >> "):") {
168 for (int i = start; i <= stop; ++i) { data >> sectorMap[i]; }
169 }
170
171 // Set the maxType variable and the type of SectorMap objects
172 if (stop == 63 || stop == 8) {
173 for (int i = 0; i < 64; ++i) { maxType = std::max(sectorMap[i], maxType); }
174 sectorType.clear();
175 //sectorType.reserve(maxType); // this would require a copy-constructor
176 ATH_MSG_DEBUG("setup() - Loop over " << maxType << " sector-types");
177
178 for (int i = 1; i <= maxType; ++i) {
179 sectorType.emplace_back(i, dataName, layout, m_cosmic_configuration);
180 RPC_CondCabling::SectorLogicSetup& sec = sectorType[i - 1];
181 sec.SetPtoTrigRoads(&trigroads);
182 for (int j = 0; j < 64; ++j) {
183 if (sectorMap[j] == i) {
184 sec << j;
185 sectorLogic.insert(SLmap_t::value_type(j, &sec));
186 ATH_MSG_DEBUG("setup() - filling sectorLogicSetup Map for type " << i << " sector " << j);
187 }
188 }
189 }
190 }
191
192 // Loop on GEOMETRY TYPES
193 for (int i = 1; i <= maxType; ++i) {
194 // Read the RPC geometry
195 if (data("RPC GEOM # :", i)) {
197 if (!(sectorType[i - 1] += RPCdata)) return StatusCode::FAILURE;
198 }
199 // Read the Wired OR geometry
200 if (data("WIRED OR # :", i)) {
202 if (!(sectorType[i - 1] += WORdata)) return StatusCode::FAILURE;
203 }
204 // Read the CMAs segmentation
205 if (data("CMAs # : pivot segmentation", i)) {
207 if (!(sectorType[i - 1] += CMAdata)) return StatusCode::FAILURE;
208 }
209 // Read the CMAs cabling
210 if (data("CMAs # : eta cabling", i)) {
212 if (!(sectorType[i - 1] += CMAdata)) return StatusCode::FAILURE;
213 }
214 }
215 }
216 ATH_MSG_DEBUG("setup() - map n. of lines read is " << nlines);
217 ATH_MSG_INFO("setup() - version is " << version << " " << setup << " " << layout << " (cosmic=" << (int)m_cosmic_configuration << ")");
218
219 for (int i = 1; i <= maxType; ++i) {
220 if (!sectorType[i - 1].setup(msg())) return StatusCode::FAILURE;
221 if (!sectorType[i - 1].check()) return StatusCode::FAILURE;
222 if (msgLvl(MSG::DEBUG)) {
223 ATH_MSG_DEBUG("calling get_cabling for i=" << i);
224 const RPC_CondCabling::SectorLogicSetup::EtaCMAmap& CMAs = sectorType[i - 1].giveEtaCMA();
225 for (const auto& cma : CMAs) {
226 unsigned int cabling = UINT_MAX;
227 if (cma.second.get_cabling(CMAinput::Pivot, 0, 0, 0, cabling)) {
228 ATH_MSG_DEBUG("got pivot cabling=" << cabling);
229 } else {
230 ATH_MSG_DEBUG("failed to get cabling");
231 }
232 }
233 }
234 }
235
236 ATH_MSG_DEBUG("setup() - " << m_readKey_map_schema.key() << " maps have been parsed");
237
238 for (int sector = 0; sector < 64; ++sector) {
239 unsigned int nRDOentries = 0;
240 int side = (sector < 32) ? 0 : 1;
241 int logic_sector = sector % 32;
242
243 if (sectorMap[sector]) {
244 // get the Sector Logic Setup
245 const RPC_CondCabling::SectorLogicSetup& Sector = sectorType[sectorMap[sector] - 1];
246
247 // get the Eta CMA map from the Sector Logic Setup
249 RPC_CondCabling::SectorLogicSetup::EtaCMAmap::const_iterator it = CMAs.begin();
250
251 bool isFirst = false;
252
253 // loop over the whole set of Eta CMAs
254 while (it != CMAs.end()) {
255 // get the set of parameters for idenfying the first RPC strip
256 unsigned int ID = (*it).second.id().Ixx_index();
257 bool inversion = (*it).second.inversion();
258 isFirst = (ID == 1 && inversion) || (ID == 0 && !inversion);
259 unsigned int PADid = (*it).first.PAD_index();
260 unsigned int cabling = UINT_MAX;
261 if ((*it).second.get_cabling(CMAinput::Pivot, 0, 0, 0, cabling)) {
262 unsigned int RPC_strip = cabling % 100;
263 unsigned int RPC_chamber = (cabling / 100) % 100;
264 unsigned int RPC_layer = 0;
265 unsigned int RPC_station = (*it).second.whichCMAstation(CMAinput::Pivot);
266 unsigned int lvl1_sector = sector;
267
268 const RPC_CondCabling::RPCchamber* rpc = Sector.find_chamber(RPC_station, RPC_chamber);
269 std::string name = rpc->stationName();
270 int sEta = (side) ? rpc->stationEta() : -rpc->stationEta();
271 int sPhi = (logic_sector == 31) ? 1 : (logic_sector + 1) / 4 + 1;
272 int dR = rpc->doubletR();
273 int dZ = rpc->doubletZ();
274 int dP = (rpc->phiReadoutPannels() == 2) ? (logic_sector + 1) % 2 + 1 : 1;
275
276 // build the Level-1 code index
277 RPCdecoder decode(Eta, lvl1_sector, RPC_station, RPC_layer, RPC_chamber, RPC_strip);
278
279 // instanciate the corresponding RDO index
280 RDOindex rdo(PADid, decode.code(), name, sEta, sPhi, dR, dZ, dP, m_idHelperSvc->rpcIdHelper());
281
282 // compute the key for retrieving RDO into the map
283 int key = side * 10000 + logic_sector * 100 + PADid;
284 // insert the RDO into the map
285 std::pair<RpcCablingCondData::RDOmap::iterator, bool> ins =
286 writeCdo->m_RDOs.insert(RpcCablingCondData::RDOmap::value_type(key, rdo));
287
288 if (!ins.second) {
289 ATH_MSG_ERROR("RpcCablingCondData::RDOmap is false for stationName="
290 << name << ", stationEta=" << sEta << ", stationPhi=" << sPhi << ", doubletR=" << dR
291 << ", doubletZ=" << dZ << ", doubletPhi=" << dP);
292 return StatusCode::FAILURE;
293 }
294
295 ++nRDOentries;
296 }
297
298 else if (!(*it).second.get_cabling(CMAinput::Pivot, 0, 0, 0, cabling) && isFirst) {
299 // try to catch configrm cabling
300 bool existLow = false;
301 bool existHigh = false;
302
303 if (!(existLow = (*it).second.get_cabling(CMAinput::LowPt, 0, 0, 0, cabling)))
304 existHigh = (*it).second.get_cabling(CMAinput::HighPt, 0, 0, 0, cabling);
305
306 if (!existLow && !existHigh) {
307 ATH_MSG_ERROR("Error while configuring the RDO map");
308 return StatusCode::FAILURE;
309 }
310
311 unsigned int RPC_strip = cabling % 100;
312 unsigned int RPC_chamber = (cabling / 100) % 100;
313 unsigned int RPC_layer = 0;
314 unsigned int RPC_station = 0;
315 if (existLow)
316 RPC_station = (*it).second.whichCMAstation(CMAinput::LowPt);
317 else
318 RPC_station = (*it).second.whichCMAstation(CMAinput::HighPt);
319 unsigned int lvl1_sector = sector;
320
321 const RPC_CondCabling::RPCchamber* rpc = Sector.find_chamber(RPC_station, RPC_chamber);
322 std::string name = rpc->stationName();
323 int sEta = (side) ? rpc->stationEta() : -rpc->stationEta();
324 int sPhi = (logic_sector == 31) ? 1 : (logic_sector + 1) / 4 + 1;
325 int dR = rpc->doubletR();
326 int dZ = rpc->doubletZ();
327 int dP = (rpc->phiReadoutPannels() == 2) ? (logic_sector + 1) % 2 + 1 : 1;
328
329 // build the Level-1 code index
330 RPCdecoder decode(Eta, lvl1_sector, RPC_station, RPC_layer, RPC_chamber, RPC_strip);
331
332 // instanciate the corresponding RDO index
333 RDOindex rdo(PADid, decode.code(), name, sEta, sPhi, dR, dZ, dP, m_idHelperSvc->rpcIdHelper());
334
335 // compute the key for retrieving RDO into the map
336 int key = side * 10000 + logic_sector * 100 + PADid;
337
338 // insert the RDO into the map
339 std::pair<RpcCablingCondData::RDOmap::iterator, bool> ins =
340 writeCdo->m_RDOs.insert(RpcCablingCondData::RDOmap::value_type(key, rdo));
341
342 if (!ins.second) {
343 ATH_MSG_ERROR("RpcCablingCondData::RDOmap is false for stationName="
344 << name << ", stationEta=" << sEta << ", stationPhi=" << sPhi << ", doubletR=" << dR
345 << ", doubletZ=" << dZ << ", doubletPhi=" << dP);
346 return StatusCode::FAILURE;
347 }
348
349 ++nRDOentries;
350 }
351
352 // increase the iterator
353 while (it != CMAs.end() && (unsigned int)(*it).first.PAD_index() == PADid) { ++it; }
354 }
355 }
356 ATH_MSG_DEBUG("setup() - sector " << sector << ", number of associated RDO (i.e. Pads) = " << nRDOentries);
357 }
358
359 DBline data_corr(MAP_corr);
360 nlines = 0;
361 while (++data_corr) {
362 ++nlines;
363 unsigned short int SubId;
364 unsigned short int SecId;
365 unsigned short int PADId;
366 unsigned short int CMAId;
367 unsigned short int ijk;
368 unsigned short int inputType;
369 unsigned int layer;
370 unsigned int type;
371 unsigned short int Channel1;
372 unsigned short int Channel2;
373 int Number;
374
375 if (data_corr("CABLE") >> data_corr.dbhex() >> SubId >> SecId >> PADId >> CMAId >> ijk >> data_corr.dbdec() >> type >> Channel1 >>
376 Channel2 >> Number) {
377 bool ok = CableParamCheck(SubId, SecId, PADId, CMAId, ijk, type, Channel1, Channel2, Number);
378
379 layer = (ijk == 0 || ijk == 2 || ijk == 3) ? 0 : 1;
380
381 if (ijk > 1) {
382 Channel1 += 32 * (ijk % 2);
383 Channel2 += 32 * (ijk % 2);
384 }
385
386 unsigned short int lh = (CMAId >> 2) & 1;
387
388 if (ijk == 0 || ijk == 1)
389 inputType = 1;
390 else
391 inputType = (lh) ? 2 : 0;
392
393 if (ijk > 5) inputType = 3;
394 if (type > 3) type = 4;
395
396 if (ok && !correct(SubId, SecId, PADId, CMAId, static_cast<CMAinput>(inputType), layer, Channel1, Channel2, Number,
397 static_cast<L1RPCcabCorrection>(type), sectorMap, sectorType)) {
398 ATH_MSG_WARNING("Cannot apply correction: "
399 << std::hex << std::setw(4) << std::showbase << SubId << " " << std::setw(4) << std::showbase << SecId
400 << " " << std::setw(3) << std::showbase << PADId << " " << std::setw(3) << std::showbase << CMAId << " "
401 << std::setw(3) << std::showbase << ijk << " " << std::dec << std::setw(1) << std::showbase << type << " "
402 << std::setw(2) << std::showbase << Channel1 << " " << std::setw(2) << std::showbase << Channel2 << " "
403 << std::setw(2) << std::showbase << Number);
404 }
405 }
406 if (data_corr("BOARD") >> data_corr.dbhex() >> SubId >> SecId >> PADId >> CMAId >> data_corr.dbdec() >> inputType >> layer >>
407 type >> Channel1 >> Channel2 >> Number) {
408 bool ok = BoardParamCheck(SubId, SecId, PADId, CMAId, inputType, layer, type, Channel1, Channel2, Number);
409
410 if (inputType > 2) inputType = 3;
411 if (type > 3) type = 4;
412
413 if (ok && !correct(SubId, SecId, PADId, CMAId, static_cast<CMAinput>(inputType), layer, Channel1, Channel2, Number,
414 static_cast<L1RPCcabCorrection>(type), sectorMap, sectorType)) {
415 ATH_MSG_WARNING("Cannot apply correction: "
416 << std::hex << std::setw(4) << std::showbase << SubId << " " << std::setw(4) << std::showbase << SecId
417 << " " << std::setw(3) << std::showbase << PADId << " " << std::setw(3) << std::showbase << CMAId << " "
418 << std::dec << std::setw(1) << inputType << " " << std::setw(1) << layer << " " << std::dec << std::setw(1)
419 << std::showbase << type << " " << std::setw(2) << std::showbase << Channel1 << " " << std::setw(2)
420 << std::showbase << Channel2 << " " << std::setw(2) << std::showbase << Number);
421 }
422 }
423 }
424 ATH_MSG_DEBUG("setup() - corrected map n. of lines read is " << nlines);
425 ATH_MSG_DEBUG("setup() - " << m_readKey_map_schema_corr.key() << " maps have been parsed");
426
427 for (int side = 0; side < 2; ++side) {
428 for (int rod = 0; rod < 16; ++rod) { (writeCdo->m_rod2hash[side][rod]).clear(); }
429 }
430
431 int hashID = 0;
432 std::set<uint32_t> ROBid;
433 IdContext rpcModuleContext = m_idHelperSvc->rpcIdHelper().module_context();
434
435 // reserve enough space in the hash-vector
436 writeCdo->m_HashVec.reserve(writeCdo->m_RDOs.size());
437
438 ATH_MSG_INFO("setup() - start building OfflineOnlineMap for " << writeCdo->m_RDOs.size() << " RDOs");
439
440 RpcCablingCondData::RDOmap::iterator pad_beg = writeCdo->m_RDOs.begin();
441 RpcCablingCondData::RDOmap::iterator pad_end = writeCdo->m_RDOs.end();
442 for (; pad_beg != pad_end; ++pad_beg) {
443 const RDOindex* pRDOindex = &((*pad_beg).second);
444 (*pad_beg).second.set_hash(hashID);
445
446 // get pointer to RDOindex class
447 writeCdo->m_HashVec.push_back(pRDOindex);
448
449 if (writeCdo->m_HashVec.size() != pRDOindex->hash() + 1) {
450 ATH_MSG_ERROR("Size of hash vector and RDO hash does not match");
451 return StatusCode::FAILURE;
452 }
453
454 // calculate m_fullListOfRobIds
455 const unsigned short int rob_id = pRDOindex->ROBid();
456 const unsigned short int rod_id = pRDOindex->RODid();
457 const unsigned short int sub_id = pRDOindex->side();
458 const unsigned short int sec_id = pRDOindex->SLid();
459 const unsigned short int pad_id = pRDOindex->PADid();
460
461 uint32_t ROD_ID = (sub_id << 16) | rod_id;
462 uint32_t ROB_ID = (sub_id << 16) | rob_id;
463
464 ROBid.insert(ROB_ID);
465 unsigned short int sub_id_index = ((sub_id == 0x65) ? 1 : 0); // convert 0x65 -> 1 (side A) and 0x66 -> 0 (side C)
466
467 Identifier id;
468 pRDOindex->pad_identifier(id);
469
470 ATH_MSG_DEBUG(hashID << "-th entry has sub_id_index=" << sub_id_index << ", ROBid=" << rob_id << ", RODid=" << rod_id << ", side="
471 << sub_id << ", SLid=" << sec_id << ", PADid=" << pad_id << ", pad_identifier=" << id.get_compact());
472
473 // build the offline_id vector
474 writeCdo->m_offline_id[sub_id_index][sec_id][pad_id] = id;
475
476 // build the map
477 std::pair<RpcCablingCondData::OfflineOnlineMap::iterator, bool> ins =
478 writeCdo->m_RDOmap.insert(RpcCablingCondData::OfflineOnlineMap::value_type(id, pRDOindex));
479 ATH_MSG_DEBUG("OfflineOnlineMap new entry: Identifier with technology="
480 << m_idHelperSvc->rpcIdHelper().technology(id) << ", stationName=" << m_idHelperSvc->rpcIdHelper().stationName(id)
481 << ", stationEta=" << m_idHelperSvc->rpcIdHelper().stationEta(id) << ", stationPhi="
482 << m_idHelperSvc->rpcIdHelper().stationPhi(id) << ", doubletR=" << m_idHelperSvc->rpcIdHelper().doubletR(id)
483 << ", doubletZ=" << m_idHelperSvc->rpcIdHelper().doubletZ(id) << ", doubletPhi="
484 << m_idHelperSvc->rpcIdHelper().doubletPhi(id) << " and hash of the RDOindex(key)= " << pRDOindex->hash());
485 if (!ins.second) {
486 ATH_MSG_ERROR("RpcCablingCondData::OfflineOnlineMap is false for technology="
487 << m_idHelperSvc->rpcIdHelper().technology(id) << ", stationName=" << m_idHelperSvc->rpcIdHelper().stationName(id)
488 << ", stationEta=" << m_idHelperSvc->rpcIdHelper().stationEta(id) << ", stationPhi="
489 << m_idHelperSvc->rpcIdHelper().stationPhi(id) << ", doubletR=" << m_idHelperSvc->rpcIdHelper().doubletR(id)
490 << ", doubletZ=" << m_idHelperSvc->rpcIdHelper().doubletZ(id) << ", doubletPhi="
491 << m_idHelperSvc->rpcIdHelper().doubletPhi(id) << " and hash of the RDOindex(key)= " << pRDOindex->hash());
492 return StatusCode::FAILURE;
493 }
494
495 // build the ROB->RDO map
496 std::pair<std::set<IdentifierHash>::iterator, bool> insert_ROB_RDO_returnVal =
497 writeCdo->m_ROB_RDO_map[ROB_ID].insert(IdentifierHash(pRDOindex->hash()));
498 if (insert_ROB_RDO_returnVal.second)
499 ATH_MSG_DEBUG("A new RDO HashId = " << pRDOindex->hash() << " registered for ROB Id = " << ROB_ID);
500 else
501 ATH_MSG_VERBOSE("The RDO HashId = " << pRDOindex->hash() << " was already registered for ROB Id = " << ROB_ID);
502
503 // build the PRD->RDO and PRD->ROB maps
504 ATH_MSG_VERBOSE("Looking for PRDs corresponding to this RDO");
505 std::list<Identifier> strip_id_list;
506 IdentifierHash rdoHashId((IdentifierHash::value_type)pRDOindex->hash());
507 ATH_MSG_DEBUG("RDO HashId = " << (int)rdoHashId << " RDO Id = " << id.get_compact() << " ROB Id = " << MSG::hex << ROB_ID
508 << MSG::dec << " ROD Id = " << MSG::hex << ROD_ID << MSG::dec);
509
510 for (unsigned short int CMAId : {2, 3, 6, 7}) { // loop over phi CMA IDs
511 for (unsigned short int ijk : {1, 2, 3}) { // loop over IJK identifiers
512 strip_id_list.clear();
513 for (unsigned short int channel : {0, 31}) { // check for the first and the last channel
514 strip_id_list.splice(strip_id_list.end(),
515 give_strip_id(sub_id_index, sec_id, pad_id, CMAId, ijk, channel, sectorMap, sectorType));
516 }
517 for (Identifier strip_id : strip_id_list) {
518 Identifier idp = m_idHelperSvc->rpcIdHelper().parentID(strip_id);
519 IdentifierHash prdHashId;
520 int gethash_code = m_idHelperSvc->rpcIdHelper().get_hash(idp, prdHashId, &rpcModuleContext);
521 if (gethash_code != 0) {
522 ATH_MSG_DEBUG("Unable to get the PRD HashId! parentID(strip_id)=" << idp.getString());
523 continue;
524 }
525
526 // fill the PRD->RDO map
527 std::pair<std::set<IdentifierHash>::iterator, bool> insertRDO_returnVal =
528 writeCdo->m_PRD_RDO_map[prdHashId].insert(rdoHashId);
529 if (insertRDO_returnVal.second) {
530 ATH_MSG_DEBUG("A new RDO HashId = " << (int)rdoHashId << " registered for PRD HashId = " << (int)prdHashId);
531 } else {
532 ATH_MSG_VERBOSE("The RDO HashId = " << (int)rdoHashId
533 << " was already registered for PRD HashId = " << (int)prdHashId);
534 }
535
536 // fill the PRD->ROB map
537 std::pair<std::set<uint32_t>::iterator, bool> insertROB_returnVal = writeCdo->m_PRD_ROB_map[prdHashId].insert(ROB_ID);
538 if (insertROB_returnVal.second) {
539 ATH_MSG_DEBUG("A new ROB Id = " << MSG::hex << ROB_ID << MSG::dec
540 << " registered for PRD HashId = " << (int)prdHashId);
541 } else {
542 ATH_MSG_VERBOSE("The ROB Id = " << MSG::hex << ROB_ID << MSG::dec
543 << " was already registered for PRD HashId = " << (int)prdHashId);
544 }
545 }
546 }
547 }
548
549 // Trigger Roads Header
550 TrigRoadsMap::const_iterator it;
551 it = trigroads.find("infos.txt");
552 if (it == trigroads.end()) {
553 ATH_MSG_WARNING("Missing HEADER FILE infos.txt");
554 } else {
555 ATH_MSG_VERBOSE("======== RPC Trigger Roads from COOL - Header infos ========");
556 ATH_MSG_VERBOSE("\n" + it->second + "\n");
557 // Read FeetPadThresholds from infos.txt
559 std::stringstream ss;
560 ss << it->second;
561 std::string word;
562 while (ss >> word) {
563 if (word == "FeetPadThresholds") {
564 feedPadThresholds.assign(3, 0);
565 ss >> feedPadThresholds.at(0);
566 ss >> feedPadThresholds.at(1);
567 ss >> feedPadThresholds.at(2);
568 ATH_MSG_VERBOSE("FeetPadThresholds set from COOL to: " << feedPadThresholds.at(0) << "," << feedPadThresholds.at(1)
569 << "," << feedPadThresholds.at(2));
570 }
571 }
572 }
573 }
574
575 // ------ begin like PCcablingInterface::RpcPadIdHash::RpcPadIdHash()
576 RDOindex index = (*pad_beg).second;
577 index.pad_identifier(id);
578
579 writeCdo->m_int2id.push_back(id);
580
581 if (writeCdo->m_int2id.size() != index.hash() + 1) {
582 ATH_MSG_ERROR("Inconsistence between PAD hash and RpcPadIdHash");
584 ATH_MSG_ERROR("Position into RpcPadIdHash map is " << writeCdo->m_int2id.size() - 1);
585 return StatusCode::FAILURE;
586 }
587
588 unsigned short int side = index.side();
589 unsigned short int rod = index.RODid();
590
591 if (rod > 15) {
592 ATH_MSG_ERROR("RPC ROD greater than 15");
593 return StatusCode::FAILURE;
594 }
595
596 IdentifierHash HashID = index.hash();
597
598 (writeCdo->m_rod2hash[(side == 0x66) ? 0 : 1][rod]).push_back(HashID);
599
600 writeCdo->m_lookup[id] = index.hash();
601
602 ATH_MSG_DEBUG("RDO loop entry " << hashID << " done");
603 ++hashID;
604 }
605 ATH_MSG_DEBUG("setup() - start recording RpcCablingCondData");
606
607 // this must be done both in case of source = COOL or ASCII
608 // ----- Initialization of Pad configuration ------ //
610 if (feedPadThresholds.size() != 3) {
611 // if thresholds vector empty, set it to default
612 feedPadThresholds.assign(3, 0);
613 feedPadThresholds.at(0) = 0;
614 feedPadThresholds.at(1) = 2;
615 feedPadThresholds.at(2) = 5;
616 }
617 ATH_MSG_INFO("Applying FeetPadThresholds : " << feedPadThresholds.at(0) << "," << feedPadThresholds.at(1) << ","
618 << feedPadThresholds.at(2));
619
620 const unsigned int NumFeetSectors = 8;
621 unsigned int FeetSectors[NumFeetSectors] = {21, 22, 25, 26, 53, 54, 57, 58};
622 const unsigned int NumSpecialFeetPads = 4;
623 unsigned int SpecialFeetPads[NumSpecialFeetPads] = {2, 4, 5, 7};
624
625 for (unsigned int is = 0; is < NumFeetSectors; is++) {
626 for (unsigned int it = 0; it < NumSpecialFeetPads; it++) {
627 writeCdo->m_RPCPadParameters_array[FeetSectors[is]][SpecialFeetPads[it]].set_feet_on(true);
628 for (unsigned int th = 0; th < 3; th++) {
629 writeCdo->m_RPCPadParameters_array[FeetSectors[is]][SpecialFeetPads[it]].set_feet_threshold(th,
630 feedPadThresholds.at(th));
631 }
632 }
633 }
634 }
635
636 // reserve enough space
637 writeCdo->m_fullListOfRobIds.reserve(ROBid.size());
638 for (uint32_t robid : ROBid) writeCdo->m_fullListOfRobIds.push_back(robid);
639
640 ATH_MSG_DEBUG("Number of valid RPC Pad IDs " << writeCdo->m_int2id.size());
641
642 for (int i = 0; i < 64; i++) writeCdo->m_SectorMap[i] = sectorMap[i];
643 writeCdo->m_SectorType = std::move(sectorType);
644 writeCdo->m_MaxType = maxType;
645
646 if (msgLvl(MSG::DEBUG)) {
647 std::stringstream ss1;
648 ss1 << "Level-1 configuration database " << std::endl;
649 ss1 << "Contains " << maxType << " Trigger Sector Types:" << std::endl;
650 ss1 << "negative sectors 0 - 15 ==> ";
651 for (int i = 0; i < 16; i++) ss1 << std::setw(2) << sectorMap[i] << " ";
652 ss1 << std::endl << "negative sectors 16 - 31 ==> ";
653 for (int i = 16; i < 32; i++) ss1 << std::setw(2) << sectorMap[i] << " ";
654 ss1 << std::endl << "positive sectors 32 - 47 ==> ";
655 for (int i = 32; i < 48; i++) ss1 << std::setw(2) << sectorMap[i] << " ";
656 ss1 << std::endl << "positive sectors 48 - 63 ==> ";
657 for (int i = 48; i < 64; i++) ss1 << std::setw(2) << sectorMap[i] << " ";
658 ss1 << std::endl;
659 ATH_MSG_DEBUG(ss1.str());
660 }
661
662 // record
663 if (writeCdo->m_RDOs.empty()) {
664 ATH_MSG_ERROR("Could not read any map configuration");
665 return StatusCode::FAILURE;
666 }
667 if (writeCdo->m_HashVec.empty()) {
668 ATH_MSG_ERROR("Could not read any HashID");
669 return StatusCode::FAILURE;
670 }
671 if (writeCdo->m_SectorType.empty()) {
672 ATH_MSG_ERROR("Could not read any sectorMap");
673 return StatusCode::FAILURE;
674 }
675 if (writeCdo->m_int2id.empty()) {
676 ATH_MSG_ERROR("Could not read any HashID");
677 return StatusCode::FAILURE;
678 }
679 if (writeCdo->m_lookup.empty()) {
680 ATH_MSG_ERROR("Could not read any HashID");
681 return StatusCode::FAILURE;
682 }
683 if (writeCdo->m_fullListOfRobIds.empty()) {
684 ATH_MSG_ERROR("Could not read any HashID");
685 return StatusCode::FAILURE;
686 }
687 ATH_MSG_DEBUG("setup() - RpcCablingCondData recorded");
688 return StatusCode::SUCCESS;
689}
690
691std::list<Identifier> RpcCablingCondAlg::give_strip_id(const unsigned short int SubsystemId, const unsigned short int SectorId,
692 const unsigned short int PADId, const unsigned short int CMAId,
693 const unsigned short ijk, const unsigned short int Channel, const sectorMap_t& smap,
694 const RpcCablingCondData::STvec& sType) const {
695 std::list<unsigned int> CodeList;
696
697 int logic_sector = SectorId + SubsystemId * 32;
698 unsigned short int Ixx = CMAId & 1;
699 unsigned short int ep = (CMAId >> 1) & 1;
700 unsigned short int lh = (CMAId >> 2) & 1;
701
702 ep = (ep == 1) ? 0 : 1;
703
704 // retrieve the Sector Logic setup
705 const RPC_CondCabling::SectorLogicSetup& s = sType[smap[logic_sector] - 1];
706
707 // retrieve the CMAparameters associated to the identifiers
708 if (ep) {
709 CMAcoverage PhiCov = (logic_sector % 2) ? OddSectors : EvenSectors;
710 CMAidentity PHI(ViewType::Phi, PhiCov, PADId, Ixx);
711 CodeList = s.give_strip_code(PHI, logic_sector, lh, ijk, Channel);
712 } else {
714 CodeList = s.give_strip_code(ETA, logic_sector, lh, ijk, Channel);
715 }
716
717 std::list<RPCofflineId> offlineIdList;
718 std::list<unsigned int>::const_iterator it = CodeList.begin();
719 while (it != CodeList.end()) {
720 RPCdecoder decode(*it);
721 if (!decode)
722 throw std::runtime_error("RpcCablingCondAlg::give_strip_id() - cannot decode LVL1 Id at " +
723 std::string(__FILE__) + ":" + std::to_string(__LINE__));
724 RPCofflineId rpcId;
725
726 int RPC_strip = decode.strip_number();
727 int RPC_chamber = decode.rpc_z_index();
728 int RPC_layer = decode.rpc_layer();
729 int RPC_station = decode.lvl1_station();
730 int sector = (decode.logic_sector()) % 32;
731
732 const RPC_CondCabling::RPCchamber* rpc = s.find_chamber(RPC_station, RPC_chamber);
733
734 rpcId.stationName = rpc->stationName();
735 rpcId.stationEta = (decode.half_barrel() == Positive) ? rpc->stationEta() : -rpc->stationEta();
736 rpcId.stationPhi = (sector == 31) ? 1 : (sector + 1) / 4 + 1;
737 rpcId.doubletR = rpc->doubletR();
738 rpcId.doubletZ = rpc->doubletZ();
739 rpcId.doubletPhi = (rpc->phiReadoutPannels() == 2) ? (sector + 1) % 2 + 1 : 1;
740 rpcId.gasGap = RPC_layer + 1;
741 rpcId.measuresPhi = static_cast<int>(decode.view());
742 rpcId.strip = RPC_strip + 1;
743
744 offlineIdList.push_back(std::move(rpcId));
745
746 ++it;
747 }
748
749 std::list<Identifier> id;
750 std::list<RPCofflineId>::const_iterator iterator = offlineIdList.begin();
751 while (iterator != offlineIdList.end()) {
752 Identifier rpcId = m_idHelperSvc->rpcIdHelper().channelID((*iterator).stationName, (*iterator).stationEta, (*iterator).stationPhi,
753 (*iterator).doubletR, (*iterator).doubletZ, (*iterator).doubletPhi,
754 (*iterator).gasGap, (*iterator).measuresPhi, (*iterator).strip);
755 id.push_back(rpcId);
756 ++iterator;
757 }
758
759 return id;
760}
761
762bool RpcCablingCondAlg::correct(const unsigned short int SubsystemId, const unsigned short int SectorId, const unsigned short int PADId,
763 const unsigned short int CMAId, const CMAinput it, const unsigned int layer,
764 const unsigned short int Channel1, const unsigned short int Channel2, const short int number,
765 const L1RPCcabCorrection type, const sectorMap_t& smap, const RpcCablingCondData::STvec& sType) {
766 int logic_sector = (SubsystemId == 0x65) ? SectorId + 32 : SectorId;
767 unsigned short int Ixx = CMAId & 1;
768 unsigned short int ep = (CMAId >> 1) & 1;
769
770 ep = (ep == 1) ? 0 : 1;
771
772 // retrieve the Sector Logic setup
773 const RPC_CondCabling::SectorLogicSetup& s = sType[smap[logic_sector] - 1];
774
775 // retrieve the CMAparameters associated to the identifiers
776 if (ep) {
777 CMAcoverage PhiCov = (logic_sector % 2) ? OddSectors : EvenSectors;
778 CMAidentity PHI(Phi, PhiCov, PADId, Ixx);
779 return s.correct(PHI, type, it, layer, Channel1, Channel2, number);
780 } else {
781 CMAidentity ETA(Eta, AllSectors, PADId, Ixx);
782 return s.correct(ETA, type, it, layer, Channel1, Channel2, number);
783 }
784 return false;
785}
786
787bool RpcCablingCondAlg::BoardParamCheck(const unsigned short int SubId, const unsigned short int SecId, const unsigned short int PADId,
788 const unsigned short int CMAId, const unsigned short int inputType, const unsigned int layer,
789 const unsigned int type, const unsigned short int Channel1, const unsigned short int Channel2,
790 const short int Number) const {
791 if (SubId != 0x65 && SubId != 0x66) {
792 ATH_MSG_ERROR("Subsystem Id out of range: " << SubId << " not in [0x65,0x66].");
793 return false;
794 }
795 if (SecId > 31) {
796 ATH_MSG_ERROR("Sector Id out of range [0/31].");
797 return false;
798 }
799 if (PADId > 8) {
800 ATH_MSG_ERROR("Pad Id out of range [0/8].");
801 return false;
802 }
803 if (CMAId > 7) {
804 ATH_MSG_ERROR("CMA Id out of range [0/7].");
805 return false;
806 }
807 if (inputType > 2) {
808 ATH_MSG_ERROR("Board input out of range [0/2].");
809 return false;
810 }
811 if (layer > 1) {
812 ATH_MSG_ERROR("Board layer out of range [0/1].");
813 return false;
814 }
815 if (type > 3) {
816 ATH_MSG_ERROR("correction type out of range [0/3].");
817 return false;
818 }
819 if (Channel1 > 63) {
820 ATH_MSG_ERROR("ijk Channel 1 out of range [0/31].");
821 return false;
822 }
823 if (Channel2 > 63) {
824 ATH_MSG_ERROR("ijk Channel 2 out of range [0/31].");
825 return false;
826 }
827 if (Number > 64) {
828 ATH_MSG_ERROR("Number out of range [0/64].");
829 return false;
830 }
831 return true;
832}
833
834bool RpcCablingCondAlg::CableParamCheck(const unsigned short int SubId, const unsigned short int SecId, const unsigned short int PADId,
835 const unsigned short int CMAId, const unsigned short int ijk, const unsigned int type,
836 const unsigned short int Channel1, const unsigned short int Channel2,
837 const short int Number) const {
838 if (SubId != 0x65 && SubId != 0x66) {
839 ATH_MSG_ERROR("Subsystem Id out of range [0x65,0x66].");
840 return false;
841 }
842 if (SecId > 31) {
843 ATH_MSG_ERROR("Sector Id out of range [0/31].");
844 return false;
845 }
846 if (PADId > 8) {
847 ATH_MSG_ERROR("Pad Id out of range [0/8].");
848 return false;
849 }
850 if (CMAId > 7) {
851 ATH_MSG_ERROR("CMA Id out of range [0/7].");
852 return false;
853 }
854 if (ijk > 5) {
855 ATH_MSG_ERROR("ijk out of range [0/5].");
856 return false;
857 }
858 if (type > 3) {
859 ATH_MSG_ERROR("correction type out of range [0/3].");
860 return false;
861 }
862 if (Channel1 > 31) {
863 ATH_MSG_ERROR("ijk Channel 1 out of range [0/31].");
864 return false;
865 }
866 if (Channel2 > 31) {
867 ATH_MSG_ERROR("ijk Channel 2 out of range [0/31].");
868 return false;
869 }
870 if (Number > 32) {
871 ATH_MSG_ERROR("Number out of range [0/32].");
872 return false;
873 }
874 return true;
875}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
CMAcoverage
Definition CMAidentity.h:14
@ OddSectors
Definition CMAidentity.h:14
@ AllSectors
Definition CMAidentity.h:14
@ EvenSectors
Definition CMAidentity.h:14
CMAinput
@ LowPt
@ HighPt
@ Pivot
L1RPCcabCorrection
RPC_CondCabling::SectorLogicSetup::TrigRoadsMap TrigRoadsMap
Definition EtaCMA.cxx:22
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t ss
@ Phi
Definition RPCdef.h:8
@ Eta
Definition RPCdef.h:8
@ Positive
Definition RPCdef.h:9
void clear()
Empty the pool.
bool msgLvl(const MSG::Level lvl) const
Base class for conditions algorithms.
This class is a collection of AttributeLists where each one is associated with a channel number.
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
const_iterator end() const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
size_type size() const
number of Chan/AttributeList pairs
ChanAttrListMap::const_iterator const_iterator
const DBfmt & dbdec() const
Definition dbline.h:373
const DBfmt & dbhex() const
Definition dbline.h:369
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
This is a "hash" representation of an Identifier.
unsigned int value_type
std::string getString() const
Provide a string form of the identifier - hexadecimal.
static std::string find_directory(const std::string &logical_file_name, const std::string &search_path)
unsigned short int SLid(void) const
Definition RDOindex.h:129
unsigned int hash(void) const
Definition RDOindex.h:142
unsigned short int ROBid(void) const
Definition RDOindex.h:125
unsigned short int RODid(void) const
Definition RDOindex.h:126
unsigned short int side(void) const
Definition RDOindex.h:127
void pad_identifier(Identifier &id) const
Definition RDOindex.cxx:69
unsigned short int PADid(void) const
Definition RDOindex.h:131
void set_hash(unsigned int h)
Definition RDOindex.cxx:49
bool set_feet_threshold(unsigned short int it, unsigned short int th)
void set_feet_on(bool feet_on)
std::string stationName() const
const EtaCMAmap & giveEtaCMA() const
std::map< CMAidentity, EtaCMA > EtaCMAmap
const RPCchamber * find_chamber(int, int) const
void SetPtoTrigRoads(const TrigRoadsMap *)
std::map< std::string, std::string, std::less<> > TrigRoadsMap
virtual StatusCode initialize() override
RpcCablingCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
std::array< int, 64 > sectorMap_t
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_map_schema_corr
StatusCode setup(const CondAttrListCollection *readCdoMap, const CondAttrListCollection *readCdoCorr, const CondAttrListCollection *readCdoEta, const CondAttrListCollection *readCdoPhi, RpcCablingCondData *writeCdo) const
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< bool > m_cosmic_configuration
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_cm_thr_eta
std::map< int, RPC_CondCabling::SectorLogicSetup * > SLmap_t
Gaudi::Property< bool > m_ApplyFeetPadThresholds
Gaudi::Property< bool > m_ForceFeetPadThresholdsFromJO
std::list< Identifier > give_strip_id(const unsigned short int SubsystemId, const unsigned short int SectorId, const unsigned short int PADId, const unsigned short int CMAId, const unsigned short ijk, const unsigned short int Channel, const sectorMap_t &smap, const RpcCablingCondData::STvec &sType) const
bool BoardParamCheck(const unsigned short int SubId, const unsigned short int SecId, const unsigned short int PADId, const unsigned short int CMAId, const unsigned short int inputType, const unsigned int layer, const unsigned int type, const unsigned short int Channel1, const unsigned short int Channel2, const short int Number) const
static bool correct(const unsigned short int SubsystemId, const unsigned short int SectorId, const unsigned short int PADId, const unsigned short int CMAId, const CMAinput it, const unsigned int layer, const unsigned short int Channel1, const unsigned short int Channel2, const short int number, const L1RPCcabCorrection type, const sectorMap_t &smap, const RpcCablingCondData::STvec &sType)
Gaudi::Property< std::string > m_database_repository
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_map_schema
bool CableParamCheck(const unsigned short int SubId, const unsigned short int SecId, const unsigned short int PADId, const unsigned short int CMAId, const unsigned short int ijk, const unsigned int type, const unsigned short int Channel1, const unsigned short int Channel2, const short int Number) const
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey_cm_thr_phi
SG::WriteCondHandleKey< RpcCablingCondData > m_writeKey
std::vector< IdentifierHash > m_rod2hash[2][16]
std::vector< Identifier > m_int2id
RPCPadParameters m_RPCPadParameters_array[MAX_LOGICSECTOR][MAX_PADID]
std::map< Identifier, int > m_lookup
std::vector< RPC_CondCabling::SectorLogicSetup > STvec
Identifier m_offline_id[2][32][10]
OfflineOnlineHashMap m_HashVec
OfflineOnlineMap m_RDOmap
std::vector< uint32_t > m_fullListOfRobIds
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
Definition index.py:1
std::string stationName
Definition RPCofflineId.h:9
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186