Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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