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
22RooStringVar is a RooAbsArg implementing string values.
23**/
24
25#include "RooStringVar.h"
26
27#include "RooFit.h"
28#include "Riostream.h"
29#include "TTree.h"
30#include "RooStreamParser.h"
31#include "RooMsgService.h"
32#include "TBranch.h"
33
34
35////////////////////////////////////////////////////////////////////////////////
36/// Constructor with initial value. The size argument is ignored.
37RooStringVar::RooStringVar(const char *name, const char *title, const char* value, Int_t) :
38 RooAbsArg(name, title),
39 _string(value)
40{
42}
43
44
45
46////////////////////////////////////////////////////////////////////////////////
47/// Copy constructor
48
49RooStringVar::RooStringVar(const RooStringVar& other, const char* name) :
50 RooAbsArg(other, name),
51 _string(other._string)
52{
54}
55
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Read object contents from given stream
60bool RooStringVar::readFromStream(std::istream& is, Bool_t compact, Bool_t)
61{
62 TString token,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,kTRUE) ;
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_t /*valueOnly*/, Bool_t 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?1:0) ;
142 }
143}
144
145
#define coutE(a)
const Bool_t kTRUE
Definition RtypesCore.h:100
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:69
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:505
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.
void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDiry=kTRUE) override
Copy cache of another RooAbsArg to our cache.
virtual void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach object to a branch of given TTree.
virtual 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.
virtual 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:89
Int_t Fill()
Definition TBranch.h:201
virtual const char * GetName() const
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:5279
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition TTree.cxx:8356
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:8505