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  sortedByPId(false),
21  sortedByTId(false)
22 {}
23 
24 namespace castor_impl {
27 }
28 
30 
32  PrecisionItem target (fId, 0);
33  std::vector<const CastorElectronicsMap::PrecisionItem*>::const_iterator item;
34 
35  if (!sortedByPId) sortById();
36 
37  item = std::lower_bound (mPItemsById.begin(), mPItemsById.end(), &target, castor_impl::LessById());
38  if (item == mPItemsById.end() || (*item)->mId != fId)
39  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
40  return 0;
41  return *item;
42 }
43 
45  CastorElectronicsId eid(fElId);
46  const PrecisionItem* i=&(mPItems[eid.linearIndex()]);
47 
48  if (i!=0 && i->mElId!=fElId) i=0;
49  return i;
50 }
51 
53  CastorElectronicsId eid(fElId);
54  const TriggerItem* i=&(mTItems[eid.linearIndex()]);
55 
56  if (i!=0 && i->mElId!=fElId) i=0;
57  return i;
58 }
59 
60 
62  TriggerItem target (fTrigId,0);
63  std::vector<const CastorElectronicsMap::TriggerItem*>::const_iterator item;
64 
66 
67  item = std::lower_bound (mTItemsByTrigId.begin(), mTItemsByTrigId.end(), &target, castor_impl::LessByTrigId());
68  if (item == mTItemsByTrigId.end() || (*item)->mTrigId != fTrigId)
69  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
70  return 0;
71  return *item;
72 }
73 
75  const PrecisionItem* item = findPByElId (fId.rawId ());
76  return DetId (item ? item->mId : 0);
77 }
78 
80  const PrecisionItem* item = findById (fId.rawId ());
81  return CastorElectronicsId (item ? item->mElId : 0);
82 }
83 
85  const TriggerItem* item = findTByElId (fId.rawId ());
86  return DetId (item ? item->mTrigId : 0);
87 }
88 
90  const TriggerItem* item = findByTrigId (fId.rawId ());
91  return CastorElectronicsId (item ? item->mElId : 0);
92 }
93 
95  const PrecisionItem* i=&(mPItems[pid.linearIndex()]);
96  if (i!=0 && i->mId!=0) {
97  eid=CastorElectronicsId(i->mElId);
98  did=HcalGenericDetId(i->mId);
99  return true;
100  } else return false;
101 }
102 
104  const TriggerItem* i=&(mTItems[pid.linearIndex()]);
105  if (i!=0 && i->mTrigId!=0) {
106  eid=CastorElectronicsId(i->mElId);
107  did=HcalGenericDetId(i->mTrigId);
108  return true;
109  } else return false;
110 }
111 
112 
113 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsId () const {
114  std::vector <CastorElectronicsId> result;
115  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
116  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
117  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
118  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
119 
120  return result;
121 }
122 
123 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsIdPrecision() const {
124  std::vector <CastorElectronicsId> result;
125  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
126  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
127  return result;
128 }
129 
130 std::vector <CastorElectronicsId> CastorElectronicsMap::allElectronicsIdTrigger() const {
131  std::vector <CastorElectronicsId> result;
132  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
133  if (item->mElId) result.push_back(CastorElectronicsId(item->mElId));
134 
135  return result;
136 }
137 
138 std::vector <HcalGenericDetId> CastorElectronicsMap::allPrecisionId () const {
139  std::vector <HcalGenericDetId> result;
140  std::set <unsigned long> allIds;
141  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
142  if (item->mId) allIds.insert (item->mId);
143  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++) {
144  result.push_back (HcalGenericDetId (*channel));
145  }
146  return result;
147 }
148 
149 std::vector <HcalTrigTowerDetId> CastorElectronicsMap::allTriggerId () const {
150  std::vector <HcalTrigTowerDetId> result;
151  std::set <unsigned long> allIds;
152  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
153  if (item->mTrigId) allIds.insert (item->mTrigId);
154  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++)
155  result.push_back (HcalTrigTowerDetId (*channel));
156  return result;
157 }
158 
160  TriggerItem& item = mTItems[fElectronicsId.linearIndex()];
161  sortedByTId=false;
162  if (item.mElId==0) item.mElId=fElectronicsId.rawId();
163  if (item.mTrigId == 0) {
164  item.mTrigId = fTriggerId.rawId (); // just cast avoiding long machinery
165  }
166  else if (item.mTrigId != fTriggerId.rawId ()) {
167  edm::LogWarning("CASTOR") << "CastorElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId << " already mapped to trigger channel "
168  << (HcalTrigTowerDetId(item.mTrigId)) << ". New value " << fTriggerId << " is ignored" ;
169  return false;
170  }
171  return true;
172 }
173 
175  PrecisionItem& item = mPItems[fElectronicsId.linearIndex()];
176 
177  sortedByPId=false;
178  if (item.mElId==0) item.mElId=fElectronicsId.rawId();
179  if (item.mId == 0) {
180  item.mId = fId.rawId ();
181  }
182  else if (item.mId != fId.rawId ()) {
183  edm::LogWarning("CASTOR") << "CastorElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId << " already mapped to channel "
184  << HcalGenericDetId(item.mId) << ". New value " << HcalGenericDetId(fId) << " is ignored" ;
185  return false;
186  }
187  return true;
188 }
189 
191  if (!sortedByPId) {
192  mPItemsById.clear();
193  for (std::vector<PrecisionItem>::const_iterator i=mPItems.begin(); i!=mPItems.end(); ++i) {
194  if (i->mElId) mPItemsById.push_back(&(*i));
195  }
196 
198  sortedByPId=true;
199  }
200 }
201 
203  if (!sortedByTId) {
204  mTItemsByTrigId.clear();
205  for (std::vector<TriggerItem>::const_iterator i=mTItems.begin(); i!=mTItems.end(); ++i) {
206  if (i->mElId) mTItemsByTrigId.push_back(&(*i));
207  }
208 
210  sortedByTId=true;
211  }
212 }
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< const TriggerItem * > mTItemsByTrigId
std::vector< CastorElectronicsId > allElectronicsIdTrigger() const
std::vector< CastorElectronicsId > allElectronicsIdPrecision() const
bool operator()(const CastorElectronicsMap::PrecisionItem *a, const CastorElectronicsMap::PrecisionItem *b)
bool mapEId2tId(CastorElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
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
std::vector< HcalTrigTowerDetId > allTriggerId() const
tuple result
Definition: query.py:137
std::vector< const PrecisionItem * > mPItemsById
uint32_t rawId() const
const PrecisionItem * findPByElId(unsigned long fElId) const
const TriggerItem * findByTrigId(unsigned long fTrigId) const
Definition: DetId.h:20
std::vector< HcalGenericDetId > allPrecisionId() const
bool operator()(const CastorElectronicsMap::TriggerItem *a, const CastorElectronicsMap::TriggerItem *b)
double b
Definition: hdecay.h:120
std::vector< CastorElectronicsId > allElectronicsId() const
std::vector< TriggerItem > mTItems
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] ...