Logo ROOT  
Reference Guide
RooStringVar.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooStringVar.cxx
19\class RooStringVar
20\ingroup Roofitcore
21
22RooStringVar is a RooAbsArg implementing string values.
23**/
24
25#include "RooStringVar.h"
26
27#include "Riostream.h"
28#include "TTree.h"
29#include "RooStreamParser.h"
30#include "RooMsgService.h"
31#include "TBranch.h"
32
33
34////////////////////////////////////////////////////////////////////////////////
35/// Constructor with initial value. The size argument is ignored.
36RooStringVar::RooStringVar(const char *name, const char *title, const char* value, Int_t) :
37 RooAbsArg(name, title),
38 _string(value)
39{
41}
42
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// Copy constructor
47
48RooStringVar::RooStringVar(const RooStringVar& other, const char* name) :
49 RooAbsArg(other, name),
50 _string(other._string)
51{
53}
54
55
56
57////////////////////////////////////////////////////////////////////////////////
58/// Read object contents from given stream
59bool RooStringVar::readFromStream(std::istream& is, Bool_t compact, Bool_t)
60{
61 TString token,errorPrefix("RooStringVar::readFromStream(") ;
62 errorPrefix.Append(GetName()) ;
63 errorPrefix.Append(")") ;
64 RooStreamParser parser(is,errorPrefix) ;
65
66 TString newValue ;
67
68 if (compact) {
69 parser.readString(newValue,kTRUE) ;
70 } else {
71 newValue = parser.readLine() ;
72 }
73
74 _string = newValue;
76
77 return false;
78}
79
80
81////////////////////////////////////////////////////////////////////////////////
82/// Copy cache of another RooAbsArg to our cache
83///
84/// Warning: This function copies the cached values of source,
85/// it is the callers responsibility to make sure the cache is clean
86
87void RooStringVar::copyCache(const RooAbsArg* source, Bool_t /*valueOnly*/, Bool_t setValDirty)
88{
89 auto other = dynamic_cast<const RooStringVar*>(source) ;
90 assert(other);
91
92 _string = other->_string;
93 if (setValDirty) {
95 }
96}
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Attach object to a branch of given TTree
102
104{
105 // First determine if branch is taken
106 TBranch* branch ;
107 if ((branch = t.GetBranch(GetName()))) {
109 } else {
110 t.Branch(GetName(), &_string);
111 }
112}
113
114
115
116////////////////////////////////////////////////////////////////////////////////
117/// Fill tree branch associated with this object
118
120{
121 // First determine if branch is taken
122 TBranch* branch = t.GetBranch(GetName()) ;
123 if (!branch) {
124 coutE(DataHandling) << "RooAbsString::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << std::endl;
125 assert(false);
126 return;
127 }
128 branch->Fill() ;
129}
130
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// (De)Activate associated tree branch
135
137{
138 TBranch* branch = t.GetBranch(GetName()) ;
139 if (branch) {
140 t.SetBranchStatus(GetName(),active?1:0) ;
141 }
142}
143
144
#define coutE(a)
Definition: RooMsgService.h:33
const Bool_t kTRUE
Definition: RtypesCore.h:100
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition: TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:78
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:514
Bool_t readString(TString &value, Bool_t zapOnError=kFALSE)
Read a string token.
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
RooStringVar is a RooAbsArg implementing string values.
Definition: RooStringVar.h:23
void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDiry=kTRUE) override
Copy cache of another RooAbsArg to our cache.
void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach object to a branch of given TTree.
void setTreeBranchStatus(TTree &t, Bool_t active) override
(De)Activate associated tree branch
bool readFromStream(std::istream &is, Bool_t compact, Bool_t verbose) override
Read object contents from given stream.
void fillTreeBranch(TTree &t) override
Fill tree branch associated with this object.
std::string _string
Definition: RooStringVar.h:74
A TTree is a list of TBranches.
Definition: TBranch.h:89
Int_t Fill()
Definition: TBranch.h:201
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:136
TString & Append(const char *cs)
Definition: TString.h:564
A TTree represents a columnar dataset.
Definition: TTree.h:79
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition: TTree.cxx:5256
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition: TTree.cxx:8339
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
Definition: TTree.h:350
virtual void SetBranchStatus(const char *bname, Bool_t status=1, UInt_t *found=0)
Set branch status to Process or DoNotProcess.
Definition: TTree.cxx:8488
@ DataHandling
Definition: RooGlobalFunc.h:65