CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 }
Status getStatus() const
Definition: CastorRawGain.h:18
uint16_t *__restrict__ id
CastorRawGain * addItem(DetId fId)
add new (empty) item
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
float getValue() const
Definition: CastorRawGain.h:15
tuple result
Definition: mps_fire.py:311
U second(std::pair< T, U > const &p)
float getVoltage() const
Definition: CastorRawGain.h:17
float getError() const
Definition: CastorRawGain.h:16
std::vector< DetId > getAllChannels() const
get list of all available channels
uint32_t rawId() const
Definition: CastorRawGain.h:26
Definition: DetId.h:17
std::vector< Item > Container
Container mItems
bool sorted() const
check if data are sorted
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
void sort()
sort values by channelId
const CastorRawGain * getValues(DetId fId) const
get value
void addValues(DetId fId, const CastorRawGain &fValues)
fill values