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(_ibooker);
108 
109  active_ = true;
110  }
111 
112  bool
113  MESetMulti::retrieve(DQMStore::IGetter& _igetter, std::string* _failedPath/* = 0*/) const
114  {
115  for(unsigned iS(0); iS < sets_.size(); ++iS)
116  if(!sets_[iS]->retrieve(_igetter, _failedPath)) return false;
117 
118  active_ = true;
119  return true;
120  }
121 
122  void
124  {
125  for(unsigned iS(0); iS < sets_.size(); ++iS)
126  sets_[iS]->clear();
127 
128  active_ = false;
129  }
130 
131  void
132  MESetMulti::reset(double _content/* = 0*/, double _error/* = 0.*/, double _entries/* = 0.*/)
133  {
134  for(unsigned iS(0); iS < sets_.size(); ++iS)
135  sets_[iS]->reset(_content, _error, _entries);
136  }
137 
138  void
139  MESetMulti::resetAll(double _content/* = 0*/, double _error/* = 0.*/, double _entries/* = 0.*/)
140  {
141  for(unsigned iS(0); iS < sets_.size(); ++iS)
142  sets_[iS]->resetAll(_content, _error, _entries);
143  }
144 
145  void
146  MESetMulti::use(unsigned _iSet) const
147  {
148  if(_iSet >= sets_.size())
149  throw_("MESetMulti index out of range");
150 
151  current_ = sets_[_iSet];
152  }
153 
154  unsigned
155  MESetMulti::getIndex(PathReplacements const& _replacements) const
156  {
157  unsigned index(0);
158  unsigned base(1);
159  for(typename ReplCandidates::const_reverse_iterator cItr(replCandidates_.rbegin()); cItr != replCandidates_.rend(); ++cItr){
160  typename PathReplacements::const_iterator rItr(_replacements.find(cItr->first));
161  if(rItr == _replacements.end())
162  throw_(cItr->first + " not given in the key for getIndex");
163  unsigned nC(cItr->second.size());
164  unsigned iR(0);
165  for(; iR != nC; ++iR)
166  if(rItr->second == cItr->second[iR]) break;
167  if(iR == nC)
168  throw_(rItr->second + " not found in replacement candidates");
169  index += iR * base;
170  base *= nC;
171  }
172 
173  return index;
174  }
175 }
tuple base
Main Program
Definition: newFWLiteAna.py:92
bool retrieve(DQMStore::IGetter &, std::string *=0) const override
Definition: MESetMulti.cc:113
std::vector< MESet * > sets_
Definition: MESetMulti.h:93
void reset(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:132
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:146
tuple path
else: Piece not in the list, fine.
void throw_(std::string const &_message) const
Definition: MESet.h:124
MESet * clone(std::string const &="") const override
Definition: MESetMulti.cc:94
void resetAll(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:139
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:163
void book(DQMStore::IBooker &) override
Definition: MESetMulti.cc:104
MESetMulti(MESet const &, ReplCandidates const &)
Definition: MESetMulti.cc:5
bool active_
Definition: MESet.h:138
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:70
ReplCandidates replCandidates_
Definition: MESetMulti.h:94
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:131
void clear() const override
Definition: MESetMulti.cc:123
unsigned getIndex(PathReplacements const &) const
Definition: MESetMulti.cc:155
tuple size
Write out results.