00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "RooFit.h"
00030
00031 #include "Riostream.h"
00032 #include "Riostream.h"
00033 #include "TObjString.h"
00034 #include "TH1.h"
00035 #include "TTree.h"
00036
00037 #include "RooArgSet.h"
00038 #include "RooAbsString.h"
00039 #include "RooStringVar.h"
00040 #include "RooMsgService.h"
00041
00042 ClassImp(RooAbsString)
00043 ;
00044
00045
00046
00047 RooAbsString::RooAbsString() : RooAbsArg(), _len(128) , _value(new char[128])
00048 {
00049
00050 }
00051
00052
00053
00054 RooAbsString::RooAbsString(const char *name, const char *title, Int_t bufLen) :
00055 RooAbsArg(name,title), _len(bufLen), _value(new char[bufLen])
00056 {
00057
00058
00059 setValueDirty() ;
00060 setShapeDirty() ;
00061 }
00062
00063
00064
00065
00066 RooAbsString::RooAbsString(const RooAbsString& other, const char* name) :
00067 RooAbsArg(other, name), _len(other._len), _value(new char[other._len])
00068 {
00069
00070
00071 strlcpy(_value,other._value,_len) ;
00072 }
00073
00074
00075
00076
00077 RooAbsString::~RooAbsString()
00078 {
00079
00080
00081 delete[] _value ;
00082 }
00083
00084
00085
00086
00087 const char* RooAbsString::getVal() const
00088 {
00089
00090
00091 if (isValueDirty()) {
00092 clearValueDirty() ;
00093 strlcpy(_value,traceEval(),_len) ;
00094 }
00095
00096 return _value ;
00097 }
00098
00099
00100
00101
00102 Bool_t RooAbsString::operator==(const char* value) const
00103 {
00104
00105
00106 return !TString(getVal()).CompareTo(value) ;
00107 }
00108
00109
00110
00111
00112 Bool_t RooAbsString::operator==(const RooAbsArg& other)
00113 {
00114
00115
00116 const RooAbsString* otherString = dynamic_cast<const RooAbsString*>(&other) ;
00117 return otherString ? operator==(otherString->getVal()) : kFALSE ;
00118 }
00119
00120
00121
00122
00123 Bool_t RooAbsString::readFromStream(istream& , Bool_t , Bool_t )
00124 {
00125
00126 return kFALSE ;
00127 }
00128
00129
00130
00131
00132 void RooAbsString::writeToStream(ostream& , Bool_t ) const
00133 {
00134
00135 }
00136
00137
00138
00139
00140 void RooAbsString::printValue(ostream& os) const
00141 {
00142
00143 os << getVal() ;
00144 }
00145
00146
00147
00148
00149 Bool_t RooAbsString::isValid() const
00150 {
00151
00152 return isValidString(getVal()) ;
00153 }
00154
00155
00156
00157
00158 Bool_t RooAbsString::isValidString(const char* value, Bool_t ) const
00159 {
00160
00161
00162
00163 if (TString(value).Length()>_len) return kFALSE ;
00164
00165 return kTRUE ;
00166 }
00167
00168
00169
00170 Bool_t RooAbsString::traceEvalHook(const char* ) const
00171 {
00172
00173 return kFALSE ;
00174 }
00175
00176
00177
00178
00179 const char* RooAbsString::traceEval() const
00180 {
00181
00182
00183 const char* value = evaluate() ;
00184
00185
00186 if (!isValidString(value)) {
00187 cxcoutD(Tracing) << "RooAbsString::traceEval(" << GetName() << "): new output too long (>" << _len << " chars): " << value << endl ;
00188 }
00189
00190
00191 traceEvalHook(value) ;
00192
00193 return value ;
00194 }
00195
00196
00197
00198
00199 void RooAbsString::syncCache(const RooArgSet*)
00200 {
00201
00202 getVal() ;
00203 }
00204
00205
00206
00207
00208 void RooAbsString::copyCache(const RooAbsArg* source, Bool_t )
00209 {
00210
00211
00212
00213
00214
00215 RooAbsString* other = dynamic_cast<RooAbsString*>(const_cast<RooAbsArg*>(source)) ;
00216 assert(other!=0) ;
00217
00218 strlcpy(_value,other->_value,_len) ;
00219 setValueDirty() ;
00220 }
00221
00222
00223
00224
00225 void RooAbsString::attachToTree(TTree& t, Int_t bufSize)
00226 {
00227
00228
00229
00230 TBranch* branch ;
00231 if ((branch = t.GetBranch(GetName()))) {
00232 t.SetBranchAddress(GetName(),_value) ;
00233 if (branch->GetCompressionLevel()<0) {
00234 cxcoutD(DataHandling) << "RooAbsString::attachToTree(" << GetName() << ") Fixing compression level of branch " << GetName() << endl ;
00235 branch->SetCompressionLevel(1) ;
00236 }
00237 } else {
00238 TString format(GetName());
00239 format.Append("/C");
00240 branch = t.Branch(GetName(), _value, (const Text_t*)format, bufSize);
00241 branch->SetCompressionLevel(1) ;
00242 }
00243 }
00244
00245
00246
00247
00248 void RooAbsString::fillTreeBranch(TTree& t)
00249 {
00250
00251
00252
00253 TBranch* branch = t.GetBranch(GetName()) ;
00254 if (!branch) {
00255 coutE(DataHandling) << "RooAbsString::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << endl ;
00256 assert(0) ;
00257 }
00258 branch->Fill() ;
00259 }
00260
00261
00262
00263
00264 void RooAbsString::setTreeBranchStatus(TTree& t, Bool_t active)
00265 {
00266
00267
00268 TBranch* branch = t.GetBranch(GetName()) ;
00269 if (branch) {
00270 t.SetBranchStatus(GetName(),active?1:0) ;
00271 }
00272 }
00273
00274
00275
00276
00277 RooAbsArg *RooAbsString::createFundamental(const char* newname) const
00278 {
00279
00280
00281 RooStringVar *fund= new RooStringVar(newname?newname:GetName(),GetTitle(),"") ;
00282 return fund;
00283 }