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