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