KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVNamedParameter Class Reference

Detailed Description

A generic named parameter storing values of different types.

The four different types which are handled are: int, double, bool, TString:

Setting and retrieving parameter values

KVNamedParameter a("a", 12.34);
a.Is<double>(); // => true
a.IsInt(); // => false
a.IsNumber(); // => true
KVNamedParameter b("b", true);
b.Is<bool>(); // => true
b.Is<TString>(); // => false
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
A generic named parameter storing values of different types.
TArc a

The same parameter can be reused to store a value with a different type:

b.Set("hello");
b.IsBool(); // => false
b.IsString(); // => true
b.Is<std::string>(); // => true

To retrieve the value of the parameter, its type must be given. This need not be the original type of the parameter, some common sense transformations are allowed:

b.GetString(); => (const char*) "hello"
b.Get<std::string>(); => (std::string) "hello"
b.Get<int>() => (int) 0
a.Get<double>(); => (double) 12.34
a.GetString(); => (const char*) "12.34"
a.GetInt(); => (int) 12
b.Set("12.34");
b.GetDouble(); => (double) 12.34
b.Get<int>() => (int) 12

Comparing parameters

Two types of comparison are possible. The == operator or member function IsEqual() test for strict equality between two parameters, i.e. they must have the same type, value, and name:

KVNamedParameter a{"A",12}, b{"A",12};
cout << (a==b) << endl; => (bool) true
b.SetName("B");
cout << b.IsEqual(&a) << endl; => (bool) false

On the other hand, HasTheSameValueAs() returns true as long as both parameters have the same type and value:

cout << b.HasTheSameValueAs(a) << endl; => (bool) true

Miscellaneous

The methods WriteToEnv(TEnv*, const TString &) and Set(TEnv*, const TString &) can be used to read/write parameter lists from/to ROOT resource files (.rootrc-style files).

Add(const KVNamedParameter &) will sum the values of two numerical parameters or concatenate two string parameters with a separating comma.

Definition at line 90 of file KVNamedParameter.h.

#include <KVNamedParameter.h>

Inheritance diagram for KVNamedParameter:

Classes

struct  typecode
 
struct  typecode< bool >
 
struct  typecode< cstring >
 
struct  typecode< double >
 
struct  typecode< int >
 
struct  typecode< KVString >
 
struct  typecode< std::string >
 
struct  typecode< TString >
 

Public Member Functions

 KVNamedParameter ()
 Default constructor.
 
 KVNamedParameter (const char *)
 
 KVNamedParameter (const char *, Bool_t)
 
 KVNamedParameter (const char *, const char *)
 
 KVNamedParameter (const char *, const KVNamedParameter &)
 Create parameter with given name "nom", and the type & value of "p".
 
 KVNamedParameter (const char *, Double_t)
 
 KVNamedParameter (const char *, Int_t)
 
virtual ~KVNamedParameter ()
 Destructor.
 
void Add (const KVNamedParameter &p)
 
virtual void Clear (Option_t *="")
 Removes the name and any assigned value.
 
Int_t Compare (const TObject *obj) const
 Compares numerical parameters for sorting lists (such as KVNameValueList)
 
template<typename T >
T Get () const
 
template<>
int Get () const
 
template<>
double Get () const
 
template<>
bool Get () const
 
template<>
KVString Get () const
 
template<>
TString Get () const
 
template<>
cstring Get () const
 
Bool_t GetBool () const
 
Double_t GetDouble () const
 
Int_t GetInt () const
 
const Char_tGetSQLType () const
 
const Char_tGetString () const
 
TString GetTString () const
 
Bool_t HasSameValueAs (const KVNamedParameter &) const
 
template<typename T >
Bool_t Is () const
 
Bool_t IsBool () const
 
Bool_t IsDouble () const
 
Bool_t IsEqual (const TObject *obj) const
 
Bool_t IsInt () const
 
Bool_t IsNumber () const
 
Bool_t IsString () const
 
virtual void ls (Option_t *opt="") const
 
