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 "RooStringVar.h"
51#include "RooTrace.h"
52#include "RooMsgService.h"
53
54using namespace std;
55
57 ;
58
59
60////////////////////////////////////////////////////////////////////////////////
61/// Default constructor
62
65{
67}
68
69
70
71////////////////////////////////////////////////////////////////////////////////
72/// Constructor from a RooArgSet.
73
76{
77 add(set) ;
79}
80
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Empty list constructor
85
88{
90}
91
92
93
94////////////////////////////////////////////////////////////////////////////////
95/// Constructor for list containing 1 initial object
96
98 const char *name) :
100{
101 add(var1);
103}
104
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Constructor for set containing 2 initial objects
109
111 const char *name) :
113{
114 add(var1); add(var2);
116}
117
118
119
120////////////////////////////////////////////////////////////////////////////////
121/// Constructor for set containing 3 initial objects
122
124 const RooAbsArg& var3,
125 const char *name) :
127{
128 add(var1); add(var2); add(var3);
130}
131
132
133
134////////////////////////////////////////////////////////////////////////////////
135/// Constructor for set containing 4 initial objects
136
138 const RooAbsArg& var3, const RooAbsArg& var4,
139 const char *name) :
141{
142 add(var1); add(var2); add(var3); add(var4);
144}
145
146
147
148////////////////////////////////////////////////////////////////////////////////
149/// Constructor for set containing 5 initial objects
150
152 const RooAbsArg& var2, const RooAbsArg& var3,
153 const RooAbsArg& var4, const RooAbsArg& var5,
154 const char *name) :
156{
157 add(var1); add(var2); add(var3); add(var4); add(var5);
159}
160
161
162
163////////////////////////////////////////////////////////////////////////////////
164/// Constructor for set containing 6 initial objects
165
167 const RooAbsArg& var3, const RooAbsArg& var4,
168 const RooAbsArg& var5, const RooAbsArg& var6,
169 const char *name) :
171{
172 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6);
174}
175
176
177
178////////////////////////////////////////////////////////////////////////////////
179/// Constructor for set containing 7 initial objects
180
182 const RooAbsArg& var3, const RooAbsArg& var4,
183 const RooAbsArg& var5, const RooAbsArg& var6,
184 const RooAbsArg& var7,
185 const char *name) :
187{
188 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;
190}
191
192
193
194////////////////////////////////////////////////////////////////////////////////
195/// Constructor for set containing 8 initial objects
196
198 const RooAbsArg& var3, const RooAbsArg& var4,
199 const RooAbsArg& var5, const RooAbsArg& var6,
200 const RooAbsArg& var7, const RooAbsArg& var8,
201 const char *name) :
203{
204 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;add(var8) ;
206}
207
208
209
210////////////////////////////////////////////////////////////////////////////////
211/// Constructor for set containing 9 initial objects
212
214 const RooAbsArg& var3, const RooAbsArg& var4,
215 const RooAbsArg& var5, const RooAbsArg& var6,
216 const RooAbsArg& var7, const RooAbsArg& var8,
217 const RooAbsArg& var9, const char *name) :
219{
220 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7); add(var8); add(var9);
222}
223
224
225
226////////////////////////////////////////////////////////////////////////////////
227/// Constructor from a root TCollection. Elements in the collection that
228/// do not inherit from RooAbsArg will be skipped. A warning message
229/// will be printed for every skipped item.
230
231RooArgList::RooArgList(const TCollection& tcoll, const char* name) :
233{
234 TIterator* iter = tcoll.MakeIterator() ;
235 TObject* obj ;
236 while((obj=iter->Next())) {
237 if (!dynamic_cast<RooAbsArg*>(obj)) {
238 coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName()
239 << " is not a RooAbsArg, ignored" << endl ;
240 continue ;
241 }
242 add(*(RooAbsArg*)obj) ;
243 }
244 delete iter ;
246}
247
248
249
250////////////////////////////////////////////////////////////////////////////////
251/// Copy constructor. Note that a copy of a list is always non-owning,
252/// even the source list is owning. To create an owning copy of
253/// a list (owning or not), use the snaphot() method.
254
255RooArgList::RooArgList(const RooArgList& other, const char *name)
256 : RooAbsCollection(other,name)
257{
259}
260
261
262
263////////////////////////////////////////////////////////////////////////////////
264/// Destructor
265
267{
269}
270
271
272
273////////////////////////////////////////////////////////////////////////////////
274/// Array operator. Element in slot 'idx' must already exist, otherwise
275/// code will abort.
276///
277/// When used as lvalue in assignment operations, the element contained in
278/// the list will not be changed, only the value of the existing element!
279
281{
282 RooAbsArg* arg = at(idx) ;
283 if (!arg) {
284 coutE(InputArguments) << "RooArgList::operator[](" << GetName() << ") ERROR: index "
285 << idx << " out of range (0," << getSize() << ")" << endl ;
287 }
288 return *arg ;
289}
290
291
292
293////////////////////////////////////////////////////////////////////////////////
294/// Write the contents of the argset in ASCII form to given stream.
295///
296/// All elements will be printed on a single line separated by a single
297/// white space. The contents of each element is written by the arguments'
298/// writeToStream() function
299
300void RooArgList::writeToStream(ostream& os, Bool_t compact)
301{
302 if (!compact) {
303 coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << endl ;
304 return ;
305 }
306
307 for (const auto obj : _list) {
308 obj->writeToStream(os,kTRUE);
309 os << " " ;
310 }
311 os << endl ;
312}
313
314
315
316////////////////////////////////////////////////////////////////////////////////
317/// Read the contents of the argset in ASCII form from given stream.
318///
319/// A single line is read, and all elements are assumed to be separated
320/// by white space. The value of each argument is read by the arguments
321/// readFromStream function.
322
324{
325 if (!compact) {
326 coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << endl ;
327 return kTRUE ;
328 }
329
330 RooStreamParser parser(is) ;
331 for (auto next : _list) {
332 if (!next->getAttribute("Dynamic")) {
333 if (next->readFromStream(is,kTRUE,verbose)) {
334 parser.zapToEnd() ;
335
336 return kTRUE ;
337 }
338 } else {
339 }
340 }
341
342 if (!parser.atEOL()) {
343 TString rest = parser.readLine() ;
344 if (verbose) {
345 coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName()
346 << "): ignoring extra characters at end of line: '" << rest << "'" << endl ;
347 }
348 }
349
350 return kFALSE ;
351}
352
#define coutW(a)
Definition: RooMsgService.h:33
#define coutE(a)
Definition: RooMsgService.h:34
#define TRACE_DESTROY
Definition: RooTrace.h:23
#define TRACE_CREATE
Definition: RooTrace.h:22
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
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:71
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:300
RooArgList()
Default constructor.
Definition: RooArgList.cxx:63
RooAbsArg & operator[](Int_t idx) const
Array operator.
Definition: RooArgList.cxx:280
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:323
virtual ~RooArgList()
Destructor.
Definition: RooArgList.cxx:266
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
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:150
@ InputArguments
Definition: RooGlobalFunc.h:68