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 #include <cstdlib>
11 
12 template<class Item>
14 {
15  public:
16  // default constructor
18 
19  // destructor:
20  virtual ~HcalCondObjectContainer();
21 
22  // get the object back
23  const Item* getValues(DetId fId) const;
24 
25  // does the object exist ?
26  const bool exists(DetId fId) const;
27 
28  // set the object/fill it in:
29  bool addValues(const Item& myItem, bool h2mode_=false);
30 
31  // list of available channels:
32  std::vector<DetId> getAllChannels() const;
33 
34  virtual std::string myname() const {return (std::string)"Hcal Undefined";}
35 
36  // setting types for easier work for getAllContainers()
37  typedef std::pair< std::string, std::vector<Item> > tHcalCont;
38  typedef std::vector< tHcalCont > tAllContWithNames;
39 
41  tAllContWithNames allContainers;
42  allContainers.push_back(tHcalCont("HB",HBcontainer));
43  allContainers.push_back(tHcalCont("HE",HEcontainer));
44  allContainers.push_back(tHcalCont("HO",HOcontainer));
45  allContainers.push_back(tHcalCont("HF",HFcontainer));
46  allContainers.push_back(tHcalCont("HT",HTcontainer));
47  allContainers.push_back(tHcalCont("ZDC",ZDCcontainer));
48  allContainers.push_back(tHcalCont("CALIB",CALIBcontainer));
49  allContainers.push_back(tHcalCont("CASTOR",CASTORcontainer));
50  return allContainers;
51  }
52 
53  private:
54  void initContainer(int container, bool h2mode_ = false);
55 
56  // bool m_h2mode;
57 
58  std::vector<Item> HBcontainer;
59  std::vector<Item> HEcontainer;
60  std::vector<Item> HOcontainer;
61  std::vector<Item> HFcontainer;
62  std::vector<Item> HTcontainer;
63  std::vector<Item> ZDCcontainer;
64  std::vector<Item> CALIBcontainer;
65  std::vector<Item> CASTORcontainer;
66 };
67 
68 
69 template<class Item>
71 //: m_h2mode(false)
72 {
73 }
74 
75 template<class Item>
77 {
78 }
79 
80 template<class Item> void
82 {
83  // if (!m_h2mode) m_h2mode = h2mode_;
84 
85  Item emptyItem;
86 
87  switch (container)
88  {
90  for (int i=0; i<(2*HcalGenericDetId::HBhalf); i++) HBcontainer.push_back(emptyItem); break;
92  if (!h2mode_) for (int i=0; i<(2*HcalGenericDetId::HEhalf); i++) HEcontainer.push_back(emptyItem);
93  else for (int i=0; i<(2*HcalGenericDetId::HEhalfh2mode); i++) HEcontainer.push_back(emptyItem);
94  break;
96  for (int i=0; i<(2*HcalGenericDetId::HOhalf); i++) HOcontainer.push_back(emptyItem); break;
98  for (int i=0; i<(2*HcalGenericDetId::HFhalf); i++) HFcontainer.push_back(emptyItem); break;
100  for (int i=0; i<(2*HcalGenericDetId::HThalf); i++) HTcontainer.push_back(emptyItem); break;
102  for (int i=0; i<(2*HcalGenericDetId::ZDChalf); i++) ZDCcontainer.push_back(emptyItem); break;
104  for (int i=0; i<(2*HcalGenericDetId::CALIBhalf); i++) CALIBcontainer.push_back(emptyItem); break;
106  for (int i=0; i<(2*HcalGenericDetId::CASTORhalf); i++) CASTORcontainer.push_back(emptyItem); break;
107  default: break;
108  }
109 }
110 
111 
112 template<class Item> const Item*
114 {
115  HcalGenericDetId myId(fId);
116  bool h2mode_ = (HEcontainer.size()==(2*HcalGenericDetId::HEhalfh2mode));
117 
118  int index = myId.hashedId(h2mode_);
119  // std::cout << "::::: getting values at index " << index << ", DetId " << myId << std::endl;
120  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
121 
122  const Item* cell = NULL;
123  if (index >= 0)
124  switch (myId.genericSubdet() ) {
126  if (index1 < HBcontainer.size())
127  cell = &(HBcontainer.at(index1) );
128  break;
130  if (index1 < HEcontainer.size())
131  cell = &(HEcontainer.at(index1) );
132  break;
134  if (index1 < HOcontainer.size())
135  cell = &(HOcontainer.at(index1) );
136  break;
138  if (index1 < HFcontainer.size())
139  cell = &(HFcontainer.at(index1) );
140  break;
142  if (index1 < HTcontainer.size())
143  cell = &(HTcontainer.at(index1) );
144  break;
146  if (index1 < ZDCcontainer.size())
147  cell = &(ZDCcontainer.at(index1) );
148  break;
150  if (index1 < CASTORcontainer.size())
151  cell = &(CASTORcontainer.at(index1) );
152  break;
154  if (index1 < CALIBcontainer.size())
155  cell = &(CALIBcontainer.at(index1) );
156  break;
157  default: break;
158  }
159 
160  // Item emptyItem;
161  // if (cell->rawId() == emptyItem.rawId() )
162  if ((!cell) || (cell->rawId() != fId ) )
163  throw cms::Exception ("Conditions not found")
164  << "Unavailable Conditions of type " << myname() << " for cell " << myId;
165  return cell;
166 }
167 
168 template<class Item> const bool
170 {
171  HcalGenericDetId myId(fId);
172  bool h2mode_ = (HEcontainer.size()==(2*HcalGenericDetId::HEhalfh2mode));
173 
174  int index = myId.hashedId(h2mode_);
175  if (index < 0) return false;
176  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
177  const Item* cell = NULL;
178  switch (myId.genericSubdet() ) {
180  if (index1 < HBcontainer.size()) cell = &(HBcontainer.at(index1) );
181  break;
183  if (index1 < HEcontainer.size()) cell = &(HEcontainer.at(index1) );
184  break;
186  if (index1 < HOcontainer.size()) cell = &(HOcontainer.at(index1) );
187  break;
189  if (index1 < HFcontainer.size()) cell = &(HFcontainer.at(index1) );
190  break;
192  if (index1 < HTcontainer.size()) cell = &(HTcontainer.at(index1) );
193  break;
195  if (index1 < ZDCcontainer.size()) cell = &(ZDCcontainer.at(index1) );
196  break;
198  if (index1 < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index1) );
199  break;
201  if (index1 < CALIBcontainer.size()) cell = &(CALIBcontainer.at(index1) );
202  break;
203  default: return false; break;
204  }
205 
206  // Item emptyItem;
207  if (cell)
208  // if (cell->rawId() != emptyItem.rawId() )
209  if (cell->rawId() == fId )
210  return true;
211 
212  return false;
213 }
214 
215 template<class Item> bool
216 HcalCondObjectContainer<Item>::addValues(const Item& myItem, bool h2mode_)
217 {
218  unsigned long myRawId = myItem.rawId();
219  HcalGenericDetId myId(myRawId);
220  int index = myId.hashedId(h2mode_);
221  bool success = false;
222  if (index < 0) success = false;
223  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
224 
225  switch (myId.genericSubdet() ) {
227  if (!HBcontainer.size() ) initContainer(myId.genericSubdet() );
228  if (index1 < HBcontainer.size())
229  {
230  HBcontainer.at(index1) = myItem;
231  success = true;
232  }
233  break;
235  if (!HEcontainer.size() ) initContainer(myId.genericSubdet(), h2mode_ );
236  if (index1 < HEcontainer.size())
237  {
238  HEcontainer.at(index1) = myItem;
239  success = true;
240  }
241  break;
243  if (!HOcontainer.size() ) initContainer(myId.genericSubdet() );
244  if (index1 < HOcontainer.size())
245  {
246  HOcontainer.at(index1) = myItem;
247  success = true;
248  }
249  break;
251  if (!HFcontainer.size() ) initContainer(myId.genericSubdet() );
252  if (index1 < HFcontainer.size())
253  {
254  HFcontainer.at(index1) = myItem;
255  success = true;
256  }
257  break;
259  if (!HTcontainer.size() ) initContainer(myId.genericSubdet() );
260  if (index1 < HTcontainer.size())
261  {
262  HTcontainer.at(index1) = myItem;
263  success = true;
264  }
265  break;
267  if (!ZDCcontainer.size() ) initContainer(myId.genericSubdet() );
268  if (index1 < ZDCcontainer.size())
269  {
270  ZDCcontainer.at(index1) = myItem;
271  success = true;
272  }
273  break;
275  if (!CASTORcontainer.size() ) initContainer(myId.genericSubdet() );
276  if (index1 < CASTORcontainer.size())
277  {
278  CASTORcontainer.at(index1) = myItem;
279  success = true;
280  }
281  break;
283  if (!CALIBcontainer.size() ) initContainer(myId.genericSubdet() );
284  if (index1 < CALIBcontainer.size())
285  {
286  CALIBcontainer.at(index1) = myItem;
287  success = true;
288  }
289  break;
290  default: break;
291  }
292 
293  if (!success)
294  throw cms::Exception ("Filling of conditions failed")
295  << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
296  return success;
297 }
298 
299 template<class Item> std::vector<DetId>
301 {
302  std::vector<DetId> channels;
303  Item emptyItem;
304  for (unsigned int i=0; i<HBcontainer.size(); i++)
305  {
306  if (emptyItem.rawId() != HBcontainer.at(i).rawId() )
307  channels.push_back( DetId(HBcontainer.at(i).rawId()) );
308  }
309  for (unsigned int i=0; i<HEcontainer.size(); i++)
310  {
311  if (emptyItem.rawId() != HEcontainer.at(i).rawId() )
312  channels.push_back( DetId(HEcontainer.at(i).rawId()) );
313  }
314  for (unsigned int i=0; i<HOcontainer.size(); i++)
315  {
316  if (emptyItem.rawId() != HOcontainer.at(i).rawId() )
317  channels.push_back( DetId(HOcontainer.at(i).rawId()) );
318  }
319  for (unsigned int i=0; i<HFcontainer.size(); i++)
320  {
321  if (emptyItem.rawId() != HFcontainer.at(i).rawId() )
322  channels.push_back( DetId(HFcontainer.at(i).rawId()) );
323  }
324  for (unsigned int i=0; i<HTcontainer.size(); i++)
325  {
326  if (emptyItem.rawId() != HTcontainer.at(i).rawId() )
327  channels.push_back( DetId(HTcontainer.at(i).rawId()) );
328  }
329  for (unsigned int i=0; i<ZDCcontainer.size(); i++)
330  {
331  if (emptyItem.rawId() != ZDCcontainer.at(i).rawId() )
332  channels.push_back( DetId(ZDCcontainer.at(i).rawId()) );
333  }
334  for (unsigned int i=0; i<CALIBcontainer.size(); i++)
335  {
336  if (emptyItem.rawId() != CALIBcontainer.at(i).rawId() )
337  channels.push_back( DetId(CALIBcontainer.at(i).rawId()) );
338  }
339  for (unsigned int i=0; i<CASTORcontainer.size(); i++)
340  {
341  if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
342  channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
343  }
344 
345  return channels;
346 }
347 
348 
349 #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