CMS 3D CMS Logo

SiPixelFedCablingTree.cc
Go to the documentation of this file.
2 #include <algorithm>
3 #include <sstream>
4 #include <iostream>
5 
6 using namespace std;
7 using namespace sipixelobjects;
8 
9 typedef std::unordered_map<int, SiPixelFedCablingTree::PixelFEDCabling>::const_iterator IMAP;
10 
11 std::vector<sipixelobjects::CablingPathToDetUnit> SiPixelFedCablingTree::pathToDetUnit(
12  uint32_t rawDetId) const
13 {
14  std::vector<sipixelobjects::CablingPathToDetUnit> result;
15  for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
16  const PixelFEDCabling & aFed = im->second;
17  for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
18  const PixelFEDLink * link = aFed.link(idxLink);
19  if (!link) continue;
20  unsigned int numberOfRocs = link->numberOfROCs();
21  for(unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
22  const PixelROC * roc = link->roc(idxRoc);
23  if (rawDetId == roc->rawId() ) {
24  CablingPathToDetUnit path = {aFed.id(), link->id(), roc->idInLink()};
25  result.push_back(path);
26  }
27  }
28  }
29  }
30  return result;
31 }
32 
33 bool SiPixelFedCablingTree::pathToDetUnitHasDetUnit(uint32_t rawDetId, unsigned int fedId) const {
34  for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
35  const PixelFEDCabling & aFed = im->second;
36  if(aFed.id() == fedId) {
37  for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
38  const PixelFEDLink * link = aFed.link(idxLink);
39  if (!link) continue;
40  unsigned int numberOfRocs = link->numberOfROCs();
41  for(unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
42  const PixelROC * roc = link->roc(idxRoc);
43  if (rawDetId == roc->rawId() ) {
44  return true;
45  }
46  }
47  }
48  }
49  }
50  return false;
51 }
52 
53 std::unordered_map<uint32_t, unsigned int> SiPixelFedCablingTree::det2fedMap() const {
54  std::unordered_map<uint32_t, unsigned int> result;
55  for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
56  auto const & aFed = im->second;
57  for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
58  auto link = aFed.link(idxLink);
59  if (!link) continue;
60  unsigned int numberOfRocs = link->numberOfROCs();
61  for(unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
62  auto roc = link->roc(idxRoc);
63  result[roc->rawId()]=aFed.id(); // we know that a det is in one fed only...
64  }
65  }
66  }
67  return result;
68 }
69 
70 std::map< uint32_t,std::vector<sipixelobjects::CablingPathToDetUnit> > SiPixelFedCablingTree::det2PathMap() const {
71  std::map< uint32_t,std::vector<sipixelobjects::CablingPathToDetUnit> > result;
72  for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
73  auto const & aFed = im->second;
74  for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
75  auto link = aFed.link(idxLink);
76  if (!link) continue;
77  unsigned int numberOfRocs = link->numberOfROCs();
78  for(unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
79  auto roc = link->roc(idxRoc);
80  CablingPathToDetUnit path = {aFed.id(), link->id(), roc->idInLink()};
81  result[roc->rawId()].push_back(path);
82  }
83  }
84  }
85  return result;
86 }
87 
89 {
90  int id = f.id();
91  theFedCablings[id] = f;
92 }
93 
94 const PixelFEDCabling * SiPixelFedCablingTree::fed(unsigned int id) const
95 {
96  auto it = theFedCablings.find(id);
97  return ( it == theFedCablings.end() ) ? nullptr : & (*it).second;
98 }
99 
101 {
102  ostringstream out;
103  if ( depth-- >=0 ) {
104  out << theVersion << endl;
105  for(IMAP it=theFedCablings.begin(); it != theFedCablings.end(); it++) {
106  out << (*it).second.print(depth);
107  }
108  }
109  out << endl;
110  return out.str();
111 }
112 
113 std::vector<const PixelFEDCabling *> SiPixelFedCablingTree::fedList() const
114 {
115  std::vector<const PixelFEDCabling *> result;
116  for (IMAP im = theFedCablings.begin(); im != theFedCablings.end(); im++) {
117  result.push_back( &(im->second) );
118  }
119  std::sort(result.begin(),result.end(),[](const PixelFEDCabling * a,const PixelFEDCabling * b){return a->id()<b->id();});
120  return result;
121 
122 }
123 
124 void SiPixelFedCablingTree::addItem(unsigned int fedId, unsigned int linkId, const PixelROC& roc)
125 {
126  PixelFEDCabling & cabling = theFedCablings[fedId];
127  if (cabling.id() != fedId) cabling=PixelFEDCabling(fedId);
128  cabling.addItem(linkId,roc);
129 }
130 
132  const CablingPathToDetUnit & path) const
133 {
134  const PixelROC* roc = nullptr;
135  const PixelFEDCabling * aFed = fed(path.fed);
136  if (aFed) {
137  const PixelFEDLink * aLink = aFed->link(path.link);
138  if (aLink) roc = aLink->roc(path.roc);
139  }
140  return roc;
141 }
142 
143 
145  const CablingPathToDetUnit & path,
146  const PixelFEDCabling * aFed) const
147 {
148  const PixelROC* roc = nullptr;
149  const PixelFEDLink * aLink = aFed->link(path.link);
150  if (aLink) roc = aLink->roc(path.roc);
151  return roc;
152 }
153 
154 
156 {
157  int status = 0;
158  for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
159  if (im->first != static_cast<int>( im->second.id())) {
160  status = 1;
161  std::cout << "PROBLEM WITH FED ID!!" << im->first <<" vs: "<< im->second.id() << std::endl;
162  }
163  im->second.checkLinkNumbering();
164  }
165  return status;
166 }
std::vector< sipixelobjects::CablingPathToDetUnit > pathToDetUnit(uint32_t rawDetId) const final
unsigned int numberOfLinks() const
number of links in FED
unsigned int idInLink() const
id of this ROC in parent Link.
Definition: PixelROC.h:43
void addItem(unsigned int linkId, const PixelROC &roc)
std::map< uint32_t, std::vector< sipixelobjects::CablingPathToDetUnit > > det2PathMap() const final
uint32_t rawId() const
return the DetUnit to which this ROC belongs to.
Definition: PixelROC.h:37
double f[11][100]
std::unordered_map< int, SiPixelFedCablingTree::PixelFEDCabling >::const_iterator IMAP
double b
Definition: hdecay.h:120
const PixelFEDCabling * fed(unsigned int idFed) const
get fed identified by its id
const PixelFEDLink * link(unsigned int id) const
return link identified by id. Link id&#39;s are ranged [1, numberOfLinks]
double a
Definition: hdecay.h:121
void addFed(const PixelFEDCabling &f)
add cabling for one fed
const sipixelobjects::PixelROC * findItemInFed(const sipixelobjects::CablingPathToDetUnit &path, const PixelFEDCabling *aFed) const
bool pathToDetUnitHasDetUnit(uint32_t rawDetId, unsigned int fedId) const final
std::unordered_map< uint32_t, unsigned int > det2fedMap() const final
void addItem(unsigned int fedId, unsigned int linkId, const sipixelobjects::PixelROC &roc)
std::vector< const PixelFEDCabling * > fedList() const
std::string print(int depth=0) const
const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &path) const final