CMS 3D CMS Logo

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