File indexing completed on 2026-09-18 09:30:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TParameter
0013 #define ROOT_TParameter
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "Riostream.h"
0025
0026 #include "TObject.h"
0027
0028 #include "TCollection.h"
0029
0030 #include "TString.h"
0031
0032 #include "TROOT.h"
0033
0034 template <class AParamType>
0035 class TParameter : public TObject {
0036
0037 public:
0038
0039 enum EStatusBits {
0040
0041 #if defined(__clang__) && __clang_major__ < 20
0042 #pragma clang diagnostic push
0043 #pragma clang diagnostic ignored "-Wshadow"
0044 #endif
0045 kMultiply = BIT(16),
0046 #if defined(__clang__) && __clang_major__ < 20
0047 #pragma clang diagnostic pop
0048 #endif
0049 kMax = BIT(17),
0050 kMin = BIT(18),
0051 kFirst = BIT(19),
0052 kLast = BIT(20),
0053 kIsConst = BIT(21)
0054 };
0055
0056 private:
0057 TString fName;
0058 AParamType fVal;
0059
0060 void Reset() { ResetBit(kMultiply); ResetBit(kMax); ResetBit(kMin);
0061 ResetBit(kFirst); ResetBit(kLast); }
0062
0063 public:
0064 TParameter(): fVal() { Reset(); SetBit(kIsConst); }
0065 TParameter(const char *name, const AParamType &val)
0066 : fName(name), fVal(val) { Reset(); SetBit(kIsConst);}
0067 TParameter(const char *name, const AParamType &val, char mergemode)
0068 : fName(name), fVal(val) { SetMergeMode(mergemode); SetBit(kIsConst);}
0069 virtual ~TParameter()
0070 {
0071
0072 ROOT::CallRecursiveRemoveIfNeeded(*this);
0073 }
0074
0075 const char *GetName() const override { return fName; }
0076 const AParamType &GetVal() const { return fVal; }
0077 Bool_t IsConst() const { return (TestBit(kIsConst) ? kTRUE : kFALSE); }
0078 void SetVal(const AParamType &val) { fVal = val; }
0079
0080
0081
0082
0083
0084
0085
0086
0087 void SetMergeMode(char mergemode = '+') {
0088 Reset();
0089 if (mergemode == '*') {
0090 SetBit(kMultiply);
0091 } else if (mergemode == 'M') {
0092 SetBit(kMax);
0093 } else if (mergemode == 'm') {
0094 SetBit(kMin);
0095 } else if (mergemode == 'f') {
0096 SetBit(kFirst);
0097 } else if (mergemode == 'l') {
0098 SetBit(kLast);
0099 }
0100 }
0101 ULong_t Hash() const override { return fName.Hash(); }
0102 Bool_t IsSortable() const override { return kTRUE; }
0103 Int_t Compare(const TObject *obj) const override
0104 {
0105
0106
0107
0108 if (this == obj) return 0;
0109 return fName.CompareTo(obj->GetName());
0110 }
0111
0112 void ls(Option_t *) const override
0113 {
0114
0115 TROOT::IndentLevel();
0116 std::cout << "OBJ: " << IsA()->GetName() << "\t" << fName << " = " << fVal << std::endl;
0117 }
0118
0119 void Print(Option_t *) const override
0120 {
0121
0122 TROOT::IndentLevel();
0123 std::cout << IsA()->GetName() << "\t" << fName << " = " << fVal << std::endl;
0124 }
0125
0126 virtual Int_t Merge(TCollection *in);
0127
0128 ClassDefOverride(TParameter,2)
0129 };
0130
0131 template <class AParamType>
0132 inline Int_t TParameter<AParamType>::Merge(TCollection *in) {
0133
0134
0135 TIter nxo(in);
0136 Int_t n = 0;
0137 while (TObject *o = nxo()) {
0138 TParameter<AParamType> *c = dynamic_cast<TParameter<AParamType> *>(o);
0139 if (c) {
0140
0141 if (fVal != c->GetVal()) ResetBit(kIsConst);
0142 if (TestBit(kMultiply)) {
0143
0144 fVal *= c->GetVal();
0145 } else if (TestBit(kMax)) {
0146
0147 if (c->GetVal() > fVal) fVal = c->GetVal();
0148 } else if (TestBit(kMin)) {
0149
0150 if (c->GetVal() < fVal) fVal = c->GetVal();
0151 } else if (TestBit(kLast)) {
0152
0153 fVal = c->GetVal();
0154 } else if (!TestBit(kFirst)) {
0155
0156 fVal += c->GetVal();
0157 }
0158 n++;
0159 }
0160 }
0161
0162 return n;
0163 }
0164
0165
0166 template <>
0167 inline Int_t TParameter<Bool_t>::Merge(TCollection *in)
0168 {
0169
0170
0171 TIter nxo(in);
0172 Int_t n = 0;
0173 while (TObject *o = nxo()) {
0174 TParameter<Bool_t> *c = dynamic_cast<TParameter<Bool_t> *>(o);
0175 if (c) {
0176
0177 if (fVal != (Bool_t) c->GetVal()) ResetBit(kIsConst);
0178 if (TestBit(TParameter::kMultiply) || TestBit(kMin)) {
0179
0180 fVal &= (Bool_t) c->GetVal();
0181 } else if (TestBit(kLast)) {
0182
0183 fVal = (Bool_t) c->GetVal();
0184 } else if (!TestBit(kFirst) || TestBit(kMax)) {
0185
0186 fVal |= (Bool_t) c->GetVal();
0187 }
0188 n++;
0189 }
0190 }
0191
0192 return n;
0193 }
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203 template <> void TParameter<Long64_t>::Streamer(TBuffer &R__b);
0204 template<> TClass *TParameter<Long64_t>::Class();
0205
0206 #endif