Bool_t operator== (const KVNamedParameter &) const
 
virtual void Print (Option_t *opt="") const
 
void Set (Bool_t)
 
void Set (const char *)
 
void Set (const char *, Bool_t)
 
void Set (const char *, const char *)
 
void Set (const char *, const KVNamedParameter &)
 Set parameter name "nom" with the type & value of "p".
 
void Set (const char *, Double_t)
 
void Set (const char *, Int_t)
 
void Set (Double_t)
 
void Set (Int_t)
 
void Set (TEnv *, const TString &p="")
 void Set(const KVNamedParameter&);
 
void WriteToEnv (TEnv *, const TString &p="")
 Write parameter in TEnv, using optional prefix p as "p.[name]".
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TNamed &named)
 
 TNamed (const TString &name, const TString &title)
 
virtual ~TNamed ()
 
void Clear (Option_t *option="") override
 
TObjectClone (const char *newname="") const override
 
Int_t Compare (const TObject *obj) const override
 
void Copy (TObject &named) const override
 
virtual void FillBuffer (char *&buffer)
 
const char * GetName () const override
 
const char * GetTitle () const override
 
ULong_t Hash () const override
 
TClassIsA () const override
 
Bool_t IsSortable () const override
 
void ls (Option_t *option="") const override
 
TNamedoperator= (const TNamed &rhs)
 
void Print (Option_t *option="") const override
 
virtual void SetName (const char *name)
 
virtual void SetNameTitle (const char *name, const char *title)
 
virtual void SetTitle (const char *title="")
 
virtual Int_t Sizeof () const
 
void Streamer (TBuffer &) override
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
- Public Member Functions inherited from TObject
 TObject ()
 
 TObject (const TObject &object)
 
virtual ~TObject ()
 
void AbstractMethod (const char *method) const
 
virtual void AppendPad (Option_t *option="")
 
virtual void Browse (TBrowser *b)
 
ULong_t CheckedHash ()
 
virtual const char * ClassName () const
 
virtual void Delete (Option_t *option="")
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 
virtual void Draw (Option_t *option="")
 
virtual void DrawClass () const
 
virtual TObjectDrawClone (Option_t *option="") const
 
virtual void Dump () const
 
virtual void Error (const char *method, const char *msgfmt,...) const
 
virtual void Execute (const char *method, const char *params, Int_t *error=nullptr)
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr)
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 
virtual TObjectFindObject (const char *name) const
 
virtual TObjectFindObject (const TObject *obj) const
 
virtual Option_tGetDrawOption () const
 
virtual const char * GetIconName () const
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 
virtual Option_tGetOption () const
 
virtual UInt_t GetUniqueID () const
 
virtual Bool_t HandleTimer (TTimer *timer)
 
Bool_t HasInconsistentHash () const
 
virtual void Info (const char *method, const char *msgfmt,...) const
 
virtual Bool_t InheritsFrom (const char *classname) const
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 
virtual void Inspect () const
 
void InvertBit (UInt_t f)
 
Bool_t IsDestructed () const
 
virtual Bool_t IsFolder () const
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
void MayNotUse (const char *method) const
 
virtual Bool_t Notify ()
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 
void operator delete (void *ptr)
 
void operator delete (void *ptr, void *vp)
 
void operator delete[] (void *ptr)
 
void operator delete[] (void *ptr, void *vp)
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 
virtual void Paint (Option_t *option="")
 
virtual void Pop ()
 
virtual Int_t Read (const char *name)
 
virtual void RecursiveRemove (TObject *obj)
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 
virtual void SetDrawOption (Option_t *option="")
 
virtual void SetUniqueID (UInt_t uid)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 
virtual Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
 
virtual Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const
 

Static Public Member Functions

template<typename T >
static T DefaultValue ()
 
template<>
int DefaultValue ()
 
template<>
double DefaultValue ()
 
template<>
bool DefaultValue ()
 
template<>
TString DefaultValue ()
 
template<>
KVString DefaultValue ()
 
template<>
cstring DefaultValue ()
 
