Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22A 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), _stringAddr(&_string)
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), _stringAddr(&_string)
51{
53}
54
55
56
57////////////////////////////////////////////////////////////////////////////////
58/// Read object contents from given stream
59bool RooStringVar::readFromStream(std::istream& is, bool compact, bool)
60{
61 TString token;
62 TString errorPrefix("RooStringVar::readFromStream(");
63 errorPrefix.Append(GetName()) ;
64 errorPrefix.Append(")") ;
65 RooStreamParser parser(is,errorPrefix) ;
66
67 TString newValue ;
68
69 if (compact) {
70 parser.readString(newValue,true) ;
71 } else {
72 newValue = parser.readLine() ;
73 }
74
75 _string = newValue;
77
78 return false;
79}
80
81
82////////////////////////////////////////////////////////////////////////////////
83/// Copy cache of another RooAbsArg to our cache
84///
85/// Warning: This function copies the cached values of source,
86/// it is the callers responsibility to make sure the cache is clean
87
88void RooStringVar::copyCache(const RooAbsArg* source, bool /*valueOnly*/, bool setValDirty)
89{
90 auto other = dynamic_cast<const RooStringVar*>(source) ;
91 assert(other);
92
93 _string = other->_string;
94 if (setValDirty) {
96 }
97}
98
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// Attach object to a branch of given TTree
103
105{
106 // First determine if branch is taken
107 TBranch* branch ;
108 if ((branch = t.GetBranch(GetName()))) {
110 } else {
111 t.Branch(GetName(), &_string);
112 }
113}
114
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// Fill tree branch associated with this object
119
121{
122 // First determine if branch is taken
123 TBranch* branch = t.GetBranch(GetName()) ;
124 if (!branch) {
125 coutE(DataHandling) << "RooAbsString::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << std::endl;
126 assert(false);
127 return;
128 }
129 branch->Fill() ;
130}
131
132
133
134////////////////////////////////////////////////////////////////////////////////
135/// (De)Activate associated tree branch
136
138{
139 TBranch* branch = t.GetBranch(GetName()) ;
140 if (branch) {
141 t.SetBranchStatus(GetName(),active?true:false) ;
142 }
143}
144
145
#define coutE(a)
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
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:431
bool readString(TString &value, bool zapOnError=false)
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...
A RooAbsArg implementing string values.
void setTreeBranchStatus(TTree &t, bool active) override
(De)Activate associated tree branch
std::string * _stringAddr
void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach object to a branch of given TTree.
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValDiry=true) override
Copy cache of another RooAbsArg to our cache.
bool readFromStream(std::istream &is, bool compact, bool verbose) override
Read object contents from given stream.
void fillTreeBranch(TTree &t) override
Fill tree branch associated with this object.
std::string _string
A TTree is a list of TBranches.
Definition TBranch.h:93
Int_t Fill()
Definition TBranch.h:205
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:139
TString & Append(const char *cs)
Definition TString.h:572
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr)
Set branch status to Process or DoNotProcess.
Definition TTree.cxx:8534
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5294
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=nullptr)
Change branch address, dealing with clone trees properly.
Definition TTree.cxx:8385
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:353