// RooAbsString is the common abstract base class for objects that represent a
// string value
//
// Implementation of RooAbsString may be derived, there no interface
// is provided to modify the contents
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include "TObjString.h"
#include "TH1.h"
#include "TTree.h"
#include "RooArgSet.h"
#include "RooAbsString.h"
#include "RooStringVar.h"
#include "RooMsgService.h"
using namespace std;
ClassImp(RooAbsString)
;
RooAbsString::RooAbsString() : RooAbsArg(), _len(128) , _value(new char[128])
{
}
RooAbsString::RooAbsString(const char *name, const char *title, Int_t bufLen) :
RooAbsArg(name,title), _len(bufLen), _value(new char[bufLen])
{
setValueDirty() ;
setShapeDirty() ;
}
RooAbsString::RooAbsString(const RooAbsString& other, const char* name) :
RooAbsArg(other, name), _len(other._len), _value(new char[other._len])
{
strlcpy(_value,other._value,_len) ;
}
RooAbsString::~RooAbsString()
{
delete[] _value ;
}
const char* RooAbsString::getVal() const
{
if (isValueDirty()) {
clearValueDirty() ;
strlcpy(_value,traceEval(),_len) ;
}
return _value ;
}
Bool_t RooAbsString::operator==(const char* value) const
{
return !TString(getVal()).CompareTo(value) ;
}
Bool_t RooAbsString::isIdentical(const RooAbsArg& other, Bool_t assumeSameType)
{
if (!assumeSameType) {
const RooAbsString* otherString = dynamic_cast<const RooAbsString*>(&other) ;
return otherString ? operator==(otherString->getVal()) : kFALSE ;
} else {
return !TString(getVal()).CompareTo(((RooAbsString&)other).getVal()) ; ;
}
}
Bool_t RooAbsString::operator==(const RooAbsArg& other)
{
const RooAbsString* otherString = dynamic_cast<const RooAbsString*>(&other) ;
return otherString ? operator==(otherString->getVal()) : kFALSE ;
}
Bool_t RooAbsString::readFromStream(istream& , Bool_t , Bool_t )
{
return kFALSE ;
}
void RooAbsString::writeToStream(ostream& , Bool_t ) const
{
}
void RooAbsString::printValue(ostream& os) const
{
os << getVal() ;
}
Bool_t RooAbsString::isValid() const
{
return isValidString(getVal()) ;
}
Bool_t RooAbsString::isValidString(const char* value, Bool_t ) const
{
if (TString(value).Length()>_len) return kFALSE ;
return kTRUE ;
}
Bool_t RooAbsString::traceEvalHook(const char* ) const
{
return kFALSE ;
}
const char* RooAbsString::traceEval() const
{
const char* value = evaluate() ;
if (!isValidString(value)) {
cxcoutD(Tracing) << "RooAbsString::traceEval(" << GetName() << "): new output too long (>" << _len << " chars): " << value << endl ;
}
traceEvalHook(value) ;
return value ;
}
void RooAbsString::syncCache(const RooArgSet*)
{
getVal() ;
}
void RooAbsString::copyCache(const RooAbsArg* source, Bool_t , Bool_t setValDirty)
{
RooAbsString* other = dynamic_cast<RooAbsString*>(const_cast<RooAbsArg*>(source)) ;
assert(other!=0) ;
strlcpy(_value,other->_value,_len) ;
if (setValDirty) {
setValueDirty() ;
}
}
void RooAbsString::attachToTree(TTree& t, Int_t bufSize)
{
TBranch* branch ;
if ((branch = t.GetBranch(GetName()))) {
t.SetBranchAddress(GetName(),_value) ;
if (branch->GetCompressionLevel()<0) {
cxcoutD(DataHandling) << "RooAbsString::attachToTree(" << GetName() << ") Fixing compression level of branch " << GetName() << endl ;
branch->SetCompressionLevel(1) ;
}
} else {
TString format(GetName());
format.Append("/C");
branch = t.Branch(GetName(), _value, (const Text_t*)format, bufSize);
branch->SetCompressionLevel(1) ;
}
}
void RooAbsString::fillTreeBranch(TTree& t)
{
TBranch* branch = t.GetBranch(GetName()) ;
if (!branch) {
coutE(DataHandling) << "RooAbsString::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << endl ;
assert(0) ;
}
branch->Fill() ;
}
void RooAbsString::setTreeBranchStatus(TTree& t, Bool_t active)
{
TBranch* branch = t.GetBranch(GetName()) ;
if (branch) {
t.SetBranchStatus(GetName(),active?1:0) ;
}
}
RooAbsArg *RooAbsString::createFundamental(const char* newname) const
{
RooStringVar *fund= new RooStringVar(newname?newname:GetName(),GetTitle(),"") ;
return fund;
}