CMS 3D CMS Logo

HcalRawGains.cc
Go to the documentation of this file.
1 
10 #include <iostream>
11 
15 
16 namespace {
17  class compareItems {
18  public:
19  bool operator()(const HcalRawGains::Item& first, const HcalRawGains::Item& second) const {
20  return first.rawId() < second.rawId();
21  }
22  };
23 
24  HcalRawGains::Container::const_iterator find(const HcalRawGains::Container& container, unsigned long id) {
25  HcalRawGains::Container::const_iterator result = container.begin();
26  for (; result != container.end(); result++) {
27  if (result->rawId() == id)
28  break; // found
29  }
30  return result;
31  }
32 } // namespace
33 
35 
37 
39  Item target(fId.rawId(), 0, 0, 0, HcalRawGain::BAD);
40  std::vector<Item>::const_iterator cell;
41  if (sorted()) {
42  cell = std::lower_bound(mItems.begin(), mItems.end(), target, compareItems());
43  } else {
44  std::cerr << "HcalRawGains::getValues-> container is not sorted. Please sort it to search effectively" << std::endl;
45  cell = find(mItems, fId.rawId());
46  }
47  if (cell == mItems.end() || cell->rawId() != target.rawId())
48  throw cms::Exception("Conditions not found")
49  << "Unavailable Raw Gains for cell " << HcalGenericDetId(target.rawId());
50  return &(*cell);
51 }
52 
53 std::vector<DetId> HcalRawGains::getAllChannels() const {
54  std::vector<DetId> result;
55  for (std::vector<Item>::const_iterator item = mItems.begin(); item != mItems.end(); item++) {
56  result.push_back(DetId(item->rawId()));
57  }
58  return result;
59 }
60 
62  HcalRawGain item(fId.rawId());
63  mItems.push_back(item);
64  mSorted = false;
65  return &(mItems.back());
66 }
67 
68 void HcalRawGains::addValues(DetId fId, const HcalRawGain& fValues) {
69  Item item(fId.rawId(), fValues.getValue(), fValues.getError(), fValues.getVoltage(), fValues.getStatus());
70  mItems.push_back(item);
71  mSorted = false;
72 }
73 
75  if (!mSorted) {
76  std::sort(mItems.begin(), mItems.end(), compareItems());
77  mSorted = true;
78  }
79 }
std::vector< DetId > getAllChannels() const
get list of all available channels
Definition: HcalRawGains.cc:53
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool sorted() const
check if data are sorted
Definition: HcalRawGains.h:29
U second(std::pair< T, U > const &p)
float getVoltage() const
Definition: HcalRawGain.h:20
float getError() const
Definition: HcalRawGain.h:19
std::vector< Item > Container
Definition: HcalRawGains.h:38
Container mItems
Definition: HcalRawGains.h:41
const HcalRawGain * getValues(DetId fId) const
get value
Definition: HcalRawGains.cc:38
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HcalRawGain * addItem(DetId fId)
add new (empty) item
Definition: HcalRawGains.cc:61
Status getStatus() const
Definition: HcalRawGain.h:21
float getValue() const
Definition: HcalRawGain.h:18
void addValues(DetId fId, const HcalRawGain &fValues)
fill values
Definition: HcalRawGains.cc:68
void sort()
sort values by channelId
Definition: HcalRawGains.cc:74