File indexing completed on 2024-04-06 12:10:54
0001 #include "EventFilter/L1TRawToDigi/interface/OmtfLinkMappingRpc.h"
0002
0003 #include <fstream>
0004
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006
0007 #include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
0008 #include "CondFormats/RPCObjects/interface/RPCEMap.h"
0009 #include "CondFormats/DataRecord/interface/RPCEMapRcd.h"
0010 #include "CondFormats/RPCObjects/interface/DccSpec.h"
0011 #include "CondFormats/RPCObjects/interface/LinkBoardElectronicIndex.h"
0012 #include "CondFormats/RPCObjects/interface/LinkBoardPackedStrip.h"
0013 #include "CondFormats/RPCObjects/interface/TriggerBoardSpec.h"
0014 #include "CondFormats/RPCObjects/interface/LinkBoardSpec.h"
0015
0016 #include "CondFormats/RPCObjects/interface/RPCAMCLinkMap.h"
0017
0018 namespace omtf {
0019
0020 bool lessLinkBoardElectronicIndex::operator()(const LinkBoardElectronicIndex& o1,
0021 const LinkBoardElectronicIndex& o2) const {
0022 if (o1.dccId < o2.dccId)
0023 return true;
0024 else if (o1.dccId == o2.dccId && o1.dccInputChannelNum < o2.dccInputChannelNum)
0025 return true;
0026 else if (o1.dccId == o2.dccId && o1.dccInputChannelNum == o2.dccInputChannelNum &&
0027 o1.tbLinkInputNum < o2.tbLinkInputNum)
0028 return true;
0029 else
0030 return false;
0031 }
0032
0033 MapEleIndex2LBIndex translateOmtf2Pact(const RpcLinkMap& omtfLink2Ele, const RPCReadOutMapping* pactCabling) {
0034 MapEleIndex2LBIndex omtf2rpc;
0035
0036 std::vector<const DccSpec*> dccs = pactCabling->dccList();
0037 for (auto it1 : dccs) {
0038 const std::vector<TriggerBoardSpec>& rmbs = it1->triggerBoards();
0039 for (auto const& it2 : rmbs) {
0040 const std::vector<LinkConnSpec>& links = it2.linkConns();
0041 for (auto const& it3 : links) {
0042 const std::vector<LinkBoardSpec>& lbs = it3.linkBoards();
0043 for (std::vector<LinkBoardSpec>::const_iterator it4 = lbs.begin(); it4 != lbs.end(); ++it4) {
0044 std::string lbNameCH = it4->linkBoardName();
0045 std::string lbName = lbNameCH.substr(0, lbNameCH.size() - 4);
0046 std::vector<EleIndex> omtfEles = omtfLink2Ele.omtfEleIndex(lbName);
0047
0048 LinkBoardElectronicIndex rpcEle = {
0049 it1->id(), it2.dccInputChannelNum(), it3.triggerBoardInputNumber(), it4->linkBoardNumInLink()};
0050 for (const auto& omtfEle : omtfEles)
0051 omtf2rpc[omtfEle] = rpcEle;
0052 }
0053 }
0054 }
0055 }
0056 LogTrace(" ") << " SIZE OF OMTF to RPC map TRANSLATION is: " << omtf2rpc.size() << std::endl;
0057 return omtf2rpc;
0058 }
0059
0060 MapLBIndex2EleIndex translatePact2Omtf(const RpcLinkMap& omtfLink2Ele, const RPCReadOutMapping* pactCabling) {
0061 MapLBIndex2EleIndex pact2omtfs;
0062 MapEleIndex2LBIndex omtf2rpcs = translateOmtf2Pact(omtfLink2Ele, pactCabling);
0063 for (const auto& omtf2rpc : omtf2rpcs) {
0064 std::pair<EleIndex, EleIndex>& omtfs = pact2omtfs[omtf2rpc.second];
0065 if (omtfs.first.fed() == 0)
0066 omtfs.first = omtf2rpc.first;
0067 else if (omtfs.second.fed() == 0)
0068 omtfs.second = omtf2rpc.first;
0069 else
0070 edm::LogError(" translatePact2Omtf ") << " PROBLEM LinkBoardElectronicIndex already USED!!!! ";
0071 }
0072 return pact2omtfs;
0073 }
0074
0075 void RpcLinkMap::init(const RPCAMCLinkMap& amcMapping) {
0076 const RPCAMCLinkMap::map_type& amcMap = amcMapping.getMap();
0077
0078 for (const auto& item : amcMap) {
0079 unsigned int fedId = item.first.getFED();
0080 unsigned int amcSlot = item.first.getAMCNumber();
0081 unsigned int link = item.first.getAMCInput();
0082 std::string lbName = item.second.getName();
0083
0084 std::string processorNameStr = "OMTF";
0085 ;
0086 if (fedId == 1380)
0087 processorNameStr = "OMTFn";
0088 else
0089 processorNameStr = "OMTFp";
0090 processorNameStr += std::to_string(amcSlot / 2 + 1);
0091 std::string processorName = processorNameStr;
0092
0093 std::map<unsigned int, std::string>& li2lb = link2lbName[processorName];
0094 std::map<std::string, unsigned int>& lb2li = lbName2link[processorName];
0095 li2lb[link] = lbName;
0096 lb2li[lbName] = link;
0097 EleIndex ele(processorName, link);
0098 lbName2OmtfIndex[lbName].push_back(ele);
0099 }
0100 }
0101
0102 void RpcLinkMap::init(const std::string& fName) {
0103 std::ifstream inFile;
0104 inFile.open(fName);
0105 if (inFile) {
0106 LogTrace("") << " reading OmtfRpcLinksMap from: " << fName;
0107 } else {
0108 LogTrace("") << " Unable to open file " << fName;
0109
0110 throw std::runtime_error("Unable to open OmtfRpcLinksMap file " + fName);
0111 }
0112
0113 std::string line;
0114 while (std::getline(inFile, line)) {
0115 line.erase(0, line.find_first_not_of(" \t\r\n"));
0116 if (line.empty() || !line.compare(0, 2, "--"))
0117 continue;
0118 std::stringstream ss(line);
0119 std::string processorName, lbName;
0120 unsigned int link, dbId;
0121 if (ss >> processorName >> link >> lbName >> dbId) {
0122 std::map<unsigned int, std::string>& li2lb = link2lbName[processorName];
0123 std::map<std::string, unsigned int>& lb2li = lbName2link[processorName];
0124 li2lb[link] = lbName;
0125 lb2li[lbName] = link;
0126 EleIndex ele(processorName, link);
0127 lbName2OmtfIndex[lbName].push_back(ele);
0128 }
0129 }
0130 inFile.close();
0131 }
0132
0133 std::vector<EleIndex> RpcLinkMap::omtfEleIndex(const std::string& lbName) const {
0134 const auto pos = lbName2OmtfIndex.find(lbName);
0135 return pos != lbName2OmtfIndex.end() ? pos->second : std::vector<EleIndex>();
0136 }
0137
0138 }