CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <stdint.h>
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  {
24  isInvalid_ = false;
25  if(index_<=db.maxIndex()) {
26  i = (int) db.sVector()[index_];
27  index_++;
28  }
29  else
30  setInvalid();
31  return *this;
32  }
33  //- Fills float from dbobject
34  Reader & operator>>( float& f)
35  {
36  isInvalid_ = false;
37  if(index_<=db.maxIndex()) {
38  f = db.sVector()[index_];
39  index_++;
40  }
41  else
42  setInvalid();
43  return *this;
44  }
45 
46 
47 
48  //- Functions to monitor integrity of dbobject
49  void setInvalid() {isInvalid_ = true;}
50  bool fail() {return isInvalid_;}
51  int index() const {return index_;}
52  int numOfTempl() const {return db.numOfTempl();}
53  float version() const {return db.version();}
54  std::vector<float> const & sVector() const {return db.sVector();}
55 
56 
57  //- Able to set the index for template header
58  void incrementIndex(int i) {index_+=i;}
59 
60  int index_;
61  bool isInvalid_;
63  };
64 
65  Reader reader() const { return Reader(*this);}
66 
68  sVector_.reserve(1000000);
69  }
71 
72  //- Allows the dbobject to be read out like cout
73  friend std::ostream& operator<<(std::ostream& s, const SiPixelTemplateDBObject& dbobject);
74 
75  //- Fills integer from dbobject
77  {
78  isInvalid_ = false;
79  if(index_<=maxIndex_) {
80  i = (int) (*this).sVector_[index_];
81  index_++;
82  }
83  else
84  (*this).setInvalid();
85  return *this;
86  }
87  //- Fills float from dbobject
89  {
90  isInvalid_ = false;
91  if(index_<=maxIndex_) {
92  f = (*this).sVector_[index_];
93  index_++;
94  }
95  else
96  (*this).setInvalid();
97  return *this;
98  }
99 
100  //- Functions to monitor integrity of dbobject
102  void setInvalid() {isInvalid_ = true;}
103  bool fail() {return isInvalid_;}
104 
105  //- Setter functions
106  void push_back(float entry) {sVector_.push_back(entry);}
107  void setIndex(int index) {index_ = index;}
110 
111  //- Accessor functions
112  int index() const {return index_;}
113  int maxIndex() const {return maxIndex_;}
114  int numOfTempl() const {return numOfTempl_;}
115  float version() const {return version_;}
116  std::vector<float> const & sVector() const {return sVector_;}
117 
118  //- Able to set the index for template header
119  void incrementIndex(int i) {index_+=i;}
120 
121  //- Allows storage of header (type = char[80]) in dbobject
123  {
124  char c[4];
125  float f;
126  };
127 
128  //- To be used to select template calibration based on detid
129  void putTemplateIDs(std::map<unsigned int,short>& t_ID) {templ_ID = t_ID;}
130  const std::map<unsigned int,short>& getTemplateIDs () const {return templ_ID;}
131 
132  bool putTemplateID(const uint32_t& detid, short& value)
133  {
134  std::map<unsigned int,short>::const_iterator id=templ_ID.find(detid);
135  if(id!=templ_ID.end()){
136  edm::LogError("SiPixelTemplateDBObject") << "Template ID for DetID " << detid
137  << " is already stored. Skipping this put" << std::endl;
138  return false;
139  }
140  else templ_ID[detid] = value;
141  return true;
142  }
143 
144  short getTemplateID(const uint32_t& detid) const
145  {
146  std::map<unsigned int,short>::const_iterator id=templ_ID.find(detid);
147  if(id!=templ_ID.end()) return id->second;
148  else edm::LogError("SiPixelTemplateDBObject") << "Template ID for DetID " << detid
149  << " is not stored" << std::endl;
150  return 0;
151  }
152 
153 private:
154  int index_;
157  float version_;
159  std::vector<float> sVector_;
160  std::map<unsigned int,short> templ_ID;
161 
163 };//end SiPixelTemplateDBObject
164 #endif
void putTemplateIDs(std::map< unsigned int, short > &t_ID)
int i
Definition: DBlmapReader.cc:9
bool putTemplateID(const uint32_t &detid, short &value)
short getTemplateID(const uint32_t &detid) const
SiPixelTemplateDBObject const & db
Reader(SiPixelTemplateDBObject const &idb)
SiPixelTemplateDBObject & operator>>(float &f)
double f[11][100]
std::map< unsigned int, short > templ_ID
void setNumOfTempl(int numOfTempl)
const std::map< unsigned int, short > & getTemplateIDs() const
#define COND_SERIALIZABLE
Definition: Serializable.h:37
SiPixelTemplateDBObject & operator>>(int &i)
list entry
Definition: mps_splice.py:62
std::vector< float > const & sVector() const
volatile std::atomic< bool > shutdown_flag false
friend std::ostream & operator<<(std::ostream &s, const SiPixelTemplateDBObject &dbobject)
std::vector< float > const & sVector() const