CMS 3D CMS Logo

SiPixelFedCablingMap.cc
Go to the documentation of this file.
4 
5 #include <vector>
6 #include <iostream>
7 #include <algorithm>
8 #include <iostream>
9 
10 using namespace sipixelobjects;
11 
13 
14  // OLD Method
15  //for (auto & v : theMap) v.second.initFrameConversion();
16  // below is the new code, works for phase0 and phase1
17 
18  // Decide if it is phase0 or phase1 based on the first fed, 0-phase0, 1200-phase1
19  unsigned int fedId = (theMap.begin())->first.fed; // get the first fed
20 
21  // Specifically for CMSSW_9_0_X, we need to call a different version of the frame
22  // conversion steered by the version name in the cabling map
23  if (theVersion.find("CMSSW_9_0_X")!=std::string::npos) {
24  for (auto & v : theMap) v.second.initFrameConversionPhase1_CMSSW_9_0_X(); // works
25  std::cout<<"*** Found CMSSW_9_0_X specific cabling map\n";
26  return;
27  }
28 
29  if(fedId>=FEDNumbering::MINSiPixeluTCAFEDID) { // phase1 >= 1200
30  for (auto & v : theMap) v.second.initFrameConversionPhase1(); // works
31  } else { // phase0
32  for (auto & v : theMap) v.second.initFrameConversion(); // works
33  }
34 
35  // if(0) { // for testing
36  // for (Map::iterator im = theMap.begin(); im != theMap.end(); im++) {
37  // unsigned int fedId = im->first.fed;
38  // unsigned int linkId = im->first.link;
39  // unsigned int rocId = im->first.roc;
40  // auto rawDetID = im->second.rawId();
41  // auto idInDetUnit = im->second.idInDetUnit();
42  // auto idInLink = im->second.idInLink();
43  // //auto v = *im;
44  // if(fedId>=1200) {
45  // //v.second.initFrameConversionPhase1(); //
46  // im->second.initFrameConversionPhase1(); //
47  // } else {
48  // im->second.initFrameConversion();
49  // }
50  // } //
51  // } // end if(0)
52 
53 }
54 
55 
57 {
58  if (fed < other.fed) return true;
59  if (fed > other.fed) return false;
60 
61  if (link < other.link) return true;
62  if (link > other.link) return false;
63 
64  if (roc < other.roc) return true;
65  if (roc > other.roc) return false;
66 
67  return false;
68 }
69 
71  : theVersion(cab->version())
72 {
73 
74  // Never called
75  std::vector<const PixelFEDCabling *> fedList = cab->fedList();
76  for (std::vector<const PixelFEDCabling *>::const_iterator ifed=fedList.begin();
77  ifed != fedList.end(); ifed++) {
78  unsigned int fed = (**ifed).id();
79  unsigned int numLink = (**ifed).numberOfLinks();
80  for (unsigned int link=1; link <= numLink; link++) {
81  const PixelFEDLink * pLink = (**ifed).link(link);
82  if (pLink==nullptr) continue;
83  //unsigned int linkId = pLink->id();
84  //if (linkId != 0 && linkId!= link)
85  // std::cout << "PROBLEM WITH LINK NUMBER!!!!" << std::endl;
86  unsigned int numberROC = pLink->numberOfROCs();
87 
88  for (unsigned int roc=1; roc <= numberROC; roc++) {
89  const PixelROC * pROC = pLink->roc(roc);
90  if (pROC==nullptr) continue;
91  //if (pROC->idInLink() != roc)
92  // std::cout << "PROBLEM WITH ROC NUMBER!!!!" << std::endl;
93  Key key = {fed, link, roc};
94  theMap[key] = (*pROC);
95  }
96  }
97  } // fed loop
98 
99 }
100 
101 std::unique_ptr<SiPixelFedCablingTree> SiPixelFedCablingMap::cablingTree() const {
102 
103  std::unique_ptr<SiPixelFedCablingTree> tree(new SiPixelFedCablingTree(theVersion));
104  for (Map::const_iterator im = theMap.begin(); im != theMap.end(); im++) {
105  const sipixelobjects::PixelROC & roc = im->second;
106  unsigned int fedId = im->first.fed;
107  unsigned int linkId = im->first.link;
108  tree->addItem(fedId, linkId, roc);
109  }
110  return tree;
111 }
112 
113 std::vector<unsigned int> SiPixelFedCablingMap::fedIds() const {
114  std::vector<unsigned int> result;
115  for (Map::const_iterator im = theMap.begin(); im != theMap.end(); im++) {
116  unsigned int fedId = im->first.fed;
117  if (find(result.begin(),result.end(),fedId) == result.end()) result.push_back(fedId);
118  }
119  return result;
120 }
121 
124  const PixelROC* roc = nullptr;
125  Key key = {path.fed, path.link, path.roc};
126  Map::const_iterator inMap = theMap.find(key);
127  if (inMap!= theMap.end()) roc = &(inMap->second);
128  return roc;
129 }
130 
131 
132 std::unordered_map<uint32_t, unsigned int> SiPixelFedCablingMap::det2fedMap() const {
133  std::unordered_map<uint32_t, unsigned int> result;
134  for (auto im = theMap.begin(); im != theMap.end(); ++im) {
135  result[im->second.rawId()] = im->first.fed; // we know: a det is in only one fed!
136  }
137  return result;
138 }
139 
140 std::map< uint32_t,std::vector<sipixelobjects::CablingPathToDetUnit> > SiPixelFedCablingMap::det2PathMap() const {
141  std::map< uint32_t,std::vector<sipixelobjects::CablingPathToDetUnit> > result;
142  for (auto im = theMap.begin(); im != theMap.end(); ++im) {
143  CablingPathToDetUnit path = {im->first.fed, im->first.link, im->first.roc};
144  result[im->second.rawId()].push_back(path);
145  }
146  return result;
147 }
148 
149 
150 std::vector<sipixelobjects::CablingPathToDetUnit> SiPixelFedCablingMap::pathToDetUnit(
151  uint32_t rawDetId) const {
152 
153  std::vector<sipixelobjects::CablingPathToDetUnit> result;
154  for (auto im = theMap.begin(); im != theMap.end(); ++im) {
155  if(im->second.rawId()==rawDetId ) {
156  CablingPathToDetUnit path = {im->first.fed, im->first.link, im->first.roc};
157  result.push_back(path);
158  }
159  }
160  return result;
161 }
162 
SiPixelFedCablingMap(const SiPixelFedCablingTree *cab)
bool operator<(const Key &other) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::map< uint32_t, std::vector< sipixelobjects::CablingPathToDetUnit > > det2PathMap() const override
std::unordered_map< uint32_t, unsigned int > det2fedMap() const override
std::vector< unsigned int > const fedList
Definition: Constants.h:87
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
if(dp >Float(M_PI)) dp-
std::vector< unsigned int > fedIds() const
std::vector< sipixelobjects::CablingPathToDetUnit > pathToDetUnit(uint32_t rawDetId) const override
const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &path) const override
std::vector< const PixelFEDCabling * > fedList() const