CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 }
23  return (a->getCh().first==b->getCh().first);
24 }
25 
26 // by detid
28  return a->getDetid() < b->getDetid();
29 }
31  return a->getDetid() < b;
32 }
33 
34 // by gbtid
36  return a->getGbtid() < b->getGbtid();
37 }
39  return a->getGbtid() < b;
40 }
41 
42 // by cooling loop
44  return a.getCoolingLoop() < b.getCoolingLoop(); }
46  return a.getCoolingLoop() < b; }
48  return (a.getCoolingLoop()==b.getCoolingLoop());
49 }
50 
51 // by power group
53  return a.getPowerGroup() < b.getPowerGroup(); }
55  return a.getPowerGroup() < b; }
57  return (a.getPowerGroup()==b.getPowerGroup());
58 }
59 
60 // Phase2TrackerCabling methods
61 
62 Phase2TrackerCabling::Phase2TrackerCabling( const std::vector<Phase2TrackerModule>& cons ):connections_(cons) {
63  // initialize the cabling (fill the transient objects and sort.
65 }
66 
72 }
73 
75  // fill the cabling objects
76  fedCabling_.reserve(connections_.size());
77  detCabling_.reserve(connections_.size());
78  gbtCabling_.reserve(connections_.size());
79  for(key module = connections_.begin();module<connections_.end();++module) {
80  fedCabling_.push_back(module);
81  detCabling_.push_back(module);
82  gbtCabling_.push_back(module);
83  }
84  // sort the cabling objects
88 }
89 
90 const Phase2TrackerModule& Phase2TrackerCabling::findFedCh(std::pair<unsigned int, unsigned int> fedch) const {
91  // look for ch
92  cabling::const_iterator itid = std::lower_bound(fedCabling_.begin(), fedCabling_.end(), fedch, chComp);
93  if (itid != fedCabling_.end() && (*itid)->getCh()==fedch)
94  return **itid;
95  else
96  throw cms::Exception("IndexNotFound") << "No connection corresponding to FED id/ch = " << fedch.first << "/" << fedch.second;
97 }
98 
100  // look for id
101  cabling::const_iterator itch = std::lower_bound (detCabling_.begin(), detCabling_.end(), detid, detidComp);
102  if (itch != detCabling_.end() && (*itch)->getDetid()==detid)
103  return **itch;
104  else
105  throw cms::Exception("IndexNotFound") << "No connection corresponding to detid = 0x" << std::hex << detid << std::dec;
106 }
107 
109  // look for id
110  cabling::const_iterator itch = std::lower_bound (gbtCabling_.begin(), gbtCabling_.end(), gbtid, gbtidComp);
111  if (itch != gbtCabling_.end() && (*itch)->getGbtid()==gbtid)
112  return **itch;
113  else
114  throw cms::Exception("IndexNotFound") << "No connection corresponding to gbtid = 0x" << std::hex << gbtid << std::dec;
115 }
116 
118  // NB: this approach involves two copies of the connections. Can we do better?
119  // since this is a relatively rare operation, I don't want to pre-sort the connections.
120 
121  // make a copy of the store
122  store resultStore = connections_;
123  // sort according to cooling
124  std::sort(resultStore.begin(),resultStore.end(),coolingOrdering);
125  // search for the proper range
126  std::pair< key, key > range = std::equal_range(resultStore.begin(),resultStore.end(),
128  // create a new cabling object
129  Phase2TrackerCabling result(store(range.first,range.second));
130  // return the new cabling object
131  return result;
132 }
133 
135  // NB: this approach involves two copies of the connections. Can we do better?
136  // since this is a relatively rare operation, I don't want to pre-sort the connections.
137 
138  // make a copy of the store
139  store resultStore = connections_;
140  // sort according to power groups
141  std::sort(resultStore.begin(),resultStore.end(),powerOrdering);
142  // search for the proper range
143  std::pair< key, key > range = std::equal_range(resultStore.begin(),resultStore.end(),
145  // create a new cabling object
146  Phase2TrackerCabling result(store(range.first,range.second));
147  // return the new cabling object
148  return result;
149 }
150 
152  std::string mystring("Summary of the cabling\n======================\n");
153  std::stringstream ss;
154  // number of modules, feds, cooling loop and power groups
155  ss << "Number of modules: " << connections_.size() << std::endl;
156  store orig(connections_);
157  ss << "Number of FEDs: ";
158  cabling tmpc(fedCabling_);
159  ss << std::distance(tmpc.begin(),std::unique(tmpc.begin(),tmpc.end(),fedeq)) << std::endl;
160  ss << "Number of cooling loops: ";
161  std::sort(orig.begin(),orig.end(),coolingOrdering);
162  store tmp(orig);
163  ss << std::distance(tmp.begin(),std::unique(tmp.begin(),tmp.end(),cooleq)) << std::endl;
164  ss << "Number of power groups: ";
165  std::sort(orig.begin(),orig.end(),powerOrdering);
166  tmp = orig;
167  ss << std::distance(tmp.begin(),std::unique(tmp.begin(),tmp.end(),poweq)) << std::endl;
168  mystring += ss.str();
169  return mystring;
170 }
171 
173  std::string mystring("Cabling:\n========\n");
174  for(std::vector<Phase2TrackerModule>::const_iterator it = connections_.begin();it<connections_.end();++it) {
175  mystring += it->description(compact);
176  }
177  return mystring;
178 }
179 
static bool powerOrdering(const Phase2TrackerModule &a, const Phase2TrackerModule &b)
Phase2TrackerCabling filterByCoolingLine(uint32_t coolingLine) const
Phase2TrackerCabling filterByPowerGroup(uint32_t powerGroup) const
const Phase2TrackerModule & findFedCh(std::pair< unsigned int, unsigned int > fedch) 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)
uint32_t getPowerGroup() const
uint32_t getCoolingLoop() const
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)
std::vector< Phase2TrackerModule >::const_iterator key
static bool detidOrdering(key a, key b)
tuple result
Definition: query.py:137
std::string summaryDescription() const
std::string description(bool compact=false) const
static bool detidComp(key a, uint32_t b)
double b
Definition: hdecay.h:120
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
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)
const Phase2TrackerModule & findDetid(uint32_t detid) const
std::vector< Phase2TrackerModule > store
Definition: vlib.h:208
const Phase2TrackerModule & findGbtid(uint32_t gbtid) const
std::vector< key > cabling