CMS 3D CMS Logo

SiStripDelay.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripObjects
4 // Class : SiStripDelay
5 // Implementation:
6 // <Notes on implementation>
7 // Original Author: M. De Mattia
8 // Created: 26/10/2010
9 
14 #include <cassert>
15 #include <sstream>
16 
18  const int sumSign,
19  const std::pair<std::string, std::string> &recordLabelPair) {
20  baseDelayVector_.push_back(&baseDelay);
21  sumSignVector_.push_back(sumSign);
22  recordLabelPair_.push_back(recordLabelPair);
23 }
24 
25 float SiStripDelay::getDelay(const uint32_t detId) const {
26  std::unordered_map<uint32_t, double>::const_iterator it = delays_.find(detId);
27  if (it != delays_.end()) {
28  return it->second;
29  }
30  return 0.;
31 }
32 
34  if (baseDelayVector_.empty()) {
35  return false;
36  }
37  std::vector<const SiStripBaseDelay *>::const_iterator it = baseDelayVector_.begin();
38  // Check for consistent size in all baseDelays
39  if (baseDelayVector_.size() > 1) {
40  for (; it != baseDelayVector_.end() - 1; ++it) {
41  if ((*it)->delaysSize() != (*(it + 1))->delaysSize()) {
42  std::cout << "makeDelay: Error, size of base delays is different!!" << std::endl;
43  return false;
44  }
45  }
46  }
47 
48  // // All checks done, fill the boost::unoredered_map with the first one
49  // (initialization) int sumSignIndex = 0; int sumSign = 0;
50  // std::vector<uint32_t>::const_iterator detIdIt;
51  // for( it = baseDelayVector_.begin(); it != baseDelayVector_.end(); ++it,
52  // ++sumSignIndex ) {
53  // std::vector<uint32_t> detIds;
54  // (*it)->detIds(detIds);
55  // sumSign = sumSignVector_[sumSignIndex];
56  // for( detIdIt = detIds.begin(); detIdIt != detIds.end(); ++detIdIt ) {
57  // // Check if is alread there so that we never rely on the default
58  // initialization boost::unordered_map<uint32_t, double>::iterator
59  // delayIt = delays_.find(*detIdIt); if( delayIt != delays_.end() ) {
60  // std::cout << "second delay = " << (*it)->delay(*detIdIt)*sumSign <<
61  // std::endl; delays_[*detIdIt] += (*it)->delay(*detIdIt)*sumSign;
62  // std::cout
63  // << "Full delay = " << delays_[*detIdIt] << std::endl;
64  // }
65  // else {
66  // std::cout << "first delay = " << (*it)->delay(*detIdIt)*sumSign <<
67  // std::endl; delays_[*detIdIt] = (*it)->delay(*detIdIt)*sumSign;
68  // }
69  // }
70  // }
71 
72  // All checks done, fill the boost::unoredered_map with the first one
73  // (initialization)
74  int sumSignIndex = 0;
75  int sumSign = sumSignVector_[sumSignIndex];
76  it = baseDelayVector_.begin();
77  std::vector<uint32_t> detIds;
78  (*it)->detIds(detIds);
79  std::vector<uint32_t>::const_iterator detIdIt = detIds.begin();
80  for (; detIdIt != detIds.end(); ++detIdIt) {
81  delays_[*detIdIt] = (*it)->delay(*detIdIt) * sumSign;
82  }
83  ++it;
84  ++sumSignIndex;
85  // Fill all the others
86  for (; it != baseDelayVector_.end(); ++it, ++sumSignIndex) {
87  std::vector<uint32_t> detIds;
88  (*it)->detIds(detIds);
89  detIdIt = detIds.begin();
90  sumSign = sumSignVector_[sumSignIndex];
91  for (; detIdIt != detIds.end(); ++detIdIt) {
92  // The same detIds should be in both maps, if not don't rely on the
93  // default initialization
94  std::unordered_map<uint32_t, double>::iterator delayIt = delays_.find(*detIdIt);
95  if (delayIt != delays_.end()) {
96  delays_[*detIdIt] += (*it)->delay(*detIdIt) * sumSign;
97  } else {
98  std::cout << "makeDelay: Warning, detId = " << *detIdIt << " not present, summing to 0..." << std::endl;
99  std::cout << "This means that the two baseDelay tags have different "
100  "detIds. PLEASE, CHECK THAT THIS IS EXPECTED."
101  << std::endl;
102  delays_[*detIdIt] = (*it)->delay(*detIdIt) * sumSign;
103  }
104  }
105  }
106 
107  return true;
108 }
109 
111  baseDelayVector_.clear();
112  sumSignVector_.clear();
113  recordLabelPair_.clear();
114  delays_.clear();
115 }
116 
117 void SiStripDelay::printDebug(std::stringstream &ss, const TrackerTopology * /*trackerTopo*/) const {
118  std::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
119  for (; it != delays_.end(); ++it) {
120  ss << "detId = " << it->first << " delay = " << it->second << std::endl;
121  }
122 }
123 
124 void SiStripDelay::printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const {
125  SiStripDetSummary summaryDelays{trackerTopo};
126  std::unordered_map<uint32_t, double>::const_iterator it = delays_.begin();
127  for (; it != delays_.end(); ++it) {
128  summaryDelays.add(it->first, it->second);
129  }
130  summaryDelays.print(ss);
131 }
void fillNewDelay(const SiStripBaseDelay &baseDelay, const int sumSign, const std::pair< std::string, std::string > &recordLabelPair)
Definition: SiStripDelay.cc:17
std::vector< std::pair< std::string, std::string > > recordLabelPair_
Definition: SiStripDelay.h:84
std::vector< const SiStripBaseDelay * > baseDelayVector_
Definition: SiStripDelay.h:82
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
void printDebug(std::stringstream &ss, const TrackerTopology *tTopo) const
Prints the delays for all the detIds.
bool makeDelay()
Builds the boost::unordered_map.
Definition: SiStripDelay.cc:33
void clear()
Empty all the containers.
std::vector< int > sumSignVector_
Definition: SiStripDelay.h:83
float getDelay(const uint32_t detId) const
Return the delay combining all the baseDelays.
Definition: SiStripDelay.cc:25
std::unordered_map< uint32_t, double > delays_
Definition: SiStripDelay.h:85