00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "RooFit.h"
00025 #include "Riostream.h"
00026
00027 #include <math.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <ctype.h>
00031 #include "TObjString.h"
00032 #include "TTree.h"
00033 #include "RooStringVar.h"
00034 #include "RooStreamParser.h"
00035 #include "RooMsgService.h"
00036
00037
00038
00039 ClassImp(RooStringVar)
00040
00041
00042
00043
00044
00045 RooStringVar::RooStringVar(const char *name, const char *title, const char* value, Int_t size) :
00046 RooAbsString(name, title, size)
00047 {
00048
00049
00050 if(!isValidString(value)) {
00051 coutW(InputArguments) << "RooStringVar::RooStringVar(" << GetName()
00052 << "): initial contents too long and ignored" << endl ;
00053 } else {
00054 strlcpy(_value,value,_len) ;
00055 }
00056
00057 setValueDirty() ;
00058 setShapeDirty() ;
00059 }
00060
00061
00062
00063
00064 RooStringVar::RooStringVar(const RooStringVar& other, const char* name) :
00065 RooAbsString(other, name)
00066 {
00067
00068 }
00069
00070
00071
00072
00073 RooStringVar::~RooStringVar()
00074 {
00075
00076 }
00077
00078
00079
00080
00081 RooStringVar::operator TString()
00082 {
00083
00084
00085 return TString(_value) ;
00086 }
00087
00088
00089
00090
00091 void RooStringVar::setVal(const char* value)
00092 {
00093
00094
00095 if (!isValidString(value)) {
00096 coutW(InputArguments) << "RooStringVar::setVal(" << GetName() << "): new string too long and ignored" << endl ;
00097 } else {
00098 if (value) {
00099 strlcpy(_value,value,_len) ;
00100 } else {
00101 _value[0] = 0 ;
00102 }
00103 }
00104 }
00105
00106
00107
00108
00109 RooAbsArg& RooStringVar::operator=(const char* newValue)
00110 {
00111
00112
00113 if (!isValidString(newValue)) {
00114 coutW(InputArguments) << "RooStringVar::operator=(" << GetName() << "): new string too long and ignored" << endl ;
00115 } else {
00116 if (newValue) {
00117 strlcpy(_value,newValue,_len) ;
00118 } else {
00119 _value[0] = 0 ;
00120 }
00121 }
00122
00123 return *this ;
00124 }
00125
00126
00127
00128
00129 Bool_t RooStringVar::readFromStream(istream& is, Bool_t compact, Bool_t verbose)
00130 {
00131
00132
00133 TString token,errorPrefix("RooStringVar::readFromStream(") ;
00134 errorPrefix.Append(GetName()) ;
00135 errorPrefix.Append(")") ;
00136 RooStreamParser parser(is,errorPrefix) ;
00137
00138 TString newValue ;
00139 Bool_t ret(kFALSE) ;
00140
00141 if (compact) {
00142 parser.readString(newValue,kTRUE) ;
00143 } else {
00144 newValue = parser.readLine() ;
00145 }
00146
00147 if (!isValidString(newValue)) {
00148 if (verbose)
00149 coutW(InputArguments) << "RooStringVar::readFromStream(" << GetName()
00150 << "): new string too long and ignored" << endl ;
00151 } else {
00152 strlcpy(_value,newValue,_len) ;
00153 }
00154
00155 return ret ;
00156 }
00157
00158
00159
00160 void RooStringVar::writeToStream(ostream& os, Bool_t ) const
00161 {
00162
00163
00164 os << getVal() ;
00165 }
00166
00167