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 #include "RooFit.h"
00029 #include "Riostream.h"
00030
00031 #include "TObjString.h"
00032 #include "TClass.h"
00033 #include "RooNameSet.h"
00034 #include "RooArgSet.h"
00035 #include "RooArgList.h"
00036
00037
00038
00039 ClassImp(RooNameSet)
00040 ;
00041
00042
00043
00044 RooNameSet::RooNameSet()
00045 {
00046
00047
00048 _len = 1024 ;
00049 _nameList = new char[_len] ;
00050 _nameList[0] = 0 ;
00051
00052 }
00053
00054
00055
00056
00057
00058 RooNameSet::RooNameSet(const RooArgSet& argSet)
00059 {
00060
00061
00062 _len = 1024 ;
00063 _nameList = new char[_len] ;
00064 _nameList[0] = 0 ;
00065 refill(argSet) ;
00066 }
00067
00068
00069
00070
00071 RooNameSet::RooNameSet(const RooNameSet& other) : TObject(other), RooPrintable(other), _nameList()
00072 {
00073
00074
00075 _len = other._len ;
00076 _nameList = new char[_len] ;
00077 strlcpy(_nameList,other._nameList,_len) ;
00078 }
00079
00080
00081
00082
00083 void RooNameSet::extendBuffer(Int_t inc)
00084 {
00085
00086 char * newbuf = new char[_len+inc] ;
00087 strncpy(newbuf,_nameList,_len) ;
00088 delete[] _nameList ;
00089 _nameList = newbuf ;
00090 _len += inc ;
00091 }
00092
00093
00094
00095
00096 void RooNameSet::refill(const RooArgSet& argSet)
00097 {
00098
00099
00100 RooArgList tmp(argSet) ;
00101 tmp.sort() ;
00102 TIterator* iter = tmp.createIterator() ;
00103 RooAbsArg* arg ;
00104 char *ptr=_nameList ;
00105 char *end=_nameList+_len-2 ;
00106 *ptr = 0 ;
00107 while((arg=(RooAbsArg*)iter->Next())) {
00108 const char* argName = arg->GetName() ;
00109 while((*ptr++ = *argName++)) {
00110 if (ptr>=end) {
00111
00112 Int_t offset = ptr-_nameList ;
00113 extendBuffer(1024) ;
00114 ptr = _nameList + offset ;
00115 end = _nameList + _len - 2;
00116 }
00117 }
00118 *(ptr-1) = ':' ;
00119 }
00120 if (ptr>_nameList) *(ptr-1)= 0 ;
00121 delete iter ;
00122 }
00123
00124
00125
00126
00127 RooArgSet* RooNameSet::select(const RooArgSet& list) const
00128 {
00129
00130
00131
00132
00133 RooArgSet* output = new RooArgSet ;
00134
00135 char buffer[1024] ;
00136 strlcpy(buffer,_nameList,1024) ;
00137 char* token = strtok(buffer,":") ;
00138
00139 while(token) {
00140 RooAbsArg* arg = list.find(token) ;
00141 if (arg) output->add(*arg) ;
00142 token = strtok(0,":") ;
00143 }
00144
00145 return output ;
00146 }
00147
00148
00149
00150
00151 RooNameSet::~RooNameSet()
00152 {
00153
00154
00155 delete[] _nameList ;
00156 }
00157
00158
00159
00160
00161 Bool_t RooNameSet::operator==(const RooNameSet& other)
00162 {
00163
00164
00165
00166 if (&other==this) return kTRUE ;
00167
00168
00169 if (strlen(_nameList) != strlen(other._nameList)) return kFALSE ;
00170
00171 return (!strcmp(_nameList,other._nameList)) ;
00172 }
00173
00174
00175
00176
00177 RooNameSet& RooNameSet::operator=(const RooNameSet& other)
00178 {
00179
00180
00181 delete[] _nameList ;
00182
00183 _len = other._len ;
00184 _nameList = new char[_len] ;
00185 strlcpy(_nameList,other._nameList,_len) ;
00186
00187 return *this ;
00188 }
00189
00190
00191
00192 void RooNameSet::printName(ostream& os) const
00193 {
00194
00195 os << GetName() ;
00196 }
00197
00198
00199
00200 void RooNameSet::printTitle(ostream& os) const
00201 {
00202
00203 os << GetTitle() ;
00204 }
00205
00206
00207
00208 void RooNameSet::printClassName(ostream& os) const
00209 {
00210
00211 os << IsA()->GetName() ;
00212 }
00213
00214
00215
00216 void RooNameSet::printValue(ostream& os) const
00217 {
00218
00219 os << _nameList ;
00220 }