// RooNameSet is a utility class that stores the names the objects
// in a RooArget. This allows to preserve the contents of a RooArgSet
// in a specific use contents beyond the lifespan of the object in
// the RooArgSet. A new RooArgSet can be created from a RooNameSet
// by offering it a list of new RooAbsArg objects.
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "TObjString.h"
#include "TClass.h"
#include "RooNameSet.h"
#include "RooArgSet.h"
#include "RooArgList.h"
ClassImp(RooNameSet)
;
RooNameSet::RooNameSet()
{
_len = 1024 ;
_nameList = new char[_len] ;
_nameList[0] = 0 ;
}
RooNameSet::RooNameSet(const RooArgSet& argSet)
{
_len = 1024 ;
_nameList = new char[_len] ;
_nameList[0] = 0 ;
refill(argSet) ;
}
RooNameSet::RooNameSet(const RooNameSet& other) : TObject(other), RooPrintable(other), _nameList()
{
_len = other._len ;
_nameList = new char[_len] ;
strcpy(_nameList,other._nameList) ;
}
void RooNameSet::extendBuffer(Int_t inc)
{
char * newbuf = new char[_len+inc] ;
strncpy(newbuf,_nameList,_len) ;
delete[] _nameList ;
_nameList = newbuf ;
_len += inc ;
}
void RooNameSet::refill(const RooArgSet& argSet)
{
RooArgList tmp(argSet) ;
tmp.sort() ;
TIterator* iter = tmp.createIterator() ;
RooAbsArg* arg ;
char *ptr=_nameList ;
char *end=_nameList+_len-2 ;
*ptr = 0 ;
while((arg=(RooAbsArg*)iter->Next())) {
const char* argName = arg->GetName() ;
while((*ptr++ = *argName++)) {
if (ptr>=end) {
Int_t offset = ptr-_nameList ;
extendBuffer(1024) ;
ptr = _nameList + offset ;
end = _nameList + _len - 2;
}
}
*(ptr-1) = ':' ;
}
if (ptr>_nameList) *(ptr-1)= 0 ;
delete iter ;
}
RooArgSet* RooNameSet::select(const RooArgSet& list) const
{
RooArgSet* output = new RooArgSet ;
char buffer[1024] ;
strcpy(buffer,_nameList) ;
char* token = strtok(buffer,":") ;
while(token) {
RooAbsArg* arg = list.find(token) ;
if (arg) output->add(*arg) ;
token = strtok(0,":") ;
}
return output ;
}
RooNameSet::~RooNameSet()
{
delete[] _nameList ;
}
Bool_t RooNameSet::operator==(const RooNameSet& other)
{
if (&other==this) return kTRUE ;
if (strlen(_nameList) != strlen(other._nameList)) return kFALSE ;
return (!strcmp(_nameList,other._nameList)) ;
}
RooNameSet& RooNameSet::operator=(const RooNameSet& other)
{
delete[] _nameList ;
_len = other._len ;
_nameList = new char[_len] ;
strcpy(_nameList,other._nameList) ;
return *this ;
}
void RooNameSet::printName(ostream& os) const
{
os << GetName() ;
}
void RooNameSet::printTitle(ostream& os) const
{
os << GetTitle() ;
}
void RooNameSet::printClassName(ostream& os) const
{
os << IsA()->GetName() ;
}
void RooNameSet::printValue(ostream& os) const
{
os << _nameList ;
}
Last change: Wed Jun 25 08:33:33 2008
Last generated: 2008-06-25 08:33
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.