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 
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 
98  for (unsigned iS(0); iS < sets_.size(); ++iS)
99  sets_[iS]->book(_ibooker);
100 
101  active_ = true;
102  }
103 
104  bool MESetMulti::retrieve(DQMStore::IGetter &_igetter, std::string *_failedPath /* = 0*/) const {
105  for (unsigned iS(0); iS < sets_.size(); ++iS)
106  if (!sets_[iS]->retrieve(_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(double _content /* = 0*/, double _error /* = 0.*/, double _entries /* = 0.*/) {
121  for (unsigned iS(0); iS < sets_.size(); ++iS)
122  sets_[iS]->reset(_content, _error, _entries);
123  }
124 
125  void MESetMulti::resetAll(double _content /* = 0*/, double _error /* = 0.*/, double _entries /* = 0.*/) {
126  for (unsigned iS(0); iS < sets_.size(); ++iS)
127  sets_[iS]->resetAll(_content, _error, _entries);
128  }
129 
130  void MESetMulti::use(unsigned _iSet) const {
131  if (_iSet >= sets_.size())
132  throw_("MESetMulti index out of range");
133 
134  current_ = sets_[_iSet];
135  }
136 
137  unsigned MESetMulti::getIndex(PathReplacements const &_replacements) const {
138  unsigned index(0);
139  unsigned base(1);
140  for (typename ReplCandidates::const_reverse_iterator cItr(replCandidates_.rbegin()); cItr != replCandidates_.rend();
141  ++cItr) {
142  typename PathReplacements::const_iterator rItr(_replacements.find(cItr->first));
143  if (rItr == _replacements.end())
144  throw_(cItr->first + " not given in the key for getIndex");
145  unsigned nC(cItr->second.size());
146  unsigned iR(0);
147  for (; iR != nC; ++iR)
148  if (rItr->second == cItr->second[iR])
149  break;
150  if (iR == nC)
151  throw_(rItr->second + " not found in replacement candidates");
152  index += iR * base;
153  base *= nC;
154  }
155 
156  return index;
157  }
158 } // namespace ecaldqm
size
Write out results.
def copy(args, dbName)
void reset(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:120
void clear() const override
Definition: MESetMulti.cc:113
#define nullptr
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:75
std::map< std::string, std::vector< std::string > > ReplCandidates
Definition: MESetMulti.h:15
void use(unsigned) const
Definition: MESetMulti.cc:130
MESet * clone(std::string const &="") const override
Definition: MESetMulti.cc:88
void throw_(std::string const &_message) const
Definition: MESet.h:122
void resetAll(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:125
base
Make Sure CMSSW is Setup ##.
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:150
~MESetMulti() override
Definition: MESetMulti.cc:61
void book(DQMStore::IBooker &) override
Definition: MESetMulti.cc:97
std::vector< MESet * > sets_
Definition: MESetMulti.h:130
bool retrieve(DQMStore::IGetter &, std::string *=0) const override
Definition: MESetMulti.cc:104
MESetMulti(MESet const &, ReplCandidates const &)
Definition: MESetMulti.cc:4
bool active_
Definition: MESet.h:134
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
ReplCandidates replCandidates_
Definition: MESetMulti.h:131
MESet & operator=(MESet const &) override
Definition: MESetMulti.cc:66
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:30
std::string path_
Definition: MESet.h:126
unsigned getIndex(PathReplacements const &) const
Definition: MESetMulti.cc:137