CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalCondObjectContainer.h
Go to the documentation of this file.
1 #ifndef HcalCondObjectContainer_h
2 #define HcalCondObjectContainer_h
3 
4 
5 #include <iostream>
6 #include <vector>
10 
11 template<class Item>
13 {
14  public:
15  // default constructor
17 
18  // destructor:
19  virtual ~HcalCondObjectContainer();
20 
21  // get the object back
22  const Item* getValues(DetId fId) const;
23 
24  // does the object exist ?
25  const bool exists(DetId fId) const;
26 
27  // set the object/fill it in:
28  bool addValues(const Item& myItem, bool h2mode_=false);
29 
30  // list of available channels:
31  std::vector<DetId> getAllChannels() const;
32 
33  virtual std::string myname() const {return (std::string)"Hcal Undefined";}
34 
35  // setting types for easier work for getAllContainers()
36  typedef std::pair< std::string, std::vector<Item> > tHcalCont;
37  typedef std::vector< tHcalCont > tAllContWithNames;
38 
40  tAllContWithNames allContainers;
41  allContainers.push_back(tHcalCont("HB",HBcontainer));
42  allContainers.push_back(tHcalCont("HE",HEcontainer));
43  allContainers.push_back(tHcalCont("HO",HOcontainer));
44  allContainers.push_back(tHcalCont("HF",HFcontainer));
45  allContainers.push_back(tHcalCont("HT",HTcontainer));
46  allContainers.push_back(tHcalCont("ZDC",ZDCcontainer));
47  allContainers.push_back(tHcalCont("CALIB",CALIBcontainer));
48  allContainers.push_back(tHcalCont("CASTOR",CASTORcontainer));
49  return allContainers;
50  }
51 
52  private:
53  void initContainer(int container, bool h2mode_ = false);
54 
55  // bool m_h2mode;
56 
57  std::vector<Item> HBcontainer;
58  std::vector<Item> HEcontainer;
59  std::vector<Item> HOcontainer;
60  std::vector<Item> HFcontainer;
61  std::vector<Item> HTcontainer;
62  std::vector<Item> ZDCcontainer;
63  std::vector<Item> CALIBcontainer;
64  std::vector<Item> CASTORcontainer;
65 };
66 
67 
68 template<class Item>
70 //: m_h2mode(false)
71 {
72 }
73 
74 template<class Item>
76 {
77 }
78 
79 template<class Item> void
81 {
82  // if (!m_h2mode) m_h2mode = h2mode_;
83 
84  Item emptyItem;
85 
86  switch (container)
87  {
89  for (int i=0; i<(2*HcalGenericDetId::HBhalf); i++) HBcontainer.push_back(emptyItem); break;
91  if (!h2mode_) for (int i=0; i<(2*HcalGenericDetId::HEhalf); i++) HEcontainer.push_back(emptyItem);
92  else for (int i=0; i<(2*HcalGenericDetId::HEhalfh2mode); i++) HEcontainer.push_back(emptyItem);
93  break;
95  for (int i=0; i<(2*HcalGenericDetId::HOhalf); i++) HOcontainer.push_back(emptyItem); break;
97  for (int i=0; i<(2*HcalGenericDetId::HFhalf); i++) HFcontainer.push_back(emptyItem); break;
99  for (int i=0; i<(2*HcalGenericDetId::HThalf); i++) HTcontainer.push_back(emptyItem); break;
101  for (int i=0; i<(2*HcalGenericDetId::ZDChalf); i++) ZDCcontainer.push_back(emptyItem); break;
103  for (int i=0; i<(2*HcalGenericDetId::CALIBhalf); i++) CALIBcontainer.push_back(emptyItem); break;
105  for (int i=0; i<(2*HcalGenericDetId::CASTORhalf); i++) CASTORcontainer.push_back(emptyItem); break;
106  default: break;
107  }
108 }
109 
110 
111 template<class Item> const Item*
113 {
114  HcalGenericDetId myId(fId);
115  bool h2mode_ = (HEcontainer.size()==(2*HcalGenericDetId::HEhalfh2mode));
116 
117  int index = myId.hashedId(h2mode_);
118  // std::cout << "::::: getting values at index " << index << ", DetId " << myId << std::endl;
119  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
120 
121  const Item* cell = NULL;
122  if (index >= 0)
123  switch (myId.genericSubdet() ) {
125  if (index1 < HBcontainer.size())
126  cell = &(HBcontainer.at(index1) );
127  break;
129  if (index1 < HEcontainer.size())
130  cell = &(HEcontainer.at(index1) );
131  break;
133  if (index1 < HOcontainer.size())
134  cell = &(HOcontainer.at(index1) );
135  break;
137  if (index1 < HFcontainer.size())
138  cell = &(HFcontainer.at(index1) );
139  break;
141  if (index1 < HTcontainer.size())
142  cell = &(HTcontainer.at(index1) );
143  break;
145  if (index1 < ZDCcontainer.size())
146  cell = &(ZDCcontainer.at(index1) );
147  break;
149  if (index1 < CASTORcontainer.size())
150  cell = &(CASTORcontainer.at(index1) );
151  break;
153  if (index1 < CALIBcontainer.size())
154  cell = &(CALIBcontainer.at(index1) );
155  break;
156  default: break;
157  }
158 
159  // Item emptyItem;
160  // if (cell->rawId() == emptyItem.rawId() )
161  if ((!cell) || (cell->rawId() != fId ) )
162  throw cms::Exception ("Conditions not found")
163  << "Unavailable Conditions of type " << myname() << " for cell " << myId;
164  return cell;
165 }
166 
167 template<class Item> const bool
169 {
170  HcalGenericDetId myId(fId);
171  bool h2mode_ = (HEcontainer.size()==(2*HcalGenericDetId::HEhalfh2mode));
172 
173  int index = myId.hashedId(h2mode_);
174  if (index < 0) return false;
175  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
176  const Item* cell = NULL;
177  switch (myId.genericSubdet() ) {
179  if (index1 < HBcontainer.size()) cell = &(HBcontainer.at(index1) );
180  break;
182  if (index1 < HEcontainer.size()) cell = &(HEcontainer.at(index1) );
183  break;
185  if (index1 < HOcontainer.size()) cell = &(HOcontainer.at(index1) );
186  break;
188  if (index1 < HFcontainer.size()) cell = &(HFcontainer.at(index1) );
189  break;
191  if (index1 < HTcontainer.size()) cell = &(HTcontainer.at(index1) );
192  break;
194  if (index1 < ZDCcontainer.size()) cell = &(ZDCcontainer.at(index1) );
195  break;
197  if (index1 < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index1) );
198  break;
200  if (index1 < CALIBcontainer.size()) cell = &(CALIBcontainer.at(index1) );
201  break;
202  default: return false; break;
203  }
204 
205  // Item emptyItem;
206  if (cell)
207  // if (cell->rawId() != emptyItem.rawId() )
208  if (cell->rawId() == fId )
209  return true;
210 
211  return false;
212 }
213 
214 template<class Item> bool
215 HcalCondObjectContainer<Item>::addValues(const Item& myItem, bool h2mode_)
216 {
217  unsigned long myRawId = myItem.rawId();
218  HcalGenericDetId myId(myRawId);
219  int index = myId.hashedId(h2mode_);
220  bool success = false;
221  if (index < 0) success = false;
222  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
223 
224  switch (myId.genericSubdet() ) {
226  if (!HBcontainer.size() ) initContainer(myId.genericSubdet() );
227  if (index1 < HBcontainer.size())
228  {
229  HBcontainer.at(index1) = myItem;
230  success = true;
231  }
232  break;
234  if (!HEcontainer.size() ) initContainer(myId.genericSubdet(), h2mode_ );
235  if (index1 < HEcontainer.size())
236  {
237  HEcontainer.at(index1) = myItem;
238  success = true;
239  }
240  break;
242  if (!HOcontainer.size() ) initContainer(myId.genericSubdet() );
243  if (index1 < HOcontainer.size())
244  {
245  HOcontainer.at(index1) = myItem;
246  success = true;
247  }
248  break;
250  if (!HFcontainer.size() ) initContainer(myId.genericSubdet() );
251  if (index1 < HFcontainer.size())
252  {
253  HFcontainer.at(index1) = myItem;
254  success = true;
255  }
256  break;
258  if (!HTcontainer.size() ) initContainer(myId.genericSubdet() );
259  if (index1 < HTcontainer.size())
260  {
261  HTcontainer.at(index1) = myItem;
262  success = true;
263  }
264  break;
266  if (!ZDCcontainer.size() ) initContainer(myId.genericSubdet() );
267  if (index1 < ZDCcontainer.size())
268  {
269  ZDCcontainer.at(index1) = myItem;
270  success = true;
271  }
272  break;
274  if (!CASTORcontainer.size() ) initContainer(myId.genericSubdet() );
275  if (index1 < CASTORcontainer.size())
276  {
277  CASTORcontainer.at(index1) = myItem;
278  success = true;
279  }
280  break;
282  if (!CALIBcontainer.size() ) initContainer(myId.genericSubdet() );
283  if (index1 < CALIBcontainer.size())
284  {
285  CALIBcontainer.at(index1) = myItem;
286  success = true;
287  }
288  break;
289  default: break;
290  }
291 
292  if (!success)
293  throw cms::Exception ("Filling of conditions failed")
294  << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
295  return success;
296 }
297 
298 template<class Item> std::vector<DetId>
300 {
301  std::vector<DetId> channels;
302  Item emptyItem;
303  for (unsigned int i=0; i<HBcontainer.size(); i++)
304  {
305  if (emptyItem.rawId() != HBcontainer.at(i).rawId() )
306  channels.push_back( DetId(HBcontainer.at(i).rawId()) );
307  }
308  for (unsigned int i=0; i<HEcontainer.size(); i++)
309  {
310  if (emptyItem.rawId() != HEcontainer.at(i).rawId() )
311  channels.push_back( DetId(HEcontainer.at(i).rawId()) );
312  }
313  for (unsigned int i=0; i<HOcontainer.size(); i++)
314  {
315  if (emptyItem.rawId() != HOcontainer.at(i).rawId() )
316  channels.push_back( DetId(HOcontainer.at(i).rawId()) );
317  }
318  for (unsigned int i=0; i<HFcontainer.size(); i++)
319  {
320  if (emptyItem.rawId() != HFcontainer.at(i).rawId() )
321  channels.push_back( DetId(HFcontainer.at(i).rawId()) );
322  }
323  for (unsigned int i=0; i<HTcontainer.size(); i++)
324  {
325  if (emptyItem.rawId() != HTcontainer.at(i).rawId() )
326  channels.push_back( DetId(HTcontainer.at(i).rawId()) );
327  }
328  for (unsigned int i=0; i<ZDCcontainer.size(); i++)
329  {
330  if (emptyItem.rawId() != ZDCcontainer.at(i).rawId() )
331  channels.push_back( DetId(ZDCcontainer.at(i).rawId()) );
332  }
333  for (unsigned int i=0; i<CALIBcontainer.size(); i++)
334  {
335  if (emptyItem.rawId() != CALIBcontainer.at(i).rawId() )
336  channels.push_back( DetId(CALIBcontainer.at(i).rawId()) );
337  }
338  for (unsigned int i=0; i<CASTORcontainer.size(); i++)
339  {
340  if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
341  channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
342  }
343 
344  return channels;
345 }
346 
347 
348 #endif
int i
Definition: DBlmapReader.cc:9
bool addValues(const Item &myItem, bool h2mode_=false)
int hashedId(bool h2mode_=false) const
std::vector< Item > HEcontainer
std::vector< Item > HBcontainer
#define abs(x)
Definition: mlp_lapack.h:159
#define NULL
Definition: scimark2.h:8
std::vector< Item > CASTORcontainer
void initContainer(int container, bool h2mode_=false)
const tAllContWithNames getAllContainers() const
const bool exists(DetId fId) const
std::vector< DetId > getAllChannels() const
std::vector< Item > ZDCcontainer
Definition: DetId.h:20
virtual std::string myname() const
std::vector< Item > HTcontainer
std::vector< Item > HOcontainer
HcalGenericSubdetector genericSubdet() const
std::vector< Item > CALIBcontainer
const Item * getValues(DetId fId) const
std::vector< Item > HFcontainer
std::pair< std::string, std::vector< Item > > tHcalCont
std::vector< tHcalCont > tAllContWithNames