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
SiPixelTemplateDBObject::putTemplateIDs
void putTemplateIDs(std::map< unsigned int, short > &t_ID)
Definition: SiPixelTemplateDBObject.h:117
SiPixelTemplateDBObject::Reader::numOfTempl
int numOfTempl() const
Definition: SiPixelTemplateDBObject.h:46
SiPixelTemplateDBObject::Reader::version
float version() const
Definition: SiPixelTemplateDBObject.h:47
SiPixelTemplateDBObject::reader
Reader reader() const
Definition: SiPixelTemplateDBObject.h:58
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
SiPixelTemplateDBObject::putTemplateID
bool putTemplateID(const uint32_t &detid, short &value)
Definition: SiPixelTemplateDBObject.h:120
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
mps_splice.entry
entry
Definition: mps_splice.py:68
SiPixelTemplateDBObject::Reader
Definition: SiPixelTemplateDBObject.h:18
SiPixelTemplateDBObject::version_
float version_
Definition: SiPixelTemplateDBObject.h:144
COND_SERIALIZABLE
#define COND_SERIALIZABLE
Definition: Serializable.h:39
SiPixelTemplateDBObject::char2float
Definition: SiPixelTemplateDBObject.h:111
SiPixelTemplateDBObject::Reader::sVector
std::vector< float > const & sVector() const
Definition: SiPixelTemplateDBObject.h:48
SiPixelTemplateDBObject::char2float::f
float f
Definition: SiPixelTemplateDBObject.h:113
SiPixelTemplateDBObject::Reader::isInvalid_
bool isInvalid_
Definition: SiPixelTemplateDBObject.h:54
SiPixelTemplateDBObject::fail
bool fail()
Definition: SiPixelTemplateDBObject.h:92
SiPixelTemplateDBObject::push_back
void push_back(float entry)
Definition: SiPixelTemplateDBObject.h:95
SiPixelTemplateDBObject::SiPixelTemplateDBObject
SiPixelTemplateDBObject()
Definition: SiPixelTemplateDBObject.h:60
SiPixelTemplateDBObject::Reader::operator>>
Reader & operator>>(float &f)
Definition: SiPixelTemplateDBObject.h:32
SiPixelTemplateDBObject::isInvalid_
bool isInvalid_
Definition: SiPixelTemplateDBObject.h:145
SiPixelTemplateDBObject::numOfTempl
int numOfTempl() const
Definition: SiPixelTemplateDBObject.h:103
SiPixelTemplateDBObject::setMaxIndex
void setMaxIndex(int maxIndex)
Definition: SiPixelTemplateDBObject.h:97
alignCSCRings.s
s
Definition: alignCSCRings.py:92
SiPixelTemplateDBObject::~SiPixelTemplateDBObject
virtual ~SiPixelTemplateDBObject()
Definition: SiPixelTemplateDBObject.h:63
SiPixelTemplateDBObject::index
int index() const
Definition: SiPixelTemplateDBObject.h:101
SiPixelTemplateDBObject::index_
int index_
Definition: SiPixelTemplateDBObject.h:141
SiPixelTemplateDBObject::version
float version() const
Definition: SiPixelTemplateDBObject.h:104
SiPixelTemplateDBObject::maxIndex
int maxIndex() const
Definition: SiPixelTemplateDBObject.h:102
SiPixelTemplateDBObject::operator>>
SiPixelTemplateDBObject & operator>>(float &f)
Definition: SiPixelTemplateDBObject.h:79
SiPixelTemplateDBObject::Reader::index_
int index_
Definition: SiPixelTemplateDBObject.h:53
SiPixelTemplateDBObject::maxIndex_
int maxIndex_
Definition: SiPixelTemplateDBObject.h:142
SiPixelTemplateDBObject::Reader::operator>>
Reader & operator>>(int &i)
Definition: SiPixelTemplateDBObject.h:22
SiPixelTemplateDBObject::incrementIndex
void incrementIndex(int i)
Definition: SiPixelTemplateDBObject.h:108
SiPixelTemplateDBObject::char2float::c
char c[4]
Definition: SiPixelTemplateDBObject.h:112
SiPixelTemplateDBObject::Reader::incrementIndex
void incrementIndex(int i)
Definition: SiPixelTemplateDBObject.h:51
SiPixelTemplateDBObject::Reader::fail
bool fail()
Definition: SiPixelTemplateDBObject.h:44
SiPixelTemplateDBObject::Reader::index
int index() const
Definition: SiPixelTemplateDBObject.h:45
SiPixelTemplateDBObject::getTemplateIDs
const std::map< unsigned int, short > & getTemplateIDs() const
Definition: SiPixelTemplateDBObject.h:118
SiPixelTemplateDBObject::sVector
std::vector< float > const & sVector() const
Definition: SiPixelTemplateDBObject.h:105
SiPixelTemplateDBObject::numOfTempl_
int numOfTempl_
Definition: SiPixelTemplateDBObject.h:143
SiPixelTemplateDBObject
Definition: SiPixelTemplateDBObject.h:16
createfilelist.int
int
Definition: createfilelist.py:10
Serializable.h
value
Definition: value.py:1
SiPixelTemplateDBObject::Reader::Reader
Reader(SiPixelTemplateDBObject const &idb)
Definition: SiPixelTemplateDBObject.h:19
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
SiPixelTemplateDBObject::setNumOfTempl
void setNumOfTempl(int numOfTempl)
Definition: SiPixelTemplateDBObject.h:98
SiPixelTemplateDBObject::getTemplateID
short getTemplateID(const uint32_t &detid) const
Definition: SiPixelTemplateDBObject.h:131
SiPixelTemplateDBObject::sVector_
std::vector< float > sVector_
Definition: SiPixelTemplateDBObject.h:146
SiPixelTemplateDBObject::Reader::db
SiPixelTemplateDBObject const & db
Definition: SiPixelTemplateDBObject.h:55
SiPixelTemplateDBObject::setVersion
void setVersion(float version)
Definition: SiPixelTemplateDBObject.h:90
SiPixelTemplateDBObject::Reader::setInvalid
void setInvalid()
Definition: SiPixelTemplateDBObject.h:43
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
relativeConstraints.value
value
Definition: relativeConstraints.py:53
SiPixelTemplateDBObject::operator>>
SiPixelTemplateDBObject & operator>>(int &i)
Definition: SiPixelTemplateDBObject.h:69
SiPixelTemplateDBObject::setInvalid
void setInvalid()
Definition: SiPixelTemplateDBObject.h:91
SiPixelTemplateDBObject::setIndex
void setIndex(int index)
Definition: SiPixelTemplateDBObject.h:96
SiPixelTemplateDBObject::operator<<
friend std::ostream & operator<<(std::ostream &s, const SiPixelTemplateDBObject &dbobject)
edm::Log
Definition: MessageLogger.h:70
SiPixelTemplateDBObject::templ_ID
std::map< unsigned int, short > templ_ID
Definition: SiPixelTemplateDBObject.h:147