Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:26

0001 #include <cstdint>
0002 #ifndef RecoLocalCalo_HcalRecAlgos_rawEnergy_h
0003 #define RecoLocalCalo_HcalRecAlgos_rawEnergy_h
0004 
0005 namespace HcalRecAlgosPrivate {
0006   template <typename T>
0007   class IsClassType {
0008     typedef char One;
0009     typedef struct {
0010       char a[2];
0011     } Two;
0012     template <typename C>
0013     static One test(int C::*);
0014     template <typename C>
0015     static Two test(...);
0016 
0017   public:
0018     enum { value = sizeof(IsClassType<T>::template test<T>(nullptr)) == 1 };
0019   };
0020 
0021   template <typename T>
0022   class HasRawEnergySetterHelper {
0023   private:
0024     template <void (T::*)(float)>
0025     struct tester;
0026     typedef char One;
0027     typedef struct {
0028       char a[2];
0029     } Two;
0030     template <typename C>
0031     static One test(tester<&C::setRawEnergy>*);
0032     template <typename C>
0033     static Two test(...);
0034 
0035   public:
0036     enum { value = sizeof(HasRawEnergySetterHelper<T>::template test<T>(nullptr)) == 1 };
0037   };
0038 
0039   template <typename T, bool is_class_type = IsClassType<T>::value>
0040   struct HasRawEnergySetter {
0041     enum { value = false };
0042   };
0043 
0044   template <typename T>
0045   struct HasRawEnergySetter<T, true> {
0046     enum { value = HasRawEnergySetterHelper<T>::value };
0047   };
0048 
0049   template <typename T, bool>
0050   struct RawEnergySetter {
0051     inline static void setRawEnergy(T&, float) {}
0052   };
0053 
0054   template <typename T>
0055   struct RawEnergySetter<T, true> {
0056     inline static void setRawEnergy(T& h, float e) { h.setRawEnergy(e); }
0057   };
0058 
0059   template <typename T>
0060   class HasRawEnergyGetterHelper {
0061   private:
0062     template <float (T::*)() const>
0063     struct tester;
0064     typedef char One;
0065     typedef struct {
0066       char a[2];
0067     } Two;
0068     template <typename C>
0069     static One test(tester<&C::eraw>*);
0070     template <typename C>
0071     static Two test(...);
0072 
0073   public:
0074     enum { value = sizeof(HasRawEnergyGetterHelper<T>::template test<T>(0)) == 1 };
0075   };
0076 
0077   template <typename T, bool is_class_type = IsClassType<T>::value>
0078   struct HasRawEnergyGetter {
0079     enum { value = false };
0080   };
0081 
0082   template <typename T>
0083   struct HasRawEnergyGetter<T, true> {
0084     enum { value = HasRawEnergyGetterHelper<T>::value };
0085   };
0086 
0087   template <typename T, bool>
0088   struct RawEnergyGetter {
0089     inline static float getRawEnergy(const T&, float v) { return v; }
0090   };
0091 
0092   template <typename T>
0093   struct RawEnergyGetter<T, true> {
0094     inline static float getRawEnergy(const T& h, float) { return h.eraw(); }
0095   };
0096 
0097   template <typename T>
0098   class HasAuxEnergySetterHelper {
0099   private:
0100     template <void (T::*)(float)>
0101     struct tester;
0102     typedef char One;
0103     typedef struct {
0104       char a[2];
0105     } Two;
0106     template <typename C>
0107     static One test(tester<&C::setAuxEnergy>*);
0108     template <typename C>
0109     static Two test(...);
0110 
0111   public:
0112     enum { value = sizeof(HasAuxEnergySetterHelper<T>::template test<T>(nullptr)) == 1 };
0113   };
0114 
0115   template <typename T, bool is_class_type = IsClassType<T>::value>
0116   struct HasAuxEnergySetter {
0117     enum { value = false };
0118   };
0119 
0120   template <typename T>
0121   struct HasAuxEnergySetter<T, true> {
0122     enum { value = HasAuxEnergySetterHelper<T>::value };
0123   };
0124 
0125   template <typename T, bool>
0126   struct AuxEnergySetter {
0127     inline static void setAuxEnergy(T&, float) {}
0128   };
0129 
0130   template <typename T>
0131   struct AuxEnergySetter<T, true> {
0132     inline static void setAuxEnergy(T& h, float e) { h.setAuxEnergy(e); }
0133   };
0134 
0135   template <typename T>
0136   class HasAuxEnergyGetterHelper {
0137   private:
0138     template <float (T::*)() const>
0139     struct tester;
0140     typedef char One;
0141     typedef struct {
0142       char a[2];
0143     } Two;
0144     template <typename C>
0145     static One test(tester<&C::eaux>*);
0146     template <typename C>
0147     static Two test(...);
0148 
0149   public:
0150     enum { value = sizeof(HasAuxEnergyGetterHelper<T>::template test<T>(0)) == 1 };
0151   };
0152 
0153   template <typename T, bool is_class_type = IsClassType<T>::value>
0154   struct HasAuxEnergyGetter {
0155     enum { value = false };
0156   };
0157 
0158   template <typename T>
0159   struct HasAuxEnergyGetter<T, true> {
0160     enum { value = HasAuxEnergyGetterHelper<T>::value };
0161   };
0162 
0163   template <typename T, bool>
0164   struct AuxEnergyGetter {
0165     inline static float getAuxEnergy(const T&, float v) { return v; }
0166   };
0167 
0168   template <typename T>
0169   struct AuxEnergyGetter<T, true> {
0170     inline static float getAuxEnergy(const T& h, float) { return h.eaux(); }
0171   };
0172 
0173   template <typename T>
0174   class HasAuxRecHitGetterHelper {
0175   private:
0176     template <uint32_t (T::*)() const>
0177     struct tester;
0178     typedef char One;
0179     typedef struct {
0180       char a[2];
0181     } Two;
0182     template <typename C>
0183     static One test(tester<&C::auxHBHE>*);
0184     template <typename C>
0185     static Two test(...);
0186 
0187   public:
0188     enum { value = sizeof(HasAuxRecHitGetterHelper<T>::template test<T>(0)) == 1 };
0189   };
0190 
0191   template <typename T, bool is_class_type = IsClassType<T>::value>
0192   struct HasAuxRecHitGetter {
0193     enum { value = false };
0194   };
0195 
0196   template <typename T>
0197   struct HasAuxRecHitGetter<T, true> {
0198     enum { value = HasAuxRecHitGetterHelper<T>::value };
0199   };
0200 
0201   template <typename T, bool>
0202   struct AuxRecHitGetter {
0203     inline static uint32_t getAuxRecHit(const T&, uint32_t v) { return v; }
0204   };
0205 
0206   template <typename T>
0207   struct AuxRecHitGetter<T, true> {
0208     inline static uint32_t getAuxRecHit(const T& h, uint32_t) { return h.auxHBHE(); }
0209   };
0210 }  // namespace HcalRecAlgosPrivate
0211 
0212 // Function for setting the raw energy in a code templated
0213 // upon the rechit type. The function call will be ignored
0214 // in case the HcalRecHit type does not have a member function
0215 // "void setRawEnergy(float)".
0216 template <typename HcalRecHit>
0217 inline void setRawEnergy(HcalRecHit& h, float e) {
0218   HcalRecAlgosPrivate::RawEnergySetter<HcalRecHit,
0219                                        HcalRecAlgosPrivate::HasRawEnergySetter<HcalRecHit>::value>::setRawEnergy(h, e);
0220 }
0221 
0222 // Function for getting the raw energy in a code templated
0223 // upon the rechit type. This function will return "valueIfNoSuchMember"
0224 // in case the HcalRecHit type does not have a member function
0225 // "float eraw() const".
0226 template <typename HcalRecHit>
0227 inline float getRawEnergy(const HcalRecHit& h, float valueIfNoSuchMember = -1.0e20) {
0228   return HcalRecAlgosPrivate::RawEnergyGetter<HcalRecHit, HcalRecAlgosPrivate::HasRawEnergyGetter<HcalRecHit>::value>::
0229       getRawEnergy(h, valueIfNoSuchMember);
0230 }
0231 
0232 // Similar functions for aux energy
0233 template <typename HcalRecHit>
0234 inline void setAuxEnergy(HcalRecHit& h, float e) {
0235   HcalRecAlgosPrivate::AuxEnergySetter<HcalRecHit,
0236                                        HcalRecAlgosPrivate::HasAuxEnergySetter<HcalRecHit>::value>::setAuxEnergy(h, e);
0237 }
0238 
0239 template <typename HcalRecHit>
0240 inline float getAuxEnergy(const HcalRecHit& h, float valueIfNoSuchMember = -1.0e20) {
0241   return HcalRecAlgosPrivate::AuxEnergyGetter<HcalRecHit, HcalRecAlgosPrivate::HasAuxEnergyGetter<HcalRecHit>::value>::
0242       getAuxEnergy(h, valueIfNoSuchMember);
0243 }
0244 
0245 // Function for getting the auxiliary word in a code templated
0246 // upon the rechit type. This function will return "valueIfNoSuchMember"
0247 // in case the HcalRecHit type does not have a member function
0248 // "uint32_t auxHBHE() const".
0249 template <typename HcalRecHit>
0250 inline uint32_t getAuxRecHitWord(const HcalRecHit& h, uint32_t valueIfNoSuchMember = 4294967295U) {
0251   return HcalRecAlgosPrivate::AuxRecHitGetter<HcalRecHit, HcalRecAlgosPrivate::HasAuxRecHitGetter<HcalRecHit>::value>::
0252       getAuxRecHit(h, valueIfNoSuchMember);
0253 }
0254 
0255 #endif  // RecoLocalCalo_HcalRecAlgos_rawEnergy_h