CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripSummary.cc
Go to the documentation of this file.
3 
4 #include <algorithm>
5 
6 SiStripSummary::SiStripSummary(std::vector<std::string>& userDBContent) {
7  userDBContent_ = userDBContent;
8  runNr_ = 0;
9  timeValue_ = 0;
10 }
11 
14  runNr_ = input.getTimeValue();
15  timeValue_ = input.getRunNr();
16  v_sum_.clear();
17  indexes_.clear();
18  v_sum_.insert(v_sum_.end(), input.v_sum_.begin(), input.v_sum_.end());
19  indexes_.insert(indexes_.end(), input.indexes_.begin(), input.indexes_.end());
20 }
21 
22 bool SiStripSummary::put(const uint32_t& DetId, InputVector& input, std::vector<std::string>& userContent) {
23  Registry::iterator p =
25 
26  if (p == indexes_.end() || p->detid != DetId) {
27  //First request for the given DetID
28  //Create entries for all the declared userDBContent
29  //and fill for the provided userContent
30 
31  DetRegistry detregistry;
32  detregistry.detid = DetId;
33  detregistry.ibegin = v_sum_.size();
34  indexes_.insert(p, detregistry);
35  InputVector tmp(userDBContent_.size(), -9999);
36 
37  for (size_t i = 0; i < userContent.size(); ++i)
38  tmp[getPosition(userContent[i])] = input[i];
39 
40  v_sum_.insert(v_sum_.end(), tmp.begin(), tmp.end());
41  } else {
42  if (p->detid == DetId) {
43  //I should already find the entries
44  //fill for the provided userContent
45 
46  for (size_t i = 0; i < userContent.size(); ++i)
47  v_sum_[p->ibegin + getPosition(userContent[i])] = input[i];
48  }
49  }
50 
51  return true;
52 }
53 
56  std::vector<std::string>& userContent) {
57  uint32_t fakeDet = region;
58  return put(fakeDet, input, userContent);
59 }
60 
63  if (p == indexes_.end() || p->detid != DetId) {
64  return SiStripSummary::Range(v_sum_.end(), v_sum_.end());
65  std::cout << "not in range " << std::endl;
66  } else
67  return SiStripSummary::Range(v_sum_.begin() + p->ibegin, v_sum_.begin() + p->ibegin + userDBContent_.size());
68 }
69 
70 std::vector<uint32_t> SiStripSummary::getDetIds() const {
71  // returns vector of DetIds in map
72  std::vector<uint32_t> DetIds_;
75  for (SiStripSummary::RegistryIterator p = begin; p != end; ++p) {
76  DetIds_.push_back(p->detid);
77  }
78  return DetIds_;
79 }
80 
81 const short SiStripSummary::getPosition(std::string elementName) const {
82  // returns position of elementName in UserDBContent_
83 
84  std::vector<std::string>::const_iterator it = find(userDBContent_.begin(), userDBContent_.end(), elementName);
85  short pos = -1;
86  if (it != userDBContent_.end())
87  pos = it - userDBContent_.begin();
88  else
89  edm::LogError("SiStripSummary") << "attempting to retrieve non existing historic DB object : " << elementName
90  << std::endl;
91  return pos;
92 }
93 
94 void SiStripSummary::setObj(const uint32_t& detID, std::string elementName, float value) {
95  // modifies value of info "elementName" for the given detID
96  // requires that an entry has be defined beforehand for detId in DB
98  if (p == indexes_.end() || p->detid != detID) {
99  throw cms::Exception("") << "not allowed to modify " << elementName
100  << " in historic DB - SummaryObj needs to be available first !";
101  }
102 
103  const SiStripSummary::Range range = getRange(detID);
104 
105  std::vector<float>::const_iterator it = range.first + getPosition(elementName);
106  std::vector<float>::difference_type pos = -1;
107  if (it != v_sum_.end()) {
108  pos = it - v_sum_.begin();
109  v_sum_.at(pos) = value;
110  }
111 }
112 
113 std::vector<float> SiStripSummary::getSummaryObj(uint32_t& detID, const std::vector<std::string>& list) const {
114  std::vector<float> SummaryObj;
115  const SiStripSummary::Range range = getRange(detID);
116  if (range.first != range.second) {
117  for (unsigned int i = 0; i < list.size(); i++) {
118  const short pos = getPosition(list.at(i));
119 
120  if (pos != -1)
121  SummaryObj.push_back(*((range.first) + pos));
122  else
123  SummaryObj.push_back(-999.);
124  }
125  } else
126  for (unsigned int i = 0; i < list.size(); i++)
127  SummaryObj.push_back(
128  -99.); // no summary obj has ever been inserted for this detid, most likely all related histos were not available in DQM
129 
130  return SummaryObj;
131 }
132 
134  const std::vector<std::string>& list) const {
135  uint32_t fakeDet = region;
136  return getSummaryObj(fakeDet, list);
137 }
138 
139 std::vector<float> SiStripSummary::getSummaryObj(uint32_t& detID) const {
140  std::vector<float> SummaryObj;
141  const SiStripSummary::Range range = getRange(detID);
142  if (range.first != range.second) {
143  for (unsigned int i = 0; i < userDBContent_.size(); i++)
144  SummaryObj.push_back(*((range.first) + i));
145  } else {
146  for (unsigned int i = 0; i < userDBContent_.size(); i++)
147  SummaryObj.push_back(-99.);
148  }
149  return SummaryObj;
150 }
151 
152 std::vector<float> SiStripSummary::getSummaryObj() const { return v_sum_; }
153 
154 std::vector<float> SiStripSummary::getSummaryObj(std::string elementName) const {
155  std::vector<float> vSumElement;
156  std::vector<uint32_t> DetIds_ = getDetIds();
157  const short pos = getPosition(elementName);
158 
159  if (pos != -1) {
160  for (unsigned int i = 0; i < DetIds_.size(); i++) {
161  const SiStripSummary::Range range = getRange(DetIds_.at(i));
162  if (range.first != range.second) {
163  vSumElement.push_back(*((range.first) + pos));
164  } else {
165  vSumElement.push_back(-99.);
166  }
167  }
168  }
169 
170  return vSumElement;
171 }
172 
174  std::cout << "Nr. of detector elements in SiStripSummary object is " << indexes_.size() << " RunNr= " << runNr_
175  << " timeValue= " << timeValue_ << std::endl;
176 }
std::vector< uint32_t > getDetIds() const
unsigned long long getTimeValue() const
const Range getRange(const uint32_t &detID) const
std::vector< DetRegistry > indexes_
Registry::const_iterator RegistryIterator
std::pair< ContainerIterator, ContainerIterator > Range
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
static std::string const input
Definition: EdmProvDump.cc:47
const uint16_t range(const Frame &aFrame)
std::vector< float > v_sum_
void setObj(const uint32_t &detID, std::string elementName, float value)
unsigned long long timeValue_
std::vector< float > InputVector
Definition: DetId.h:17
bool put(const uint32_t &detID, InputVector &input, std::vector< std::string > &userContent)
std::vector< std::string > getUserDBContent() const
int getRunNr() const
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
string end
Definition: dataset.py:937
std::vector< float > getSummaryObj() const
tuple cout
Definition: gather_cfg.py:144
std::vector< std::string > userDBContent_
tmp
align.sh
Definition: createJobs.py:716
const short getPosition(std::string elementName) const