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