21 return StatusCode::SUCCESS;
26 const EventContext& ctx = Gaudi::Hive::currentContext();
30 if (writeHandle.isValid()) {
31 ATH_MSG_DEBUG(
"CondHandle " << writeHandle.fullKey() <<
" is already valid."
32 <<
". In theory this should not be called, but may happen"
33 <<
" if multiple concurrent events are being processed out of order.");
34 return StatusCode::SUCCESS;
43 return StatusCode::FAILURE;
45 writeHandle.addDependency(readHandle_map_schema);
46 ATH_MSG_DEBUG(
"Size of CondAttrListCollection readCdoMap->size()= " << readCdoMap->size());
53 return StatusCode::FAILURE;
55 ATH_MSG_DEBUG(
"Size of CondAttrListCollection readCdoMap_corr->size()= " << readCdoCorr->size());
56 writeHandle.addDependency(readHandle_map_schema_corr);
63 return StatusCode::FAILURE;
65 ATH_MSG_DEBUG(
"Size of CondAttrListCollection readCdo_cm_thr_eta->size()= " << readCdoEta->size());
66 writeHandle.addDependency(readHandle_cm_thr_eta);
73 return StatusCode::FAILURE;
75 ATH_MSG_DEBUG(
"Size of CondAttrListCollection readCdo_cm_thr_phi->size()= " << readCdoPhi->size());
76 writeHandle.addDependency(readHandle_cm_thr_phi);
78 std::unique_ptr<RpcCablingCondData> writeCdo{std::make_unique<RpcCablingCondData>()};
79 ATH_CHECK(
setup(readCdoMap, readCdoCorr, readCdoEta, readCdoPhi, writeCdo.get()));
81 if (writeHandle.record(std::move(writeCdo)).isFailure()) {
82 ATH_MSG_FATAL(
"Could not record RpcCondCablingData " << writeHandle.key() <<
" with EventRange " << writeHandle.getRange()
83 <<
" into Conditions Store");
84 return StatusCode::SUCCESS;
87 ATH_MSG_INFO(
"recorded new " << writeHandle.key() <<
" with range " << writeHandle.getRange());
88 return StatusCode::SUCCESS;
99 std::vector<unsigned short int> feedPadThresholds;
100 std::map<std::string, std::string> trigroads;
108 std::stringstream MAP(atr_map[
"Map"].data<std::string>());
115 std::stringstream MAP_corr(atr_map_corr[
"Map"].data<std::string>());
121 std::string etaCM_File;
124 for (itr_eta = readCdoEta->
begin(); itr_eta != readCdoEta->
end(); ++itr_eta) {
126 etaCM_File = *(
static_cast<const std::string*
>((atr[
"CM_File"]).addressOfData()));
127 etaTh0 = *(
static_cast<const std::string*
>((atr[
"Th0"]).addressOfData()));
128 trigroads[etaCM_File] = etaTh0;
135 std::string phiCM_File;
138 for (itr = readCdoPhi->
begin(); itr != readCdoPhi->
end(); ++itr) {
140 phiCM_File = *(
static_cast<const std::string*
>((atr[
"CM_File"]).addressOfData()));
141 phiTh0 = *(
static_cast<const std::string*
>((atr[
"Th0"]).addressOfData()));
142 trigroads[phiCM_File] = phiTh0;
151 unsigned int nlines = 0;
157 ATH_MSG_DEBUG(
"setup() - Reading routine. nlines = " << nlines);
164 if (
data(
"SECTOR TYPES (") >>
start >>
"-" >>
stop >>
"):") {
170 for (
int i = 0;
i < 64; ++
i) { maxType =
std::max(sectorMap[
i], maxType); }
173 ATH_MSG_DEBUG(
"setup() - Loop over " << maxType <<
" sector-types");
175 for (
int i = 1;
i <= maxType; ++
i) {
179 for (
int j = 0; j < 64; ++j) {
180 if (sectorMap[j] ==
i) {
182 sectorLogic.insert(SLmap_t::value_type(j, &sec));
183 ATH_MSG_DEBUG(
"setup() - filling sectorLogicSetup Map for type " <<
i <<
" sector " << j);
190 for (
int i = 1;
i <= maxType; ++
i) {
192 if (
data(
"RPC GEOM # :",
i)) {
194 if (!(sectorType[
i - 1] +=
RPCdata))
return StatusCode::FAILURE;
197 if (
data(
"WIRED OR # :",
i)) {
199 if (!(sectorType[
i - 1] += WORdata))
return StatusCode::FAILURE;
202 if (
data(
"CMAs # : pivot segmentation",
i)) {
204 if (!(sectorType[
i - 1] +=
CMAdata))
return StatusCode::FAILURE;
207 if (
data(
"CMAs # : eta cabling",
i)) {
209 if (!(sectorType[
i - 1] +=
CMAdata))
return StatusCode::FAILURE;
213 ATH_MSG_DEBUG(
"setup() - map n. of lines read is " << nlines);
216 for (
int i = 1;
i <= maxType; ++
i) {
217 if (!sectorType[
i - 1].
setup(
msg()))
return StatusCode::FAILURE;
218 if (!sectorType[
i - 1].
check())
return StatusCode::FAILURE;
222 for (
const auto& cma : CMAs) {
223 unsigned int cabling = UINT_MAX;
235 for (
int sector = 0; sector < 64; ++sector) {
236 unsigned int nRDOentries = 0;
237 int side = (sector < 32) ? 0 : 1;
238 int logic_sector = sector % 32;
240 if (sectorMap[sector]) {
246 RPC_CondCabling::SectorLogicSetup::EtaCMAmap::const_iterator
it = CMAs.begin();
248 bool isFirst =
false;
251 while (
it != CMAs.end()) {
253 unsigned int ID = (*it).second.id().Ixx_index();
254 bool inversion = (*it).second.inversion();
255 isFirst = (
ID == 1 && inversion) || (
ID == 0 && !inversion);
256 unsigned int PADid = (*it).first.PAD_index();
257 unsigned int cabling = UINT_MAX;
259 unsigned int RPC_strip =
cabling % 100;
260 unsigned int RPC_chamber = (
cabling / 100) % 100;
261 unsigned int RPC_layer = 0;
262 unsigned int RPC_station = (*it).second.whichCMAstation(
CMAinput::Pivot);
263 unsigned int lvl1_sector = sector;
268 int sPhi = (logic_sector == 31) ? 1 : (logic_sector + 1) / 4 + 1;
280 int key =
side * 10000 + logic_sector * 100 + PADid;
282 std::pair<RpcCablingCondData::RDOmap::iterator, bool> ins =
283 writeCdo->
m_RDOs.insert(RpcCablingCondData::RDOmap::value_type(
key, rdo));
286 ATH_MSG_ERROR(
"RpcCablingCondData::RDOmap is false for stationName="
287 <<
name <<
", stationEta=" << sEta <<
", stationPhi=" << sPhi <<
", doubletR=" << dR
288 <<
", doubletZ=" << dZ <<
", doubletPhi=" << dP);
289 return StatusCode::FAILURE;
297 bool existLow =
false;
298 bool existHigh =
false;
303 if (!existLow && !existHigh) {
305 return StatusCode::FAILURE;
308 unsigned int RPC_strip =
cabling % 100;
309 unsigned int RPC_chamber = (
cabling / 100) % 100;
310 unsigned int RPC_layer = 0;
311 unsigned int RPC_station = 0;
316 unsigned int lvl1_sector = sector;
321 int sPhi = (logic_sector == 31) ? 1 : (logic_sector + 1) / 4 + 1;
333 int key =
side * 10000 + logic_sector * 100 + PADid;
336 std::pair<RpcCablingCondData::RDOmap::iterator, bool> ins =
337 writeCdo->
m_RDOs.insert(RpcCablingCondData::RDOmap::value_type(
key, rdo));
340 ATH_MSG_ERROR(
"RpcCablingCondData::RDOmap is false for stationName="
341 <<
name <<
", stationEta=" << sEta <<
", stationPhi=" << sPhi <<
", doubletR=" << dR
342 <<
", doubletZ=" << dZ <<
", doubletPhi=" << dP);
343 return StatusCode::FAILURE;
350 while (
it != CMAs.end() && (
unsigned int)(*it).first.PAD_index() == PADid) { ++
it; }
353 ATH_MSG_DEBUG(
"setup() - sector " << sector <<
", number of associated RDO (i.e. Pads) = " << nRDOentries);
356 DBline data_corr(MAP_corr);
358 while (++data_corr) {
360 unsigned short int SubId;
361 unsigned short int SecId;
362 unsigned short int PADId;
363 unsigned short int CMAId;
364 unsigned short int ijk;
368 unsigned short int Channel1;
369 unsigned short int Channel2;
372 if (data_corr(
"CABLE") >> data_corr.
dbhex() >> SubId >> SecId >> PADId >> CMAId >> ijk >> data_corr.
dbdec() >>
type >> Channel1 >>
373 Channel2 >> Number) {
374 bool ok =
CableParamCheck(SubId, SecId, PADId, CMAId, ijk,
type, Channel1, Channel2, Number);
376 layer = (ijk == 0 || ijk == 2 || ijk == 3) ? 0 : 1;
379 Channel1 += 32 * (ijk % 2);
380 Channel2 += 32 * (ijk % 2);
383 unsigned short int lh = (CMAId >> 2) & 1;
385 if (ijk == 0 || ijk == 1)
396 << std::hex << std::setw(4) << std::showbase << SubId <<
" " << std::setw(4) << std::showbase << SecId
397 <<
" " << std::setw(3) << std::showbase << PADId <<
" " << std::setw(3) << std::showbase << CMAId <<
" "
398 << std::setw(3) << std::showbase << ijk <<
" " << std::dec << std::setw(1) << std::showbase <<
type <<
" "
399 << std::setw(2) << std::showbase << Channel1 <<
" " << std::setw(2) << std::showbase << Channel2 <<
" "
400 << std::setw(2) << std::showbase << Number);
403 if (data_corr(
"BOARD") >> data_corr.
dbhex() >> SubId >> SecId >> PADId >> CMAId >> data_corr.
dbdec() >>
inputType >>
layer >>
404 type >> Channel1 >> Channel2 >> Number) {
413 << std::hex << std::setw(4) << std::showbase << SubId <<
" " << std::setw(4) << std::showbase << SecId
414 <<
" " << std::setw(3) << std::showbase << PADId <<
" " << std::setw(3) << std::showbase << CMAId <<
" "
415 << std::dec << std::setw(1) <<
inputType <<
" " << std::setw(1) <<
layer <<
" " << std::dec << std::setw(1)
416 << std::showbase <<
type <<
" " << std::setw(2) << std::showbase << Channel1 <<
" " << std::setw(2)
417 << std::showbase << Channel2 <<
" " << std::setw(2) << std::showbase << Number);
421 ATH_MSG_DEBUG(
"setup() - corrected map n. of lines read is " << nlines);
429 std::set<uint32_t> ROBid;
435 ATH_MSG_INFO(
"setup() - start building OfflineOnlineMap for " << writeCdo->
m_RDOs.size() <<
" RDOs");
439 for (; pad_beg != pad_end; ++pad_beg) {
440 const RDOindex* pRDOindex = &((*pad_beg).second);
444 writeCdo->
m_HashVec.push_back(pRDOindex);
447 ATH_MSG_ERROR(
"Size of hash vector and RDO hash does not match");
448 return StatusCode::FAILURE;
452 const unsigned short int rob_id = pRDOindex->
ROBid();
453 const unsigned short int rod_id = pRDOindex->
RODid();
454 const unsigned short int sub_id = pRDOindex->
side();
455 const unsigned short int sec_id = pRDOindex->
SLid();
456 const unsigned short int pad_id = pRDOindex->
PADid();
458 uint32_t ROD_ID = (sub_id << 16) | rod_id;
459 uint32_t ROB_ID = (sub_id << 16) | rob_id;
461 ROBid.insert(ROB_ID);
462 unsigned short int sub_id_index = ((sub_id == 0x65) ? 1 : 0);
467 ATH_MSG_DEBUG(hashID <<
"-th entry has sub_id_index=" << sub_id_index <<
", ROBid=" << rob_id <<
", RODid=" << rod_id <<
", side="
468 << sub_id <<
", SLid=" << sec_id <<
", PADid=" << pad_id <<
", pad_identifier=" <<
id.get_compact());
474 std::pair<RpcCablingCondData::OfflineOnlineMap::iterator, bool> ins =
475 writeCdo->
m_RDOmap.insert(RpcCablingCondData::OfflineOnlineMap::value_type(
id, pRDOindex));
476 ATH_MSG_DEBUG(
"OfflineOnlineMap new entry: Identifier with technology="
478 <<
", stationEta=" <<
m_idHelperSvc->rpcIdHelper().stationEta(
id) <<
", stationPhi="
480 <<
", doubletZ=" <<
m_idHelperSvc->rpcIdHelper().doubletZ(
id) <<
", doubletPhi="
481 <<
m_idHelperSvc->rpcIdHelper().doubletPhi(
id) <<
" and hash of the RDOindex(key)= " << pRDOindex->
hash());
483 ATH_MSG_ERROR(
"RpcCablingCondData::OfflineOnlineMap is false for technology="
485 <<
", stationEta=" <<
m_idHelperSvc->rpcIdHelper().stationEta(
id) <<
", stationPhi="
487 <<
", doubletZ=" <<
m_idHelperSvc->rpcIdHelper().doubletZ(
id) <<
", doubletPhi="
488 <<
m_idHelperSvc->rpcIdHelper().doubletPhi(
id) <<
" and hash of the RDOindex(key)= " << pRDOindex->
hash());
489 return StatusCode::FAILURE;
495 if (insert_ROB_RDO_returnVal.second)
496 ATH_MSG_DEBUG(
"A new RDO HashId = " << pRDOindex->
hash() <<
" registered for ROB Id = " << ROB_ID);
498 ATH_MSG_VERBOSE(
"The RDO HashId = " << pRDOindex->
hash() <<
" was already registered for ROB Id = " << ROB_ID);
502 std::list<Identifier> strip_id_list;
504 ATH_MSG_DEBUG(
"RDO HashId = " << (
int)rdoHashId <<
" RDO Id = " <<
id.get_compact() <<
" ROB Id = " << MSG::hex << ROB_ID
505 << MSG::dec <<
" ROD Id = " << MSG::hex << ROD_ID << MSG::dec);
507 for (
unsigned short int CMAId : {2, 3, 6, 7}) {
508 for (
unsigned short int ijk : {1, 2, 3}) {
509 strip_id_list.clear();
510 for (
unsigned short int channel : {0, 31}) {
511 strip_id_list.splice(strip_id_list.end(),
517 int gethash_code =
m_idHelperSvc->rpcIdHelper().get_hash(idp, prdHashId, &rpcModuleContext);
518 if (gethash_code != 0) {
526 if (insertRDO_returnVal.second) {
527 ATH_MSG_DEBUG(
"A new RDO HashId = " << (
int)rdoHashId <<
" registered for PRD HashId = " << (
int)prdHashId);
530 <<
" was already registered for PRD HashId = " << (
int)prdHashId);
535 if (insertROB_returnVal.second) {
536 ATH_MSG_DEBUG(
"A new ROB Id = " << MSG::hex << ROB_ID << MSG::dec
537 <<
" registered for PRD HashId = " << (
int)prdHashId);
540 <<
" was already registered for PRD HashId = " << (
int)prdHashId);
547 std::map<std::string, std::string>::const_iterator
it;
548 it = trigroads.find(
"infos.txt");
549 if (
it == trigroads.end()) {
552 ATH_MSG_VERBOSE(
"======== RPC Trigger Roads from COOL - Header infos ========");
556 std::stringstream
ss;
560 if (word ==
"FeetPadThresholds") {
561 feedPadThresholds.assign(3, 0);
562 ss >> feedPadThresholds.at(0);
563 ss >> feedPadThresholds.at(1);
564 ss >> feedPadThresholds.at(2);
565 ATH_MSG_VERBOSE(
"FeetPadThresholds set from COOL to: " << feedPadThresholds.at(0) <<
"," << feedPadThresholds.at(1)
566 <<
"," << feedPadThresholds.at(2));
574 index.pad_identifier(
id);
579 ATH_MSG_ERROR(
"Inconsistence between PAD hash and RpcPadIdHash");
582 return StatusCode::FAILURE;
586 unsigned short int rod =
index.RODid();
590 return StatusCode::FAILURE;
602 ATH_MSG_DEBUG(
"setup() - start recording RpcCablingCondData");
607 if (feedPadThresholds.size() != 3) {
609 feedPadThresholds.assign(3, 0);
610 feedPadThresholds.at(0) = 0;
611 feedPadThresholds.at(1) = 2;
612 feedPadThresholds.at(2) = 5;
614 ATH_MSG_INFO(
"Applying FeetPadThresholds : " << feedPadThresholds.at(0) <<
"," << feedPadThresholds.at(1) <<
","
615 << feedPadThresholds.at(2));
617 const unsigned int NumFeetSectors = 8;
618 unsigned int FeetSectors[NumFeetSectors] = {21, 22, 25, 26, 53, 54, 57, 58};
619 const unsigned int NumSpecialFeetPads = 4;
620 unsigned int SpecialFeetPads[NumSpecialFeetPads] = {2, 4, 5, 7};
622 for (
unsigned int is = 0; is < NumFeetSectors; is++) {
623 for (
unsigned int it = 0;
it < NumSpecialFeetPads;
it++) {
625 for (
unsigned int th = 0;
th < 3;
th++) {
627 feedPadThresholds.at(
th));
644 std::stringstream ss1;
645 ss1 <<
"Level-1 configuration database " << std::endl;
646 ss1 <<
"Contains " << maxType <<
" Trigger Sector Types:" << std::endl;
647 ss1 <<
"negative sectors 0 - 15 ==> ";
648 for (
int i = 0;
i < 16;
i++) ss1 << std::setw(2) << sectorMap[
i] <<
" ";
649 ss1 << std::endl <<
"negative sectors 16 - 31 ==> ";
650 for (
int i = 16;
i < 32;
i++) ss1 << std::setw(2) << sectorMap[
i] <<
" ";
651 ss1 << std::endl <<
"positive sectors 32 - 47 ==> ";
652 for (
int i = 32;
i < 48;
i++) ss1 << std::setw(2) << sectorMap[
i] <<
" ";
653 ss1 << std::endl <<
"positive sectors 48 - 63 ==> ";
654 for (
int i = 48;
i < 64;
i++) ss1 << std::setw(2) << sectorMap[
i] <<
" ";
660 if (writeCdo->
m_RDOs.empty()) {
662 return StatusCode::FAILURE;
666 return StatusCode::FAILURE;
670 return StatusCode::FAILURE;
674 return StatusCode::FAILURE;
678 return StatusCode::FAILURE;
682 return StatusCode::FAILURE;
685 return StatusCode::SUCCESS;
689 const unsigned short int PADId,
const unsigned short int CMAId,
692 std::list<unsigned int> CodeList;
694 int logic_sector = SectorId + SubsystemId * 32;
695 unsigned short int Ixx = CMAId & 1;
696 unsigned short int ep = (CMAId >> 1) & 1;
697 unsigned short int lh = (CMAId >> 2) & 1;
699 ep = (ep == 1) ? 0 : 1;
708 CodeList =
s.give_strip_code(
PHI, logic_sector,
lh, ijk,
Channel);
711 CodeList =
s.give_strip_code(
ETA, logic_sector,
lh, ijk,
Channel);
714 std::list<RPCofflineId> offlineIdList;
715 std::list<unsigned int>::const_iterator
it = CodeList.begin();
716 while (
it != CodeList.end()) {
719 throw std::runtime_error(
"RpcCablingCondAlg::give_strip_id() - cannot decode LVL1 Id at " +
723 int RPC_strip =
decode.strip_number();
724 int RPC_chamber =
decode.rpc_z_index();
725 int RPC_layer =
decode.rpc_layer();
726 int RPC_station =
decode.lvl1_station();
727 int sector = (
decode.logic_sector()) % 32;
733 rpcId.
stationPhi = (sector == 31) ? 1 : (sector + 1) / 4 + 1;
737 rpcId.
gasGap = RPC_layer + 1;
739 rpcId.
strip = RPC_strip + 1;
741 offlineIdList.push_back(rpcId);
746 std::list<Identifier>
id;
747 std::list<RPCofflineId>::const_iterator
iterator = offlineIdList.begin();
748 while (
iterator != offlineIdList.end()) {
749 Identifier rpcId =
m_idHelperSvc->rpcIdHelper().channelID((*iterator).stationName, (*iterator).stationEta, (*iterator).stationPhi,
750 (*iterator).doubletR, (*iterator).doubletZ, (*iterator).doubletPhi,
751 (*iterator).gasGap, (*iterator).measuresPhi, (*iterator).strip);
760 const unsigned short int CMAId,
const CMAinput it,
const unsigned int layer,
761 const unsigned short int Channel1,
const unsigned short int Channel2,
const short int number,
763 int logic_sector = (SubsystemId == 0x65) ? SectorId + 32 : SectorId;
764 unsigned short int Ixx = CMAId & 1;
765 unsigned short int ep = (CMAId >> 1) & 1;
767 ep = (ep == 1) ? 0 : 1;
785 const unsigned short int CMAId,
const unsigned short int inputType,
const unsigned int layer,
786 const unsigned int type,
const unsigned short int Channel1,
const unsigned short int Channel2,
787 const short int Number)
const {
788 if (SubId != 0x65 && SubId != 0x66) {
789 ATH_MSG_ERROR(
"Subsystem Id out of range: " << SubId <<
" not in [0x65,0x66].");
832 const unsigned short int CMAId,
const unsigned short int ijk,
const unsigned int type,
833 const unsigned short int Channel1,
const unsigned short int Channel2,
834 const short int Number)
const {
835 if (SubId != 0x65 && SubId != 0x66) {