Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondFormatsHcalObjectsHcalSiPMCharacteristics_h
0002 #define CondFormatsHcalObjectsHcalSiPMCharacteristics_h
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include <vector>
0007 #include <set>
0008 #include <algorithm>
0009 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0010 #include <atomic>
0011 #endif
0012 
0013 //forward declarations
0014 namespace HcalSiPMCharacteristicsAddons {
0015   class Helper;
0016 }
0017 
0018 class HcalSiPMCharacteristics {
0019 public:
0020   class PrecisionItem {
0021   public:
0022     PrecisionItem() {
0023       type_ = auxi1_ = pixels_ = 0;
0024       parLin1_ = parLin2_ = parLin3_ = crossTalk_ = auxi2_ = 0;
0025     }
0026     PrecisionItem(
0027         int type, int pixels, float parLin1, float parLin2, float parLin3, float crossTalk, int auxi1, float auxi2)
0028         : type_(type),
0029           pixels_(pixels),
0030           parLin1_(parLin1),
0031           parLin2_(parLin2),
0032           parLin3_(parLin3),
0033           crossTalk_(crossTalk),
0034           auxi1_(auxi1),
0035           auxi2_(auxi2) {}
0036 
0037     int type_;
0038     int pixels_;
0039     float parLin1_;
0040     float parLin2_;
0041     float parLin3_;
0042     float crossTalk_;
0043     int auxi1_;
0044     float auxi2_;
0045 
0046     COND_SERIALIZABLE;
0047   };
0048 
0049   HcalSiPMCharacteristics() {}
0050   HcalSiPMCharacteristics(const HcalSiPMCharacteristicsAddons::Helper& helper);
0051   ~HcalSiPMCharacteristics();
0052 
0053   // swap function
0054   void swap(HcalSiPMCharacteristics& other);
0055   // copy-ctor
0056   HcalSiPMCharacteristics(const HcalSiPMCharacteristics& src);
0057   // copy assignment operator
0058   HcalSiPMCharacteristics& operator=(const HcalSiPMCharacteristics& rhs);
0059   // move constructor
0060 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0061   HcalSiPMCharacteristics(HcalSiPMCharacteristics&& other);
0062 #endif
0063 
0064   /// get # of types
0065   unsigned int getTypes() const { return mPItems.size(); }
0066   int getType(unsigned int k) const { return mPItems[k].type_; }
0067   /// get # of pixels
0068   int getPixels(int type) const;
0069   /// get nonlinearity constants
0070   std::vector<float> getNonLinearities(int type) const;
0071   /// get cross talk
0072   float getCrossTalk(int type) const;
0073   /// get auxiliary words
0074   int getAuxi1(int type) const;
0075   float getAuxi2(int type) const;
0076 
0077   const PrecisionItem* findByType(int type) const;
0078 
0079   // sorting
0080   void sortByType();
0081   void initialize();
0082 
0083 protected:
0084   std::vector<PrecisionItem> mPItems;
0085   std::vector<const PrecisionItem*> mPItemsByType COND_TRANSIENT;
0086 
0087   COND_SERIALIZABLE;
0088 };
0089 
0090 namespace HcalSiPMCharacteristicsAddons {
0091   class LessByType {
0092   public:
0093     bool operator()(const HcalSiPMCharacteristics::PrecisionItem* a,
0094                     const HcalSiPMCharacteristics::PrecisionItem* b) const {
0095       return a->type_ < b->type_;
0096     }
0097     bool operator()(const HcalSiPMCharacteristics::PrecisionItem& a,
0098                     const HcalSiPMCharacteristics::PrecisionItem& b) const {
0099       return a.type_ < b.type_;
0100     }
0101     bool equal(const HcalSiPMCharacteristics::PrecisionItem* a, const HcalSiPMCharacteristics::PrecisionItem* b) const {
0102       return a->type_ == b->type_;
0103     }
0104     bool good(const HcalSiPMCharacteristics::PrecisionItem& a) const { return a.type_; }
0105   };
0106   class Helper {
0107   public:
0108     Helper();
0109     // Load a new entry
0110     bool loadObject(int type,
0111                     int pixels,
0112                     float parLin1,
0113                     float parLin2,
0114                     float parLin3,
0115                     float crossTalk,
0116                     int auxi1 = 0,
0117                     float auxi2 = 0);
0118 
0119     std::set<HcalSiPMCharacteristics::PrecisionItem, LessByType> mPItems;
0120   };
0121 }  // namespace HcalSiPMCharacteristicsAddons
0122 
0123 #endif