Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:31

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> 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 private:
0101   int index_;
0102   int maxIndex_;
0103   int numOfTempl_;
0104   float version_;
0105   bool isInvalid_;
0106   std::vector<float> sVector_;
0107   std::map<unsigned int, short> templ_ID;
0108 
0109   COND_SERIALIZABLE;
0110 };  //end SiPixel2DTemplateDBObject
0111 #endif