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  while (true) {
34  replacements.clear();
35  typename ReplCandidates::const_iterator rItr(replCandidates_.begin());
36  bool last(setReplacements(rItr));
37  sets_.push_back(_seed.clone(formPath(replacements)));
38  if (last)
39  break;
40  }
41 
42  current_ = sets_[0];
43  }
44 
46  : MESet(_orig), current_(nullptr), sets_(_orig.sets_.size(), nullptr), replCandidates_(_orig.replCandidates_) {
47  if (sets_.empty())
48  return;
49 
50  for (unsigned iS(0); iS < sets_.size(); ++iS) {
51  if (!_orig.sets_[iS])
52  continue;
53  sets_[iS] = _orig.sets_[iS]->clone();
54  if (_orig.sets_[iS] == _orig.current_)
55  current_ = sets_[iS];
56  }
57  }
58 
60  for (unsigned iS(0); iS < sets_.size(); ++iS)
61  delete sets_[iS];
62  }
63 
65  for (unsigned iS(0); iS < sets_.size(); ++iS)
66  delete sets_[iS];
67  sets_.clear();
68  current_ = nullptr;
69 
70  MESetMulti const *pRhs(dynamic_cast<MESetMulti const *>(&_rhs));
71  if (pRhs) {
72  sets_.assign(pRhs->sets_.size(), nullptr);
73 
74  for (unsigned iS(0); iS < pRhs->sets_.size(); ++iS) {
75  sets_[iS] = pRhs->sets_[iS]->clone();
76  if (pRhs->sets_[iS] == pRhs->current_)
77  current_ = sets_[iS];
78  }
79 
81  }
82 
83  return MESet::operator=(_rhs);
84  }
85 
86  MESet *MESetMulti::clone(std::string const &_path /* = ""*/) const {
88  if (!_path.empty())
89  path_ = _path;
90  MESet *copy(new MESetMulti(*this));
91  path_ = path;
92  return copy;
93  }
94 
95  void MESetMulti::book(DQMStore::IBooker &_ibooker, EcalElectronicsMapping const *electronicsMap) {
96  for (unsigned iS(0); iS < sets_.size(); ++iS)
97  sets_[iS]->book(_ibooker, electronicsMap);
98 
99  active_ = true;
100  }
101 
102  bool MESetMulti::retrieve(EcalElectronicsMapping const *electronicsMap,
103  DQMStore::IGetter &_igetter,
104  std::string *_failedPath /* = 0*/) const {
105  for (unsigned iS(0); iS < sets_.size(); ++iS)
106  if (!sets_[iS]->retrieve(electronicsMap, _igetter, _failedPath))
107  return false;
108 
109  active_ = true;
110  return true;
111  }
112 
113  void MESetMulti::clear() const {
114  for (unsigned iS(0); iS < sets_.size(); ++iS)
115  sets_[iS]->clear();
116 
117  active_ = false;
118  }
119 
120  void MESetMulti::reset(EcalElectronicsMapping const *electronicsMap,
121  double _content /* = 0*/,
122  double _error /* = 0.*/,
123  double _entries /* = 0.*/) {
124  for (unsigned iS(0); iS < sets_.size(); ++iS)
125  sets_[iS]->reset(electronicsMap, _content, _error, _entries);
126  }
127 
128  void MESetMulti::resetAll(double _content /* = 0*/, double _error /* = 0.*/, double _entries /* = 0.*/) {
129  for (unsigned iS(0); iS < sets_.size(); ++iS)
130  sets_[iS]->resetAll(_content, _error, _entries);
131  }
132 
133  void MESetMulti::use(unsigned _iSet) const {
134  if (_iSet >= sets_.size())
135  throw_("MESetMulti index out of range");
136 
137  current_ = sets_[_iSet];
138  }
139 
140  unsigned MESetMulti::getIndex(PathReplacements const &_replacements) const {
141  unsigned index(0);
142  unsigned base(1);
143  for (typename ReplCandidates::const_reverse_iterator cItr(replCandidates_.rbegin()); cItr != replCandidates_.rend();
144  ++cItr) {
145  typename PathReplacements::const_iterator rItr(_replacements.find(cItr->first));
146  if (rItr == _replacements.end())
147  throw_(cItr->first + " not given in the key for getIndex");
148  unsigned nC(cItr->second.size());
149  unsigned iR(0);
150  for (; iR != nC; ++iR)
151  if (rItr->second == cItr->second[iR])
152  break;
153  if (iR == nC)
154  throw_(rItr->second + " not found in replacement candidates");
155  index += iR * base;
156  base *= nC;
157  }
158 
159  return index;
160  }
161 } // namespace ecaldqm
void use(unsigned) const
Definition: MESetMulti.cc:133
bool retrieve(EcalElectronicsMapping const *, DQMStore::IGetter &, std::string *=nullptr) const override
Definition: MESetMulti.cc:102
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:86
void resetAll(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:128
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:75
~MESetMulti() override
Definition: MESetMulti.cc:59
std::vector< MESet * > sets_
Definition: MESetMulti.h:183
unsigned getIndex(PathReplacements const &) const
Definition: MESetMulti.cc:140
MESetMulti(MESet const &, ReplCandidates const &)
Definition: MESetMulti.cc:4
bool active_
Definition: MESet.h:163
void reset(EcalElectronicsMapping const *, double=0., double=0., double=0.) override
Definition: MESetMulti.cc:120
void book(DQMStore::IBooker &, EcalElectronicsMapping const *) override
Definition: MESetMulti.cc:95
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
ReplCandidates replCandidates_
Definition: MESetMulti.h:184
MESet & operator=(MESet const &) override
Definition: MESetMulti.cc:64
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:46
std::string path_
Definition: MESet.h:155
void clear() const override
Definition: MESetMulti.cc:113
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:153