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