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) 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(int container, bool h2mode_ = false);
40  void initContainer(int container);
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
58 //CastorCondObjectContainer<Item>::initContainer(int container, bool h2mode_)
60 {
61  //m_h2mode = h2mode_;
62 
63  Item emptyItem;
64 
65  switch (container)
66  {
68  for (int i=0; i<(2*HcalGenericDetId::CASTORhalf); i++) CASTORcontainer.push_back(emptyItem); break;
69  default: break;
70  }
71 }
72 
73 
74 template<class Item> const Item*
76 {
77  HcalGenericDetId myId(fId);
78  //int index = myId.hashedId(m_h2mode);
79  int index = myId.hashedId();
80  // std::cout << "::::: getting values at index " << index << ", DetId " << myId << std::endl;
81  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
82 
83  const Item* cell = NULL;
84  if (index >= 0)
85  switch (myId.genericSubdet() ) {
87  if (index1 < CASTORcontainer.size())
88  cell = &(CASTORcontainer.at(index1) );
89  break;
90  default: break;
91  }
92 
93  // Item emptyItem;
94  // if (cell->rawId() == emptyItem.rawId() )
95  if ((!cell) || (cell->rawId() != fId ) )
96  throw cms::Exception ("Conditions not found")
97  << "Unavailable Conditions of type " << myname() << " for cell " << myId;
98  return cell;
99 }
100 
101 template<class Item> const bool
103 {
104  HcalGenericDetId myId(fId);
105  //int index = myId.hashedId(m_h2mode);
106  int index = myId.hashedId();
107  if (index < 0) return false;
108  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
109  const Item* cell = NULL;
110  switch (myId.genericSubdet() ) {
112  if (index1 < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index1) );
113  break;
114  default: return false; break;
115  }
116 
117  // Item emptyItem;
118  if (cell)
119  // if (cell->rawId() != emptyItem.rawId() )
120  if (cell->rawId() == fId )
121  return true;
122 
123  return false;
124 }
125 
126 template<class Item> bool
127 //CastorCondObjectContainer<Item>::addValues(const Item& myItem, bool h2mode_)
129 {
130  unsigned long myRawId = myItem.rawId();
131  HcalGenericDetId myId(myRawId);
132  //int index = myId.hashedId(h2mode_);
133  int index = myId.hashedId();
134  bool success = false;
135  if (index < 0) success = false;
136  unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
137 
138 
139  switch (myId.genericSubdet() ) {
141  if (!CASTORcontainer.size() ) initContainer(myId.genericSubdet() );
142  if (index1 < CASTORcontainer.size())
143  {
144  CASTORcontainer.at(index1) = myItem;
145  success = true;
146  }
147  break;
148  default: break;
149  }
150 
151  if (!success)
152  throw cms::Exception ("Filling of conditions failed")
153  << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
154 
155  return success;
156 }
157 
158 template<class Item> std::vector<DetId>
160 {
161  std::vector<DetId> channels;
162  Item emptyItem;
163  for (unsigned int i=0; i<CASTORcontainer.size(); i++)
164  {
165  if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
166  channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
167  }
168 
169  return channels;
170 }
171 
172 
173 #endif
int i
Definition: DBlmapReader.cc:9
int hashedId(bool h2mode_=false) const
std::vector< DetId > getAllChannels() const
#define abs(x)
Definition: mlp_lapack.h:159
#define NULL
Definition: scimark2.h:8
const bool exists(DetId fId) const
const Item * getValues(DetId fId) const
Definition: DetId.h:20
bool addValues(const Item &myItem)
HcalGenericSubdetector genericSubdet() const