22 return StatusCode::SUCCESS;
27 const EventContext& ctx = Gaudi::Hive::currentContext();
31 if (writeHandle.isValid()) {
32 ATH_MSG_DEBUG(
"CondHandle " << writeHandle.fullKey() <<
" is already valid."
33 <<
". In theory this should not be called, but may happen"
34 <<
" if multiple concurrent events are being processed out of order.");
35 return StatusCode::SUCCESS;
44 return StatusCode::FAILURE;
46 writeHandle.addDependency(readHandle_map_schema);
47 ATH_MSG_DEBUG(
"Size of CondAttrListCollection readCdoMap->size()= " << readCdoMap->size());
54 return StatusCode::FAILURE;
56 ATH_MSG_DEBUG(
"Size of CondAttrListCollection readCdoMap_corr->size()= " << readCdoCorr->size());
57 writeHandle.addDependency(readHandle_map_schema_corr);
64 return StatusCode::FAILURE;
66 ATH_MSG_DEBUG(
"Size of CondAttrListCollection readCdo_cm_thr_eta->size()= " << readCdoEta->size());
67 writeHandle.addDependency(readHandle_cm_thr_eta);
74 return StatusCode::FAILURE;
76 ATH_MSG_DEBUG(
"Size of CondAttrListCollection readCdo_cm_thr_phi->size()= " << readCdoPhi->size());
77 writeHandle.addDependency(readHandle_cm_thr_phi);
79 std::unique_ptr<RpcCablingCondData> writeCdo{std::make_unique<RpcCablingCondData>()};
80 ATH_CHECK(
setup(readCdoMap, readCdoCorr, readCdoEta, readCdoPhi, writeCdo.get()));
82 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
83 ATH_MSG_FATAL(
"Could not record RpcCondCablingData " << writeHandle.key() <<
" with EventRange " << writeHandle.getRange()
84 <<
" into Conditions Store");
85 return StatusCode::SUCCESS;
88 ATH_MSG_INFO(
"recorded new " << writeHandle.key() <<
" with range " << writeHandle.getRange());
89 return StatusCode::SUCCESS;
100 std::vector<unsigned short int> feedPadThresholds;
101 std::map<std::string, std::string> trigroads;
109 std::stringstream MAP(atr_map[
"Map"].data<std::string>());
116 std::stringstream MAP_corr(atr_map_corr[
"Map"].data<std::string>());
122 std::string etaCM_File;
125 for (itr_eta = readCdoEta->
begin(); itr_eta != readCdoEta->
end(); ++itr_eta) {
127 etaCM_File = *(
static_cast<const std::string*
>((atr[
"CM_File"]).addressOfData()));
128 etaTh0 = *(
static_cast<const std::string*
>((atr[
"Th0"]).addressOfData()));
129 trigroads[etaCM_File] = etaTh0;
136 std::string phiCM_File;
139 for (itr = readCdoPhi->
begin(); itr != readCdoPhi->
end(); ++itr) {
141 phiCM_File = *(
static_cast<const std::string*
>((atr[
"CM_File"]).addressOfData()));
142 phiTh0 = *(
static_cast<const std::string*
>((atr[
"Th0"]).addressOfData()));
143 trigroads[phiCM_File] = phiTh0;
152 unsigned int nlines = 0;
158 ATH_MSG_DEBUG(
"setup() - Reading routine. nlines = " << nlines);
165 if (
data(
"SECTOR TYPES (") >>
start >>
"-" >>
stop >>
"):") {
171 for (
int i = 0;
i < 64; ++
i) { maxType =
std::max(sectorMap[
i], maxType); }
174 ATH_MSG_DEBUG(
"setup() - Loop over " << maxType <<
" sector-types");
176 for (
int i = 1;
i <= maxType; ++
i) {
180 for (
int j = 0; j < 64; ++j) {
181 if (sectorMap[j] ==
i) {
183 sectorLogic.insert(SLmap_t::value_type(j, &sec));
184 ATH_MSG_DEBUG(
"setup() - filling sectorLogicSetup Map for type " <<
i <<
" sector " << j);
191 for (
int i = 1;
i <= maxType; ++
i) {
193 if (
data(
"RPC GEOM # :",
i)) {
195 if (!(sectorType[
i - 1] +=
RPCdata))
return StatusCode::FAILURE;
198 if (
data(
"WIRED OR # :",
i)) {
200 if (!(sectorType[
i - 1] += WORdata))
return StatusCode::FAILURE;
203 if (
data(
"CMAs # : pivot segmentation",
i)) {
205 if (!(sectorType[
i - 1] +=
CMAdata))
return StatusCode::FAILURE;
208 if (
data(
"CMAs # : eta cabling",
i)) {
210 if (!(sectorType[
i - 1] +=
CMAdata))
return StatusCode::FAILURE;
214 ATH_MSG_DEBUG(
"setup() - map n. of lines read is " << nlines);
217 for (
int i = 1;
i <= maxType; ++
i) {
218 if (!sectorType[
i - 1].
setup(
msg()))
return StatusCode::FAILURE;
219 if (!sectorType[
i - 1].
check())
return StatusCode::FAILURE;
223 for (
const auto& cma : CMAs) {
224 unsigned int cabling = UINT_MAX;
236 for (
int sector = 0; sector < 64; ++sector) {
237 unsigned int nRDOentries = 0;
238 int side = (sector < 32) ? 0 : 1;
239 int logic_sector = sector % 32;
241 if (sectorMap[sector]) {
247 RPC_CondCabling::SectorLogicSetup::EtaCMAmap::const_iterator
it = CMAs.begin();
249 bool isFirst =
false;
252 while (
it != CMAs.end()) {
254 unsigned int ID = (*it).second.id().Ixx_index();
255 bool inversion = (*it).second.inversion();
256 isFirst = (
ID == 1 && inversion) || (
ID == 0 && !inversion);
257 unsigned int PADid = (*it).first.PAD_index();
258 unsigned int cabling = UINT_MAX;
260 unsigned int RPC_strip =
cabling % 100;
261 unsigned int RPC_chamber = (
cabling / 100) % 100;
262 unsigned int RPC_layer = 0;
263 unsigned int RPC_station = (*it).second.whichCMAstation(
CMAinput::Pivot);
264 unsigned int lvl1_sector = sector;
269 int sPhi = (logic_sector == 31) ? 1 : (logic_sector + 1) / 4 + 1;
281 int key =
side * 10000 + logic_sector * 100 + PADid;
283 std::pair<RpcCablingCondData::RDOmap::iterator, bool> ins =
284 writeCdo->
m_RDOs.insert(RpcCablingCondData::RDOmap::value_type(
key, rdo));
287 ATH_MSG_ERROR(
"RpcCablingCondData::RDOmap is false for stationName="
288 <<
name <<
", stationEta=" << sEta <<
", stationPhi=" << sPhi <<
", doubletR=" << dR
289 <<
", doubletZ=" << dZ <<
", doubletPhi=" << dP);
290 return StatusCode::FAILURE;
298 bool existLow =
false;
299 bool existHigh =
false;
304 if (!existLow && !existHigh) {
306 return StatusCode::FAILURE;
309 unsigned int RPC_strip =
cabling % 100;
310 unsigned int RPC_chamber = (
cabling / 100) % 100;
311 unsigned int RPC_layer = 0;
312 unsigned int RPC_station = 0;
317 unsigned int lvl1_sector = sector;
322 int sPhi = (logic_sector == 31) ? 1 : (logic_sector + 1) / 4 + 1;
334 int key =
side * 10000 + logic_sector * 100 + PADid;
337 std::pair<RpcCablingCondData::RDOmap::iterator, bool> ins =
338 writeCdo->
m_RDOs.insert(RpcCablingCondData::RDOmap::value_type(
key, rdo));
341 ATH_MSG_ERROR(
"RpcCablingCondData::RDOmap is false for stationName="
342 <<
name <<
", stationEta=" << sEta <<
", stationPhi=" << sPhi <<
", doubletR=" << dR
343 <<
", doubletZ=" << dZ <<
", doubletPhi=" << dP);
344 return StatusCode::FAILURE;
351 while (
it != CMAs.end() && (
unsigned int)(*it).first.PAD_index() == PADid) { ++
it; }
354 ATH_MSG_DEBUG(
"setup() - sector " << sector <<
", number of associated RDO (i.e. Pads) = " << nRDOentries);
357 DBline data_corr(MAP_corr);
359 while (++data_corr) {
361 unsigned short int SubId;
362 unsigned short int SecId;
363 unsigned short int PADId;
364 unsigned short int CMAId;
365 unsigned short int ijk;
369 unsigned short int Channel1;
370 unsigned short int Channel2;
373 if (data_corr(
"CABLE") >> data_corr.
dbhex() >> SubId >> SecId >> PADId >> CMAId >> ijk >> data_corr.
dbdec() >>
type >> Channel1 >>
374 Channel2 >> Number) {
375 bool ok =
CableParamCheck(SubId, SecId, PADId, CMAId, ijk,
type, Channel1, Channel2, Number);
377 layer = (ijk == 0 || ijk == 2 || ijk == 3) ? 0 : 1;
380 Channel1 += 32 * (ijk % 2);
381 Channel2 += 32 * (ijk % 2);
384 unsigned short int lh = (CMAId >> 2) & 1;
386 if (ijk == 0 || ijk == 1)
397 << std::hex << std::setw(4) << std::showbase << SubId <<
" " << std::setw(4) << std::showbase << SecId
398 <<
" " << std::setw(3) << std::showbase << PADId <<
" " << std::setw(3) << std::showbase << CMAId <<
" "
399 << std::setw(3) << std::showbase << ijk <<
" " << std::dec << std::setw(1) << std::showbase <<
type <<
" "
400 << std::setw(2) << std::showbase << Channel1 <<
" " << std::setw(2) << std::showbase << Channel2 <<
" "
401 << std::setw(2) << std::showbase << Number);
404 if (data_corr(
"BOARD") >> data_corr.
dbhex() >> SubId >> SecId >> PADId >> CMAId >> data_corr.
dbdec() >>
inputType >>
layer >>
405 type >> Channel1 >> Channel2 >> Number) {
414 << std::hex << std::setw(4) << std::showbase << SubId <<
" " << std::setw(4) << std::showbase << SecId
415 <<
" " << std::setw(3) << std::showbase << PADId <<
" " << std::setw(3) << std::showbase << CMAId <<
" "
416 << std::dec << std::setw(1) <<
inputType <<
" " << std::setw(1) <<
layer <<
" " << std::dec << std::setw(1)
417 << std::showbase <<
type <<
" " << std::setw(2) << std::showbase << Channel1 <<
" " << std::setw(2)
418 << std::showbase << Channel2 <<
" " << std::setw(2) << std::showbase << Number);
422 ATH_MSG_DEBUG(
"setup() - corrected map n. of lines read is " << nlines);
430 std::set<uint32_t> ROBid;
436 ATH_MSG_INFO(
"setup() - start building OfflineOnlineMap for " << writeCdo->
m_RDOs.size() <<
" RDOs");
440 for (; pad_beg != pad_end; ++pad_beg) {
441 const RDOindex* pRDOindex = &((*pad_beg).second);
445 writeCdo->
m_HashVec.push_back(pRDOindex);
448 ATH_MSG_ERROR(
"Size of hash vector and RDO hash does not match");
449 return StatusCode::FAILURE;
453 const unsigned short int rob_id = pRDOindex->
ROBid();
454 const unsigned short int rod_id = pRDOindex->
RODid();
455 const unsigned short int sub_id = pRDOindex->
side();
456 const unsigned short int sec_id = pRDOindex->
SLid();
457 const unsigned short int pad_id = pRDOindex->
PADid();
459 uint32_t ROD_ID = (sub_id << 16) | rod_id;
460 uint32_t ROB_ID = (sub_id << 16) | rob_id;
462 ROBid.insert(ROB_ID);
463 unsigned short int sub_id_index = ((sub_id == 0x65) ? 1 : 0);
468 ATH_MSG_DEBUG(hashID <<
"-th entry has sub_id_index=" << sub_id_index <<
", ROBid=" << rob_id <<
", RODid=" << rod_id <<
", side="
469 << sub_id <<
", SLid=" << sec_id <<
", PADid=" << pad_id <<
", pad_identifier=" <<
id.get_compact());
475 std::pair<RpcCablingCondData::OfflineOnlineMap::iterator, bool> ins =
476 writeCdo->
m_RDOmap.insert(RpcCablingCondData::OfflineOnlineMap::value_type(
id, pRDOindex));
477 ATH_MSG_DEBUG(
"OfflineOnlineMap new entry: Identifier with technology="
479 <<
", stationEta=" <<
m_idHelperSvc->rpcIdHelper().stationEta(
id) <<
", stationPhi="
481 <<
", doubletZ=" <<
m_idHelperSvc->rpcIdHelper().doubletZ(
id) <<
", doubletPhi="
482 <<
m_idHelperSvc->rpcIdHelper().doubletPhi(
id) <<
" and hash of the RDOindex(key)= " << pRDOindex->
hash());
484 ATH_MSG_ERROR(
"RpcCablingCondData::OfflineOnlineMap is false for technology="
486 <<
", stationEta=" <<
m_idHelperSvc->rpcIdHelper().stationEta(
id) <<
", stationPhi="
488 <<
", doubletZ=" <<
m_idHelperSvc->rpcIdHelper().doubletZ(
id) <<
", doubletPhi="
489 <<
m_idHelperSvc->rpcIdHelper().doubletPhi(
id) <<
" and hash of the RDOindex(key)= " << pRDOindex->
hash());
490 return StatusCode::FAILURE;
496 if (insert_ROB_RDO_returnVal.second)
497 ATH_MSG_DEBUG(
"A new RDO HashId = " << pRDOindex->
hash() <<
" registered for ROB Id = " << ROB_ID);
499 ATH_MSG_VERBOSE(
"The RDO HashId = " << pRDOindex->
hash() <<
" was already registered for ROB Id = " << ROB_ID);
503 std::list<Identifier> strip_id_list;
505 ATH_MSG_DEBUG(
"RDO HashId = " << (
int)rdoHashId <<
" RDO Id = " <<
id.get_compact() <<
" ROB Id = " << MSG::hex << ROB_ID
506 << MSG::dec <<
" ROD Id = " << MSG::hex << ROD_ID << MSG::dec);
508 for (
unsigned short int CMAId : {2, 3, 6, 7}) {
509 for (
unsigned short int ijk : {1, 2, 3}) {
510 strip_id_list.clear();
511 for (
unsigned short int channel : {0, 31}) {
512 strip_id_list.splice(strip_id_list.end(),
518 int gethash_code =
m_idHelperSvc->rpcIdHelper().get_hash(idp, prdHashId, &rpcModuleContext);
519 if (gethash_code != 0) {
527 if (insertRDO_returnVal.second) {
528 ATH_MSG_DEBUG(
"A new RDO HashId = " << (
int)rdoHashId <<
" registered for PRD HashId = " << (
int)prdHashId);
531 <<
" was already registered for PRD HashId = " << (
int)prdHashId);
536 if (insertROB_returnVal.second) {
537 ATH_MSG_DEBUG(
"A new ROB Id = " << MSG::hex << ROB_ID << MSG::dec
538 <<
" registered for PRD HashId = " << (
int)prdHashId);
541 <<
" was already registered for PRD HashId = " << (
int)prdHashId);
548 std::map<std::string, std::string>::const_iterator
it;
549 it = trigroads.find(
"infos.txt");
550 if (
it == trigroads.end()) {
553 ATH_MSG_VERBOSE(
"======== RPC Trigger Roads from COOL - Header infos ========");
557 std::stringstream
ss;
561 if (word ==
"FeetPadThresholds") {
562 feedPadThresholds.assign(3, 0);
563 ss >> feedPadThresholds.at(0);
564 ss >> feedPadThresholds.at(1);
565 ss >> feedPadThresholds.at(2);
566 ATH_MSG_VERBOSE(
"FeetPadThresholds set from COOL to: " << feedPadThresholds.at(0) <<
"," << feedPadThresholds.at(1)
567 <<
"," << feedPadThresholds.at(2));
575 index.pad_identifier(
id);
580 ATH_MSG_ERROR(
"Inconsistence between PAD hash and RpcPadIdHash");
583 return StatusCode::FAILURE;
587 unsigned short int rod =
index.RODid();
591 return StatusCode::FAILURE;
603 ATH_MSG_DEBUG(
"setup() - start recording RpcCablingCondData");
608 if (feedPadThresholds.size() != 3) {
610 feedPadThresholds.assign(3, 0);
611 feedPadThresholds.at(0) = 0;
612 feedPadThresholds.at(1) = 2;
613 feedPadThresholds.at(2) = 5;
615 ATH_MSG_INFO(
"Applying FeetPadThresholds : " << feedPadThresholds.at(0) <<
"," << feedPadThresholds.at(1) <<
","
616 << feedPadThresholds.at(2));
618 const unsigned int NumFeetSectors = 8;
619 unsigned int FeetSectors[NumFeetSectors] = {21, 22, 25, 26, 53, 54, 57, 58};
620 const unsigned int NumSpecialFeetPads = 4;
621 unsigned int SpecialFeetPads[NumSpecialFeetPads] = {2, 4, 5, 7};
623 for (
unsigned int is = 0; is < NumFeetSectors; is++) {
624 for (
unsigned int it = 0;
it < NumSpecialFeetPads;
it++) {
626 for (
unsigned int th = 0;
th < 3;
th++) {
628 feedPadThresholds.at(
th));
645 std::stringstream ss1;
646 ss1 <<
"Level-1 configuration database " << std::endl;
647 ss1 <<
"Contains " << maxType <<
" Trigger Sector Types:" << std::endl;
648 ss1 <<
"negative sectors 0 - 15 ==> ";
649 for (
int i = 0;
i < 16;
i++) ss1 << std::setw(2) << sectorMap[
i] <<
" ";
650 ss1 << std::endl <<
"negative sectors 16 - 31 ==> ";
651 for (
int i = 16;
i < 32;
i++) ss1 << std::setw(2) << sectorMap[
i] <<
" ";
652 ss1 << std::endl <<
"positive sectors 32 - 47 ==> ";
653 for (
int i = 32;
i < 48;
i++) ss1 << std::setw(2) << sectorMap[
i] <<
" ";
654 ss1 << std::endl <<
"positive sectors 48 - 63 ==> ";
655 for (
int i = 48;
i < 64;
i++) ss1 << std::setw(2) << sectorMap[
i] <<
" ";
661 if (writeCdo->
m_RDOs.empty()) {
663 return StatusCode::FAILURE;
667 return StatusCode::FAILURE;
671 return StatusCode::FAILURE;
675 return StatusCode::FAILURE;
679 return StatusCode::FAILURE;
683 return StatusCode::FAILURE;
686 return StatusCode::SUCCESS;
690 const unsigned short int PADId,
const unsigned short int CMAId,
693 std::list<unsigned int> CodeList;
695 int logic_sector = SectorId + SubsystemId * 32;
696 unsigned short int Ixx = CMAId & 1;
697 unsigned short int ep = (CMAId >> 1) & 1;
698 unsigned short int lh = (CMAId >> 2) & 1;
700 ep = (ep == 1) ? 0 : 1;
709 CodeList =
s.give_strip_code(
PHI, logic_sector,
lh, ijk,
Channel);
712 CodeList =
s.give_strip_code(
ETA, logic_sector,
lh, ijk,
Channel);
715 std::list<RPCofflineId> offlineIdList;
716 std::list<unsigned int>::const_iterator
it = CodeList.begin();
717 while (
it != CodeList.end()) {
720 throw std::runtime_error(
"RpcCablingCondAlg::give_strip_id() - cannot decode LVL1 Id at " +
724 int RPC_strip =
decode.strip_number();
725 int RPC_chamber =
decode.rpc_z_index();
726 int RPC_layer =
decode.rpc_layer();
727 int RPC_station =
decode.lvl1_station();
728 int sector = (
decode.logic_sector()) % 32;
734 rpcId.
stationPhi = (sector == 31) ? 1 : (sector + 1) / 4 + 1;
738 rpcId.
gasGap = RPC_layer + 1;
740 rpcId.
strip = RPC_strip + 1;
742 offlineIdList.push_back(std::move(rpcId));
747 std::list<Identifier>
id;
748 std::list<RPCofflineId>::const_iterator
iterator = offlineIdList.begin();
749 while (
iterator != offlineIdList.end()) {
750 Identifier rpcId =
m_idHelperSvc->rpcIdHelper().channelID((*iterator).stationName, (*iterator).stationEta, (*iterator).stationPhi,
751 (*iterator).doubletR, (*iterator).doubletZ, (*iterator).doubletPhi,
752 (*iterator).gasGap, (*iterator).measuresPhi, (*iterator).strip);
761 const unsigned short int CMAId,
const CMAinput it,
const unsigned int layer,
762 const unsigned short int Channel1,
const unsigned short int Channel2,
const short int number,
764 int logic_sector = (SubsystemId == 0x65) ? SectorId + 32 : SectorId;
765 unsigned short int Ixx = CMAId & 1;
766 unsigned short int ep = (CMAId >> 1) & 1;
768 ep = (ep == 1) ? 0 : 1;
786 const unsigned short int CMAId,
const unsigned short int inputType,
const unsigned int layer,
787 const unsigned int type,
const unsigned short int Channel1,
const unsigned short int Channel2,
788 const short int Number)
const {
789 if (SubId != 0x65 && SubId != 0x66) {
790 ATH_MSG_ERROR(
"Subsystem Id out of range: " << SubId <<
" not in [0x65,0x66].");
833 const unsigned short int CMAId,
const unsigned short int ijk,
const unsigned int type,
834 const unsigned short int Channel1,
const unsigned short int Channel2,
835 const short int Number)
const {
836 if (SubId != 0x65 && SubId != 0x66) {