CMS 3D CMS Logo

SiPixel2DTemplateDBObject.h
Go to the documentation of this file.
1 #ifndef CondFormats_SiPixelObjects_SiPixel2DTemplateDBObject_h
2 #define CondFormats_SiPixelObjects_SiPixel2DTemplateDBObject_h 1
3 
5 
6 #include <vector>
7 #include <map>
8 #include <cstdint>
10 
11 // ******************************************************************************************
14 // ******************************************************************************************
15 
17 public:
19  : index_(0), maxIndex_(0), numOfTempl_(1), version_(-99.9), isInvalid_(false), sVector_(0) {
20  sVector_.reserve(1000000);
21  }
23 
24  //- Allows the dbobject to be read out like cout
25  friend std::ostream& operator<<(std::ostream& s, const SiPixel2DTemplateDBObject& dbobject);
26 
27  //- Fills integer from dbobject
29  isInvalid_ = false;
30  if (index_ <= maxIndex_) {
31  i = (int)(*this).sVector_[index_];
32  index_++;
33  } else
34  (*this).setInvalid();
35  return *this;
36  }
37  //- Fills float from dbobject
39  isInvalid_ = false;
40  if (index_ <= maxIndex_) {
41  f = (*this).sVector_[index_];
42  index_++;
43  } else
44  (*this).setInvalid();
45  return *this;
46  }
47 
48  //- Functions to monitor integrity of dbobject
49  void setVersion(float version) { version_ = version; }
50  void setInvalid() { isInvalid_ = true; }
51  bool fail() { return isInvalid_; }
52 
53  //- Setter functions
54  void push_back(float entry) { sVector_.push_back(entry); }
55  void setIndex(int index) { index_ = index; }
58 
59  //- Accessor functions
60  int index() const { return index_; }
61  int maxIndex() const { return maxIndex_; }
62  int numOfTempl() const { return numOfTempl_; }
63  float version() const { return version_; }
64  std::vector<float> const& sVector() const { return sVector_; }
65 
66  //- Able to set the index for template header
67  void incrementIndex(int i) { index_ += i; }
68 
69  //- Allows storage of header (type = char[80]) in dbobject
70  union char2float {
71  char c[4];
72  float f;
73  };
74 
75  //- To be used to select template calibration based on detid
76  void putTemplateIDs(std::map<unsigned int, short>& t_ID) { templ_ID = t_ID; }
77  const std::map<unsigned int, short>& getTemplateIDs() const { return templ_ID; }
78 
79  bool putTemplateID(const uint32_t& detid, short& value) {
80  std::map<unsigned int, short>::const_iterator id = templ_ID.find(detid);
81  if (id != templ_ID.end()) {
82  edm::LogError("SiPixel2DTemplateDBObject")
83  << "2Dtemplate ID for DetID " << detid << " is already stored. Skipping this put" << std::endl;
84  return false;
85  } else
86  templ_ID[detid] = value;
87  return true;
88  }
89 
90  short getTemplateID(const uint32_t& detid) const {
91  std::map<unsigned int, short>::const_iterator id = templ_ID.find(detid);
92  if (id != templ_ID.end())
93  return id->second;
94  else
95  edm::LogError("SiPixel2DTemplateDBObject")
96  << "2Dtemplate ID for DetID " << detid << " is not stored" << std::endl;
97  return 0;
98  }
99 
100  class Reader {
101  public:
103 
104  bool fail() { return isInvalid_; }
105 
106  int index() const { return index_; }
107  //- Able to set the index for template header
108  void incrementIndex(int i) { index_ += i; }
109 
110  //- Fills integer from dbobject
111  Reader& operator>>(int& i) {
112  isInvalid_ = false;
113  if (index_ <= object_.maxIndex_) {
115  index_++;
116  } else
117  isInvalid_ = true;
118  return *this;
119  }
120  //- Fills float from dbobject
121  Reader& operator>>(float& f) {
122  isInvalid_ = false;
123  if (index_ <= object_.maxIndex_) {
125  index_++;
126  } else
127  isInvalid_ = true;
128  return *this;
129  }
130 
131  private:
133  int index_;
135  };
136  friend class Reader;
137 
138 private:
139  int index_;
142  float version_;
144  std::vector<float> sVector_;
145  std::map<unsigned int, short> templ_ID;
146 
148 }; //end SiPixel2DTemplateDBObject
149 #endif
std::vector< float > const & sVector() const
SiPixel2DTemplateDBObject const & object_
SiPixel2DTemplateDBObject & operator>>(int &i)
Log< level::Error, false > LogError
double f[11][100]
Definition: value.py:1
void putTemplateIDs(std::map< unsigned int, short > &t_ID)
friend std::ostream & operator<<(std::ostream &s, const SiPixel2DTemplateDBObject &dbobject)
#define COND_SERIALIZABLE
Definition: Serializable.h:39
short getTemplateID(const uint32_t &detid) const
std::map< unsigned int, short > templ_ID
Reader(SiPixel2DTemplateDBObject const &object)
bool putTemplateID(const uint32_t &detid, short &value)
SiPixel2DTemplateDBObject & operator>>(float &f)
const std::map< unsigned int, short > & getTemplateIDs() const