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