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 
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 protected:
26 #ifndef __GCCXML__
29 #endif
30 
32  unsigned int indexFor(DetId) const;
33  unsigned int sizeFor(DetId) const;
35  inline HcalOtherSubdetector extractOther(const DetId& id) const { return HcalOtherSubdetector((id.rawId()>>20)&0x1F); }
36  std::string textForId(const DetId& id) const;
37 private:
39 
41 };
42 
43 template<class Item>
45 public:
46  // default constructor
48 
49  // destructor:
50  virtual ~HcalCondObjectContainer();
51 
52  // get the object back
53  const Item* getValues(DetId fId, bool throwOnFail=true) const;
54 
55  // does the object exist ?
56  const bool exists(DetId fId) const;
57 
58  // set the object/fill it in:
59  bool addValues(const Item& myItem);
60 
61  // list of available channels:
62  std::vector<DetId> getAllChannels() const;
63 
64  virtual std::string myname() const {return (std::string)"Hcal Undefined";}
65 
66  // setting types for easier work for getAllContainers()
67  typedef std::pair< std::string, std::vector<Item> > tHcalCont;
68  typedef std::vector< tHcalCont > tAllContWithNames;
69 
71  tAllContWithNames allContainers;
72  allContainers.push_back(tHcalCont("HB",HBcontainer));
73  allContainers.push_back(tHcalCont("HE",HEcontainer));
74  allContainers.push_back(tHcalCont("HO",HOcontainer));
75  allContainers.push_back(tHcalCont("HF",HFcontainer));
76  allContainers.push_back(tHcalCont("HT",HTcontainer));
77  allContainers.push_back(tHcalCont("ZDC",ZDCcontainer));
78  allContainers.push_back(tHcalCont("CALIB",CALIBcontainer));
79  allContainers.push_back(tHcalCont("CASTOR",CASTORcontainer));
80  return allContainers;
81  }
82 
83  private:
84  void initContainer(DetId container);
85 
86  std::vector<Item> HBcontainer;
87  std::vector<Item> HEcontainer;
88  std::vector<Item> HOcontainer;
89  std::vector<Item> HFcontainer;
90  std::vector<Item> HTcontainer;
91  std::vector<Item> ZDCcontainer;
92  std::vector<Item> CALIBcontainer;
93  std::vector<Item> CASTORcontainer;
94 
95 
97 };
98 
99 
100 template<class Item>
102 {
103 }
104 
105 template<class Item> void
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*
132 HcalCondObjectContainer<Item>::getValues(DetId fId, bool throwOnFail) const {
133  unsigned int index=indexFor(fId);
134 
135  const Item* cell = NULL;
136 
137  if (index<0xFFFFFFFu) {
138  if (fId.det()==DetId::Hcal) {
139  switch (HcalSubdetector(fId.subdetId())) {
140  case(HcalBarrel) : if (index < HBcontainer.size()) cell = &(HBcontainer.at(index) ); break;
141  case(HcalEndcap) : if (index < HEcontainer.size()) cell = &(HEcontainer.at(index) ); break;
142  case(HcalForward) : if (index < HFcontainer.size()) cell = &(HFcontainer.at(index) ); break;
143  case(HcalOuter) : if (index < HOcontainer.size()) cell = &(HOcontainer.at(index) ); break;
144  case(HcalTriggerTower) : if (index < HTcontainer.size()) cell = &(HTcontainer.at(index) ); break;
145  case(HcalOther) : if (extractOther(fId)==HcalCalibration)
146  if (index < CALIBcontainer.size()) cell = &(CALIBcontainer.at(index) );
147  break;
148  default: break;
149  }
150  } else if (fId.det()==DetId::Calo) {
152  if (index < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index) );
153  } else if (fId.subdetId()==HcalZDCDetId::SubdetectorId) {
154  if (index < ZDCcontainer.size()) cell = &(ZDCcontainer.at(index) );
155  }
156  }
157  }
158 
159  if ((!cell)) {
160  if (throwOnFail) {
161  throw cms::Exception ("Conditions not found")
162  << "Unavailable Conditions of type " << myname() << " for cell " << textForId(fId);
163  }
164  } else if (!hcalEqualDetId(cell,fId)) {
165  if (throwOnFail) {
166  throw cms::Exception ("Conditions mismatch")
167  << "Requested conditions of type " << myname() << " for cell " << textForId(fId) << " got conditions for cell " << textForId(DetId(cell->rawId()));
168  }
169  cell=0;
170  }
171 
172  return cell;
173 }
174 
175 template<class Item> const bool
177  const Item* cell = getValues(fId,false);
178 
179  if (cell) {
180  if (hcalEqualDetId(cell,fId))
181  return true;
182  }
183  return false;
184 }
185 
186 template<class Item> bool
188  bool success = false;
189  DetId fId(myItem.rawId());
190  unsigned int index=indexFor(fId);
191 
192  Item* cell = NULL;
193 
194  if (index<0xFFFFFFFu) {
195  if (fId.det()==DetId::Hcal) {
196  switch (HcalSubdetector(fId.subdetId())) {
197  case(HcalBarrel) : if (!HBcontainer.size() ) initContainer(fId);
198  if (index < HBcontainer.size()) cell = &(HBcontainer.at(index) ); break;
199  case(HcalEndcap) : if (!HEcontainer.size() ) initContainer(fId);
200  if (index < HEcontainer.size()) cell = &(HEcontainer.at(index) ); break;
201  case(HcalForward) : if (!HFcontainer.size() ) initContainer(fId);
202  if (index < HFcontainer.size()) cell = &(HFcontainer.at(index) ); break;
203  case(HcalOuter) : if (!HOcontainer.size() ) initContainer(fId);
204  if (index < HOcontainer.size()) cell = &(HOcontainer.at(index) ); break;
205  case(HcalTriggerTower) : if (!HTcontainer.size() ) initContainer(fId);
206  if (index < HTcontainer.size()) cell = &(HTcontainer.at(index) ); break;
207  case(HcalOther) : if (extractOther(fId)==HcalCalibration) {
208  if (!CALIBcontainer.size() ) initContainer(fId);
209  if (index < CALIBcontainer.size()) cell = &(CALIBcontainer.at(index) );
210  }
211  break;
212  default: break;
213  }
214  } else if (fId.det()==DetId::Calo) {
215  if (fId.subdetId()==HcalCastorDetId::SubdetectorId) {
216  if (!CASTORcontainer.size() ) initContainer(fId);
217  if (index < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index) );
218  } else if (fId.subdetId()==HcalZDCDetId::SubdetectorId) {
219  if (!ZDCcontainer.size() ) initContainer(fId);
220  if (index < ZDCcontainer.size()) cell = &(ZDCcontainer.at(index) );
221  }
222  }
223  }
224 
225  if (cell!=0) {
226  (*cell)=myItem;
227  success=true;
228  }
229 
230  if (!success)
231  throw cms::Exception ("Filling of conditions failed")
232  << " no valid filling possible for Conditions of type " << myname() << " for DetId " << textForId(fId);
233  return success;
234 }
235 
236 template<class Item> std::vector<DetId>
238  std::vector<DetId> channels;
239  Item emptyItem;
240  for (unsigned int i=0; i<HBcontainer.size(); i++) {
241  if (emptyItem.rawId() != HBcontainer.at(i).rawId() )
242  channels.push_back( DetId(HBcontainer.at(i).rawId()) );
243  }
244  for (unsigned int i=0; i<HEcontainer.size(); i++) {
245  if (emptyItem.rawId() != HEcontainer.at(i).rawId() )
246  channels.push_back( DetId(HEcontainer.at(i).rawId()) );
247  }
248  for (unsigned int i=0; i<HOcontainer.size(); i++) {
249  if (emptyItem.rawId() != HOcontainer.at(i).rawId() )
250  channels.push_back( DetId(HOcontainer.at(i).rawId()) );
251  }
252  for (unsigned int i=0; i<HFcontainer.size(); i++) {
253  if (emptyItem.rawId() != HFcontainer.at(i).rawId() )
254  channels.push_back( DetId(HFcontainer.at(i).rawId()) );
255  }
256  for (unsigned int i=0; i<HTcontainer.size(); i++) {
257  if (emptyItem.rawId() != HTcontainer.at(i).rawId() )
258  channels.push_back( DetId(HTcontainer.at(i).rawId()) );
259  }
260  for (unsigned int i=0; i<ZDCcontainer.size(); i++) {
261  if (emptyItem.rawId() != ZDCcontainer.at(i).rawId() )
262  channels.push_back( DetId(ZDCcontainer.at(i).rawId()) );
263  }
264  for (unsigned int i=0; i<CALIBcontainer.size(); i++) {
265  if (emptyItem.rawId() != CALIBcontainer.at(i).rawId() )
266  channels.push_back( DetId(CALIBcontainer.at(i).rawId()) );
267  }
268  for (unsigned int i=0; i<CASTORcontainer.size(); i++) {
269  if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
270  channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
271  }
272 
273  return channels;
274 }
275 
276 #endif
bool hcalEqualDetId(Item *cell, const DetId &fId)
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