CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OmtfLinkMappingRpc.cc
Go to the documentation of this file.
2 
3 #include <fstream>
4 
6 
15 
17 
18 namespace omtf {
19 
21  const LinkBoardElectronicIndex& o2) const {
22  if (o1.dccId < o2.dccId)
23  return true;
24  else if (o1.dccId == o2.dccId && o1.dccInputChannelNum < o2.dccInputChannelNum)
25  return true;
26  else if (o1.dccId == o2.dccId && o1.dccInputChannelNum == o2.dccInputChannelNum &&
28  return true;
29  else
30  return false;
31  }
32 
33  MapEleIndex2LBIndex translateOmtf2Pact(const RpcLinkMap& omtfLink2Ele, const RPCReadOutMapping* pactCabling) {
34  MapEleIndex2LBIndex omtf2rpc;
35 
36  std::vector<const DccSpec*> dccs = pactCabling->dccList();
37  for (auto it1 : dccs) {
38  const std::vector<TriggerBoardSpec>& rmbs = it1->triggerBoards();
39  for (auto const& it2 : rmbs) {
40  const std::vector<LinkConnSpec>& links = it2.linkConns();
41  for (auto const& it3 : links) {
42  const std::vector<LinkBoardSpec>& lbs = it3.linkBoards();
43  for (std::vector<LinkBoardSpec>::const_iterator it4 = lbs.begin(); it4 != lbs.end(); ++it4) {
44  std::string lbNameCH = it4->linkBoardName();
45  std::string lbName = lbNameCH.substr(0, lbNameCH.size() - 4);
46  std::vector<EleIndex> omtfEles = omtfLink2Ele.omtfEleIndex(lbName);
47  // if (!omtfEles.empty()) std::cout <<" isOK ! " << it4->linkBoardName() <<" has: " << omtfEles.size() << " first: "<< omtfEles[0] << std::endl;
48  LinkBoardElectronicIndex rpcEle = {
49  it1->id(), it2.dccInputChannelNum(), it3.triggerBoardInputNumber(), it4->linkBoardNumInLink()};
50  for (const auto& omtfEle : omtfEles)
51  omtf2rpc[omtfEle] = rpcEle;
52  }
53  }
54  }
55  }
56  LogTrace(" ") << " SIZE OF OMTF to RPC map TRANSLATION is: " << omtf2rpc.size() << std::endl;
57  return omtf2rpc;
58  }
59 
60  MapLBIndex2EleIndex translatePact2Omtf(const RpcLinkMap& omtfLink2Ele, const RPCReadOutMapping* pactCabling) {
61  MapLBIndex2EleIndex pact2omtfs;
62  MapEleIndex2LBIndex omtf2rpcs = translateOmtf2Pact(omtfLink2Ele, pactCabling);
63  for (const auto& omtf2rpc : omtf2rpcs) {
64  std::pair<EleIndex, EleIndex>& omtfs = pact2omtfs[omtf2rpc.second];
65  if (omtfs.first.fed() == 0)
66  omtfs.first = omtf2rpc.first;
67  else if (omtfs.second.fed() == 0)
68  omtfs.second = omtf2rpc.first;
69  else
70  edm::LogError(" translatePact2Omtf ") << " PROBLEM LinkBoardElectronicIndex already USED!!!! ";
71  }
72  return pact2omtfs;
73  }
74 
75  void RpcLinkMap::init(const RPCAMCLinkMap& amcMapping) {
76  const RPCAMCLinkMap::map_type& amcMap = amcMapping.getMap();
77 
78  for (const auto& item : amcMap) {
79  unsigned int fedId = item.first.getFED();
80  unsigned int amcSlot = item.first.getAMCNumber();
81  unsigned int link = item.first.getAMCInput();
82  std::string lbName = item.second.getName();
83 
84  std::string processorNameStr = "OMTF";
85  ;
86  if (fedId == 1380)
87  processorNameStr = "OMTFn";
88  else
89  processorNameStr = "OMTFp";
90  processorNameStr += std::to_string(amcSlot / 2 + 1);
91  std::string processorName = processorNameStr;
92 
93  std::map<unsigned int, std::string>& li2lb = link2lbName[processorName];
94  std::map<std::string, unsigned int>& lb2li = lbName2link[processorName];
95  li2lb[link] = lbName;
96  lb2li[lbName] = link;
97  EleIndex ele(processorName, link);
98  lbName2OmtfIndex[lbName].push_back(ele);
99  }
100  }
101 
103  std::ifstream inFile;
104  inFile.open(fName);
105  if (inFile) {
106  LogTrace("") << " reading OmtfRpcLinksMap from: " << fName;
107  } else {
108  LogTrace("") << " Unable to open file " << fName;
109 
110  throw std::runtime_error("Unable to open OmtfRpcLinksMap file " + fName);
111  }
112 
114  while (std::getline(inFile, line)) {
115  line.erase(0, line.find_first_not_of(" \t\r\n")); //cut first character
116  if (line.empty() || !line.compare(0, 2, "--"))
117  continue; // empty or comment line
118  std::stringstream ss(line);
119  std::string processorName, lbName;
120  unsigned int link, dbId;
121  if (ss >> processorName >> link >> lbName >> dbId) {
122  std::map<unsigned int, std::string>& li2lb = link2lbName[processorName];
123  std::map<std::string, unsigned int>& lb2li = lbName2link[processorName];
124  li2lb[link] = lbName;
125  lb2li[lbName] = link;
126  EleIndex ele(processorName, link);
127  lbName2OmtfIndex[lbName].push_back(ele);
128  }
129  }
130  inFile.close();
131  }
132 
133  std::vector<EleIndex> RpcLinkMap::omtfEleIndex(const std::string& lbName) const {
134  const auto pos = lbName2OmtfIndex.find(lbName);
135  return pos != lbName2OmtfIndex.end() ? pos->second : std::vector<EleIndex>();
136  }
137 
138 } // namespace omtf
unsigned int link(const std::string &board, const std::string &lbName) const
std::map< std::string, std::map< unsigned int, std::string > > link2lbName
std::map< std::string, std::vector< EleIndex > > lbName2OmtfIndex
std::vector< EleIndex > omtfEleIndex(const std::string &lbName) const
MapLBIndex2EleIndex translatePact2Omtf(const RpcLinkMap &omtfLnks, const RPCReadOutMapping *pactCabling)
bool operator()(const LinkBoardElectronicIndex &o1, const LinkBoardElectronicIndex &o2) const
std::string to_string(const V &value)
Definition: OMSAccess.h:71
std::vector< const DccSpec * > dccList() const
all FEDs in map
std::map< LinkBoardElectronicIndex, std::pair< EleIndex, EleIndex >, lessLinkBoardElectronicIndex > MapLBIndex2EleIndex
std::map< EleIndex, LinkBoardElectronicIndex > MapEleIndex2LBIndex
#define LogTrace(id)
std::map< std::string, std::map< std::string, unsigned int > > lbName2link
if(conf_.getParameter< bool >("UseStripCablingDB"))
map_type & getMap()
Definition: RPCAMCLinkMap.h:27
std::map< RPCAMCLink, RPCLBLink > map_type
Definition: RPCAMCLinkMap.h:13
const std::string & lbName(const std::string &board, unsigned int link) const
MapEleIndex2LBIndex translateOmtf2Pact(const RpcLinkMap &omtfLnks, const RPCReadOutMapping *pactCabling)
void init(const RPCAMCLinkMap &es)