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 
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
bTagCombinedSVVariables_cff.indices
indices
Definition: bTagCombinedSVVariables_cff.py:67
ecaldqm::MESet::throw_
void throw_(std::string const &_message) const
Definition: MESet.h:121
electrons_cff.bool
bool
Definition: electrons_cff.py:372
ecaldqm
Definition: DQWorker.h:24
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
ecaldqm::MESet::operator=
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
ecaldqm::MESet::PathReplacements
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:31
ecaldqm::MESetMulti::replCandidates_
ReplCandidates replCandidates_
Definition: MESetMulti.h:131
ecaldqm::MESetMulti::use
void use(unsigned) const
Definition: MESetMulti.cc:130
ecaldqm::MESetMulti::MESetMulti
MESetMulti(MESet const &, ReplCandidates const &)
Definition: MESetMulti.cc:4
dqmdumpme.last
last
Definition: dqmdumpme.py:56
ecaldqm::MESet::clone
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:75
ecaldqm::MESetMulti::getIndex
unsigned getIndex(PathReplacements const &) const
Definition: MESetMulti.cc:137
ecaldqm::MESetMulti::resetAll
void resetAll(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:125
ecaldqm::MESet::active_
bool active_
Definition: MESet.h:133
ecaldqm::MESetMulti::book
void book(DQMStore::IBooker &) override
Definition: MESetMulti.cc:97
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ecaldqm::MESetMulti
Definition: MESetMulti.h:13
ecaldqm::MESetMulti::~MESetMulti
~MESetMulti() override
Definition: MESetMulti.cc:61
ecaldqm::MESetMulti::clear
void clear() const override
Definition: MESetMulti.cc:113
ecaldqm::MESet::path_
std::string path_
Definition: MESet.h:125
ecaldqm::MESetMulti::operator=
MESet & operator=(MESet const &) override
Definition: MESetMulti.cc:66
ecaldqm::MESetMulti::reset
void reset(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:120
ecaldqm::MESetMulti::sets_
std::vector< MESet * > sets_
Definition: MESetMulti.h:130
ecaldqm::MESetMulti::retrieve
bool retrieve(DQMStore::IGetter &, std::string *=nullptr) const override
Definition: MESetMulti.cc:104
ecaldqm::MESetMulti::current_
MESet * current_
Definition: MESetMulti.h:129
dqm::implementation::IGetter
Definition: DQMStore.h:484
ecaldqm::MESet::formPath
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:150
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
MESetMulti.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
btvTracks_cfi._content
_content
Definition: btvTracks_cfi.py:5
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
ecaldqm::MESetMulti::clone
MESet * clone(std::string const &="") const override
Definition: MESetMulti.cc:88
ecaldqm::MESetMulti::ReplCandidates
std::map< std::string, std::vector< std::string > > ReplCandidates
Definition: MESetMulti.h:15
ecaldqm::MESet
Definition: MESet.h:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443