CMS 3D CMS Logo

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