Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooArgSet.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooArgSet.h,v 1.45 2007/08/09 19:55:47 wouter 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_ARG_SET
17#define ROO_ARG_SET
18
19#include "RooAbsCollection.h"
20
21class RooAbsArg ;
22class RooArgList ;
23
25public:
26
27 // Constructors, assignment etc.
28 RooArgSet();
29
30 /// Construct a (non-owning) RooArgSet from one or more
31 /// RooFit objects. The set will not own its contents.
32 /// \tparam Ts Parameter pack of objects that derive from RooAbsArg or RooFit collections; or a name.
33 /// \param arg A RooFit object.
34 /// Note that you can also pass a `double` as first argument
35 /// when constructing a RooArgSet, and another templated
36 /// constructor will be used where a RooConstVar is implicitly
37 /// created from the `double` value.
38 /// \param moreArgsOrName Arbitrary number of
39 /// - Further RooFit objects that derive from RooAbsArg
40 /// - RooFit collections of such objects
41 /// - `double`s from which a RooConstVar is implicitly created via `RooFit::RooConst`.
42 /// - A name for the set. Given multiple names, the last-given name prevails.
43 template<typename... Args_t>
44 RooArgSet(const RooAbsArg& arg, Args_t &&... moreArgsOrName)
45 /*NB: Making this a delegating constructor led to linker errors with MSVC*/
46 {
47 // This constructor should cause a failed static_assert if any of the input
48 // arguments is a temporary (r-value reference), which will be checked in
49 // processArg. This works statically because of the universal reference
50 // mechanism with templated functions.
51 // Unfortunately, we can't check the first arg, because it's type can't be
52 // a template parameter and hence a universal reference can't be used.
53 // This problem is solved by introducing another templated constructor below,
54 // which accepts a RooAbsArg && as the first argument which is forwarded to
55 // be the second argument for this constructor.
56 processArgs(arg, std::forward<Args_t>(moreArgsOrName)...);
57 }
58
59 /// This constructor will provoke a `static_assert`, because passing a
60 /// RooAbsArg as r-value reference is not allowed.
61 template<typename... Args_t>
62 RooArgSet(RooAbsArg && arg, Args_t &&... moreArgsOrName)
63 : RooArgSet{arg, std::move(arg), std::forward<Args_t>(moreArgsOrName)...} {}
64
65 template<typename... Args_t>
66 explicit RooArgSet(double arg, Args_t &&... moreArgsOrName) {
67 processArgs(arg, std::forward<Args_t>(moreArgsOrName)...);
68 }
69
70 /// Construct a (non-owning) RooArgSet from iterators.
71 /// \tparam Iterator_t An iterator pointing to RooFit objects or to pointers/references of those.
72 /// \param beginIt Iterator to first element to add.
73 /// \param endIt Iterator to end of range to be added.
74 /// \param name Optional name of the collection.
75 template<typename Iterator_t,
76 typename value_type = typename std::remove_pointer<typename std::iterator_traits<Iterator_t>::value_type>::type,
77 typename = std::enable_if<std::is_convertible<const value_type*, const RooAbsArg*>::value> >
78 RooArgSet(Iterator_t beginIt, Iterator_t endIt, const char* name="") :
80 for (auto it = beginIt; it != endIt; ++it) {
81 processArg(*it);
82 }
83 }
84
85 /// Construct a non-owning RooArgSet from a vector of RooAbsArg pointers.
86 /// This constructor is mainly intended for pyROOT. With cppyy, a Python list
87 /// or tuple can be implicitly converted to an std::vector, and by enabling
88 /// implicit construction of a RooArgSet from a std::vector, we indirectly
89 /// enable implicit conversion from a Python list/tuple to RooArgSets.
90 /// \param vec A vector with pointers to the arguments or doubles for RooFit::RooConst().
91 RooArgSet(std::vector<RooAbsArgPtrOrDouble> const& vec) {
92 for(auto const& arg : vec) {
93 if(arg.hasPtr) processArg(arg.ptr);
94 else processArg(arg.val);
95 }
96 }
97
98 RooArgSet(const RooArgSet& other, const char *name="");
99 /// Move constructor.
100 RooArgSet(RooArgSet && other) : RooAbsCollection(std::move(other)) {}
101
102 RooArgSet(const RooArgSet& set1, const RooArgSet& set2,
103 const char *name="");
104
105 RooArgSet(const RooAbsCollection& coll) ;
106 RooArgSet(const RooAbsCollection& collection, const RooAbsArg* var1);
107 explicit RooArgSet(const TCollection& tcoll, const char* name="") ;
108 explicit RooArgSet(const char *name);
109
110 ~RooArgSet() override;
111 TObject* clone(const char* newname) const override { return new RooArgSet(*this,newname); }
112 TObject* create(const char* newname) const override { return new RooArgSet(newname); }
113 RooArgSet& operator=(const RooArgSet& other) { RooAbsCollection::operator=(other) ; return *this ;}
114
115 using RooAbsCollection::operator[];
116 RooAbsArg& operator[](const TString& str) const;
117
118
119 /// Shortcut for readFromStream(std::istream&, bool, const char*, const char*, bool), setting
120 /// `flagReadAtt` and `section` to 0.
121 virtual bool readFromStream(std::istream& is, bool compact, bool verbose=false) {
122 // I/O streaming interface (machine readable)
123 return readFromStream(is, compact, nullptr, nullptr, verbose) ;
124 }
125 bool readFromStream(std::istream& is, bool compact, const char* flagReadAtt, const char* section, bool verbose=false) ;
126 virtual void writeToStream(std::ostream& os, bool compact, const char* section=nullptr) const;
127 void writeToFile(const char* fileName) const ;
128 bool readFromFile(const char* fileName, const char* flagReadAtt=nullptr, const char* section=nullptr, bool verbose=false) ;
129
130
131 /// Check if this exact instance is in this collection.
132 bool containsInstance(const RooAbsArg& var) const override {
133 return find(var) == &var;
134 }
135
136 static void cleanup() ;
137
138 bool isInRange(const char* rangeSpec) ;
139
142
143 /// Use RooAbsCollection::selectByName(), but return as RooArgSet.
144 inline RooArgSet* selectByName(const char* nameList, bool verbose=false) const {
145 return static_cast<RooArgSet*>(RooAbsCollection::selectByName(nameList, verbose));
146 }
147
148 /// Use RooAbsCollection::selecCommon(), but return as RooArgSet.
149 inline RooArgSet* selectCommon(const RooAbsCollection& refColl) const {
150 return static_cast<RooArgSet*>(RooAbsCollection::selectCommon(refColl));
151 }
152
153 /// Use RooAbsCollection::snapshot(), but return as RooArgSet.
154 inline RooArgSet * snapshot(bool deepCopy = true) const {
155 return static_cast<RooArgSet*>(RooAbsCollection::snapshot(deepCopy));
156 }
157
158protected:
159 bool checkForDup(const RooAbsArg& arg, bool silent) const ;
160 bool canBeAdded(const RooAbsArg& arg, bool silent) const override {
161 return !checkForDup(arg, silent);
162 }
163
164private:
165
166 template<typename... Args_t>
167 void processArgs(Args_t &&... args) {
168 // Expand parameter pack in C++ 11 way:
169 int dummy[] = { 0, (processArg(std::forward<Args_t>(args)), 0) ... };
170 (void)dummy;
171 }
172 void processArg(const RooAbsArg& arg) { add(arg); }
173 void processArg(const RooAbsArg* arg) { add(*arg); }
174 void processArg(RooAbsArg* var) { add(*var); }
175 template<class Arg_t>
176 void processArg(Arg_t && arg) {
177 assert_is_no_temporary(std::forward<Arg_t>(arg));
178 add(arg);
179 }
180 void processArg(const char* name) { _name = name; }
181 void processArg(double value);
182 void processArg(const RooAbsCollection& coll) { add(coll); if (_name.Length() == 0) _name = coll.GetName(); }
183 // this overload with r-value references is needed so we don't trigger the
184 // templated function with the failing static_assert for r-value references
185 void processArg(RooAbsCollection && coll) { processArg(coll); }
186 void processArg(const RooArgList& list);
187
188 ClassDefOverride(RooArgSet,1) // Set of RooAbsArg objects
189};
190
191
192namespace RooFitShortHand {
193
194template<class... Args_t>
195RooArgSet S(Args_t&&... args) {
196 return {std::forward<Args_t>(args)...};
197}
198
199} // namespace RooFitShortHand
200
201
202#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:79
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
TString _name
Our name.
static void assert_is_no_temporary(T &&)
RooAbsCollection * selectByName(const char *nameList, bool verbose=false) const
Create a subset of the current collection, consisting only of those elements with names matching the ...
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
RooAbsCollection & operator=(const RooAbsCollection &other)
Assign values from the elements in other to our elements.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
bool isInRange(const char *rangeSpec)
void processArg(RooAbsCollection &&coll)
Definition RooArgSet.h:185
TObject * clone(const char *newname) const override
Definition RooArgSet.h:111
RooArgSet & operator=(const RooArgSet &other)
Definition RooArgSet.h:113
bool checkForDup(const RooAbsArg &arg, bool silent) const
Check if element with var's name is already in set.
RooArgSet(RooAbsArg &&arg, Args_t &&... moreArgsOrName)
This constructor will provoke a static_assert, because passing a RooAbsArg as r-value reference is no...
Definition RooArgSet.h:62
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:154
void processArg(Arg_t &&arg)
Definition RooArgSet.h:176
RooArgSet()
Default constructor.
Definition RooArgSet.cxx:79
RooArgSet(std::vector< RooAbsArgPtrOrDouble > const &vec)
Construct a non-owning RooArgSet from a vector of RooAbsArg pointers.
Definition RooArgSet.h:91
~RooArgSet() override
Destructor.
bool containsInstance(const RooAbsArg &var) const override
Check if this exact instance is in this collection.
Definition RooArgSet.h:132
void processArg(const char *name)
Definition RooArgSet.h:180
RooArgSet(RooArgSet &&other)
Move constructor.
Definition RooArgSet.h:100
bool canBeAdded(const RooAbsArg &arg, bool silent) const override
Determine whether it's possible to add a given RooAbsArg to the collection or not.
Definition RooArgSet.h:160
void writeToFile(const char *fileName) const
Write contents of the argset to specified file.
TObject * create(const char *newname) const override
Definition RooArgSet.h:112
void processArgs(Args_t &&... args)
Definition RooArgSet.h:167
void processArg(const RooAbsArg *arg)
Definition RooArgSet.h:173
void processArg(const RooAbsCollection &coll)
Definition RooArgSet.h:182
RooArgSet(double arg, Args_t &&... moreArgsOrName)
Definition RooArgSet.h:66
void processArg(const RooArgList &list)
RooArgSet * selectByName(const char *nameList, bool verbose=false) const
Use RooAbsCollection::selectByName(), but return as RooArgSet.
Definition RooArgSet.h:144
bool readFromFile(const char *fileName, const char *flagReadAtt=nullptr, const char *section=nullptr, bool verbose=false)
Read contents of the argset from specified file.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
Definition RooArgSet.h:149
void processArg(RooAbsArg *var)
Definition RooArgSet.h:174
static void cleanup()
Definition RooArgSet.cxx:73
virtual bool readFromStream(std::istream &is, bool compact, bool verbose=false)
Shortcut for readFromStream(std::istream&, bool, const char*, const char*, bool), setting flagReadAtt...
Definition RooArgSet.h:121
RooArgSet(Iterator_t beginIt, Iterator_t endIt, const char *name="")
Construct a (non-owning) RooArgSet from iterators.
Definition RooArgSet.h:78
void processArg(const RooAbsArg &arg)
Definition RooArgSet.h:172
RooAbsArg & operator[](const TString &str) const
Get reference to an element using its name.
RooArgSet(const RooAbsArg &arg, Args_t &&... moreArgsOrName)
Construct a (non-owning) RooArgSet from one or more RooFit objects.
Definition RooArgSet.h:44
virtual void writeToStream(std::ostream &os, bool compact, const char *section=nullptr) const
Write the contents of the argset in ASCII form to given stream.
Collection abstract base class.
Definition TCollection.h:65
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
RooArgSet S(Args_t &&... args)
Definition RooArgSet.h:195