CMS 3D CMS Logo

HDQMSummary.cc
Go to the documentation of this file.
3 
4 #include <algorithm>
5 
6 HDQMSummary::HDQMSummary(std::vector<std::string>& userDBContent) {
7  userDBContent_ = userDBContent;
8  runNr_ = 0;
9  timeValue_ = 0;
10 }
11 
13  userDBContent_ = input.getUserDBContent();
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 HDQMSummary::put(const uint32_t& DetId, InputVector& input, std::vector<std::string>& userContent) {
23  Registry::iterator p = std::lower_bound(indexes_.begin(), indexes_.end(), DetId, HDQMSummary::StrictWeakOrdering());
24 
25  if (p == indexes_.end() || p->detid != DetId) {
26  //First request for the given DetID
27  //Create entries for all the declared userDBContent
28  //and fill for the provided userContent
29 
30  DetRegistry detregistry;
31  detregistry.detid = DetId;
32  detregistry.ibegin = v_sum_.size();
33  indexes_.insert(p, detregistry);
34  InputVector tmp(userDBContent_.size(), -9999);
35 
36  for (size_t i = 0; i < userContent.size(); ++i)
37  tmp[getPosition(userContent[i])] = input[i];
38 
39  v_sum_.insert(v_sum_.end(), tmp.begin(), tmp.end());
40  } else {
41  if (p->detid == DetId) {
42  //I should already find the entries
43  //fill for the provided userContent
44 
45  for (size_t i = 0; i < userContent.size(); ++i)
46  v_sum_[p->ibegin + getPosition(userContent[i])] = input[i];
47  }
48  }
49 
50  return true;
51 }
52 
53 const HDQMSummary::Range HDQMSummary::getRange(const uint32_t& DetId) const {
55  if (p == indexes_.end() || p->detid != DetId) {
56  edm::LogWarning("HDQMSummary") << "not in range";
57  return HDQMSummary::Range(v_sum_.end(), v_sum_.end());
58  }
59  return HDQMSummary::Range(v_sum_.begin() + p->ibegin, v_sum_.begin() + p->ibegin + userDBContent_.size());
60 }
61 
62 std::vector<uint32_t> HDQMSummary::getDetIds() const {
63  // returns vector of DetIds in map
64  std::vector<uint32_t> DetIds_;
67  for (HDQMSummary::RegistryIterator p = begin; p != end; ++p) {
68  DetIds_.push_back(p->detid);
69  }
70  return DetIds_;
71 }
72 
73 const short HDQMSummary::getPosition(std::string elementName) const {
74  // returns position of elementName in UserDBContent_
75 
76  std::vector<std::string>::const_iterator it = find(userDBContent_.begin(), userDBContent_.end(), elementName);
77  short pos = -1;
78  if (it != userDBContent_.end())
79  pos = it - userDBContent_.begin();
80  else
81  edm::LogError("HDQMSummary") << "attempting to retrieve non existing historic DB object : " << elementName
82  << std::endl;
83  return pos;
84 }
85 
86 void HDQMSummary::setObj(const uint32_t& detID, std::string elementName, float value) {
87  // modifies value of info "elementName" for the given detID
88  // requires that an entry has be defined beforehand for detId in DB
90  if (p == indexes_.end() || p->detid != detID) {
91  throw cms::Exception("") << "not allowed to modify " << elementName
92  << " in historic DB - SummaryObj needs to be available first !";
93  }
94 
95  const HDQMSummary::Range range = getRange(detID);
96 
97  std::vector<float>::const_iterator it = range.first + getPosition(elementName);
98  std::vector<float>::difference_type pos = -1;
99  if (it != v_sum_.end()) {
100  pos = it - v_sum_.begin();
101  v_sum_.at(pos) = value;
102  }
103 }
104 
105 std::vector<float> HDQMSummary::getSummaryObj(uint32_t& detID, const std::vector<std::string>& _list) const {
106  std::vector<std::string> list = _list;
107  std::vector<float> SummaryObj;
108  const HDQMSummary::Range range = getRange(detID);
109  if (range.first != range.second) {
110  for (unsigned int i = 0; i < list.size(); i++) {
111  const short pos = getPosition(list.at(i));
112 
113  if (pos != -1)
114  SummaryObj.push_back(*((range.first) + pos));
115  else
116  SummaryObj.push_back(-999.);
117  }
118  } else
119  for (unsigned int i = 0; i < list.size(); i++)
120  SummaryObj.push_back(
121  -99.); // no summary obj has ever been inserted for this detid, most likely all related histos were not available in DQM
122 
123  return SummaryObj;
124 }
125 
126 std::vector<float> HDQMSummary::getSummaryObj(uint32_t& detID) const {
127  std::vector<float> SummaryObj;
128  const HDQMSummary::Range range = getRange(detID);
129  if (range.first != range.second) {
130  for (unsigned int i = 0; i < userDBContent_.size(); i++)
131  SummaryObj.push_back(*((range.first) + i));
132  } else {
133  for (unsigned int i = 0; i < userDBContent_.size(); i++)
134  SummaryObj.push_back(-99.);
135  }
136  return SummaryObj;
137 }
138 
139 std::vector<float> HDQMSummary::getSummaryObj() const { return v_sum_; }
140 
141 std::vector<float> HDQMSummary::getSummaryObj(std::string elementName) const {
142  std::vector<float> vSumElement;
143  std::vector<uint32_t> DetIds_ = getDetIds();
144  const short pos = getPosition(elementName);
145 
146  if (pos != -1) {
147  for (unsigned int i = 0; i < DetIds_.size(); i++) {
148  const HDQMSummary::Range range = getRange(DetIds_.at(i));
149  if (range.first != range.second) {
150  vSumElement.push_back(*((range.first) + pos));
151  } else {
152  vSumElement.push_back(-99.);
153  }
154  }
155  }
156 
157  return vSumElement;
158 }
159 
161  std::cout << "Nr. of detector elements in HDQMSummary object is " << indexes_.size() << " RunNr= " << runNr_
162  << " timeValue= " << timeValue_ << std::endl;
163 }
std::pair< ContainerIterator, ContainerIterator > Range
Definition: HDQMSummary.h:56
bool put(const uint32_t &detID, InputVector &input, std::vector< std::string > &userContent)
Definition: HDQMSummary.cc:22
const Range getRange(const uint32_t &detID) const
Definition: HDQMSummary.cc:53
std::vector< float > v_sum_
Definition: HDQMSummary.h:117
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
void setObj(const uint32_t &detID, std::string elementName, float value)
Definition: HDQMSummary.cc:86
std::vector< float > getSummaryObj() const
Definition: HDQMSummary.cc:139
static std::string const input
Definition: EdmProvDump.cc:50
unsigned long long timeValue_
Definition: HDQMSummary.h:121
std::vector< float > InputVector
Definition: HDQMSummary.h:59
std::vector< uint32_t > getDetIds() const
Definition: HDQMSummary.cc:62
void print()
Definition: HDQMSummary.cc:160
Registry::const_iterator RegistryIterator
Definition: HDQMSummary.h:58
std::vector< DetRegistry > indexes_
Definition: HDQMSummary.h:118
Definition: value.py:1
std::vector< std::string > userDBContent_
Definition: HDQMSummary.h:116
Definition: DetId.h:17
Log< level::Warning, false > LogWarning
tmp
align.sh
Definition: createJobs.py:716
const short getPosition(std::string elementName) const
Definition: HDQMSummary.cc:73