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
CastorCondObjectContainer::getValues
const Item * getValues(DetId fId, bool throwOnFail=true) const
Definition: CastorCondObjectContainer.h:65
mps_fire.i
i
Definition: mps_fire.py:428
CastorCondObjectContainer::exists
const bool exists(DetId fId) const
Definition: CastorCondObjectContainer.h:88
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
CastorCondObjectContainer::CASTORcontainer
std::vector< Item > CASTORcontainer
Definition: CastorCondObjectContainer.h:43
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
COND_SERIALIZABLE
#define COND_SERIALIZABLE
Definition: Serializable.h:39
HcalCastorDetId::SubdetectorId
static const int SubdetectorId
Definition: HcalCastorDetId.h:28
CastorCondObjectContainer::~CastorCondObjectContainer
~CastorCondObjectContainer()
Definition: CastorCondObjectContainer.h:53
DetId::Calo
Definition: DetId.h:29
CastorCondObjectContainer::getAllChannels
std::vector< DetId > getAllChannels() const
Definition: CastorCondObjectContainer.h:119
DetId
Definition: DetId.h:17
summarizeEdmComparisonLogfiles.success
success
Definition: summarizeEdmComparisonLogfiles.py:115
CastorCondObjectContainer::initContainer
void initContainer()
Definition: CastorCondObjectContainer.h:56
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalCastorDetId
Definition: HcalCastorDetId.h:23
HcalCastorDetId::module
int module() const
get the module (1-2 for EM, 1-12 for HAD)
Definition: HcalCastorDetId.h:58
CastorCondObjectContainer::hashed_id
unsigned int hashed_id(DetId fId) const
Definition: CastorCondObjectContainer.h:131
HcalCastorDetId::zside
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalCastorDetId.h:50
CastorCondObjectContainer
Definition: CastorCondObjectContainer.h:16
Serializable.h
CastorCondObjectContainer::addValues
bool addValues(const Item &myItem)
Definition: CastorCondObjectContainer.h:98
HcalCastorDetId::sector
int sector() const
get the sector (1-16)
Definition: HcalCastorDetId.h:62
CastorCondObjectContainer::CastorCondObjectContainer
CastorCondObjectContainer()
Definition: CastorCondObjectContainer.h:50
HcalCastorDetId::kSizeForDenseIndexing
Definition: HcalCastorDetId.h:71
DetId.h
Exception
Definition: hltDiff.cc:245
ewkTauDQM_cfi.channels
channels
Definition: ewkTauDQM_cfi.py:14
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
CastorCondObjectContainer::myname
std::string myname() const
Definition: CastorCondObjectContainer.h:37
HcalCastorDetId.h