CMS 3D CMS Logo

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