CMS 3D CMS Logo

HcalCondObjectContainer.h
Go to the documentation of this file.
1 #ifndef HcalCondObjectContainer_h
2 #define HcalCondObjectContainer_h
3 
6 
7 #include <vector>
13 
14 class HcalTopology;
15 
16 //#define HCAL_COND_SUPPRESS_DEFAULT
17 
19 public:
20  const HcalTopology* topo() const { return topo_; }
22  void setTopo(const HcalTopology* topo) ;
23 protected:
26 #ifndef __GCCXML__
29 #endif
30 
32  unsigned int indexFor(DetId) const;
33  unsigned int sizeFor(DetId) const;
35  inline HcalOtherSubdetector extractOther(const DetId& id) const { return HcalOtherSubdetector((id.rawId()>>20)&0x1F); }
36  std::string textForId(const DetId& id) const;
37 private:
39 
41 };
42 
43 template<class Item>
45 public:
46  // default constructor
48 
49  // destructor:
50  virtual ~HcalCondObjectContainer();
51 
52  // get the object back
53  const Item* getValues(DetId fId, bool throwOnFail=true) const;
54 
55  // does the object exist ?
56  const bool exists(DetId fId) const;
57 
58  // set the object/fill it in:
59  bool addValues(const Item& myItem);
60 
61  // list of available channels:
62  std::vector<DetId> getAllChannels() const;
63 
64  virtual std::string myname() const {return (std::string)"Hcal Undefined";}
65 
66  // setting types for easier work for getAllContainers()
67  typedef std::pair< std::string, std::vector<Item> > tHcalCont;
68  typedef std::vector< tHcalCont > tAllContWithNames;
69 
70  const tAllContWithNames getAllContainers() const{
71  tAllContWithNames allContainers;
72  allContainers.push_back(tHcalCont("HB",HBcontainer));
73  allContainers.push_back(tHcalCont("HE",HEcontainer));
74  allContainers.push_back(tHcalCont("HO",HOcontainer));
75  allContainers.push_back(tHcalCont("HF",HFcontainer));
76  allContainers.push_back(tHcalCont("HT",HTcontainer));
77  allContainers.push_back(tHcalCont("ZDC",ZDCcontainer));
78  allContainers.push_back(tHcalCont("CALIB",CALIBcontainer));
79  allContainers.push_back(tHcalCont("CASTOR",CASTORcontainer));
80  return allContainers;
81  }
82 
83  private:
84  void initContainer(DetId container);
85 
86  std::vector<Item> HBcontainer;
87  std::vector<Item> HEcontainer;
88  std::vector<Item> HOcontainer;
89  std::vector<Item> HFcontainer;
90  std::vector<Item> HTcontainer;
91  std::vector<Item> ZDCcontainer;
92  std::vector<Item> CALIBcontainer;
93  std::vector<Item> CASTORcontainer;
94 
95 
97 };
98 
99 
100 template<class Item>
102 {
103 }
104 
105 template<class Item> void
107  Item emptyItem;
108 
109  if (fId.det()==DetId::Hcal) {
110  switch (HcalSubdetector(fId.subdetId())) {
111  case HcalBarrel:
112  for (unsigned int i = 0; i < sizeFor(fId); i++) HBcontainer.push_back(emptyItem);
113  break;
114  case HcalEndcap:
115  for (unsigned int i = 0; i < sizeFor(fId); i++) HEcontainer.push_back(emptyItem);
116  break;
117  case HcalOuter:
118  for (unsigned int i = 0; i < sizeFor(fId); i++) HOcontainer.push_back(emptyItem);
119  break;
120  case HcalForward:
121  for (unsigned int i = 0; i < sizeFor(fId); i++) HFcontainer.push_back(emptyItem);
122  break;
123  case HcalTriggerTower:
124  for (unsigned int i = 0; i < sizeFor(fId); i++) HTcontainer.push_back(emptyItem);
125  break;
126  case HcalOther:
127  if (extractOther(fId) == HcalCalibration) {
128  for (unsigned int i = 0; i < sizeFor(fId); i++) CALIBcontainer.push_back(emptyItem);
129  }
130  break;
131  default:
132  break;
133  }
134  } else if (fId.det()==DetId::Calo) {
136  for (unsigned int i=0; i<sizeFor(fId); i++) CASTORcontainer.push_back(emptyItem);
137  } else if (fId.subdetId()==HcalZDCDetId::SubdetectorId) {
138  for (unsigned int i=0; i<sizeFor(fId); i++) ZDCcontainer.push_back(emptyItem);
139  }
140  }
141 }
142 
143 
144 template<class Item> const Item*
145 HcalCondObjectContainer<Item>::getValues(DetId fId, bool throwOnFail) const {
146  unsigned int index=indexFor(fId);
147 
148  const Item* cell = nullptr;
149 
150  if (index<0xFFFFFFFu) {
151  if (fId.det()==DetId::Hcal) {
152  switch (HcalSubdetector(fId.subdetId())) {
153  case HcalBarrel:
154  if (index < HBcontainer.size()) cell = &(HBcontainer.at(index));
155  break;
156  case HcalEndcap:
157  if (index < HEcontainer.size()) cell = &(HEcontainer.at(index));
158  break;
159  case HcalForward:
160  if (index < HFcontainer.size()) cell = &(HFcontainer.at(index));
161  break;
162  case HcalOuter:
163  if (index < HOcontainer.size()) cell = &(HOcontainer.at(index));
164  break;
165  case HcalTriggerTower:
166  if (index < HTcontainer.size()) cell = &(HTcontainer.at(index));
167  break;
168  case HcalOther:
169  if (extractOther(fId) == HcalCalibration && index < CALIBcontainer.size()) cell = &(CALIBcontainer.at(index));
170  break;
171  default:
172  break;
173  }
174  } else if (fId.det()==DetId::Calo) {
176  if (index < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index) );
177  } else if (fId.subdetId()==HcalZDCDetId::SubdetectorId) {
178  if (index < ZDCcontainer.size()) cell = &(ZDCcontainer.at(index) );
179  }
180  }
181  }
182 
183  if ((!cell)) {
184  if (throwOnFail) {
185  throw cms::Exception ("Conditions not found")
186  << "Unavailable Conditions of type " << myname() << " for cell " << textForId(fId);
187  }
188  } else if (!hcalEqualDetId(cell,fId)) {
189  if (throwOnFail) {
190  throw cms::Exception ("Conditions mismatch")
191  << "Requested conditions of type " << myname() << " for cell " << textForId(fId) << " got conditions for cell " << textForId(DetId(cell->rawId()));
192  }
193  cell=nullptr;
194  }
195 
196  return cell;
197 }
198 
199 template<class Item> const bool
201  const Item* cell = getValues(fId,false);
202 
203  if (cell) {
204  if (hcalEqualDetId(cell,fId))
205  return true;
206  }
207  return false;
208 }
209 
210 template<class Item> bool
212  bool success = false;
213  DetId fId(myItem.rawId());
214  unsigned int index=indexFor(fId);
215 
216  Item* cell = nullptr;
217 
218  if (index<0xFFFFFFFu) {
219  if (fId.det()==DetId::Hcal) {
220  switch (HcalSubdetector(fId.subdetId())) {
221  case HcalBarrel:
222  if (HBcontainer.empty() ) initContainer(fId);
223  if (index < HBcontainer.size()) cell = &(HBcontainer.at(index) );
224  break;
225  case HcalEndcap:
226  if (HEcontainer.empty() ) initContainer(fId);
227  if (index < HEcontainer.size()) cell = &(HEcontainer.at(index) );
228  break;
229  case HcalForward:
230  if (HFcontainer.empty() ) initContainer(fId);
231  if (index < HFcontainer.size()) cell = &(HFcontainer.at(index) );
232  break;
233  case HcalOuter:
234  if (HOcontainer.empty() ) initContainer(fId);
235  if (index < HOcontainer.size()) cell = &(HOcontainer.at(index) );
236  break;
237  case HcalTriggerTower:
238  if (HTcontainer.empty() ) initContainer(fId);
239  if (index < HTcontainer.size()) cell = &(HTcontainer.at(index) );
240  break;
241  case HcalOther:
242  if (extractOther(fId)==HcalCalibration) {
243  if (CALIBcontainer.empty() ) initContainer(fId);
244  if (index < CALIBcontainer.size()) cell = &(CALIBcontainer.at(index) );
245  }
246  break;
247  default:
248  break;
249  }
250  } else if (fId.det()==DetId::Calo) {
251  if (fId.subdetId()==HcalCastorDetId::SubdetectorId) {
252  if (CASTORcontainer.empty() ) initContainer(fId);
253  if (index < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index) );
254  } else if (fId.subdetId()==HcalZDCDetId::SubdetectorId) {
255  if (ZDCcontainer.empty() ) initContainer(fId);
256  if (index < ZDCcontainer.size()) cell = &(ZDCcontainer.at(index) );
257  }
258  }
259  }
260 
261  if (cell!=nullptr) {
262  (*cell)=myItem;
263  success=true;
264  }
265 
266  if (!success)
267  throw cms::Exception ("Filling of conditions failed")
268  << " no valid filling possible for Conditions of type " << myname() << " for DetId " << textForId(fId);
269  return success;
270 }
271 
272 template<class Item> std::vector<DetId>
274  std::vector<DetId> channels;
275  Item emptyItem;
276  for (unsigned int i=0; i<HBcontainer.size(); i++) {
277  if (emptyItem.rawId() != HBcontainer.at(i).rawId() )
278  channels.push_back( DetId(HBcontainer.at(i).rawId()) );
279  }
280  for (unsigned int i=0; i<HEcontainer.size(); i++) {
281  if (emptyItem.rawId() != HEcontainer.at(i).rawId() )
282  channels.push_back( DetId(HEcontainer.at(i).rawId()) );
283  }
284  for (unsigned int i=0; i<HOcontainer.size(); i++) {
285  if (emptyItem.rawId() != HOcontainer.at(i).rawId() )
286  channels.push_back( DetId(HOcontainer.at(i).rawId()) );
287  }
288  for (unsigned int i=0; i<HFcontainer.size(); i++) {
289  if (emptyItem.rawId() != HFcontainer.at(i).rawId() )
290  channels.push_back( DetId(HFcontainer.at(i).rawId()) );
291  }
292  for (unsigned int i=0; i<HTcontainer.size(); i++) {
293  if (emptyItem.rawId() != HTcontainer.at(i).rawId() )
294  channels.push_back( DetId(HTcontainer.at(i).rawId()) );
295  }
296  for (unsigned int i=0; i<ZDCcontainer.size(); i++) {
297  if (emptyItem.rawId() != ZDCcontainer.at(i).rawId() )
298  channels.push_back( DetId(ZDCcontainer.at(i).rawId()) );
299  }
300  for (unsigned int i=0; i<CALIBcontainer.size(); i++) {
301  if (emptyItem.rawId() != CALIBcontainer.at(i).rawId() )
302  channels.push_back( DetId(CALIBcontainer.at(i).rawId()) );
303  }
304  for (unsigned int i=0; i<CASTORcontainer.size(); i++) {
305  if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
306  channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
307  }
308 
309  return channels;
310 }
311 
312 #endif
bool hcalEqualDetId(Item *cell, const DetId &fId)
HcalCondObjectContainerBase(HcalCondObjectContainerBase const &o)
unsigned int indexFor(DetId) const
std::vector< Item > HEcontainer
std::vector< Item > HBcontainer
std::vector< Item > CASTORcontainer
const Item * getValues(DetId fId, bool throwOnFail=true) const
HcalOtherSubdetector extractOther(const DetId &id) const
unsigned int sizeFor(DetId) const
const tAllContWithNames getAllContainers() const
HcalCondObjectContainerBase & operator=(HcalCondObjectContainerBase const &o)
const bool exists(DetId fId) const
std::vector< DetId > getAllChannels() const
HcalOtherSubdetector
Definition: HcalAssistant.h:32
HcalSubdetector
Definition: HcalAssistant.h:31
std::vector< Item > ZDCcontainer
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
static const int SubdetectorId
HcalCondObjectContainer(const HcalTopology *topo)
Definition: DetId.h:18
#define COND_TRANSIENT
Definition: Serializable.h:61
static const int SubdetectorId
Definition: HcalZDCDetId.h:25
virtual std::string myname() const
#define COND_SERIALIZABLE
Definition: Serializable.h:38
std::string textForId(const DetId &id) const
std::vector< Item > HTcontainer
std::vector< Item > HOcontainer
std::vector< Item > CALIBcontainer
void initContainer(DetId container)
bool addValues(const Item &myItem)
Detector det() const
get the detector field from this detid
Definition: DetId.h:36
std::vector< Item > HFcontainer
std::pair< std::string, std::vector< Item > > tHcalCont
void setTopo(const HcalTopology *topo)
std::vector< tHcalCont > tAllContWithNames
const HcalTopology * topo() const