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 implements a string values RooAbsArg
23**/
24
25#include "RooFit.h"
26#include "Riostream.h"
27
28#include <math.h>
29#include "TObjString.h"
30#include "TTree.h"
31#include "RooStringVar.h"
32#include "RooStreamParser.h"
33#include "RooMsgService.h"
34
35
36
37using namespace std;
38
40
41
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Constructor with initial value and internal buffer size
46
47RooStringVar::RooStringVar(const char *name, const char *title, const char* value, Int_t size) :
48 RooAbsString(name, title, size)
49{
50 if(!isValidString(value)) {
51 coutW(InputArguments) << "RooStringVar::RooStringVar(" << GetName()
52 << "): initial contents too long and ignored" << endl ;
53 } else {
54 strlcpy(_value,value,_len) ;
55 }
56
59}
60
61
62
63////////////////////////////////////////////////////////////////////////////////
64/// Copy constructor
65
66RooStringVar::RooStringVar(const RooStringVar& other, const char* name) :
67 RooAbsString(other, name)
68{
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Destructor
75
77{
78}
79
80
81
82////////////////////////////////////////////////////////////////////////////////
83
84RooStringVar::operator TString()
85{
86 // Cast operator to TString
87 return TString(_value) ;
88}
89
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// Set value to given TString
94
95void RooStringVar::setVal(const char* value)
96{
97 if (!isValidString(value)) {
98 coutW(InputArguments) << "RooStringVar::setVal(" << GetName() << "): new string too long and ignored" << endl ;
99 } else {
100 if (value) {
101 strlcpy(_value,value,_len) ;
102 } else {
103 _value[0] = 0 ;
104 }
105 }
106}
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Set value to given TString
112
113RooAbsArg& RooStringVar::operator=(const char* newValue)
114{
115 if (!isValidString(newValue)) {
116 coutW(InputArguments) << "RooStringVar::operator=(" << GetName() << "): new string too long and ignored" << endl ;
117 } else {
118 if (newValue) {
119 strlcpy(_value,newValue,_len) ;
120 } else {
121 _value[0] = 0 ;
122 }
123 }
124
125 return *this ;
126}
127
128
129
130////////////////////////////////////////////////////////////////////////////////
131/// Read object contents from given stream
132
134{
135 TString token,errorPrefix("RooStringVar::readFromStream(") ;
136 errorPrefix.Append(GetName()) ;
137 errorPrefix.Append(")") ;
138 RooStreamParser parser(is,errorPrefix) ;
139
140 TString newValue ;
141 Bool_t ret(kFALSE) ;
142
143 if (compact) {
144 parser.readString(newValue,kTRUE) ;
145 } else {
146 newValue = parser.readLine() ;
147 }
148
149 if (!isValidString(newValue)) {
150 if (verbose)
151 coutW(InputArguments) << "RooStringVar::readFromStream(" << GetName()
152 << "): new string too long and ignored" << endl ;
153 } else {
154 strlcpy(_value,newValue,_len) ;
155 }
156
157 return ret ;
158}
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Write object contents to given stream
163
164void RooStringVar::writeToStream(ostream& os, Bool_t /*compact*/) const
165{
166 os << getVal() ;
167}
168
169
#define coutW(a)
Definition: RooMsgService.h:33
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition: RooAbsArg.h:471
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:466
RooAbsString is the common abstract base class for objects that represent a string value.
Definition: RooAbsString.h:25
virtual Bool_t isValidString(const char *, Bool_t printError=kFALSE) const
Check if given string value is valid.
char * _value
Definition: RooAbsString.h:68
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 implements a string values RooAbsArg.
Definition: RooStringVar.h:23
virtual RooAbsArg & operator=(const char *newValue)
Set value to given TString.
virtual void setVal(const char *newVal)
Set value to given TString.
virtual const char * getVal() const
Return value of object. Calculated if dirty, otherwise cached value is returned.
Definition: RooStringVar.h:34
virtual ~RooStringVar()
Destructor.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
TString & Append(const char *cs)
Definition: TString.h:559
@ InputArguments
Definition: RooGlobalFunc.h:68