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