CMS 3D CMS Logo

CastorCondObjectContainer.h
Go to the documentation of this file.
1 #ifndef CastorCondObjectContainer_h
2 #define CastorCondObjectContainer_h
3 //
4 //Adapted for CASTOR by L. Mundim
5 //
7 
8 #include <iostream>
9 #include <vector>
13 #include <cstdlib>
14 
15 template<class Item>
17 {
18  public:
19  // default constructor
21 
22  // destructor:
24 
25  // get the object back
26  const Item* getValues(DetId fId, bool throwOnFail=true) const;
27 
28  // does the object exist ?
29  const bool exists(DetId fId) const;
30 
31  // set the object/fill it in:
32  bool addValues(const Item& myItem);
33  //bool addValues(const Item& myItem, bool h2mode_=false);
34 
35  // list of available channels:
36  std::vector<DetId> getAllChannels() const;
37 
38  std::string myname() const {return (std::string)"Castor Undefined";}
39 
40  private:
41  void initContainer();
42  unsigned int hashed_id(DetId fId) const;
43 
44  std::vector<Item> CASTORcontainer;
45 
47 };
48 
49 
50 template<class Item>
51 //CastorCondObjectContainer<Item>::CastorCondObjectContainer(): m_h2mode(false)
53 {
54 }
55 
56 template<class Item>
58 {
59 }
60 
61 template<class Item> void
63 {
64  Item emptyItem;
65 
66  if (CASTORcontainer.empty())
68  CASTORcontainer.push_back(emptyItem);
69 
70 }
71 
72 
73 template<class Item> const Item*
75 {
76  const Item* cell = NULL;
77  HcalCastorDetId myId(fId);
78 
80  unsigned int index = hashed_id(fId);
81 
82  if (index < CASTORcontainer.size())
83  cell = &(CASTORcontainer.at(index) );
84  }
85 
86 
87  if ((!cell) || (cell->rawId() != fId ) ) {
88  if (throwOnFail) {
89  throw cms::Exception ("Conditions not found")
90  << "Unavailable Conditions of type " << myname() << " for cell " << myId;
91  } else {
92  cell=0;
93  }
94  }
95  return cell;
96 }
97 
98 template<class Item> const bool
100 {
101  const Item* cell = getValues(fId,false);
102  if (cell)
103  // if (cell->rawId() != emptyItem.rawId() )
104  if (cell->rawId() == fId )
105  return true;
106  return false;
107 }
108 
109 template<class Item> bool
111 {
112  unsigned long myRawId = myItem.rawId();
113  HcalCastorDetId myId(myRawId);
114  unsigned int index = hashed_id(myId);
115  bool success = false;
116 
117 
118  if (CASTORcontainer.empty() ) initContainer();
119  if (index < CASTORcontainer.size())
120  {
121  CASTORcontainer.at(index) = myItem;
122  success = true;
123  }
124 
125 
126  if (!success)
127  throw cms::Exception ("Filling of conditions failed")
128  << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
129 
130  return success;
131 }
132 
133 template<class Item> std::vector<DetId>
135 {
136  std::vector<DetId> channels;
137  Item emptyItem;
138  for (unsigned int i=0; i<CASTORcontainer.size(); i++)
139  {
140  if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
141  channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
142  }
143 
144  return channels;
145 }
146 
147 
148 template<class Item>
150  // the historical packing from HcalGeneric is different from HcalCastorDetId, so we clone the old packing here.
151  HcalCastorDetId tid(fId);
152  int zside = tid.zside();
153  int sector = tid.sector();
154  int module = tid.module();
155  static const int CASTORhalf=224;
156 
157  int index = 14*(sector-1) + (module-1);
158  if (zside == -1) index += CASTORhalf;
159 
160  return index;
161 }
162 
163 #endif
int sector() const
get the sector (1-16)
std::vector< DetId > getAllChannels() const
#define NULL
Definition: scimark2.h:8
int module() const
get the module (1-2 for EM, 1-12 for HAD)
const Item * getValues(DetId fId, bool throwOnFail=true) const
const bool exists(DetId fId) const
unsigned int hashed_id(DetId fId) const
int zside() const
get the z-side of the cell (1/-1)
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
Definition: DetId.h:18
#define COND_SERIALIZABLE
Definition: Serializable.h:38
bool addValues(const Item &myItem)
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
Definition: vlib.h:208