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
|
/**
\class HcalRawGains
\author Fedor Ratnikov (UMd)
POOL object to store Gain values 4xCapId
$Author: ratnikov
$Date: 2007/01/09 22:49:21 $
$Revision: 1.3 $
*/
#include <iostream>
#include "FWCore/Utilities/interface/Exception.h"
#include "CondFormats/HcalObjects/interface/HcalRawGains.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
namespace {
class compareItems {
public:
bool operator()(const HcalRawGains::Item& first, const HcalRawGains::Item& second) const {
return first.rawId() < second.rawId();
}
};
HcalRawGains::Container::const_iterator find(const HcalRawGains::Container& container, unsigned long id) {
HcalRawGains::Container::const_iterator result = container.begin();
for (; result != container.end(); result++) {
if (result->rawId() == id)
break; // found
}
return result;
}
} // namespace
HcalRawGains::HcalRawGains() : mSorted(false) {}
HcalRawGains::~HcalRawGains() {}
const HcalRawGain* HcalRawGains::getValues(DetId fId) const {
Item target(fId.rawId(), 0, 0, 0, HcalRawGain::BAD);
std::vector<Item>::const_iterator cell;
if (sorted()) {
cell = std::lower_bound(mItems.begin(), mItems.end(), target, compareItems());
} else {
std::cerr << "HcalRawGains::getValues-> container is not sorted. Please sort it to search effectively" << std::endl;
cell = find(mItems, fId.rawId());
}
if (cell == mItems.end() || cell->rawId() != target.rawId())
throw cms::Exception("Conditions not found")
<< "Unavailable Raw Gains for cell " << HcalGenericDetId(target.rawId());
return &(*cell);
}
std::vector<DetId> HcalRawGains::getAllChannels() const {
std::vector<DetId> result;
for (std::vector<Item>::const_iterator item = mItems.begin(); item != mItems.end(); item++) {
result.push_back(DetId(item->rawId()));
}
return result;
}
HcalRawGain* HcalRawGains::addItem(DetId fId) {
HcalRawGain item(fId.rawId());
mItems.push_back(item);
mSorted = false;
return &(mItems.back());
}
void HcalRawGains::addValues(DetId fId, const HcalRawGain& fValues) {
Item item(fId.rawId(), fValues.getValue(), fValues.getError(), fValues.getVoltage(), fValues.getStatus());
mItems.push_back(item);
mSorted = false;
}
void HcalRawGains::sort() {
if (!mSorted) {
std::sort(mItems.begin(), mItems.end(), compareItems());
mSorted = true;
}
}
|