CMS 3D CMS Logo

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