Logo ROOT  
Reference Guide
RooStringVar.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooStringVar.h,v 1.23 2007/05/11 09:11:30 verkerke Exp $
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 #ifndef ROO_STRING_VAR
17 #define ROO_STRING_VAR
18 
19 #include "RooAbsArg.h"
20 
21 #include <string>
22 
23 class RooStringVar final : public RooAbsArg {
24 public:
25  // Constructors, assignment etc.
26  RooStringVar() { }
27  RooStringVar(const char *name, const char *title, const char* value, Int_t size=1024) ;
28  RooStringVar(const RooStringVar& other, const char* name=0);
29  virtual TObject* clone(const char* newname) const override { return new RooStringVar(*this,newname); }
30  virtual ~RooStringVar() = default;
31 
32  // Parameter value and error accessors
33  virtual operator TString() {return TString(_string.c_str()); }
34  const char* getVal() const { clearValueDirty(); return _string.c_str(); }
35  void setVal(const char* newVal) { _string = newVal ? newVal : ""; setValueDirty(); }
36  virtual RooAbsArg& operator=(const char* newVal) { setVal(newVal); return *this; }
37 
38  // We implement a fundamental type of AbsArg that can be stored in a dataset
39  bool isFundamental() const override { return true; }
40 
41  // I/O streaming interface (machine readable)
42  bool readFromStream(std::istream& is, Bool_t compact, Bool_t verbose) override;
43  void writeToStream(std::ostream& os, Bool_t /*compact*/) const override { os << _string; }
44 
45  // Return value and unit accessors
46  bool operator==(const char* val) const { return _string == val; }
47  bool operator==(const RooAbsArg& other) const override {
48  auto otherStr = dynamic_cast<const RooStringVar*>(&other);
49  return otherStr && _string == otherStr->_string;
50  }
51  bool isIdentical(const RooAbsArg& other, Bool_t /*assumeSameType*/) const override { return *this == other; }
52 
53  // Printing interface (human readable)
54  virtual void printValue(std::ostream& os) const override { os << _string; }
55 
56 
57  RooAbsArg *createFundamental(const char* newname=0) const override {
58  return new RooStringVar(newname ? newname : GetName(), GetTitle(), "", 1);
59  }
60 
61 protected:
62  // Internal consistency checking (needed by RooDataSet)
63  virtual Bool_t isValid() const override { return true; }
64  virtual Bool_t isValidString(const char*, Bool_t /*printError=kFALSE*/) const { return true; }
65 
66  virtual void syncCache(const RooArgSet* /*nset*/ = nullptr) override { }
67  void copyCache(const RooAbsArg* source, Bool_t valueOnly=kFALSE, Bool_t setValDiry=kTRUE) override;
68  virtual void attachToTree(TTree& t, Int_t bufSize=32000) override;
69  virtual void attachToVStore(RooVectorDataStore&) override { }
70  virtual void fillTreeBranch(TTree& t) override;
71  virtual void setTreeBranchStatus(TTree& t, Bool_t active) override;
72 
73 private:
74  std::string _string;
75  ClassDefOverride(RooStringVar,2) // String-valued variable
76 };
77 
78 #endif
RooStringVar::isIdentical
bool isIdentical(const RooAbsArg &other, Bool_t) const override
Definition: RooStringVar.h:65
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::getVal
const char * getVal() const
Definition: RooStringVar.h:48
RooStringVar::~RooStringVar
virtual ~RooStringVar()=default
RooStringVar::_string
std::string _string
Definition: RooStringVar.h:88
RooStringVar::RooStringVar
RooStringVar()
Definition: RooStringVar.h:40
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
TTree
Definition: TTree.h:79
RooAbsArg.h
RooStringVar::operator=
virtual RooAbsArg & operator=(const char *newVal)
Definition: RooStringVar.h:50
RooStringVar::syncCache
virtual void syncCache(const RooArgSet *=nullptr) override
Definition: RooStringVar.h:80
RooStringVar::attachToVStore
virtual void attachToVStore(RooVectorDataStore &) override
Definition: RooStringVar.h:83
TString
Definition: TString.h:136
ClassDefOverride
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
bool
RooStringVar::fillTreeBranch
virtual void fillTreeBranch(TTree &t) override
Fill tree branch associated with this object.
Definition: RooStringVar.cxx:120
RooStringVar::setVal
void setVal(const char *newVal)
Definition: RooStringVar.h:49
RooStringVar::isFundamental
bool isFundamental() const override
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition: RooStringVar.h:53
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooStringVar::printValue
virtual void printValue(std::ostream &os) const override
Interface to print value of object.
Definition: RooStringVar.h:68
RooStringVar::writeToStream
void writeToStream(std::ostream &os, Bool_t) const override
Definition: RooStringVar.h:57
RooStringVar::isValidString
virtual Bool_t isValidString(const char *, Bool_t) const
Definition: RooStringVar.h:78
RooStringVar::isValid
virtual Bool_t isValid() const override
WVE (08/21/01) Probably obsolete now.
Definition: RooStringVar.h:77
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
RooVectorDataStore
Definition: RooVectorDataStore.h:35
TObject
Definition: TObject.h:37
RooStringVar::attachToTree
virtual void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach object to a branch of given TTree.
Definition: RooStringVar.cxx:104
RooStringVar::operator==
bool operator==(const char *val) const
Definition: RooStringVar.h:60
name
char name[80]
Definition: TGX11.cxx:110
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooStringVar::createFundamental
RooAbsArg * createFundamental(const char *newname=0) const override
Create a fundamental-type object that stores our type of value.
Definition: RooStringVar.h:71
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
RooStringVar::clone
virtual TObject * clone(const char *newname) const override
Definition: RooStringVar.h:43
RooAbsArg::clearValueDirty
void clearValueDirty() const
Definition: RooAbsArg.h:554
RooStringVar::setTreeBranchStatus
virtual void setTreeBranchStatus(TTree &t, Bool_t active) override
(De)Activate associated tree branch
Definition: RooStringVar.cxx:137
RooArgSet
Definition: RooArgSet.h:28
int