CMS 3D CMS Logo

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 }
CastorElectronicsMap::operator=
CastorElectronicsMap & operator=(const CastorElectronicsMap &rhs)
Definition: CastorElectronicsMap.cc:46
castor_impl::LessByTrigId::operator()
bool operator()(const CastorElectronicsMap::TriggerItem *a, const CastorElectronicsMap::TriggerItem *b)
Definition: CastorElectronicsMap.cc:32
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
HcalGenericDetId
Definition: HcalGenericDetId.h:15
CastorElectronicsId::linearIndex
int linearIndex() const
Definition: CastorElectronicsId.h:47
CastorElectronicsMap::sortById
void sortById() const
Definition: CastorElectronicsMap.cc:232
CastorElectronicsMap::findByTrigId
const TriggerItem * findByTrigId(unsigned long fTrigId) const
Definition: CastorElectronicsMap.cc:92
castor_impl::LessById
Definition: CastorElectronicsMap.cc:24
CastorElectronicsMap::allTriggerId
std::vector< HcalTrigTowerDetId > allTriggerId() const
Definition: CastorElectronicsMap.cc:190
CastorElectronicsMap::findById
const PrecisionItem * findById(unsigned long fId) const
Definition: CastorElectronicsMap.cc:61
CastorElectronicsMap::TriggerItem
Definition: CastorElectronicsMap.h:89
CastorElectronicsMap.h
CastorElectronicsMap::findPByElId
const PrecisionItem * findPByElId(unsigned long fElId) const
Definition: CastorElectronicsMap.cc:74
CastorElectronicsId
Readout chain identification for Castor Bits for the readout chain : some names need change!...
Definition: CastorElectronicsId.h:20
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CastorElectronicsMap::CastorElectronicsMap
CastorElectronicsMap()
Definition: CastorElectronicsMap.cc:17
DetId
Definition: DetId.h:17
castor_impl::LessByTrigId
Definition: CastorElectronicsMap.cc:30
CastorElectronicsMap::swap
void swap(CastorElectronicsMap &other)
Definition: CastorElectronicsMap.cc:52
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
CastorElectronicsMap::mapEId2tId
bool mapEId2tId(CastorElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
Definition: CastorElectronicsMap.cc:201
CastorElectronicsMap::~CastorElectronicsMap
~CastorElectronicsMap()
Definition: CastorElectronicsMap.cc:38
trackingPlots.other
other
Definition: trackingPlots.py:1467
b
double b
Definition: hdecay.h:118
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
CastorElectronicsMap::mTItems
std::vector< TriggerItem > mTItems
Definition: CastorElectronicsMap.h:106
a
double a
Definition: hdecay.h:119
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
CastorElectronicsId::rawId
uint32_t rawId() const
Definition: CastorElectronicsId.h:29
castor_impl
Definition: CastorElectronicsMap.cc:23
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
CastorElectronicsMap::allElectronicsIdPrecision
std::vector< CastorElectronicsId > allElectronicsIdPrecision() const
Definition: CastorElectronicsMap.cc:161
CastorElectronicsMap::findTByElId
const TriggerItem * findTByElId(unsigned long fElId) const
Definition: CastorElectronicsMap.cc:83
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CastorElectronicsMap::lookup
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
Definition: CastorElectronicsMap.cc:105
CastorElectronicsMap::allElectronicsIdTrigger
std::vector< CastorElectronicsId > allElectronicsIdTrigger() const
Definition: CastorElectronicsMap.cc:169
filterCSVwithJSON.target
target
Definition: filterCSVwithJSON.py:32
CastorElectronicsMap::lookupTrigger
const DetId lookupTrigger(CastorElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Definition: CastorElectronicsMap.cc:115
CastorElectronicsMap::mapEId2chId
bool mapEId2chId(CastorElectronicsId fElectronicsId, DetId fId)
Definition: CastorElectronicsMap.cc:216
CastorElectronicsMap
Definition: CastorElectronicsMap.h:30
mps_fire.result
result
Definition: mps_fire.py:311
CastorElectronicsMap::mPItemsById
std::atomic< std::vector< const PrecisionItem * > * > mPItemsById
Definition: CastorElectronicsMap.h:108
castor_impl::LessById::operator()
bool operator()(const CastorElectronicsMap::PrecisionItem *a, const CastorElectronicsMap::PrecisionItem *b)
Definition: CastorElectronicsMap.cc:26
CastorElectronicsMap::sortByTriggerId
void sortByTriggerId() const
Definition: CastorElectronicsMap.cc:249
CastorElectronicsMap::mPItems
std::vector< PrecisionItem > mPItems
Definition: CastorElectronicsMap.h:105
CastorElectronicsMap::allPrecisionId
std::vector< HcalGenericDetId > allPrecisionId() const
Definition: CastorElectronicsMap.cc:178
CastorElectronicsMap::allElectronicsId
std::vector< CastorElectronicsId > allElectronicsId() const
Definition: CastorElectronicsMap.cc:149
CastorElectronicsMap::PrecisionItem
Definition: CastorElectronicsMap.h:80
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14
CastorElectronicsMap::mTItemsByTrigId
std::atomic< std::vector< const TriggerItem * > * > mTItemsByTrigId
Definition: CastorElectronicsMap.h:109