Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooArgList.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooArgList.h,v 1.14 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_ARG_LIST
17#define ROO_ARG_LIST
18
19#include "RooAbsCollection.h"
20
21
23public:
24
25 // Constructors, assignment etc.
26 RooArgList();
27 RooArgList(const RooAbsCollection& coll) ;
28 explicit RooArgList(const TCollection& tcoll, const char* name="") ;
29 explicit RooArgList(const char *name);
30 /// Construct a (non-owning) RooArgList from one or more
31 /// RooFit objects.
32 /// \param arg A RooFit object to be put in the set.
33 /// Note that you can also pass a `double` as first argument
34 /// when constructing a RooArgList, and another templated
35 /// constructor will be used where a RooConstVar is implicitly
36 /// created from the `double` value.
37 /// \param moreArgsOrName Arbitrary number of
38 /// - RooFit objects deriving from RooAbsArg.
39 /// - `double`s from which a RooConstVar is implicitly created via `RooFit::RooConst`.
40 /// - A c-string to name the set.
41
42 template<typename... Args_t>
43 RooArgList(RooAbsArg const& arg, Args_t &&... moreArgsOrName)
44 /*NB: Making this a delegating constructor led to linker errors with MSVC*/
45 {
46 // This constructor should cause a failed static_assert if any of the input
47 // arguments is a temporary (r-value reference), which will be checked in
48 // processArg. This works statically because of the universal reference
49 // mechanism with templated functions.
50 // Unfortunately, we can't check the first arg, because it's type can't be
51 // a template parameter and hence a universal reference can't be used.
52 // This problem is solved by introducing another templated constructor below,
53 // which accepts a RooAbsArg && as the first argument which is forwarded to
54 // be the second argument for this constructor.
55 processArgs(arg, std::forward<Args_t>(moreArgsOrName)...);
56 }
57
58 /// This constructor will provoke a `static_assert`, because passing a
59 /// RooAbsArg as r-value reference is not allowed.
60 template<typename... Args_t>
61 RooArgList(RooAbsArg && arg, Args_t &&... moreArgsOrName)
62 : RooArgList{arg, std::move(arg), std::forward<Args_t>(moreArgsOrName)...} {}
63
64 template<typename... Args_t>
65 explicit RooArgList(double arg, Args_t &&... moreArgsOrName) {
66 processArgs(arg, std::forward<Args_t>(moreArgsOrName)...);
67 }
68
69 /// Construct from iterators.
70 /// \tparam Iterator_t An iterator pointing to RooFit objects or pointers/references thereof.
71 /// \param beginIt Iterator to first element to add.
72 /// \param endIt Iterator to end of range to be added.
73 /// \param name Optional name of the collection.
74 template<typename Iterator_t,
75 typename value_type = typename std::remove_pointer<typename std::iterator_traits<Iterator_t>::value_type>,
76 typename = std::enable_if<std::is_convertible<const value_type*, const RooAbsArg*>::value> >
77 RooArgList(Iterator_t beginIt, Iterator_t endIt, const char* name="") :
79 for (auto it = beginIt; it != endIt; ++it) {
80 processArg(*it);
81 }
82 }
83
84 /// Construct a non-owning RooArgList from a vector of RooAbsArg pointers.
85 /// This constructor is mainly intended for pyROOT. With cppyy, a Python list
86 /// or tuple can be implicitly converted to an std::vector, and by enabling
87 /// implicit construction of a RooArgList from a std::vector, we indirectly
88 /// enable implicit conversion from a Python list/tuple to RooArgLists.
89 /// \param vec A vector with pointers to the arguments or doubles for RooFit::RooConst().
90 RooArgList(std::vector<RooAbsArgPtrOrDouble> const& vec) {
91 for(auto const& arg : vec) {
92 if(arg.hasPtr) processArg(arg.ptr);
93 else processArg(arg.val);
94 }
95 }
96
97 ~RooArgList() override;
98 // Create a copy of an existing list. New variables cannot be added
99 // to a copied list. The variables in the copied list are independent
100 // of the original variables.
101 RooArgList(const RooArgList& other, const char *name="");
102 /// Move constructor.
103 RooArgList(RooArgList && other) : RooAbsCollection(std::move(other)) {}
104 TObject* clone(const char* newname) const override { return new RooArgList(*this,newname); }
105 TObject* create(const char* newname) const override { return new RooArgList(newname); }
106 RooArgList& operator=(const RooArgList& other) { RooAbsCollection::operator=(other) ; return *this ; }
107
108
109 /// Return object at given index, or nullptr if index is out of range
110 inline RooAbsArg* at(Int_t idx) const {
111
112 if (idx >= static_cast<Int_t>(_list.size()))
113 return nullptr;
114
115 return _list[idx];
116 }
117
118 // I/O streaming interface (machine readable)
119 virtual bool readFromStream(std::istream& is, bool compact, bool verbose=false);
120 virtual void writeToStream(std::ostream& os, bool compact);
121
122 /// Access element by index.
124 assert(0 <= idx && idx < static_cast<Int_t>(_list.size()));
125 return *_list[idx];
126 }
127
128protected:
129 bool canBeAdded(RooAbsArg const&, bool) const override { return true; }
130
131private:
132 template<typename... Args_t>
133 void processArgs(Args_t &&... args) {
134 // Expand parameter pack in C++ 11 way:
135 int dummy[] = { 0, (processArg(std::forward<Args_t>(args)), 0) ... };
136 (void)dummy;
137 }
138 void processArg(const RooAbsArg& arg) { add(arg); }
139 void processArg(const RooAbsArg* arg) { add(*arg); }
140 void processArg(RooAbsArg* arg) { add(*arg); }
141 template<class Arg_t>
142 void processArg(Arg_t && arg) {
143 assert_is_no_temporary(std::forward<Arg_t>(arg));
144 add(arg);
145 }
146 void processArg(const char* name) { _name = name; }
147 void processArg(double value);
148
149 ClassDefOverride(RooArgList,1) // Ordered list of RooAbsArg objects
150};
151
152
154
155template<class... Args_t>
156RooArgList L(Args_t&&... args) {
157 return {std::forward<Args_t>(args)...};
158}
159
160} // namespace RooFitShortHand
161
162
163#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
char name[80]
Definition TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:74
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
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 &&)
Storage_t _list
Actual object storage.
RooAbsCollection & operator=(const RooAbsCollection &other)
Assign values from the elements in other to our elements.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
virtual void writeToStream(std::ostream &os, bool compact)
Write the contents of the argset in ASCII form to given stream.
bool canBeAdded(RooAbsArg const &, bool) const override
Determine whether it's possible to add a given RooAbsArg to the collection or not.
Definition RooArgList.h:129
RooArgList(RooAbsArg const &arg, Args_t &&... moreArgsOrName)
Construct a (non-owning) RooArgList from one or more RooFit objects.
Definition RooArgList.h:43
TObject * create(const char *newname) const override
Definition RooArgList.h:105
RooArgList(std::vector< RooAbsArgPtrOrDouble > const &vec)
Construct a non-owning RooArgList from a vector of RooAbsArg pointers.
Definition RooArgList.h:90
TObject * clone(const char *newname) const override
Definition RooArgList.h:104
void processArgs(Args_t &&... args)
Definition RooArgList.h:133
RooArgList(Iterator_t beginIt, Iterator_t endIt, const char *name="")
Construct from iterators.
Definition RooArgList.h:77
RooArgList(RooArgList &&other)
Move constructor.
Definition RooArgList.h:103
RooArgList()
Default constructor.
void processArg(Arg_t &&arg)
Definition RooArgList.h:142
void processArg(const RooAbsArg &arg)
Definition RooArgList.h:138
RooArgList & operator=(const RooArgList &other)
Definition RooArgList.h:106
void processArg(const RooAbsArg *arg)
Definition RooArgList.h:139
RooAbsArg & operator[](Int_t idx) const
Access element by index.
Definition RooArgList.h:123
RooArgList(double arg, Args_t &&... moreArgsOrName)
Definition RooArgList.h:65
void processArg(RooAbsArg *arg)
Definition RooArgList.h:140
RooArgList(RooAbsArg &&arg, Args_t &&... moreArgsOrName)
This constructor will provoke a static_assert, because passing a RooAbsArg as r-value reference is no...
Definition RooArgList.h:61
~RooArgList() override
Destructor.
void processArg(const char *name)
Definition RooArgList.h:146
virtual bool readFromStream(std::istream &is, bool compact, bool verbose=false)
Read the contents of the argset in ASCII form from given stream.
Collection abstract base class.
Definition TCollection.h:65
Mother of all ROOT objects.
Definition TObject.h:41
RooArgList L(Args_t &&... args)
Definition RooArgList.h:156