1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
#include "DQM/EcalCommon/interface/MESetMulti.h"
namespace ecaldqm {
MESetMulti::MESetMulti(MESet const &_seed, ReplCandidates const &_replCandidates)
: MESet(_seed), current_(nullptr), sets_(), replCandidates_(_replCandidates) {
PathReplacements replacements;
std::map<std::string, unsigned> indices;
// recursive function to set replacements
// indices gives the multi index in each dimension
// dimensions are alphanumerically ordered from the use of std::map
std::function<bool(typename ReplCandidates::const_iterator &)> setReplacements(
[&setReplacements, &replacements, &indices, this](typename ReplCandidates::const_iterator &_rItr) {
unsigned &index(indices[_rItr->first]);
replacements[_rItr->first] = _rItr->second[index];
// one dimension set, go to next
++_rItr;
if (_rItr == this->replCandidates_.end()) {
// this is the last dimension. Increment the index and retutn to the
// first
_rItr = this->replCandidates_.begin();
++index;
} else if (setReplacements(_rItr))
++index;
if (index != _rItr->second.size())
return false;
// index has counted to the maximum of this dimension, carry over
index = 0;
return true;
});
// [dim0 = 0, dim1 = 0] -> 0, [dim0 = 0, dim1 = 1] -> 1, ...
while (true) {
replacements.clear();
typename ReplCandidates::const_iterator rItr(replCandidates_.begin());
bool last(setReplacements(rItr));
sets_.push_back(_seed.clone(formPath(replacements)));
if (last)
break;
}
current_ = sets_[0];
}
MESetMulti::MESetMulti(MESetMulti const &_orig)
: MESet(_orig), current_(nullptr), sets_(_orig.sets_.size(), nullptr), replCandidates_(_orig.replCandidates_) {
if (sets_.empty())
return;
for (unsigned iS(0); iS < sets_.size(); ++iS) {
if (!_orig.sets_[iS])
continue;
sets_[iS] = _orig.sets_[iS]->clone();
if (_orig.sets_[iS] == _orig.current_)
current_ = sets_[iS];
}
}
MESetMulti::~MESetMulti() {
for (unsigned iS(0); iS < sets_.size(); ++iS)
delete sets_[iS];
}
MESet &MESetMulti::operator=(MESet const &_rhs) {
for (unsigned iS(0); iS < sets_.size(); ++iS)
delete sets_[iS];
sets_.clear();
current_ = nullptr;
MESetMulti const *pRhs(dynamic_cast<MESetMulti const *>(&_rhs));
if (pRhs) {
sets_.assign(pRhs->sets_.size(), nullptr);
for (unsigned iS(0); iS < pRhs->sets_.size(); ++iS) {
sets_[iS] = pRhs->sets_[iS]->clone();
if (pRhs->sets_[iS] == pRhs->current_)
current_ = sets_[iS];
}
replCandidates_ = pRhs->replCandidates_;
}
return MESet::operator=(_rhs);
}
MESet *MESetMulti::clone(std::string const &_path /* = ""*/) const {
std::string path(path_);
if (!_path.empty())
path_ = _path;
MESet *copy(new MESetMulti(*this));
path_ = path;
return copy;
}
void MESetMulti::book(DQMStore::IBooker &_ibooker, EcalElectronicsMapping const *electronicsMap) {
for (unsigned iS(0); iS < sets_.size(); ++iS)
sets_[iS]->book(_ibooker, electronicsMap);
active_ = true;
}
bool MESetMulti::retrieve(EcalElectronicsMapping const *electronicsMap,
DQMStore::IGetter &_igetter,
std::string *_failedPath /* = 0*/) const {
for (unsigned iS(0); iS < sets_.size(); ++iS)
if (!sets_[iS]->retrieve(electronicsMap, _igetter, _failedPath))
return false;
active_ = true;
return true;
}
void MESetMulti::clear() const {
for (unsigned iS(0); iS < sets_.size(); ++iS)
sets_[iS]->clear();
active_ = false;
}
void MESetMulti::reset(EcalElectronicsMapping const *electronicsMap,
double _content /* = 0*/,
double _error /* = 0.*/,
double _entries /* = 0.*/) {
for (unsigned iS(0); iS < sets_.size(); ++iS)
sets_[iS]->reset(electronicsMap, _content, _error, _entries);
}
void MESetMulti::resetAll(double _content /* = 0*/, double _error /* = 0.*/, double _entries /* = 0.*/) {
for (unsigned iS(0); iS < sets_.size(); ++iS)
sets_[iS]->resetAll(_content, _error, _entries);
}
void MESetMulti::use(unsigned _iSet) const {
if (_iSet >= sets_.size())
throw_("MESetMulti index out of range");
current_ = sets_[_iSet];
}
unsigned MESetMulti::getIndex(PathReplacements const &_replacements) const {
unsigned index(0);
unsigned base(1);
for (typename ReplCandidates::const_reverse_iterator cItr(replCandidates_.rbegin()); cItr != replCandidates_.rend();
++cItr) {
typename PathReplacements::const_iterator rItr(_replacements.find(cItr->first));
if (rItr == _replacements.end())
throw_(cItr->first + " not given in the key for getIndex");
unsigned nC(cItr->second.size());
unsigned iR(0);
for (; iR != nC; ++iR)
if (rItr->second == cItr->second[iR])
break;
if (iR == nC)
throw_(rItr->second + " not found in replacement candidates");
index += iR * base;
base *= nC;
}
return index;
}
} // namespace ecaldqm
|