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 
22 RooStringVar 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.
37 RooStringVar::RooStringVar(const char *name, const char *title, const char* value, Int_t) :
38  RooAbsArg(name, title),
39  _string(value)
40 {
41  setValueDirty();
42 }
43 
44 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Copy constructor
48 
49 RooStringVar::RooStringVar(const RooStringVar& other, const char* name) :
50  RooAbsArg(other, name),
51  _string(other._string)
52 {
53  setValueDirty();
54 }
55 
56 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Read object contents from given stream
60 bool 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;
76  setValueDirty();
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 
88 void 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) {
95  setValueDirty() ;
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 
RooStreamParser.h
RooStreamParser::readString
Bool_t readString(TString &value, Bool_t zapOnError=kFALSE)
Read a string token.
Definition: RooStreamParser.cxx:490
RooStringVar::readFromStream
bool readFromStream(std::istream &is, Bool_t compact, Bool_t verbose) override
Read object contents from given stream.
Definition: RooStringVar.cxx:60
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooStringVar.h
RooStringVar::_string
std::string _string
Definition: RooStringVar.h:88
RooMsgService.h
RooFit.h
RooStringVar::RooStringVar
RooStringVar()
Definition: RooStringVar.h:40
TBranch.h
coutE
#define coutE(a)
Definition: RooMsgService.h:33
TTree
Definition: TTree.h:79
TTree::SetBranchAddress
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition: TTree.cxx:8205
TTree.h
TString
Definition: TString.h:136
bool
RooStringVar::fillTreeBranch
virtual void fillTreeBranch(TTree &t) override
Fill tree branch associated with this object.
Definition: RooStringVar.cxx:120
TBranch::Fill
Int_t Fill()
Definition: TBranch.h:201
TBranch
Definition: TBranch.h:89
TTree::GetBranch
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition: TTree.cxx:5210
RooFit::DataHandling
@ DataHandling
Definition: RooGlobalFunc.h:69
RooStreamParser
Definition: RooStreamParser.h:21
TTree::Branch
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:349
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
RooStreamParser::readLine
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
Definition: RooStreamParser.cxx:309
RooStringVar::copyCache
void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDiry=kTRUE) override
Copy cache of another RooAbsArg to our cache.
Definition: RooStringVar.cxx:88
RooStringVar
Definition: RooStringVar.h:23
RooStringVar::attachToTree
virtual void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach object to a branch of given TTree.
Definition: RooStringVar.cxx:104
name
char name[80]
Definition: TGX11.cxx:110
RooAbsArg
Definition: RooAbsArg.h:73
RooAbsArg::setValueDirty
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:505
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
Riostream.h
TTree::SetBranchStatus
virtual void SetBranchStatus(const char *bname, Bool_t status=1, UInt_t *found=0)
Set branch status to Process or DoNotProcess.
Definition: TTree.cxx:8354
RooStringVar::setTreeBranchStatus
virtual void setTreeBranchStatus(TTree &t, Bool_t active) override
(De)Activate associated tree branch
Definition: RooStringVar.cxx:137
int