CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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> 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 private:
101  int index_;
104  float version_;
106  std::vector<float> sVector_;
107  std::map<unsigned int, short> templ_ID;
108 
110 }; //end SiPixel2DTemplateDBObject
111 #endif
std::vector< float > sVector() const
SiPixel2DTemplateDBObject & operator>>(int &i)
Log< level::Error, false > LogError
const std::map< unsigned int, short > & getTemplateIDs() const
void putTemplateIDs(std::map< unsigned int, short > &t_ID)
short getTemplateID(const uint32_t &detid) const
friend std::ostream & operator<<(std::ostream &s, const SiPixel2DTemplateDBObject &dbobject)
#define COND_SERIALIZABLE
Definition: Serializable.h:39
std::map< unsigned int, short > templ_ID
list entry
Definition: mps_splice.py:68
bool putTemplateID(const uint32_t &detid, short &value)
SiPixel2DTemplateDBObject & operator>>(float &f)