CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CastorElectronicsMap.cc
Go to the documentation of this file.
1 
11 #include <iostream>
12 #include <set>
13 
16 
18  : mPItems(CastorElectronicsId::maxLinearIndex + 1),
19  mTItems(CastorElectronicsId::maxLinearIndex + 1),
20  mPItemsById(nullptr),
21  mTItemsByTrigId(nullptr) {}
22 
23 namespace castor_impl {
24  class LessById {
25  public:
27  return a->mId < b->mId;
28  }
29  };
30  class LessByTrigId {
31  public:
33  return a->mTrigId < b->mTrigId;
34  }
35  };
36 } // namespace castor_impl
37 
39  delete mPItemsById.load();
40  delete mTItemsByTrigId.load();
41 }
42 // copy-ctor
44  : mPItems(src.mPItems), mTItems(src.mTItems), mPItemsById(nullptr), mTItemsByTrigId(nullptr) {}
45 // copy assignment operator
48  temp.swap(*this);
49  return *this;
50 }
51 // public swap function
53  std::swap(mPItems, other.mPItems);
54  std::swap(mTItems, other.mTItems);
55  other.mTItemsByTrigId.exchange(mTItemsByTrigId.exchange(other.mTItemsByTrigId));
56  other.mPItemsById.exchange(mPItemsById.exchange(other.mPItemsById));
57 }
58 // move constructor
60 
62  PrecisionItem target(fId, 0);
63  std::vector<const CastorElectronicsMap::PrecisionItem*>::const_iterator item;
64 
65  sortById();
66 
67  item = std::lower_bound((*mPItemsById).begin(), (*mPItemsById).end(), &target, castor_impl::LessById());
68  if (item == (*mPItemsById).end() || (*item)->mId != fId)
69  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
70  return nullptr;
71  return *item;
72 }
73 
75  CastorElectronicsId eid(fElId);
76  const PrecisionItem* i = &(mPItems[eid.linearIndex()]);
77 
78  if (i != nullptr && i->mElId != fElId)
79  i = nullptr;
80  return i;
81 }
82 
84  CastorElectronicsId eid(fElId);
85  const TriggerItem* i = &(mTItems[eid.linearIndex()]);
86 
87  if (i != nullptr && i->mElId != fElId)
88  i = nullptr;
89  return i;
90 }
91 
93  TriggerItem target(fTrigId, 0);
94  std::vector<const CastorElectronicsMap::TriggerItem*>::const_iterator item;
95 
97 
98  item = std::lower_bound((*mTItemsByTrigId).begin(), (*mTItemsByTrigId).end(), &target, castor_impl::LessByTrigId());
99  if (item == (*mTItemsByTrigId).end() || (*item)->mTrigId != fTrigId)
100  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
101  return nullptr;
102  return *item;
103 }
104 
106  const PrecisionItem* item = findPByElId(fId.rawId());
107  return DetId(item ? item->mId : 0);
108 }
109 
111  const PrecisionItem* item = findById(fId.rawId());
112  return CastorElectronicsId(item ? item->mElId : 0);
113 }
114 
116  const TriggerItem* item = findTByElId(fId.rawId());
117  return DetId(item ? item->mTrigId : 0);
118 }
119 
121  const TriggerItem* item = findByTrigId(fId.rawId());
122  return CastorElectronicsId(item ? item->mElId : 0);
123 }
124 
127  HcalGenericDetId& did) const {
128  const PrecisionItem* i = &(mPItems[pid.linearIndex()]);
129  if (i != nullptr && i->mId != 0) {
130  eid = CastorElectronicsId(i->mElId);
131  did = HcalGenericDetId(i->mId);
132  return true;
133  } else
134  return false;
135 }
136 
139  HcalTrigTowerDetId& did) const {
140  const TriggerItem* i = &(mTItems[pid.linearIndex()]);
141  if (i != nullptr && i->mTrigId != 0) {
142  eid = CastorElectronicsId(i->mElId);
143  did = HcalGenericDetId(i->mTrigId);
144  return true;
145  } else
146  return false;
147 }
148 
149 std::vector<CastorElectronicsId> CastorElectronicsMap::allElectronicsId() const {
150  std::vector<CastorElectronicsId> result;
151  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
152  if (item->mElId)
153  result.push_back(CastorElectronicsId(item->mElId));
154  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
155  if (item->mElId)
156  result.push_back(CastorElectronicsId(item->mElId));
157 
158  return result;
159 }
160 
161 std::vector<CastorElectronicsId> CastorElectronicsMap::allElectronicsIdPrecision() const {
162  std::vector<CastorElectronicsId> result;
163  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
164  if (item->mElId)
165  result.push_back(CastorElectronicsId(item->mElId));
166  return result;
167 }
168 
169 std::vector<CastorElectronicsId> CastorElectronicsMap::allElectronicsIdTrigger() const {
170  std::vector<CastorElectronicsId> result;
171  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
172  if (item->mElId)
173  result.push_back(CastorElectronicsId(item->mElId));
174 
175  return result;
176 }
177 
178 std::vector<HcalGenericDetId> CastorElectronicsMap::allPrecisionId() const {
179  std::vector<HcalGenericDetId> result;
180  std::set<unsigned long> allIds;
181  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
182  if (item->mId)
183  allIds.insert(item->mId);
184  for (std::set<unsigned long>::const_iterator channel = allIds.begin(); channel != allIds.end(); channel++) {
185  result.push_back(HcalGenericDetId(*channel));
186  }
187  return result;
188 }
189 
190 std::vector<HcalTrigTowerDetId> CastorElectronicsMap::allTriggerId() const {
191  std::vector<HcalTrigTowerDetId> result;
192  std::set<unsigned long> allIds;
193  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
194  if (item->mTrigId)
195  allIds.insert(item->mTrigId);
196  for (std::set<unsigned long>::const_iterator channel = allIds.begin(); channel != allIds.end(); channel++)
197  result.push_back(HcalTrigTowerDetId(*channel));
198  return result;
199 }
200 
202  TriggerItem& item = mTItems[fElectronicsId.linearIndex()];
203  if (item.mElId == 0)
204  item.mElId = fElectronicsId.rawId();
205  if (item.mTrigId == 0) {
206  item.mTrigId = fTriggerId.rawId(); // just cast avoiding long machinery
207  } else if (item.mTrigId != fTriggerId.rawId()) {
208  edm::LogWarning("CASTOR") << "CastorElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId
209  << " already mapped to trigger channel " << (HcalTrigTowerDetId(item.mTrigId))
210  << ". New value " << fTriggerId << " is ignored";
211  return false;
212  }
213  return true;
214 }
215 
217  PrecisionItem& item = mPItems[fElectronicsId.linearIndex()];
218 
219  if (item.mElId == 0)
220  item.mElId = fElectronicsId.rawId();
221  if (item.mId == 0) {
222  item.mId = fId.rawId();
223  } else if (item.mId != fId.rawId()) {
224  edm::LogWarning("CASTOR") << "CastorElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId
225  << " already mapped to channel " << HcalGenericDetId(item.mId) << ". New value "
226  << HcalGenericDetId(fId) << " is ignored";
227  return false;
228  }
229  return true;
230 }
231 
233  if (!mPItemsById) {
234  auto ptr = new std::vector<const PrecisionItem*>;
235  for (auto i = mPItems.begin(); i != mPItems.end(); ++i) {
236  if (i->mElId)
237  (*ptr).push_back(&(*i));
238  }
239  std::sort((*ptr).begin(), (*ptr).end(), castor_impl::LessById());
240  //atomically try to swap this to become mPItemsById
241  std::vector<const PrecisionItem*>* expect = nullptr;
242  bool exchanged = mPItemsById.compare_exchange_strong(expect, ptr);
243  if (!exchanged) {
244  delete ptr;
245  }
246  }
247 }
248 
250  if (!mTItemsByTrigId) {
251  auto ptr = new std::vector<const TriggerItem*>;
252  for (auto i = mTItems.begin(); i != mTItems.end(); ++i) {
253  if (i->mElId)
254  (*ptr).push_back(&(*i));
255  }
256 
257  std::sort((*ptr).begin(), (*ptr).end(), castor_impl::LessByTrigId());
258  //atomically try to swap this to become mTItemsByTrigId
259  std::vector<const TriggerItem*>* expect = nullptr;
260  bool exchanged = mTItemsByTrigId.compare_exchange_strong(expect, ptr);
261  if (!exchanged) {
262  delete ptr;
263  }
264  }
265 }
std::vector< PrecisionItem > mPItems
const DetId lookupTrigger(CastorElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
std::vector< CastorElectronicsId > allElectronicsIdTrigger() const
std::vector< CastorElectronicsId > allElectronicsIdPrecision() const
bool operator()(const CastorElectronicsMap::PrecisionItem *a, const CastorElectronicsMap::PrecisionItem *b)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void swap(CastorElectronicsMap &other)
std::atomic< std::vector< const PrecisionItem * > * > mPItemsById
bool mapEId2tId(CastorElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
tuple result
Definition: mps_fire.py:311
const PrecisionItem * findById(unsigned long fId) const
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
const TriggerItem * findTByElId(unsigned long fElId) const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::vector< HcalTrigTowerDetId > allTriggerId() const
uint32_t rawId() const
const PrecisionItem * findPByElId(unsigned long fElId) const
const TriggerItem * findByTrigId(unsigned long fTrigId) const
Definition: DetId.h:17
std::vector< HcalGenericDetId > allPrecisionId() const
bool operator()(const CastorElectronicsMap::TriggerItem *a, const CastorElectronicsMap::TriggerItem *b)
double b
Definition: hdecay.h:118
std::vector< CastorElectronicsId > allElectronicsId() const
std::atomic< std::vector< const TriggerItem * > * > mTItemsByTrigId
std::vector< TriggerItem > mTItems
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
CastorElectronicsMap & operator=(const CastorElectronicsMap &rhs)
double a
Definition: hdecay.h:119
bool mapEId2chId(CastorElectronicsId fElectronicsId, DetId fId)
Readout chain identification for Castor Bits for the readout chain : some names need change! [31:26] ...
Log< level::Warning, false > LogWarning