CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CondFormats/SiPixelObjects/interface/SiPixelTemplateDBObject.h

Go to the documentation of this file.
00001 #ifndef CondFormats_SiPixelObjects_SiPixelTemplateDBObject_h
00002 #define CondFormats_SiPixelObjects_SiPixelTemplateDBObject_h 1
00003 
00004 #include <vector>
00005 #include <map>
00006 #include <stdint.h>
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 // ******************************************************************************************
00012 // ******************************************************************************************
00013 
00014 class SiPixelTemplateDBObject {
00015 public:
00016         SiPixelTemplateDBObject():index_(0),maxIndex_(0),numOfTempl_(1),version_(-99.9),isInvalid_(false),sVector_(0) {
00017                 sVector_.reserve(1000000);
00018         }
00019         virtual ~SiPixelTemplateDBObject(){}
00020         
00021         //- Allows the dbobject to be read out like cout
00022         friend std::ostream& operator<<(std::ostream& s, const SiPixelTemplateDBObject& dbobject);
00023 
00024         //- Fills integer from dbobject
00025         SiPixelTemplateDBObject& operator>>( int& i)
00026                 {
00027                         isInvalid_ = false;
00028                         if(index_<=maxIndex_) {
00029                                 i = (int) (*this).sVector_[index_];
00030                                 index_++;
00031                         }
00032                         else
00033                                 (*this).setInvalid();
00034                         return *this;
00035                 }
00036         //- Fills float from dbobject
00037         SiPixelTemplateDBObject& operator>>( float& f)
00038                 {
00039                         isInvalid_ = false;
00040                         if(index_<=maxIndex_) {
00041                                 f = (*this).sVector_[index_];
00042                                 index_++;
00043                         }
00044                         else
00045                                 (*this).setInvalid();
00046                         return *this;
00047                 }
00048 
00049         //- Functions to monitor integrity of dbobject
00050         void setVersion(float version) {version_ = version;}
00051         void setInvalid() {isInvalid_ = true;}
00052         bool fail() {return isInvalid_;}
00053 
00054         //- Setter functions
00055         void push_back(float entry) {sVector_.push_back(entry);}
00056         void setIndex(int index) {index_ = index;}
00057         void setMaxIndex(int maxIndex) {maxIndex_ = maxIndex;}
00058         void setNumOfTempl(int numOfTempl) {numOfTempl_ = numOfTempl;}
00059         
00060         //- Accessor functions
00061         int index() const {return index_;}
00062         int maxIndex() const {return maxIndex_;}
00063         int numOfTempl() const {return numOfTempl_;}
00064         float version() const {return version_;}
00065         std::vector<float> sVector() const {return sVector_;}
00066 
00067         //- Able to set the index for template header 
00068         void incrementIndex(int i) {index_+=i;}
00069 
00070         //- Allows storage of header (type = char[80]) in dbobject
00071         union char2float
00072         {
00073                 char  c[4];
00074                 float f;
00075         };
00076 
00077         //- To be used to select template calibration based on detid
00078         void putTemplateIDs(std::map<unsigned int,short>& t_ID) {templ_ID = t_ID;}
00079         const std::map<unsigned int,short>& getTemplateIDs () const {return templ_ID;}
00080 
00081         bool putTemplateID(const uint32_t& detid, short& value)
00082                 {
00083                         std::map<unsigned int,short>::const_iterator id=templ_ID.find(detid);
00084                         if(id!=templ_ID.end()){
00085                                 edm::LogError("SiPixelTemplateDBObject") << "Template ID for DetID " << detid
00086                                                                                                                                                                                                  << " is already stored. Skipping this put" << std::endl;
00087                                 return false;
00088                         }
00089                         else templ_ID[detid] = value;
00090                         return true;
00091                 }
00092 
00093         short getTemplateID(const uint32_t& detid) const
00094                 {
00095                         std::map<unsigned int,short>::const_iterator id=templ_ID.find(detid);
00096                         if(id!=templ_ID.end()) return id->second;
00097                         else edm::LogError("SiPixelTemplateDBObject") << "Template ID for DetID " << detid
00098                                                                                                                                                                                                                 << " is not stored" << std::endl;
00099                         return 0;
00100                 }
00101         
00102 private:
00103         int index_;
00104         int maxIndex_;
00105         int numOfTempl_;
00106         float version_;
00107         bool isInvalid_;
00108         std::vector<float> sVector_;
00109         std::map<unsigned int,short> templ_ID;
00110 };//end SiPixelTemplateDBObject
00111 #endif