CMS 3D CMS Logo

Phase2TrackerCabling.cc
Go to the documentation of this file.
5 #include <sstream>
6 
7 // These functions are used to sort and search the cabling objects
8 
9 // by FED id/ch
11  if (a->getCh().first == b->getCh().first)
12  return a->getCh().second < b->getCh().second;
13  else
14  return a->getCh().first < b->getCh().first;
15 }
16 bool Phase2TrackerCabling::chComp(Phase2TrackerCabling::key a, std::pair<unsigned int, unsigned int> b) {
17  if (a->getCh().first == b.first)
18  return a->getCh().second < b.second;
19  else
20  return a->getCh().first < b.first;
21 }
22 bool Phase2TrackerCabling::fedeq(key a, key b) { return (a->getCh().first == b->getCh().first); }
23 
24 // by detid
26  return a->getDetid() < b->getDetid();
27 }
28 bool Phase2TrackerCabling::detidComp(Phase2TrackerCabling::key a, uint32_t b) { return a->getDetid() < b; }
29 
30 // by gbtid
32  return a->getGbtid() < b->getGbtid();
33 }
34 bool Phase2TrackerCabling::gbtidComp(Phase2TrackerCabling::key a, uint32_t b) { return a->getGbtid() < b; }
35 
36 // by cooling loop
38  return a.getCoolingLoop() < b.getCoolingLoop();
39 }
40 bool Phase2TrackerCabling::coolingComp(const Phase2TrackerModule& a, uint32_t b) { return a.getCoolingLoop() < b; }
42  return (a.getCoolingLoop() == b.getCoolingLoop());
43 }
44 
45 // by power group
47  return a.getPowerGroup() < b.getPowerGroup();
48 }
49 bool Phase2TrackerCabling::powerComp(const Phase2TrackerModule& a, uint32_t b) { return a.getPowerGroup() < b; }
51  return (a.getPowerGroup() == b.getPowerGroup());
52 }
53 
54 // Phase2TrackerCabling methods
55 
56 Phase2TrackerCabling::Phase2TrackerCabling(const std::vector<Phase2TrackerModule>& cons) : connections_(cons) {
57  // initialize the cabling (fill the transient objects and sort.
59 }
60 
62  connections_ = src.connections_;
63  fedCabling_ = src.fedCabling_;
64  detCabling_ = src.detCabling_;
65  gbtCabling_ = src.gbtCabling_;
66 }
67 
69  // fill the cabling objects
70  fedCabling_.reserve(connections_.size());
71  detCabling_.reserve(connections_.size());
72  gbtCabling_.reserve(connections_.size());
73  for (key module = connections_.begin(); module < connections_.end(); ++module) {
74  fedCabling_.push_back(module);
75  detCabling_.push_back(module);
76  gbtCabling_.push_back(module);
77  }
78  // sort the cabling objects
82 }
83 
84 const Phase2TrackerModule& Phase2TrackerCabling::findFedCh(std::pair<unsigned int, unsigned int> fedch) const {
85  // look for ch
86  cabling::const_iterator itid = std::lower_bound(fedCabling_.begin(), fedCabling_.end(), fedch, chComp);
87  if (itid != fedCabling_.end() && (*itid)->getCh() == fedch)
88  return **itid;
89  else
90  throw cms::Exception("IndexNotFound")
91  << "No connection corresponding to FED id/ch = " << fedch.first << "/" << fedch.second;
92 }
93 
95  // look for id
96  cabling::const_iterator itch = std::lower_bound(detCabling_.begin(), detCabling_.end(), detid, detidComp);
97  if (itch != detCabling_.end() && (*itch)->getDetid() == detid)
98  return **itch;
99  else
100  throw cms::Exception("IndexNotFound")
101  << "No connection corresponding to detid = 0x" << std::hex << detid << std::dec;
102 }
103 
105  // look for id
106  cabling::const_iterator itch = std::lower_bound(gbtCabling_.begin(), gbtCabling_.end(), gbtid, gbtidComp);
107  if (itch != gbtCabling_.end() && (*itch)->getGbtid() == gbtid)
108  return **itch;
109  else
110  throw cms::Exception("IndexNotFound")
111  << "No connection corresponding to gbtid = 0x" << std::hex << gbtid << std::dec;
112 }
113 
115  // NB: this approach involves two copies of the connections. Can we do better?
116  // since this is a relatively rare operation, I don't want to pre-sort the connections.
117 
118  // make a copy of the store
119  store resultStore = connections_;
120  // sort according to cooling
121  std::sort(resultStore.begin(), resultStore.end(), coolingOrdering);
122  // search for the proper range
123  std::pair<key, key> range = std::equal_range(resultStore.begin(),
124  resultStore.end(),
125  Phase2TrackerModule(Phase2TrackerModule::SS, 0, 0, 0, 0, 0, coolingLine),
127  // create a new cabling object
128  Phase2TrackerCabling result(store(range.first, range.second));
129  // return the new cabling object
130  return result;
131 }
132 
134  // NB: this approach involves two copies of the connections. Can we do better?
135  // since this is a relatively rare operation, I don't want to pre-sort the connections.
136 
137  // make a copy of the store
138  store resultStore = connections_;
139  // sort according to power groups
140  std::sort(resultStore.begin(), resultStore.end(), powerOrdering);
141  // search for the proper range
142  std::pair<key, key> range = std::equal_range(resultStore.begin(),
143  resultStore.end(),
144  Phase2TrackerModule(Phase2TrackerModule::SS, 0, 0, 0, 0, powerGroup, 0),
145  powerOrdering);
146  // create a new cabling object
147  Phase2TrackerCabling result(store(range.first, range.second));
148  // return the new cabling object
149  return result;
150 }
151 
153  std::string mystring("Summary of the cabling\n======================\n");
154  std::stringstream ss;
155  // number of modules, feds, cooling loop and power groups
156  ss << "Number of modules: " << connections_.size() << std::endl;
157  store orig(connections_);
158  ss << "Number of FEDs: ";
159  cabling tmpc(fedCabling_);
160  ss << std::distance(tmpc.begin(), std::unique(tmpc.begin(), tmpc.end(), fedeq)) << std::endl;
161  ss << "Number of cooling loops: ";
162  std::sort(orig.begin(), orig.end(), coolingOrdering);
163  store tmp(orig);
164  ss << std::distance(tmp.begin(), std::unique(tmp.begin(), tmp.end(), cooleq)) << std::endl;
165  ss << "Number of power groups: ";
166  std::sort(orig.begin(), orig.end(), powerOrdering);
167  tmp = orig;
168  ss << std::distance(tmp.begin(), std::unique(tmp.begin(), tmp.end(), poweq)) << std::endl;
169  mystring += ss.str();
170  return mystring;
171 }
172 
174  std::string mystring("Cabling:\n========\n");
175  for (std::vector<Phase2TrackerModule>::const_iterator it = connections_.begin(); it < connections_.end(); ++it) {
176  mystring += it->description(compact);
177  }
178  return mystring;
179 }
static bool powerOrdering(const Phase2TrackerModule &a, const Phase2TrackerModule &b)
Phase2TrackerCabling filterByCoolingLine(uint32_t coolingLine) const
static bool gbtidOrdering(key a, key b)
static bool coolingOrdering(const Phase2TrackerModule &a, const Phase2TrackerModule &b)
static bool powerComp(const Phase2TrackerModule &a, uint32_t b)
static bool chOrdering(key a, key b)
static bool cooleq(const Phase2TrackerModule &a, const Phase2TrackerModule &b)
static bool coolingComp(const Phase2TrackerModule &a, uint32_t b)
static bool poweq(const Phase2TrackerModule &a, const Phase2TrackerModule &b)
Phase2TrackerCabling filterByPowerGroup(uint32_t powerGroup) const
const Phase2TrackerModule & findGbtid(uint32_t gbtid) const
std::vector< Phase2TrackerModule >::const_iterator key
static bool detidOrdering(key a, key b)
def unique(seq, keepstr=True)
Definition: tier0.py:24
const Phase2TrackerModule & findFedCh(std::pair< unsigned int, unsigned int > fedch) const
static bool detidComp(key a, uint32_t b)
double b
Definition: hdecay.h:120
const Phase2TrackerModule & findDetid(uint32_t detid) const
std::string summaryDescription() const
static bool chComp(key a, std::pair< unsigned int, unsigned int > b)
static bool fedeq(key a, key b)
double a
Definition: hdecay.h:121
static bool gbtidComp(key a, uint32_t b)
std::string description(bool compact=false) const
tmp
align.sh
Definition: createJobs.py:716
std::vector< Phase2TrackerModule > store
std::vector< key > cabling