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), mTItemsByTrigId(nullptr)
21 {}
22 
23 namespace castor_impl {
24  class LessById {public: bool operator () (const CastorElectronicsMap::PrecisionItem* a, const CastorElectronicsMap::PrecisionItem* b) {return a->mId < b->mId;}};
25  class LessByTrigId {public: bool operator () (const CastorElectronicsMap::TriggerItem* a, const CastorElectronicsMap::TriggerItem* b) {return a->mTrigId < b->mTrigId;}};
26 }
27 
29  delete mPItemsById.load();
30  delete mTItemsByTrigId.load();
31 }
32 // copy-ctor
34  : mPItems(src.mPItems), mTItems(src.mTItems),
36 // copy assignment operator
40  temp.swap(*this);
41  return *this;
42 }
43 // public swap function
45  std::swap(mPItems, other.mPItems);
46  std::swap(mTItems, other.mTItems);
47  other.mTItemsByTrigId.exchange(mTItemsByTrigId.exchange(other.mTItemsByTrigId));
48  other.mPItemsById.exchange(mPItemsById.exchange(other.mPItemsById));
49 }
50 // move constructor
53  other.swap(*this);
54 }
55 
57  PrecisionItem target (fId, 0);
58  std::vector<const CastorElectronicsMap::PrecisionItem*>::const_iterator item;
59 
60  sortById();
61 
62  item = std::lower_bound ((*mPItemsById).begin(), (*mPItemsById).end(), &target, castor_impl::LessById());
63  if (item == (*mPItemsById).end() || (*item)->mId != fId)
64  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
65  return 0;
66  return *item;
67 }
68 
70  CastorElectronicsId eid(fElId);
71  const PrecisionItem* i=&(mPItems[eid.linearIndex()]);
72 
73  if (i!=0 && i->mElId!=fElId) i=0;
74  return i;
75 }
76 
78  CastorElectronicsId eid(fElId);
79  const TriggerItem* i=&(mTItems[eid.linearIndex()]);
80 
81  if (i!=0 && i->mElId!=fElId) i=0;
82  return i;
83 }
84 
85 
87  TriggerItem target (fTrigId,0);
88  std::vector<const CastorElectronicsMap::TriggerItem*>::const_iterator item;
89 
91 
92  item = std::lower_bound ((*mTItemsByTrigId).begin(), (*mTItemsByTrigId).end(), &target, castor_impl::LessByTrigId());
93  if (item == (*mTItemsByTrigId).end() || (*item)->mTrigId != fTrigId)
94  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
95  return 0;
96  return *item;
97 }
98 
100  const PrecisionItem* item = findPByElId (fId.rawId ());
101  return DetId (item ? item->mId : 0);
102 }
103 
105  const PrecisionItem* item = findById (fId.rawId ());
106  return CastorElectronicsId (item ? item->mElId : 0);
107 }
108 
110  const TriggerItem* item = findTByElId (fId.rawId ());
111  return DetId (item ? item->mTrigId : 0);
112 }
113 
115  const TriggerItem* item = findByTrigId (fId.rawId ());
116  return CastorElectronicsId (item ? item->mElId : 0);
117 }
118 
120  const PrecisionItem* i=&(mPItems[pid.linearIndex()]);
121  if (i!=0 && i->mId!=0) {
122  eid=CastorElectronicsId(i->mElId);
123  did=HcalGenericDetId(i->mId);
124  return true;
125  } else return false;
126 }
127 
129  const TriggerItem* i=&(mTItems[pid.linearIndex()]);
130  if (i!=0 && i->mTrigId!=0) {
131  eid=CastorElectronicsId(i->mElId);
132  did=HcalGenericDetId(i->mTrigId);
133  return true;
134  } else return false;
135 }
136 
137 
138 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsId () const {
139  std::vector <CastorElectronicsId> result;
140  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
141  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
142  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
143  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
144 
145  return result;
146 }
147 
148 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsIdPrecision() const {
149  std::vector <CastorElectronicsId> result;
150  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
151  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
152  return result;
153 }
154 
155 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsIdTrigger() const {
156  std::vector <CastorElectronicsId> result;
157  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
158  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
159 
160  return result;
161 }
162 
163 std::vector <HcalGenericDetId> CastorElectronicsMap::allPrecisionId () const {
164  std::vector <HcalGenericDetId> result;
165  std::set <unsigned long> allIds;
166  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
167  if (item->mId) allIds.insert (item->mId);
168  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++) {
169  result.push_back (HcalGenericDetId (*channel));
170  }
171  return result;
172 }
173 
174 std::vector <HcalTrigTowerDetId> CastorElectronicsMap::allTriggerId () const {
175  std::vector <HcalTrigTowerDetId> result;
176  std::set <unsigned long> allIds;
177  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
178  if (item->mTrigId) allIds.insert (item->mTrigId);
179  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++)
180  result.push_back (HcalTrigTowerDetId (*channel));
181  return result;
182 }
183 
185  TriggerItem& item = mTItems[fElectronicsId.linearIndex()];
186  if (item.mElId==0) item.mElId=fElectronicsId.rawId();
187  if (item.mTrigId == 0) {
188  item.mTrigId = fTriggerId.rawId (); // just cast avoiding long machinery
189  }
190  else if (item.mTrigId != fTriggerId.rawId ()) {
191  edm::LogWarning("CASTOR") << "CastorElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId << " already mapped to trigger channel "
192  << (HcalTrigTowerDetId(item.mTrigId)) << ". New value " << fTriggerId << " is ignored" ;
193  return false;
194  }
195  return true;
196 }
197 
199  PrecisionItem& item = mPItems[fElectronicsId.linearIndex()];
200 
201  if (item.mElId==0) item.mElId=fElectronicsId.rawId();
202  if (item.mId == 0) {
203  item.mId = fId.rawId ();
204  }
205  else if (item.mId != fId.rawId ()) {
206  edm::LogWarning("CASTOR") << "CastorElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId << " already mapped to channel "
207  << HcalGenericDetId(item.mId) << ". New value " << HcalGenericDetId(fId) << " is ignored" ;
208  return false;
209  }
210  return true;
211 }
212 
214  if (!mPItemsById) {
215  auto ptr = new std::vector<const PrecisionItem*>;
216  for (auto i=mPItems.begin(); i!=mPItems.end(); ++i) {
217  if (i->mElId) (*ptr).push_back(&(*i));
218  }
219  std::sort ((*ptr).begin(), (*ptr).end(), castor_impl::LessById ());
220  //atomically try to swap this to become mPItemsById
221  std::vector<const PrecisionItem*>* expect = nullptr;
222  bool exchanged = mPItemsById.compare_exchange_strong(expect, ptr);
223  if(!exchanged) {
224  delete ptr;
225  }
226  }
227 }
228 
230  if (!mTItemsByTrigId) {
231  auto ptr = new std::vector<const TriggerItem*>;
232  for (auto i=mTItems.begin(); i!=mTItems.end(); ++i) {
233  if (i->mElId) (*ptr).push_back(&(*i));
234  }
235 
236  std::sort ((*ptr).begin(), (*ptr).end(), castor_impl::LessByTrigId ());
237  //atomically try to swap this to become mTItemsByTrigId
238  std::vector<const TriggerItem*>* expect = nullptr;
239  bool exchanged = mTItemsByTrigId.compare_exchange_strong(expect, ptr);
240  if(!exchanged) {
241  delete ptr;
242  }
243  }
244 }
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
void swap(CastorElectronicsMap &other)
#define nullptr
std::atomic< std::vector< const PrecisionItem * > * > mPItemsById
bool mapEId2tId(CastorElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:18
std::vector< HcalGenericDetId > allPrecisionId() const
double b
Definition: hdecay.h:120
std::vector< CastorElectronicsId > allElectronicsId() const
std::atomic< std::vector< const TriggerItem * > * > mTItemsByTrigId
std::vector< TriggerItem > mTItems
CastorElectronicsMap & operator=(const CastorElectronicsMap &rhs)
double a
Definition: hdecay.h:121
bool mapEId2chId(CastorElectronicsId fElectronicsId, DetId fId)
Readout chain identification for Castor Bits for the readout chain : some names need change! [31:26] ...