Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:11

0001 #ifndef CALOTSAMPLESBASE_ICC
0002 #define CALOTSAMPLESBASE_ICC 1
0003 
0004 #include "CalibFormats/CaloObjects/interface/CaloTSamplesBase.h"
0005 
0006 template <class Ttype>
0007 CaloTSamplesBase<Ttype>::CaloTSamplesBase(Ttype *mydata, uint32_t length) : m_id(0), m_size(0), m_pre(0) {
0008   std::fill(mydata, mydata + length, 0);
0009 }
0010 
0011 template <class Ttype>
0012 CaloTSamplesBase<Ttype>::CaloTSamplesBase(const CaloTSamplesBase<Ttype> &cs) {
0013   if (&cs != this) {
0014     m_id = cs.m_id;
0015     m_size = cs.m_size;
0016     m_pre = cs.m_pre;
0017   }
0018 }
0019 
0020 template <class Ttype>
0021 CaloTSamplesBase<Ttype>::CaloTSamplesBase(Ttype *mydata, uint32_t length, const DetId &id, uint32_t size, uint32_t pre)
0022     : m_id(id), m_size(size), m_pre(pre) {
0023   assert(length >= size);
0024   assert(pre <= size);
0025   std::fill(mydata, mydata + length, 0);
0026 }
0027 
0028 template <class Ttype>
0029 CaloTSamplesBase<Ttype>::~CaloTSamplesBase() {}
0030 
0031 template <class Ttype>
0032 void CaloTSamplesBase<Ttype>::setZero() {
0033   std::fill(data(0), data(0) + capacity(), 0);
0034 }
0035 
0036 template <class Ttype>
0037 DetId CaloTSamplesBase<Ttype>::id() const {
0038   return m_id;
0039 }
0040 
0041 template <class Ttype>
0042 uint32_t CaloTSamplesBase<Ttype>::size() const {
0043   return m_size;
0044 }
0045 
0046 template <class Ttype>
0047 uint32_t CaloTSamplesBase<Ttype>::pre() const {
0048   return m_pre;
0049 }
0050 
0051 template <class Ttype>
0052 bool CaloTSamplesBase<Ttype>::zero() const {
0053   for (uint32_t i(0); i != capacity(); ++i) {
0054     if (0 != (*cdata(i)))
0055       return false;
0056   }
0057   return true;
0058 }
0059 
0060 template <class Ttype>
0061 Ttype &CaloTSamplesBase<Ttype>::operator[](uint32_t i) {
0062   assert(capacity() > i);
0063   return *data(i);
0064 }
0065 
0066 template <class Ttype>
0067 const Ttype &CaloTSamplesBase<Ttype>::operator[](uint32_t i) const {
0068   assert(capacity() > i);
0069   return *cdata(i);
0070 }
0071 
0072 template <class Ttype>
0073 CaloTSamplesBase<Ttype> &CaloTSamplesBase<Ttype>::operator=(const CaloTSamplesBase<Ttype> &cs) {
0074   if (&cs != this) {
0075     m_id = cs.m_id;
0076     m_size = cs.m_size;
0077     m_pre = cs.m_pre;
0078   }
0079   return *this;
0080 }
0081 
0082 template <class Ttype>
0083 CaloTSamplesBase<Ttype> &CaloTSamplesBase<Ttype>::operator*=(Ttype value) {
0084   for (uint32_t i(0); i != m_size; ++i) {
0085     (*data(i)) *= value;
0086   }
0087   return *this;
0088 }
0089 
0090 template <class Ttype>
0091 CaloTSamplesBase<Ttype> &CaloTSamplesBase<Ttype>::operator+=(Ttype value) {
0092   for (uint32_t i(0); i != m_size; ++i) {
0093     (*data(i)) += value;
0094   }
0095   return *this;
0096 }
0097 
0098 template <class Ttype>
0099 CaloTSamplesBase<Ttype> &CaloTSamplesBase<Ttype>::operator+=(const CaloTSamplesBase<Ttype> &cs) {
0100   assert(m_size == cs.size());
0101   assert(capacity() == cs.capacity());
0102 
0103   for (uint32_t i(0); i != m_size; ++i) {
0104     (*data(i)) += (*cs.cdata(i));
0105   }
0106   return *this;
0107 }
0108 
0109 template <class Ttype>
0110 std::ostream &operator<<(std::ostream &s, const CaloTSamplesBase<Ttype> &sam) {
0111   s << "DetId=" << sam.id().rawId();
0112   s << ", " << sam.size() << " samples.";
0113   for (uint32_t i(0); i != sam.size(); ++i) {
0114     s << "\n" << i << " : " << sam[i];
0115   }
0116   s << std::endl;
0117   return s;
0118 }
0119 
0120 #endif