Warning, file /include/root/TParameter.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 { kMultiply = BIT(16),
0040 kMax = BIT(17),
0041 kMin = BIT(18),
0042 kFirst = BIT(19),
0043 kLast = BIT(20),
0044 kIsConst = BIT(21)
0045 };
0046
0047 private:
0048 TString fName;
0049 AParamType fVal;
0050
0051 void Reset() { ResetBit(kMultiply); ResetBit(kMax); ResetBit(kMin);
0052 ResetBit(kFirst); ResetBit(kLast); }
0053
0054 public:
0055 TParameter(): fVal() { Reset(); SetBit(kIsConst); }
0056 TParameter(const char *name, const AParamType &val)
0057 : fName(name), fVal(val) { Reset(); SetBit(kIsConst);}
0058 TParameter(const char *name, const AParamType &val, char mergemode)
0059 : fName(name), fVal(val) { SetMergeMode(mergemode); SetBit(kIsConst);}
0060 virtual ~TParameter()
0061 {
0062
0063 ROOT::CallRecursiveRemoveIfNeeded(*this);
0064 }
0065
0066 const char *GetName() const override { return fName; }
0067 const AParamType &GetVal() const { return fVal; }
0068 Bool_t IsConst() const { return (TestBit(kIsConst) ? kTRUE : kFALSE); }
0069 void SetVal(const AParamType &val) { fVal = val; }
0070
0071
0072
0073
0074
0075
0076
0077
0078 void SetMergeMode(char mergemode = '+') {
0079 Reset();
0080 if (mergemode == '*') {
0081 SetBit(kMultiply);
0082 } else if (mergemode == 'M') {
0083 SetBit(kMax);
0084 } else if (mergemode == 'm') {
0085 SetBit(kMin);
0086 } else if (mergemode == 'f') {
0087 SetBit(kFirst);
0088 } else if (mergemode == 'l') {
0089 SetBit(kLast);
0090 }
0091 }
0092 ULong_t Hash() const override { return fName.Hash(); }
0093 Bool_t IsSortable() const override { return kTRUE; }
0094 Int_t Compare(const TObject *obj) const override
0095 {
0096
0097
0098
0099 if (this == obj) return 0;
0100 return fName.CompareTo(obj->GetName());
0101 }
0102
0103 void ls(Option_t *) const override
0104 {
0105
0106 TROOT::IndentLevel();
0107 std::cout << "OBJ: " << IsA()->GetName() << "\t" << fName << " = " << fVal << std::endl;
0108 }
0109
0110 void Print(Option_t *) const override
0111 {
0112
0113 TROOT::IndentLevel();
0114 std::cout << IsA()->GetName() << "\t" << fName << " = " << fVal << std::endl;
0115 }
0116
0117 virtual Int_t Merge(TCollection *in);
0118
0119 ClassDefOverride(TParameter,2)
0120 };
0121
0122 template <class AParamType>
0123 inline Int_t TParameter<AParamType>::Merge(TCollection *in) {
0124
0125
0126 TIter nxo(in);
0127 Int_t n = 0;
0128 while (TObject *o = nxo()) {
0129 TParameter<AParamType> *c = dynamic_cast<TParameter<AParamType> *>(o);
0130 if (c) {
0131
0132 if (fVal != c->GetVal()) ResetBit(kIsConst);
0133 if (TestBit(kMultiply)) {
0134
0135 fVal *= c->GetVal();
0136 } else if (TestBit(kMax)) {
0137
0138 if (c->GetVal() > fVal) fVal = c->GetVal();
0139 } else if (TestBit(kMin)) {
0140
0141 if (c->GetVal() < fVal) fVal = c->GetVal();
0142 } else if (TestBit(kLast)) {
0143
0144 fVal = c->GetVal();
0145 } else if (!TestBit(kFirst)) {
0146
0147 fVal += c->GetVal();
0148 }
0149 n++;
0150 }
0151 }
0152
0153 return n;
0154 }
0155
0156
0157 template <>
0158 inline Int_t TParameter<Bool_t>::Merge(TCollection *in)
0159 {
0160
0161
0162 TIter nxo(in);
0163 Int_t n = 0;
0164 while (TObject *o = nxo()) {
0165 TParameter<Bool_t> *c = dynamic_cast<TParameter<Bool_t> *>(o);
0166 if (c) {
0167
0168 if (fVal != (Bool_t) c->GetVal()) ResetBit(kIsConst);
0169 if (TestBit(TParameter::kMultiply) || TestBit(kMin)) {
0170
0171 fVal &= (Bool_t) c->GetVal();
0172 } else if (TestBit(kLast)) {
0173
0174 fVal = (Bool_t) c->GetVal();
0175 } else if (!TestBit(kFirst) || TestBit(kMax)) {
0176
0177 fVal |= (Bool_t) c->GetVal();
0178 }
0179 n++;
0180 }
0181 }
0182
0183 return n;
0184 }
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194 template <> void TParameter<Long64_t>::Streamer(TBuffer &R__b);
0195 template<> TClass *TParameter<Long64_t>::Class();
0196
0197 #endif