CMS 3D CMS Logo

MESetMulti.cc
Go to the documentation of this file.
2 
3 namespace ecaldqm {
4  MESetMulti::MESetMulti(MESet const &_seed, ReplCandidates const &_replCandidates)
5  : MESet(_seed), current_(nullptr), sets_(), replCandidates_(_replCandidates) {
6  PathReplacements replacements;
7  std::map<std::string, unsigned> indices;
8  // recursive function to set replacements
9  // indices gives the multi index in each dimension
10  // dimensions are alphanumerically ordered from the use of std::map
11  std::function<bool(typename ReplCandidates::const_iterator &)> setReplacements(
12  [&setReplacements, &replacements, &indices, this](typename ReplCandidates::const_iterator &_rItr) {
13  unsigned &index(indices[_rItr->first]);
14  replacements[_rItr->first] = _rItr->second[index];
15  // one dimension set, go to next
16  ++_rItr;
17  if (_rItr == this->replCandidates_.end()) {
18  // this is the last dimension. Increment the index and retutn to the
19  // first
20  _rItr = this->replCandidates_.begin();
21  ++index;
22  } else if (setReplacements(_rItr))
23  ++index;
24 
25  if (index != _rItr->second.size())
26  return false;
27  // index has counted to the maximum of this dimension, carry over
28  index = 0;
29  return true;
30  });
31 
32  // [dim0 = 0, dim1 = 0] -> 0, [dim0 = 0, dim1 = 1] -> 1, ...
33  unsigned iM(0);
34  while (true) {
35  replacements.clear();
36  typename ReplCandidates::const_iterator rItr(replCandidates_.begin());
37  bool last(setReplacements(rItr));
38  sets_.push_back(_seed.clone(formPath(replacements)));
39  if (last)
40  break;
41  ++iM;
42  }
43 
44  current_ = sets_[0];
45  }
46 
48  : MESet(_orig), current_(nullptr), sets_(_orig.sets_.size(), nullptr), replCandidates_(_orig.replCandidates_) {
49  if (sets_.empty())
50  return;
51 
52  for (unsigned iS(0); iS < sets_.size(); ++iS) {
53  if (!_orig.sets_[iS])
54  continue;
55  sets_[iS] = _orig.sets_[iS]->clone();
56  if (_orig.sets_[iS] == _orig.current_)
57  current_ = sets_[iS];
58  }
59  }
60 
62  for (unsigned iS(0); iS < sets_.size(); ++iS)
63  delete sets_[iS];
64  }
65 
67  for (unsigned iS(0); iS < sets_.size(); ++iS)
68  delete sets_[iS];
69  sets_.clear();
70  current_ = nullptr;
71 
72  MESetMulti const *pRhs(dynamic_cast<MESetMulti const *>(&_rhs));
73  if (pRhs) {
74  sets_.assign(pRhs->sets_.size(), nullptr);
75 
76  for (unsigned iS(0); iS < pRhs->sets_.size(); ++iS) {
77  sets_[iS] = pRhs->sets_[iS]->clone();
78  if (pRhs->sets_[iS] == pRhs->current_)
79  current_ = sets_[iS];
80  }
81 
83  }
84 
85  return MESet::operator=(_rhs);
86  }
87 
88  MESet *MESetMulti::clone(std::string const &_path /* = ""*/) const {
90  if (!_path.empty())
91  path_ = _path;
92  MESet *copy(new MESetMulti(*this));
93  path_ = path;
94  return copy;
95  }
96 
97  void MESetMulti::book(DQMStore::IBooker &_ibooker, EcalElectronicsMapping const *electronicsMap) {
98  for (unsigned iS(0); iS < sets_.size(); ++iS)
99  sets_[iS]->book(_ibooker, electronicsMap);
100 
101  active_ = true;
102  }
103 
104  bool MESetMulti::retrieve(EcalElectronicsMapping const *electronicsMap,
105  DQMStore::IGetter &_igetter,
106  std::string *_failedPath /* = 0*/) const {
107  for (unsigned iS(0); iS < sets_.size(); ++iS)
108  if (!sets_[iS]->retrieve(electronicsMap, _igetter, _failedPath))
109  return false;
110 
111  active_ = true;
112  return true;
113  }
114 
115  void MESetMulti::clear() const {
116  for (unsigned iS(0); iS < sets_.size(); ++iS)
117  sets_[iS]->clear();
118 
119  active_ = false;
120  }
121 
122  void MESetMulti::reset(EcalElectronicsMapping const *electronicsMap,
123  double _content /* = 0*/,
124  double _error /* = 0.*/,
125  double _entries /* = 0.*/) {
126  for (unsigned iS(0); iS < sets_.size(); ++iS)
127  sets_[iS]->reset(electronicsMap, _content, _error, _entries);
128  }
129 
130  void MESetMulti::resetAll(double _content /* = 0*/, double _error /* = 0.*/, double _entries /* = 0.*/) {
131  for (unsigned iS(0); iS < sets_.size(); ++iS)
132  sets_[iS]->resetAll(_content, _error, _entries);
133  }
134 
135  void MESetMulti::use(unsigned _iSet) const {
136  if (_iSet >= sets_.size())
137  throw_("MESetMulti index out of range");
138 
139  current_ = sets_[_iSet];
140  }
141 
142  unsigned MESetMulti::getIndex(PathReplacements const &_replacements) const {
143  unsigned index(0);
144  unsigned base(1);
145  for (typename ReplCandidates::const_reverse_iterator cItr(replCandidates_.rbegin()); cItr != replCandidates_.rend();
146  ++cItr) {
147  typename PathReplacements::const_iterator rItr(_replacements.find(cItr->first));
148  if (rItr == _replacements.end())
149  throw_(cItr->first + " not given in the key for getIndex");
150  unsigned nC(cItr->second.size());
151  unsigned iR(0);
152  for (; iR != nC; ++iR)
153  if (rItr->second == cItr->second[iR])
154  break;
155  if (iR == nC)
156  throw_(rItr->second + " not found in replacement candidates");
157  index += iR * base;
158  base *= nC;
159  }
160 
161  return index;
162  }
163 } // namespace ecaldqm
size
Write out results.
void use(unsigned) const
Definition: MESetMulti.cc:135
bool retrieve(EcalElectronicsMapping const *, DQMStore::IGetter &, std::string *=nullptr) const override
Definition: MESetMulti.cc:104
base
Main Program
Definition: newFWLiteAna.py:92
void throw_(std::string const &_message) const
Definition: MESet.h:149
std::map< std::string, std::vector< std::string > > ReplCandidates
Definition: MESetMulti.h:15
MESet * clone(std::string const &="") const override
Definition: MESetMulti.cc:88
void resetAll(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:130
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:75
~MESetMulti() override
Definition: MESetMulti.cc:61
std::vector< MESet * > sets_
Definition: MESetMulti.h:183
unsigned getIndex(PathReplacements const &) const
Definition: MESetMulti.cc:142
MESetMulti(MESet const &, ReplCandidates const &)
Definition: MESetMulti.cc:4
bool active_
Definition: MESet.h:161
void reset(EcalElectronicsMapping const *, double=0., double=0., double=0.) override
Definition: MESetMulti.cc:122
void book(DQMStore::IBooker &, EcalElectronicsMapping const *) override
Definition: MESetMulti.cc:97
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
ReplCandidates replCandidates_
Definition: MESetMulti.h:184
MESet & operator=(MESet const &) override
Definition: MESetMulti.cc:66
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:46
std::string path_
Definition: MESet.h:153
void clear() const override
Definition: MESetMulti.cc:115
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:153