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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/*
* =====================================================================================
*
* Filename: CSCDQM_Cache.cc
*
* Description: MonitorObject cache implementation
*
* Version: 1.0
* Created: 12/01/2008 11:36:11 AM
* Revision: none
* Compiler: gcc
*
* Author: Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
* Company: CERN, CH
*
* =====================================================================================
*/
#include "CSCDQM_Cache.h"
namespace cscdqm {
/**
* @brief Get Monitoring Object on Histogram Definition
* @param histo Histogram definition
* @param mo Monitoring Object to return
* @return true if MO was found in cache and false otherwise
*/
const bool Cache::get(const HistoDef& histo, MonitorObject*& mo) {
if (typeid(histo) == EMUHistoDefT) {
return getEMU(histo.getId(), mo);
} else if (typeid(histo) == FEDHistoDefT) {
return getFED(histo.getId(), histo.getFEDId(), mo);
} else if (typeid(histo) == DDUHistoDefT) {
return getDDU(histo.getId(), histo.getDDUId(), mo);
} else if (typeid(histo) == CSCHistoDefT) {
return getCSC(histo.getId(), histo.getCrateId(), histo.getDMBId(), histo.getAddId(), mo);
} else if (typeid(histo) == ParHistoDefT) {
return getPar(histo.getId(), mo);
}
return false;
}
/**
* @brief Get EMU MO on Histogram Id
* @param id Histogram identifier
* @param mo Monitoring Object to return
* @return true if MO was found in cache and false otherwise
*/
const bool Cache::getEMU(const HistoId& id, MonitorObject*& mo) {
if (data[id]) {
mo = data[id];
return true;
}
return false;
}
/**
* @brief Get FED MO on Histogram Id and FED Id
* @param id Histogram identifier
* @param fedId FED identifier
* @param mo Monitoring Object to return
* @return true if MO was found in cache and false otherwise
*/
const bool Cache::getFED(const HistoId& id, const HwId& fedId, MonitorObject*& mo) {
/** If not cached (last FED) - find FED */
if (fedPointerValue != fedId) {
fedPointer = fedData.find(fedId);
if (fedPointer == fedData.end()) {
fedPointerValue = 0;
return false;
}
fedPointerValue = fedId;
}
/** Get MO from static array */
if (fedPointer->second[id]) {
mo = fedPointer->second[id];
return true;
}
return false;
}
/**
* @brief Get DDU MO on Histogram Id and DDU Id
* @param id Histogram identifier
* @param dduId DDU identifier
* @param mo Monitoring Object to return
* @return true if MO was found in cache and false otherwise
*/
const bool Cache::getDDU(const HistoId& id, const HwId& dduId, MonitorObject*& mo) {
/** If not cached (last DDU) - find DDU */
if (dduPointerValue != dduId) {
dduPointer = dduData.find(dduId);
if (dduPointer == dduData.end()) {
dduPointerValue = 0;
return false;
}
dduPointerValue = dduId;
}
/** Get MO from static array */
if (dduPointer->second[id]) {
mo = dduPointer->second[id];
return true;
}
return false;
}
/**
* @brief Get CSC MO on Histogram Id and CSC Crate and DMB Ids
* @param id Histogram identifier
* @param crateId CSC Crate identifier
* @param dmbId CSC DMB identifier
* @param mo Monitoring Object to return
* @return true if MO was found in cache and false otherwise
*/
const bool Cache::getCSC(
const HistoId& id, const HwId& crateId, const HwId& dmbId, const HwId& addId, MonitorObject*& mo) {
/** If not cached (last CSC) - find CSC */
if (cscPointer == cscData.end() || cscPointer->crateId != crateId || cscPointer->dmbId != dmbId) {
cscPointer = cscData.find(boost::make_tuple(crateId, dmbId));
}
/** Get Monitor object from multi_index List */
if (cscPointer != cscData.end()) {
CSCHistoMapType::const_iterator hit = cscPointer->mos.find(boost::make_tuple(id, addId));
if (hit != cscPointer->mos.end()) {
mo = const_cast<MonitorObject*>(hit->mo);
return true;
}
}
return false;
}
/**
* @brief Get Parameter MO on Histogram Id
* @param id Histogram identifier
* @param mo Monitoring Object to return
* @return true if MO was found in cache and false otherwise
*/
const bool Cache::getPar(const HistoId& id, MonitorObject*& mo) {
if (data[id]) {
mo = data[id];
return true;
}
return false;
}
/**
* @brief Put Monitoring Object into cache
* @param histo Histogram Definition
* @param mo Monitoring Object to put
* @return
*/
void Cache::put(const HistoDef& histo, MonitorObject* mo) {
HistoId id = histo.getId();
/** EMU MO */
if (typeid(histo) == EMUHistoDefT) {
data[id] = mo;
} else
/** FED MO */
if (typeid(histo) == FEDHistoDefT) {
HwId fedId = histo.getFEDId();
if (fedPointerValue != fedId) {
fedPointer = fedData.find(fedId);
}
if (fedPointer == fedData.end()) {
MonitorObject** mos = new MonitorObject*[h::namesSize];
for (unsigned int i = 0; i < h::namesSize; i++)
mos[i] = nullptr;
fedPointer = fedData.insert(fedData.end(), std::make_pair(fedId, mos));
}
fedPointer->second[id] = mo;
fedPointerValue = fedId;
} else
/** DDU MO */
if (typeid(histo) == DDUHistoDefT) {
HwId dduId = histo.getDDUId();
if (dduPointerValue != dduId) {
dduPointer = dduData.find(dduId);
}
if (dduPointer == dduData.end()) {
MonitorObject** mos = new MonitorObject*[h::namesSize];
for (unsigned int i = 0; i < h::namesSize; i++)
mos[i] = nullptr;
dduPointer = dduData.insert(dduData.end(), std::make_pair(dduId, mos));
}
dduPointer->second[id] = mo;
dduPointerValue = dduId;
} else
/** CSC MO */
if (typeid(histo) == CSCHistoDefT) {
HwId crateId = histo.getCrateId();
HwId dmbId = histo.getDMBId();
HwId addId = histo.getAddId();
CSCHistoKeyType histoKey(id, addId, mo);
if (cscPointer == cscData.end() || cscPointer->crateId != crateId || cscPointer->dmbId != dmbId) {
cscPointer = cscData.find(boost::make_tuple(crateId, dmbId));
}
if (cscPointer == cscData.end()) {
CSCKeyType cscKey(crateId, dmbId);
cscPointer = cscData.insert(cscData.end(), cscKey);
}
CSCHistoMapType* mos = const_cast<CSCHistoMapType*>(&cscPointer->mos);
mos->insert(histoKey);
} else
/** Parameter MO */
if (typeid(histo) == ParHistoDefT) {
data[id] = mo;
}
/** Add histo (if mo is not null!) into lookup list */
if (mo) {
lookupData.insert(lookupData.end(), LookupKeyType(histo, mo));
}
}
/**
* @brief Iterator to get booked CSC identifiers on enumerator
* @param n iterator (0 and up)
* @param crateId CSC Crate Id returned
* @param dmbId CSC DMB Id returned
* @return true if CSC on n found, false - otherwise
*/
const bool Cache::nextBookedCSC(unsigned int& n, unsigned int& crateId, unsigned int& dmbId) const {
if (n < cscData.size()) {
CSCMapType::const_iterator iter = cscData.begin();
for (unsigned int i = n; i > 0; i--)
iter++;
crateId = iter->crateId;
dmbId = iter->dmbId;
n++;
return true;
}
return false;
}
/**
* @brief Iterator to get booked FED identifier on enumerator
* @param n iterator (0 and up)
* @param fedId FED Id returned
* @return true if FED on n found, false - otherwise
*/
const bool Cache::nextBookedFED(unsigned int& n, unsigned int& fedId) const {
if (n < fedData.size()) {
FEDMapType::const_iterator iter = fedData.begin();
for (unsigned int i = n; i > 0; i--)
iter++;
fedId = iter->first;
n++;
return true;
}
return false;
}
/**
* @brief Iterator to get booked DDU identifier on enumerator
* @param n iterator (0 and up)
* @param dduId DDU Id returned
* @return true if DDU on n found, false - otherwise
*/
const bool Cache::nextBookedDDU(unsigned int& n, unsigned int& dduId) const {
if (n < dduData.size()) {
DDUMapType::const_iterator iter = dduData.begin();
for (unsigned int i = n; i > 0; i--)
iter++;
dduId = iter->first;
n++;
return true;
}
return false;
}
/**
* @brief Check if CSC was booked on given identifiers
* @param crateId CSC Crate Id
* @param dmbId CSC DMB Id
* @return true if CSC was booked, false - otherwise
*/
const bool Cache::isBookedCSC(const HwId& crateId, const HwId& dmbId) const {
CSCMapType::const_iterator it = cscData.find(boost::make_tuple(crateId, dmbId));
if (it != cscData.end()) {
return true;
}
return false;
}
/**
* @brief Check if FED was booked on given identifier
* @param fedId FED Id
* @return true if FED was booked, false - otherwise
*/
const bool Cache::isBookedFED(const HwId& fedId) const {
FEDMapType::const_iterator iter = fedData.find(fedId);
return (iter != fedData.end());
}
/**
* @brief Check if DDU was booked on given identifier
* @param dduId DDU Id
* @return true if DDU was booked, false - otherwise
*/
const bool Cache::isBookedDDU(const HwId& dduId) const {
DDUMapType::const_iterator iter = dduData.find(dduId);
return (iter != dduData.end());
}
} // namespace cscdqm
|