- Static Public Member Functions inherited from TNamed
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
- Static Public Member Functions inherited from TObject
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Longptr_t GetDtorOnly ()
 
static Bool_t GetObjectStat ()
 
static void SetDtorOnly (void *obj)
 
static void SetObjectStat (Bool_t stat)
 

Private Types

enum  { kIsString = BIT(14) , kIsDouble = BIT(15) , kIsInt = BIT(16) , kIsBool = BIT(17) }
 
enum  { kBitMask = 0x0003c000 }
 

Private Member Functions

Int_t GetType () const
 
void ResetBits ()
 
void SetType (UInt_t f)
 

Private Attributes

Double_t fNumber
 used to store numerical (integer or floating-point) values
 

Friends

class KVNameValueList
 

Additional Inherited Members

- Public Types inherited from TObject
enum  EDeprecatedStatusBits
 
enum  EStatusBits
 
- Public Attributes inherited from TObject
 kBitMask
 
 kCanDelete
 
 kCannotPick
 
 kHasUUID
 
 kInconsistent
 
 kInvalidObject
 
 kIsOnHeap
 
 kIsReferenced
 
 kMustCleanup
 
 kNoContextMenu
 
 kNotDeleted
 
 kObjInCanvas
 
 kOverwrite
 
 kSingleKey
 
 kWriteDelete
 
 kZombie
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 
void MakeZombie ()
 
- Protected Attributes inherited from TNamed
TString fName
 
TString fTitle
 
- Protected Attributes inherited from TObject
 kOnlyPrepStep
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
kIsString 
kIsDouble 
kIsInt 
kIsBool 

Definition at line 94 of file KVNamedParameter.h.

◆ anonymous enum

anonymous enum
private
Enumerator
kBitMask 

Definition at line 103 of file KVNamedParameter.h.

Constructor & Destructor Documentation

◆ KVNamedParameter() [1/7]

KVNamedParameter::KVNamedParameter ( )

Default constructor.

Definition at line 17 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [2/7]

KVNamedParameter::KVNamedParameter ( const char *  nom)

Definition at line 37 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [3/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
const char *  val 
)

Definition at line 47 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [4/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
Double_t  val 
)

Definition at line 79 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [5/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
Int_t  val 
)

Definition at line 111 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [6/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
Bool_t  val 
)

Definition at line 121 of file KVNamedParameter.cpp.

◆ KVNamedParameter() [7/7]

KVNamedParameter::KVNamedParameter ( const char *  nom,
const KVNamedParameter p 
)

Create parameter with given name "nom", and the type & value of "p".

Definition at line 132 of file KVNamedParameter.cpp.

◆ ~KVNamedParameter()

KVNamedParameter::~KVNamedParameter ( )
virtual

Destructor.

Definition at line 28 of file KVNamedParameter.cpp.

Member Function Documentation

◆ Add()

void KVNamedParameter::Add ( const KVNamedParameter p)

Numerical values: Add the numerical value of "p" to this parameter Strings: add string to comma-separated list of values If parameters are not same type, print warning and do nothing

Definition at line 181 of file KVNamedParameter.cpp.

◆ Clear()

void KVNamedParameter::Clear ( Option_t = "")
virtual

Removes the name and any assigned value.

Reimplemented from TObject.

Definition at line 259 of file KVNamedParameter.cpp.

◆ Compare()

Int_t KVNamedParameter::Compare ( const TObject obj) const
virtual

Compares numerical parameters for sorting lists (such as KVNameValueList)

Reimplemented from TObject.

Definition at line 501 of file KVNamedParameter.cpp.

◆ DefaultValue() [1/7]

template<typename T >
static T KVNamedParameter::DefaultValue ( )
static

◆ DefaultValue() [2/7]

template<>
int KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 231 of file KVNamedParameter.h.

◆ DefaultValue() [3/7]

template<>
double KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 235 of file KVNamedParameter.h.

◆ DefaultValue() [4/7]

template<>
bool KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 239 of file KVNamedParameter.h.

◆ DefaultValue() [5/7]

