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 public:
18  // default constructor
20 
21  // destructor:
23 
24  // get the object back
25  const Item* getValues(DetId fId, bool throwOnFail = true) const;
26 
27  // does the object exist ?
28  const bool exists(DetId fId) const;
29 
30  // set the object/fill it in:
31  bool addValues(const Item& myItem);
32  //bool addValues(const Item& myItem, bool h2mode_=false);
33 
34  // list of available channels:
35  std::vector<DetId> getAllChannels() const;
36 
37  std::string myname() const { return (std::string) "Castor Undefined"; }
38 
39 private:
40  void initContainer();
41  unsigned int hashed_id(DetId fId) const;
42 
43  std::vector<Item> CASTORcontainer;
44 
46 };
47 
48 template <class Item>
49 //CastorCondObjectContainer<Item>::CastorCondObjectContainer(): m_h2mode(false)
51 
52 template <class Item>
54 
55 template <class Item>
57  Item emptyItem;
58 
59  if (CASTORcontainer.empty())
60  for (int i = 0; i < HcalCastorDetId::kSizeForDenseIndexing; i++)
61  CASTORcontainer.push_back(emptyItem);
62 }
63 
64 template <class Item>
65 const Item* CastorCondObjectContainer<Item>::getValues(DetId fId, bool throwOnFail) const {
66  const Item* cell = nullptr;
67  HcalCastorDetId myId(fId);
68 
69  if (fId.det() == DetId::Calo && fId.subdetId() == HcalCastorDetId::SubdetectorId) {
70  unsigned int index = hashed_id(fId);
71 
72  if (index < CASTORcontainer.size())
73  cell = &(CASTORcontainer.at(index));
74  }
75 
76  if ((!cell) || (cell->rawId() != fId)) {
77  if (throwOnFail) {
78  throw cms::Exception("Conditions not found")
79  << "Unavailable Conditions of type " << myname() << " for cell " << myId;
80  } else {
81  cell = nullptr;
82  }
83  }
84  return cell;
85 }
86 
87 template <class Item>
89  const Item* cell = getValues(fId, false);
90  if (cell)
91  // if (cell->rawId() != emptyItem.rawId() )
92  if (cell->rawId() == fId)
93  return true;
94  return false;
95 }
96 
97 template <class Item>
99  unsigned long myRawId = myItem.rawId();
100  HcalCastorDetId myId(myRawId);
101  unsigned int index = hashed_id(myId);
102  bool success = false;
103 
104  if (CASTORcontainer.empty())
105  initContainer();
106  if (index < CASTORcontainer.size()) {
107  CASTORcontainer.at(index) = myItem;
108  success = true;
109  }
110 
111  if (!success)
112  throw cms::Exception("Filling of conditions failed")
113  << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
114 
115  return success;
116 }
117 
118 template <class Item>
120  std::vector<DetId> channels;
121  Item emptyItem;
122  for (unsigned int i = 0; i < CASTORcontainer.size(); i++) {
123  if (emptyItem.rawId() != CASTORcontainer.at(i).rawId())
124  channels.push_back(DetId(CASTORcontainer.at(i).rawId()));
125  }
126 
127  return channels;
128 }
129 
130 template <class Item>
132  // the historical packing from HcalGeneric is different from HcalCastorDetId, so we clone the old packing here.
133  HcalCastorDetId tid(fId);
134  int zside = tid.zside();
135  int sector = tid.sector();
136  int module = tid.module();
137  static const int CASTORhalf = 224;
138 
139  int index = 14 * (sector - 1) + (module - 1);
140  if (zside == -1)
141  index += CASTORhalf;
142 
143  return index;
144 }
145 
146 #endif
const Item * getValues(DetId fId, bool throwOnFail=true) const
int zside(DetId const &)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
std::vector< DetId > getAllChannels() const
int module() const
get the module (1-2 for EM, 1-12 for HAD)
int zside() const
get the z-side of the cell (1/-1)
unsigned int hashed_id(DetId fId) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
int sector() const
get the sector (1-16)
static const int SubdetectorId
Definition: DetId.h:17
#define COND_SERIALIZABLE
Definition: Serializable.h:39
bool addValues(const Item &myItem)
const bool exists(DetId fId) const