CMS 3D CMS Logo

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