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 std::unordered_map<uint32_t, unsigned int> SiPixelFedCablingTree::det2fedMap() const {
34  std::unordered_map<uint32_t, unsigned int> result;
35  for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
36  auto const & aFed = im->second;
37  for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
38  auto link = aFed.link(idxLink);
39  if (!link) continue;
40  unsigned int numberOfRocs = link->numberOfROCs();
41  for(unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
42  auto roc = link->roc(idxRoc);
43  result[roc->rawId()]=aFed.id(); // we know that a det is in one fed only...
44  }
45  }
46  }
47  return result;
48 }
49 
50 std::map< uint32_t,std::vector<sipixelobjects::CablingPathToDetUnit> > SiPixelFedCablingTree::det2PathMap() const {
51  std::map< uint32_t,std::vector<sipixelobjects::CablingPathToDetUnit> > result;
52  for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
53  auto const & aFed = im->second;
54  for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
55  auto link = aFed.link(idxLink);
56  if (!link) continue;
57  unsigned int numberOfRocs = link->numberOfROCs();
58  for(unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
59  auto roc = link->roc(idxRoc);
60  CablingPathToDetUnit path = {aFed.id(), link->id(), roc->idInLink()};
61  result[roc->rawId()].push_back(path);
62  }
63  }
64  }
65  return result;
66 }
67 
69 {
70  int id = f.id();
71  theFedCablings[id] = f;
72 }
73 
74 const PixelFEDCabling * SiPixelFedCablingTree::fed(unsigned int id) const
75 {
76  auto it = theFedCablings.find(id);
77  return ( it == theFedCablings.end() ) ? 0 : & (*it).second;
78 }
79 
81 {
82  ostringstream out;
83  if ( depth-- >=0 ) {
84  out << theVersion << endl;
85  for(IMAP it=theFedCablings.begin(); it != theFedCablings.end(); it++) {
86  out << (*it).second.print(depth);
87  }
88  }
89  out << endl;
90  return out.str();
91 }
92 
93 std::vector<const PixelFEDCabling *> SiPixelFedCablingTree::fedList() const
94 {
95  std::vector<const PixelFEDCabling *> result;
96  for (IMAP im = theFedCablings.begin(); im != theFedCablings.end(); im++) {
97  result.push_back( &(im->second) );
98  }
99  std::sort(result.begin(),result.end(),[](const PixelFEDCabling * a,const PixelFEDCabling * b){return a->id()<b->id();});
100  return result;
101 
102 }
103 
104 void SiPixelFedCablingTree::addItem(unsigned int fedId, unsigned int linkId, const PixelROC& roc)
105 {
106  PixelFEDCabling & cabling = theFedCablings[fedId];
107  if (cabling.id() != fedId) cabling=PixelFEDCabling(fedId);
108  cabling.addItem(linkId,roc);
109 }
110 
112  const CablingPathToDetUnit & path) const
113 {
114  const PixelROC* roc = 0;
115  const PixelFEDCabling * aFed = fed(path.fed);
116  if (aFed) {
117  const PixelFEDLink * aLink = aFed->link(path.link);
118  if (aLink) roc = aLink->roc(path.roc);
119  }
120  return roc;
121 }
122 
123 
125  const CablingPathToDetUnit & path,
126  const PixelFEDCabling * aFed) const
127 {
128  const PixelROC* roc = 0;
129  const PixelFEDLink * aLink = aFed->link(path.link);
130  if (aLink) roc = aLink->roc(path.roc);
131  return roc;
132 }
133 
134 
136 {
137  int status = 0;
138  for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
139  if (im->first != static_cast<int>( im->second.id())) {
140  status = 1;
141  std::cout << "PROBLEM WITH FED ID!!" << im->first <<" vs: "<< im->second.id() << std::endl;
142  }
143  im->second.checkLinkNumbering();
144  }
145  return status;
146 }
unsigned int numberOfLinks() const
number of links in FED
std::map< uint32_t, std::vector< sipixelobjects::CablingPathToDetUnit > > det2PathMap() const override
unsigned int idInLink() const
id of this ROC in parent Link.
Definition: PixelROC.h:43
void addItem(unsigned int linkId, const PixelROC &roc)
std::unordered_map< uint32_t, unsigned int > det2fedMap() const override
virtual std::vector< sipixelobjects::CablingPathToDetUnit > pathToDetUnit(uint32_t rawDetId) const
uint32_t rawId() const
return the DetUnit to which this ROC belongs to.
Definition: PixelROC.h:37
double f[11][100]
virtual const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &path) const
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
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