test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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
22  find (const CastorRawGains::Container& container, unsigned long id) {
23  CastorRawGains::Container::const_iterator result = container.begin ();
24  for (; result != container.end (); result++) {
25  if (result->rawId () == id) break; // found
26  }
27  return result;
28  }
29 }
30 
32  : mSorted (false) {}
33 
35 
37  Item target (fId.rawId (), 0, 0, 0, CastorRawGain::BAD);
38  std::vector<Item>::const_iterator cell;
39  if (sorted ()) {
40  cell = std::lower_bound (mItems.begin(), mItems.end(), target, compareItems ());
41  }
42  else {
43  std::cerr << "CastorRawGains::getValues-> container is not sorted. Please sort it to search effectively" << std::endl;
44  cell = find (mItems, fId.rawId ());
45  }
46  if (cell == mItems.end() || cell->rawId () != target.rawId ())
47  throw cms::Exception ("Conditions not found") << "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 
59 
61  CastorRawGain item (fId.rawId ());
62  mItems.push_back (item);
63  mSorted = false;
64  return &(mItems.back ());
65 }
66 
67 void CastorRawGains::addValues (DetId fId, const CastorRawGain& fValues) {
68  Item item (fId.rawId (), fValues.getValue(), fValues.getError(), fValues.getVoltage(), fValues.getStatus());
69  mItems.push_back (item);
70  mSorted = false;
71 }
72 
73 
75  if (!mSorted) {
76  std::sort (mItems.begin(), mItems.end(), compareItems ());
77  mSorted = true;
78  }
79 }
Status getStatus() const
Definition: CastorRawGain.h:17
CastorRawGain * addItem(DetId fId)
add new (empty) item
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
float getValue() const
Definition: CastorRawGain.h:14
tuple result
Definition: mps_fire.py:83
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
float getVoltage() const
Definition: CastorRawGain.h:16
float getError() const
Definition: CastorRawGain.h:15
std::vector< DetId > getAllChannels() const
get list of all available channels
uint32_t rawId() const
Definition: CastorRawGain.h:30
Definition: DetId.h:18
std::vector< Item > Container
Container mItems
bool sorted() const
check if data are sorted
void sort()
sort values by channelId
const CastorRawGain * getValues(DetId fId) const
get value
volatile std::atomic< bool > shutdown_flag false
void addValues(DetId fId, const CastorRawGain &fValues)
fill values