template<>
TString KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 243 of file KVNamedParameter.h.

◆ DefaultValue() [6/7]

template<>
KVString KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 247 of file KVNamedParameter.h.

◆ DefaultValue() [7/7]

template<>
cstring KVNamedParameter::DefaultValue ( )
inlinestatic

Definition at line 251 of file KVNamedParameter.h.

◆ Get() [1/7]

template<typename T >
T KVNamedParameter::Get ( ) const
inline

compile-time error if one of allowed specializations not used

Definition at line 155 of file KVNamedParameter.h.

◆ Get() [2/7]

template<>
int KVNamedParameter::Get ( ) const
inline

Definition at line 203 of file KVNamedParameter.h.

◆ Get() [3/7]

template<>
double KVNamedParameter::Get ( ) const
inline

Definition at line 207 of file KVNamedParameter.h.

◆ Get() [4/7]

template<>
bool KVNamedParameter::Get ( ) const
inline

Definition at line 211 of file KVNamedParameter.h.

◆ Get() [5/7]

template<>
KVString KVNamedParameter::Get ( ) const
inline

Definition at line 215 of file KVNamedParameter.h.

◆ Get() [6/7]

template<>
TString KVNamedParameter::Get ( ) const
inline

Definition at line 219 of file KVNamedParameter.h.

◆ Get() [7/7]

template<>
cstring KVNamedParameter::Get ( ) const
inline

Definition at line 223 of file KVNamedParameter.h.

◆ GetBool()

Bool_t KVNamedParameter::GetBool ( ) const

returns boolean if parameter value is of boolean type if string, conversion to integer is attempted

Definition at line 353 of file KVNamedParameter.cpp.

◆ GetDouble()

Double_t KVNamedParameter::GetDouble ( ) const

returns double if parameter value is of numerical type if string, conversion to floating point is attempted

Definition at line 319 of file KVNamedParameter.cpp.

◆ GetInt()

Int_t KVNamedParameter::GetInt ( ) const

returns integer if parameter value is of numerical type if string, conversion to integer is attempted

Definition at line 336 of file KVNamedParameter.cpp.

◆ GetSQLType()

const Char_t * KVNamedParameter::GetSQLType ( ) const

Returns type of parameter for use in SQLite database "INTEGER", "REAL", or "TEXT"

Definition at line 535 of file KVNamedParameter.cpp.

◆ GetString()

const Char_t * KVNamedParameter::GetString ( ) const

Returns value of parameter as a string, whatever the type (integer or floating values are converted to a string, booleans are "true" or "false")

Definition at line 274 of file KVNamedParameter.cpp.

◆ GetTString()

TString KVNamedParameter::GetTString ( ) const

Returns value of parameter as a TString, whatever the type (integer or floating values are converted to a string)

Definition at line 297 of file KVNamedParameter.cpp.

◆ GetType()

Int_t KVNamedParameter::GetType ( ) const
inlineprivate

compare this value with the values kIsString, kIsDouble, etc.

Definition at line 111 of file KVNamedParameter.h.

◆ HasSameValueAs()

Bool_t KVNamedParameter::HasSameValueAs ( const KVNamedParameter other) const

