Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:33

0001 #ifndef CondFormats_SiPixelObjects_SiPixel2DTemplateDBObject_h
0002 #define CondFormats_SiPixelObjects_SiPixel2DTemplateDBObject_h 1
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include <vector>
0007 #include <map>
0008 #include <cstdint>
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 // ******************************************************************************************
0012 //! \class SiPixel2DTemplateDBObject
0013 //!
0014 // ******************************************************************************************
0015 
0016 class SiPixel2DTemplateDBObject {
0017 public:
0018   SiPixel2DTemplateDBObject()
0019       : index_(0), maxIndex_(0), numOfTempl_(1), version_(-99.9), isInvalid_(false), sVector_(0) {
0020     sVector_.reserve(1000000);
0021   }
0022   virtual ~SiPixel2DTemplateDBObject() {}
0023 
0024   //- Allows the dbobject to be read out like cout
0025   friend std::ostream& operator<<(std::ostream& s, const SiPixel2DTemplateDBObject& dbobject);
0026 
0027   //- Fills integer from dbobject
0028   SiPixel2DTemplateDBObject& operator>>(int& i) {
0029     isInvalid_ = false;
0030     if (index_ <= maxIndex_) {
0031       i = (int)(*this).sVector_[index_];
0032       index_++;
0033     } else
0034       (*this).setInvalid();
0035     return *this;
0036   }
0037   //- Fills float from dbobject
0038   SiPixel2DTemplateDBObject& operator>>(float& f) {
0039     isInvalid_ = false;
0040     if (index_ <= maxIndex_) {
0041       f = (*this).sVector_[index_];
0042       index_++;
0043     } else
0044       (*this).setInvalid();
0045     return *this;
0046   }
0047 
0048   //- Functions to monitor integrity of dbobject
0049   void setVersion(float version) { version_ = version; }
0050   void setInvalid() { isInvalid_ = true; }
0051   bool fail() { return isInvalid_; }
0052 
0053   //- Setter functions
0054   void push_back(float entry) { sVector_.push_back(entry); }
0055   void setIndex(int index) { index_ = index; }
0056   void setMaxIndex(int maxIndex) { maxIndex_ = maxIndex; }
0057   void setNumOfTempl(int numOfTempl) { numOfTempl_ = numOfTempl; }
0058 
0059   //- Accessor functions
0060   int index() const { return index_; }
0061   int maxIndex() const { return maxIndex_; }
0062   int numOfTempl() const { return numOfTempl_; }
0063   float version() const { return version_; }
0064   std::vector<float> const& sVector() const { return sVector_; }
0065 
0066   //- Able to set the index for template header
0067   void incrementIndex(int i) { index_ += i; }
0068 
0069   //- Allows storage of header (type = char[80]) in dbobject
0070   union char2float {
0071     char c[4];
0072     float f;
0073   };
0074 
0075   //- To be used to select template calibration based on detid
0076   void putTemplateIDs(std::map<unsigned int, short>& t_ID) { templ_ID = t_ID; }
0077   const std::map<unsigned int, short>& getTemplateIDs() const { return templ_ID; }
0078 
0079   bool putTemplateID(const uint32_t& detid, short& value) {
0080     std::map<unsigned int, short>::const_iterator id = templ_ID.find(detid);
0081     if (id != templ_ID.end()) {
0082       edm::LogError("SiPixel2DTemplateDBObject")
0083           << "2Dtemplate ID for DetID " << detid << " is already stored. Skipping this put" << std::endl;
0084       return false;
0085     } else
0086       templ_ID[detid] = value;
0087     return true;
0088   }
0089 
0090   short getTemplateID(const uint32_t& detid) const {
0091     std::map<unsigned int, short>::const_iterator id = templ_ID.find(detid);
0092     if (id != templ_ID.end())
0093       return id->second;
0094     else
0095       edm::LogError("SiPixel2DTemplateDBObject")
0096           << "2Dtemplate ID for DetID " << detid << " is not stored" << std::endl;
0097     return 0;
0098   }
0099 
0100   class Reader {
0101   public:
0102     Reader(SiPixel2DTemplateDBObject const& object) : object_(object), index_(0), isInvalid_(false) {}
0103 
0104     bool fail() { return isInvalid_; }
0105 
0106     int index() const { return index_; }
0107     //- Able to set the index for template header
0108     void incrementIndex(int i) { index_ += i; }
0109 
0110     //- Fills integer from dbobject
0111     Reader& operator>>(int& i) {
0112       isInvalid_ = false;
0113       if (index_ <= object_.maxIndex_) {
0114         i = (int)object_.sVector_[index_];
0115         index_++;
0116       } else
0117         isInvalid_ = true;
0118       return *this;
0119     }
0120     //- Fills float from dbobject
0121     Reader& operator>>(float& f) {
0122       isInvalid_ = false;
0123       if (index_ <= object_.maxIndex_) {
0124         f = object_.sVector_[index_];
0125         index_++;
0126       } else
0127         isInvalid_ = true;
0128       return *this;
0129     }
0130 
0131   private:
0132     SiPixel2DTemplateDBObject const& object_;
0133     int index_;
0134     bool isInvalid_;
0135   };
0136   friend class Reader;
0137 
0138 private:
0139   int index_;
0140   int maxIndex_;
0141   int numOfTempl_;
0142   float version_;
0143   bool isInvalid_;
0144   std::vector<float> sVector_;
0145   std::map<unsigned int, short> templ_ID;
0146 
0147   COND_SERIALIZABLE;
0148 };  //end SiPixel2DTemplateDBObject
0149 #endif