CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalSiPMCharacteristics.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iostream>
3 #include <set>
4 
7 
9 
10 namespace hcal_impl {
12 }
13 
15  delete mPItemsByType.load();
16 }
17 
18 // copy-ctor
20  : mPItems(src.mPItems), mPItemsByType(nullptr) {}
21 
22 // copy assignment operator
25  temp.swap(*this);
26  return *this;
27 }
28 
29 // public swap function
31  std::swap(mPItems, other.mPItems);
32  other.mPItemsByType.exchange(mPItemsByType.exchange(other.mPItemsByType.load(std::memory_order_acquire),
33  std::memory_order_acq_rel),
34  std::memory_order_acq_rel);
35 }
36 
37 // move constructor
39  other.swap(*this);
40 }
41 
43  HcalSiPMCharacteristics::PrecisionItem target(type, 0, 0, 0, 0, 0, 0, 0);
44  std::vector<const HcalSiPMCharacteristics::PrecisionItem*>::const_iterator item;
45 
46  sortByType();
47  auto const& ptr = (*mPItemsByType.load(std::memory_order_acquire));
48  item = std::lower_bound (ptr.begin(), ptr.end(), &target, hcal_impl::LessByType());
49  if (item == ptr.end() || (*item)->type_ != type)
50  // throw cms::Exception ("Conditions not found") << "Unavailable SiPMCharacteristics for type " << type;
51  return 0;
52  return *item;
53 }
54 
55 bool HcalSiPMCharacteristics::loadObject(int type, int pixels, float parLin1,
56  float parLin2, float parLin3,
57  float crossTalk, int auxi1,
58  float auxi2) {
60  if (item) {
61  edm::LogWarning("HCAL") << "HcalSiPMCharacteristics::loadObject type "
62  << type << " already exists with pixels "
63  << item->pixels_ << " NoLinearity parameters "
64  << item->parLin1_ << ":" << item->parLin2_ << ":"
65  << item->parLin3_ << " CrossTalk parameter "
66  << item->crossTalk_ << " new values " << pixels
67  << ", " << parLin1 << ", " << parLin2 << ", "
68  << parLin3 << ", " << crossTalk << ", " << auxi1
69  << " and " << auxi2 << " are ignored";
70  return false;
71  } else {
73  parLin2,parLin3,crossTalk,
74  auxi1,auxi2);
75  mPItems.push_back(target);
76  if (mPItemsByType) {
77  delete mPItemsByType.load();
78  mPItemsByType = nullptr;
79  }
80  return true;
81  }
82 }
83 
86  return (item ? item->pixels_ : 0);
87 }
88 
89 std::vector<float> HcalSiPMCharacteristics::getNonLinearities(int type) const {
91  std::vector<float> pars;
92  if (item) {
93  pars.push_back(item->parLin1_);
94  pars.push_back(item->parLin2_);
95  pars.push_back(item->parLin3_);
96  }
97  return pars;
98 }
99 
101  const PrecisionItem* item = findByType(type);
102  return (item ? item->crossTalk_ : 0);
103 }
104 
107  return (item ? item->auxi1_ : 0);
108 }
109 
112  return (item ? item->auxi2_ : 0);
113 }
114 
116  if (!mPItemsByType.load(std::memory_order_acquire)) {
117  auto ptr = new std::vector<const PrecisionItem*>;
118  for (auto i=mPItems.begin(); i!=mPItems.end(); ++i) {
119  if (i->type_) (*ptr).push_back(&(*i));
120  }
121 
122  std::sort ((*ptr).begin(), (*ptr).end(), hcal_impl::LessByType());
123  //atomically try to swap this to become mPItemsByType
124  std::vector<const PrecisionItem*>* expect = nullptr;
125  bool exchanged = mPItemsByType.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
126  if(!exchanged) {
127  delete ptr;
128  }
129  }
130 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
std::atomic< std::vector< const PrecisionItem * > * > mPItemsByType
#define nullptr
void swap(HcalSiPMCharacteristics &other)
float getCrossTalk(int type) const
get cross talk
HcalSiPMCharacteristics & operator=(const HcalSiPMCharacteristics &rhs)
bool operator()(const HcalSiPMCharacteristics::PrecisionItem *a, const HcalSiPMCharacteristics::PrecisionItem *b)
bool loadObject(int type, int pixels, float parLin1, float parLin2, float parLin3, float crossTalk, int auxi1=0, float auxi2=0)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const PrecisionItem * findByType(int type) const
int getAuxi1(int type) const
get auxiliary words
double b
Definition: hdecay.h:120
std::vector< float > getNonLinearities(int type) const
get nonlinearity constants
double a
Definition: hdecay.h:121
float getAuxi2(int type) const
int getPixels(int type) const
get # of pixels
std::vector< PrecisionItem > mPItems