Returns kTRUF if the two parameters have the same type and the same value (don't care about parameter names)

Definition at line 401 of file KVNamedParameter.cpp.

◆ Is()

template<typename T >
Bool_t KVNamedParameter::Is ( ) const
inline

Definition at line 283 of file KVNamedParameter.h.

◆ IsBool()

Bool_t KVNamedParameter::IsBool ( ) const
inline

Definition at line 179 of file KVNamedParameter.h.

◆ IsDouble()

Bool_t KVNamedParameter::IsDouble ( ) const
inline

Definition at line 171 of file KVNamedParameter.h.

◆ IsEqual()

Bool_t KVNamedParameter::IsEqual ( const TObject obj) const
virtual

Test for equality between two parameters Returns kTRUE if both the name, the type, and the value of the parameters are identical

Reimplemented from TObject.

Definition at line 370 of file KVNamedParameter.cpp.

◆ IsInt()

Bool_t KVNamedParameter::IsInt ( ) const
inline

Definition at line 175 of file KVNamedParameter.h.

◆ IsNumber()

Bool_t KVNamedParameter::IsNumber ( ) const
inline

Definition at line 183 of file KVNamedParameter.h.

◆ IsString()

Bool_t KVNamedParameter::IsString ( ) const
inline

Definition at line 167 of file KVNamedParameter.h.

◆ ls()

void KVNamedParameter::ls ( Option_t option = "") const
virtual

compact listing of parameter name & value, used by KVNameValueList::Print option controls what is printed: "" (default) : all parameters "int" : only integer parameters "bool" : only boolean parameters "double" : only double parameters "string" : only string parameters

Reimplemented from TObject.

Definition at line 453 of file KVNamedParameter.cpp.

◆ operator==()

Bool_t KVNamedParameter::operator== ( const KVNamedParameter other) const

Test for equality between two parameters Returns kTRUE if both the name, the type, and the value of the parameters are identical

Definition at line 386 of file KVNamedParameter.cpp.

◆ Print()

void KVNamedParameter::Print ( Option_t opt = "") const
virtual

Reimplemented from TObject.

Definition at line 433 of file KVNamedParameter.cpp.

◆ ResetBits()

void KVNamedParameter::ResetBits ( )
inlineprivate

Definition at line 106 of file KVNamedParameter.h.

◆ Set() [1/10]

void KVNamedParameter::Set ( Bool_t  val)

Definition at line 216 of file KVNamedParameter.cpp.

◆ Set() [2/10]

void KVNamedParameter::Set ( const char *  val)

Definition at line 68 of file KVNamedParameter.cpp.

◆ Set() [3/10]

void KVNamedParameter::Set ( const char *  name,
Bool_t  val 
)

Definition at line 154 of file KVNamedParameter.cpp.

◆ Set() [4/10]

void KVNamedParameter::Set ( const char *  name,
const char *  val 
)

Definition at line 57 of file KVNamedParameter.cpp.

◆ Set() [5/10]

void KVNamedParameter::Set ( const char *  nom,
const KVNamedParameter p 
)

Set parameter name "nom" with the type & value of "p".

Definition at line 166 of file KVNamedParameter.cpp.

◆ Set() [6/10]

void KVNamedParameter::Set ( const char *  name,
Double_t  val 
)

Definition at line 89 of file KVNamedParameter.cpp.

◆ Set() [7/10]

void KVNamedParameter::Set ( const char *  name,
Int_t  val 
)

Definition at line 143 of file KVNamedParameter.cpp.

◆ Set() [8/10]

void KVNamedParameter::Set ( Double_t  val)

Definition at line 100 of file KVNamedParameter.cpp.

◆ Set() [9/10]

void KVNamedParameter::Set ( Int_t  val)

Definition at line 205 of file KVNamedParameter.cpp.

◆ Set() [10/10]

void KVNamedParameter::Set ( TEnv e,
const TString p = "" 
)

void Set(const KVNamedParameter&);

Look for value in TEnv with same name as this parameter, or prefixed with "p." If found, set value according to TEnv

Definition at line 240 of file KVNamedParameter.cpp.

◆ SetType()

void KVNamedParameter::SetType ( UInt_t  f)
inlineprivate

Definition at line 117 of file KVNamedParameter.h.

◆ WriteToEnv()

void KVNamedParameter::WriteToEnv ( TEnv e,
const TString p = "" 
)

Write parameter in TEnv, using optional prefix p as "p.[name]".

Definition at line 517 of file KVNamedParameter.cpp.

Friends And Related Symbol Documentation

◆ KVNameValueList

friend class KVNameValueList
friend

Definition at line 92 of file KVNamedParameter.h.

Member Data Documentation

◆ fNumber

Double_t KVNamedParameter::fNumber
private

used to store numerical (integer or floating-point) values

Definition at line 124 of file KVNamedParameter.h.