CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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), mTItemsByTrigId(nullptr)
21 {}
22 
23 namespace castor_impl {
26 }
27 
29  if (mPItemsById) {
30  delete mPItemsById;
31  mPItemsById = nullptr;
32  }
33  if (mTItemsByTrigId) {
34  delete mTItemsByTrigId;
35  mTItemsByTrigId = nullptr;
36  }
37 }
38 // copy-ctor
40  : mPItems(src.mPItems), mTItems(src.mTItems),
41  mPItemsById(nullptr), mTItemsByTrigId(nullptr) {}
42 // copy assignment operator
46  temp.swap(*this);
47  return *this;
48 }
49 // public swap function
51  std::swap(mPItems, other.mPItems);
52  std::swap(mTItems, other.mTItems);
53  other.mTItemsByTrigId.exchange(mTItemsByTrigId.exchange(other.mTItemsByTrigId));
54  other.mPItemsById.exchange(mPItemsById.exchange(other.mPItemsById));
55 }
56 // move constructor
59  other.swap(*this);
60 }
61 
63  PrecisionItem target (fId, 0);
64  std::vector<const CastorElectronicsMap::PrecisionItem*>::const_iterator item;
65 
66  sortById();
67 
68  item = std::lower_bound ((*mPItemsById).begin(), (*mPItemsById).end(), &target, castor_impl::LessById());
69  if (item == (*mPItemsById).end() || (*item)->mId != fId)
70  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
71  return 0;
72  return *item;
73 }
74 
76  CastorElectronicsId eid(fElId);
77  const PrecisionItem* i=&(mPItems[eid.linearIndex()]);
78 
79  if (i!=0 && i->mElId!=fElId) i=0;
80  return i;
81 }
82 
84  CastorElectronicsId eid(fElId);
85  const TriggerItem* i=&(mTItems[eid.linearIndex()]);
86 
87  if (i!=0 && i->mElId!=fElId) i=0;
88  return i;
89 }
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 0;
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 
126  const PrecisionItem* i=&(mPItems[pid.linearIndex()]);
127  if (i!=0 && i->mId!=0) {
128  eid=CastorElectronicsId(i->mElId);
129  did=HcalGenericDetId(i->mId);
130  return true;
131  } else return false;
132 }
133 
135  const TriggerItem* i=&(mTItems[pid.linearIndex()]);
136  if (i!=0 && i->mTrigId!=0) {
137  eid=CastorElectronicsId(i->mElId);
138  did=HcalGenericDetId(i->mTrigId);
139  return true;
140  } else return false;
141 }
142 
143 
144 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsId () const {
145  std::vector <CastorElectronicsId> result;
146  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
147  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
148  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
149  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
150 
151  return result;
152 }
153 
154 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsIdPrecision() const {
155  std::vector <CastorElectronicsId> result;
156  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
157  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
158  return result;
159 }
160 
161 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsIdTrigger() const {
162  std::vector <CastorElectronicsId> result;
163  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
164  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
165 
166  return result;
167 }
168 
169 std::vector <HcalGenericDetId> CastorElectronicsMap::allPrecisionId () const {
170  std::vector <HcalGenericDetId> result;
171  std::set <unsigned long> allIds;
172  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
173  if (item->mId) allIds.insert (item->mId);
174  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++) {
175  result.push_back (HcalGenericDetId (*channel));
176  }
177  return result;
178 }
179 
180 std::vector <HcalTrigTowerDetId> CastorElectronicsMap::allTriggerId () const {
181  std::vector <HcalTrigTowerDetId> result;
182  std::set <unsigned long> allIds;
183  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
184  if (item->mTrigId) allIds.insert (item->mTrigId);
185  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++)
186  result.push_back (HcalTrigTowerDetId (*channel));
187  return result;
188 }
189 
191  TriggerItem& item = mTItems[fElectronicsId.linearIndex()];
192  if (item.mElId==0) item.mElId=fElectronicsId.rawId();
193  if (item.mTrigId == 0) {
194  item.mTrigId = fTriggerId.rawId (); // just cast avoiding long machinery
195  }
196  else if (item.mTrigId != fTriggerId.rawId ()) {
197  edm::LogWarning("CASTOR") << "CastorElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId << " already mapped to trigger channel "
198  << (HcalTrigTowerDetId(item.mTrigId)) << ". New value " << fTriggerId << " is ignored" ;
199  return false;
200  }
201  return true;
202 }
203 
205  PrecisionItem& item = mPItems[fElectronicsId.linearIndex()];
206 
207  if (item.mElId==0) item.mElId=fElectronicsId.rawId();
208  if (item.mId == 0) {
209  item.mId = fId.rawId ();
210  }
211  else if (item.mId != fId.rawId ()) {
212  edm::LogWarning("CASTOR") << "CastorElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId << " already mapped to channel "
213  << HcalGenericDetId(item.mId) << ". New value " << HcalGenericDetId(fId) << " is ignored" ;
214  return false;
215  }
216  return true;
217 }
218 
220  if (!mPItemsById) {
221  auto ptr = new std::vector<const PrecisionItem*>;
222  for (auto i=mPItems.begin(); i!=mPItems.end(); ++i) {
223  if (i->mElId) (*ptr).push_back(&(*i));
224  }
225  std::sort ((*ptr).begin(), (*ptr).end(), castor_impl::LessById ());
226  //atomically try to swap this to become mPItemsById
227  std::vector<const PrecisionItem*>* expect = nullptr;
228  bool exchanged = mPItemsById.compare_exchange_strong(expect, ptr);
229  if(!exchanged) {
230  delete ptr;
231  }
232  }
233 }
234 
236  if (!mTItemsByTrigId) {
237  auto ptr = new std::vector<const TriggerItem*>;
238  for (auto i=mTItems.begin(); i!=mTItems.end(); ++i) {
239  if (i->mElId) (*ptr).push_back(&(*i));
240  }
241 
242  std::sort ((*ptr).begin(), (*ptr).end(), castor_impl::LessByTrigId ());
243  //atomically try to swap this to become mTItemsByTrigId
244  std::vector<const TriggerItem*>* expect = nullptr;
245  bool exchanged = mTItemsByTrigId.compare_exchange_strong(expect, ptr);
246  if(!exchanged) {
247  delete ptr;
248  }
249  }
250 }
int i
Definition: DBlmapReader.cc:9
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)
#define nullptr
void swap(CastorElectronicsMap &other)
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
tuple result
Definition: query.py:137
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
bool operator()(const CastorElectronicsMap::TriggerItem *a, const CastorElectronicsMap::TriggerItem *b)
tuple pid
Definition: sysUtil.py:22
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] ...