CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 //
6 #include <iostream>
7 #include <vector>
11 #include <cstdlib>
12 
13 template<class Item>
15 {
16  public:
17  // default constructor
19 
20  // destructor:
22 
23  // get the object back
24  const Item* getValues(DetId fId, bool throwOnFail=true) const;
25 
26  // does the object exist ?
27  const bool exists(DetId fId) const;
28 
29  // set the object/fill it in:
30  bool addValues(const Item& myItem);
31  //bool addValues(const Item& myItem, bool h2mode_=false);
32 
33  // list of available channels:
34  std::vector<DetId> getAllChannels() const;
35 
36  std::string myname() const {return (std::string)"Castor Undefined";}
37 
38  private:
39  void initContainer();
40  unsigned int hashed_id(DetId fId) const;
41 
42  std::vector<Item> CASTORcontainer;
43 };
44 
45 
46 template<class Item>
47 //CastorCondObjectContainer<Item>::CastorCondObjectContainer(): m_h2mode(false)
49 {
50 }
51 
52 template<class Item>
54 {
55 }
56 
57 template<class Item> void
59 {
60  Item emptyItem;
61 
62  if (CASTORcontainer.empty())
64  CASTORcontainer.push_back(emptyItem);
65 
66 }
67 
68 
69 template<class Item> const Item*
71 {
72  const Item* cell = NULL;
73  HcalCastorDetId myId(fId);
74 
76  unsigned int index = hashed_id(fId);
77 
78  if (index < CASTORcontainer.size())
79  cell = &(CASTORcontainer.at(index) );
80  }
81 
82 
83  if ((!cell) || (cell->rawId() != fId ) ) {
84  if (throwOnFail) {
85  throw cms::Exception ("Conditions not found")
86  << "Unavailable Conditions of type " << myname() << " for cell " << myId;
87  } else {
88  cell=0;
89  }
90  }
91  return cell;
92 }
93 
94 template<class Item> const bool
96 {
97  const Item* cell = getValues(fId,false);
98  if (cell)
99  // if (cell->rawId() != emptyItem.rawId() )
100  if (cell->rawId() == fId )
101  return true;
102  return false;
103 }
104 
105 template<class Item> bool
107 {
108  unsigned long myRawId = myItem.rawId();
109  HcalCastorDetId myId(myRawId);
110  unsigned int index = hashed_id(myId);
111  bool success = false;
112 
113 
114  if (CASTORcontainer.empty() ) initContainer();
115  if (index < CASTORcontainer.size())
116  {
117  CASTORcontainer.at(index) = myItem;
118  success = true;
119  }
120 
121 
122  if (!success)
123  throw cms::Exception ("Filling of conditions failed")
124  << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
125 
126  return success;
127 }
128 
129 template<class Item> std::vector<DetId>
131 {
132  std::vector<DetId> channels;
133  Item emptyItem;
134  for (unsigned int i=0; i<CASTORcontainer.size(); i++)
135  {
136  if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
137  channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
138  }
139 
140  return channels;
141 }
142 
143 
144 template<class Item>
146  // the historical packing from HcalGeneric is different from HcalCastorDetId, so we clone the old packing here.
147  HcalCastorDetId tid(fId);
148  int zside = tid.zside();
149  int sector = tid.sector();
150  int module = tid.module();
151  static const int CASTORhalf=224;
152 
153  int index = 14*(sector-1) + (module-1);
154  if (zside == -1) index += CASTORhalf;
155 
156  return index;
157 }
158 
159 #endif
int i
Definition: DBlmapReader.cc:9
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
bool addValues(const Item &myItem)
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
Definition: vlib.h:208