Logo ROOT  
Reference Guide
RooArgList.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/// \class RooArgList
19/// RooArgList is a container object that can hold multiple RooAbsArg objects.
20/// The container has list semantics which means that:
21///
22/// - Contained objects are ordered, The iterator
23/// follows the object insertion order.
24///
25/// - Objects can be retrieved by name and index
26///
27/// - Multiple objects with the same name are allowed
28///
29/// Ownership of contents.
30///
31/// Unowned objects are inserted with the add() method. Owned objects
32/// are added with addOwned() or addClone(). A RooArgSet either owns all
33/// of it contents, or none, which is determined by the first <add>
34/// call. Once an ownership status is selected, inappropriate <add> calls
35/// will return error status. Clearing the list via removeAll() resets the
36/// ownership status. Arguments supplied in the constructor are always added
37/// as unowned elements.
38///
39///
40
41#include "Riostream.h"
42#include <iomanip>
43#include "TClass.h"
44#include "RooArgList.h"
45#include "RooErrorHandler.h"
46#include "RooStreamParser.h"
47#include "RooFormula.h"
48#include "RooAbsRealLValue.h"
50#include "RooTrace.h"
51#include "RooMsgService.h"
52
53using namespace std;
54
56 ;
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// Default constructor
61
64{
66}
67
68
69
70////////////////////////////////////////////////////////////////////////////////
71/// Constructor from a RooArgSet.
72
74 RooAbsCollection(set.GetName())
75{
76 add(set) ;
78}
79
80
81
82////////////////////////////////////////////////////////////////////////////////
83/// Empty list constructor
84
87{
89}
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Constructor for list containing 1 initial object
95
97 const char *name) :
99{
100 add(var1);
102}
103
104
105
106////////////////////////////////////////////////////////////////////////////////
107/// Constructor for set containing 2 initial objects
108
110 const char *name) :
112{
113 add(var1); add(var2);
115}
116
117
118
119////////////////////////////////////////////////////////////////////////////////
120/// Constructor for set containing 3 initial objects
121
123 const RooAbsArg& var3,
124 const char *name) :
126{
127 add(var1); add(var2); add(var3);
129}
130
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Constructor for set containing 4 initial objects
135
137 const RooAbsArg& var3, const RooAbsArg& var4,
138 const char *name) :
140{
141 add(var1); add(var2); add(var3); add(var4);
143}
144
145
146
147////////////////////////////////////////////////////////////////////////////////
148/// Constructor for set containing 5 initial objects
149
151 const RooAbsArg& var2, const RooAbsArg& var3,
152 const RooAbsArg& var4, const RooAbsArg& var5,
153 const char *name) :
155{
156 add(var1); add(var2); add(var3); add(var4); add(var5);
158}
159
160
161
162////////////////////////////////////////////////////////////////////////////////
163/// Constructor for set containing 6 initial objects
164
166 const RooAbsArg& var3, const RooAbsArg& var4,
167 const RooAbsArg& var5, const RooAbsArg& var6,
168 const char *name) :
170{
171 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6);
173}
174
175
176
177////////////////////////////////////////////////////////////////////////////////
178/// Constructor for set containing 7 initial objects
179
181 const RooAbsArg& var3, const RooAbsArg& var4,
182 const RooAbsArg& var5, const RooAbsArg& var6,
183 const RooAbsArg& var7,
184 const char *name) :
186{
187 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;
189}
190
191
192
193////////////////////////////////////////////////////////////////////////////////
194/// Constructor for set containing 8 initial objects
195
197 const RooAbsArg& var3, const RooAbsArg& var4,
198 const RooAbsArg& var5, const RooAbsArg& var6,
199 const RooAbsArg& var7, const RooAbsArg& var8,
200 const char *name) :
202{
203 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;add(var8) ;
205}
206
207
208
209////////////////////////////////////////////////////////////////////////////////
210/// Constructor for set containing 9 initial objects
211
213 const RooAbsArg& var3, const RooAbsArg& var4,
214 const RooAbsArg& var5, const RooAbsArg& var6,
215 const RooAbsArg& var7, const RooAbsArg& var8,
216 const RooAbsArg& var9, const char *name) :
218{
219 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7); add(var8); add(var9);
221}
222
223
224
225////////////////////////////////////////////////////////////////////////////////
226/// Constructor from a root TCollection. Elements in the collection that
227/// do not inherit from RooAbsArg will be skipped. A warning message
228/// will be printed for every skipped item.
229
230RooArgList::RooArgList(const TCollection& tcoll, const char* name) :
232{
233 TIterator* iter = tcoll.MakeIterator() ;
234 TObject* obj ;
235 while((obj=iter->Next())) {
236 if (!dynamic_cast<RooAbsArg*>(obj)) {
237 coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName()
238 << " is not a RooAbsArg, ignored" << endl ;
239 continue ;
240 }
241 add(*(RooAbsArg*)obj) ;
242 }
243 delete iter ;
245}
246
247
248
249////////////////////////////////////////////////////////////////////////////////
250/// Copy constructor. Note that a copy of a list is always non-owning,
251/// even the source list is owning. To create an owning copy of
252/// a list (owning or not), use the snaphot() method.
253
254RooArgList::RooArgList(const RooArgList& other, const char *name)
255 : RooAbsCollection(other,name)
256{
258}
259
260
261
262////////////////////////////////////////////////////////////////////////////////
263/// Destructor
264
266{
268}
269
270
271
272////////////////////////////////////////////////////////////////////////////////
273/// Array operator. Element in slot 'idx' must already exist, otherwise
274/// code will abort.
275///
276/// When used as lvalue in assignment operations, the element contained in
277/// the list will not be changed, only the value of the existing element!
278
280{
281 RooAbsArg* arg = at(idx) ;
282 if (!arg) {
283 coutE(InputArguments) << "RooArgList::operator[](" << GetName() << ") ERROR: index "
284 << idx << " out of range (0," << getSize() << ")" << endl ;
286 }
287 return *arg ;
288}
289
290
291
292////////////////////////////////////////////////////////////////////////////////
293/// Write the contents of the argset in ASCII form to given stream.
294///
295/// All elements will be printed on a single line separated by a single
296/// white space. The contents of each element is written by the arguments'
297/// writeToStream() function
298
299void RooArgList::writeToStream(ostream& os, Bool_t compact)
300{
301 if (!compact) {
302 coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << endl ;
303 return ;
304 }
305
306 for (const auto obj : _list) {
307 obj->writeToStream(os,kTRUE);
308 os << " " ;
309 }
310 os << endl ;
311}
312
313
314
315////////////////////////////////////////////////////////////////////////////////
316/// Read the contents of the argset in ASCII form from given stream.
317///
318/// A single line is read, and all elements are assumed to be separated
319/// by white space. The value of each argument is read by the arguments
320/// readFromStream function.
321
323{
324 if (!compact) {
325 coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << endl ;
326 return kTRUE ;
327 }
328
329 RooStreamParser parser(is) ;
330 for (auto next : _list) {
331 if (!next->getAttribute("Dynamic")) {
332 if (next->readFromStream(is,kTRUE,verbose)) {
333 parser.zapToEnd() ;
334
335 return kTRUE ;
336 }
337 } else {
338 }
339 }
340
341 if (!parser.atEOL()) {
342 TString rest = parser.readLine() ;
343 if (verbose) {
344 coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName()
345 << "): ignoring extra characters at end of line: '" << rest << "'" << endl ;
346 }
347 }
348
349 return kFALSE ;
350}
351
#define coutW(a)
Definition: RooMsgService.h:32
#define coutE(a)
Definition: RooMsgService.h:33
#define TRACE_DESTROY
Definition: RooTrace.h:23
#define TRACE_CREATE
Definition: RooTrace.h:22
const Bool_t kFALSE
Definition: RtypesCore.h:90
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
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:73
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Int_t getSize() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
const char * GetName() const
Returns name of object.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:74
virtual void writeToStream(std::ostream &os, Bool_t compact)
Write the contents of the argset in ASCII form to given stream.
Definition: RooArgList.cxx:299
RooArgList()
Default constructor.
Definition: RooArgList.cxx:62
RooAbsArg & operator[](Int_t idx) const
Array operator.
Definition: RooArgList.cxx:279
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read the contents of the argset in ASCII form from given stream.
Definition: RooArgList.cxx:322
virtual ~RooArgList()
Destructor.
Definition: RooArgList.cxx:265
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
static void softAbort()
Bool_t atEOL()
If true, parser is at end of line in stream.
void zapToEnd(Bool_t inclContLines=kFALSE)
Eat all characters up to and including then end of the current line.
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
Collection abstract base class.
Definition: TCollection.h:63
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const =0
Iterator abstract base class.
Definition: TIterator.h:30
virtual TObject * Next()=0
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
Basic string class.
Definition: TString.h:131
@ InputArguments
Definition: RooGlobalFunc.h:68