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 
97  void MESetMulti::book(DQMStore::IBooker &_ibooker, EcalElectronicsMapping const *electronicsMap) {
98  for (unsigned iS(0); iS < sets_.size(); ++iS)
99  sets_[iS]->book(_ibooker, electronicsMap);
100 
101  active_ = true;
102  }
103 
104  bool MESetMulti::retrieve(EcalElectronicsMapping const *electronicsMap,
105  DQMStore::IGetter &_igetter,
106  std::string *_failedPath /* = 0*/) const {
107  for (unsigned iS(0); iS < sets_.size(); ++iS)
108  if (!sets_[iS]->retrieve(electronicsMap, _igetter, _failedPath))
109  return false;
110 
111  active_ = true;
112  return true;
113  }
114 
115  void MESetMulti::clear() const {
116  for (unsigned iS(0); iS < sets_.size(); ++iS)
117  sets_[iS]->clear();
118 
119  active_ = false;
120  }
121 
122  void MESetMulti::reset(EcalElectronicsMapping const *electronicsMap,
123  double _content /* = 0*/,
124  double _error /* = 0.*/,
125  double _entries /* = 0.*/) {
126  for (unsigned iS(0); iS < sets_.size(); ++iS)
127  sets_[iS]->reset(electronicsMap, _content, _error, _entries);
128  }
129 
130  void MESetMulti::resetAll(double _content /* = 0*/, double _error /* = 0.*/, double _entries /* = 0.*/) {
131  for (unsigned iS(0); iS < sets_.size(); ++iS)
132  sets_[iS]->resetAll(_content, _error, _entries);
133  }
134 
135  void MESetMulti::use(unsigned _iSet) const {
136  if (_iSet >= sets_.size())
137  throw_("MESetMulti index out of range");
138 
139  current_ = sets_[_iSet];
140  }
141 
142  unsigned MESetMulti::getIndex(PathReplacements const &_replacements) const {
143  unsigned index(0);
144  unsigned base(1);
145  for (typename ReplCandidates::const_reverse_iterator cItr(replCandidates_.rbegin()); cItr != replCandidates_.rend();
146  ++cItr) {
147  typename PathReplacements::const_iterator rItr(_replacements.find(cItr->first));
148  if (rItr == _replacements.end())
149  throw_(cItr->first + " not given in the key for getIndex");
150  unsigned nC(cItr->second.size());
151  unsigned iR(0);
152  for (; iR != nC; ++iR)
153  if (rItr->second == cItr->second[iR])
154  break;
155  if (iR == nC)
156  throw_(rItr->second + " not found in replacement candidates");
157  index += iR * base;
158  base *= nC;
159  }
160 
161  return index;
162  }
163 } // namespace ecaldqm
EcalElectronicsMapping
Definition: EcalElectronicsMapping.h:28
ecaldqm::MESet::throw_
void throw_(std::string const &_message) const
Definition: MESet.h:149
electrons_cff.bool
bool
Definition: electrons_cff.py:366
ecaldqm::MESetMulti::reset
void reset(EcalElectronicsMapping const *, double=0., double=0., double=0.) override
Definition: MESetMulti.cc:122
ecaldqm
Definition: DQWorker.h:37
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:46
ecaldqm::MESetMulti::replCandidates_
ReplCandidates replCandidates_
Definition: MESetMulti.h:184
ecaldqm::MESetMulti::use
void use(unsigned) const
Definition: MESetMulti.cc:135
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:142
ecaldqm::MESetMulti::resetAll
void resetAll(double=0., double=0., double=0.) override
Definition: MESetMulti.cc:130
ecaldqm::MESet::active_
bool active_
Definition: MESet.h:161
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:115
ecaldqm::MESet::path_
std::string path_
Definition: MESet.h:153
ecaldqm::MESetMulti::operator=
MESet & operator=(MESet const &) override
Definition: MESetMulti.cc:66
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ecaldqm::MESetMulti::sets_
std::vector< MESet * > sets_
Definition: MESetMulti.h:183
ecaldqm::MESetMulti::current_
MESet * current_
Definition: MESetMulti.h:182
ecaldqm::MESetMulti::retrieve
bool retrieve(EcalElectronicsMapping const *, DQMStore::IGetter &, std::string *=nullptr) const override
Definition: MESetMulti.cc:104
dqm::implementation::IGetter
Definition: DQMStore.h:484
ecaldqm::MESet::formPath
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:153
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
dqmdumpme.indices
indices
Definition: dqmdumpme.py:50
ecaldqm::MESetMulti::book
void book(DQMStore::IBooker &, EcalElectronicsMapping const *) override
Definition: MESetMulti.cc:97
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:42
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443