ROOT  6.06/09
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 //
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 <fstream>
44 #include "TClass.h"
45 #include "RooArgList.h"
46 #include "RooErrorHandler.h"
47 #include "RooStreamParser.h"
48 #include "RooFormula.h"
49 #include "RooAbsRealLValue.h"
50 #include "RooAbsCategoryLValue.h"
51 #include "RooStringVar.h"
52 #include "RooTrace.h"
53 #include "RooMsgService.h"
54 
55 using namespace std;
56 
58  ;
59 
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Default constructor
63 
66 {
68 }
69 
70 
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Constructor from a RooArgSet.
74 
76  RooAbsCollection(set.GetName())
77 {
78  add(set) ;
80 }
81 
82 
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Empty list constructor
86 
88  RooAbsCollection(name)
89 {
91 }
92 
93 
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Constructor for list containing 1 initial object
97 
99  const char *name) :
100  RooAbsCollection(name)
101 {
102  add(var1);
104 }
105 
106 
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Constructor for set containing 2 initial objects
110 
111 RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2,
112  const char *name) :
113  RooAbsCollection(name)
114 {
115  add(var1); add(var2);
117 }
118 
119 
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Constructor for set containing 3 initial objects
123 
124 RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2,
125  const RooAbsArg& var3,
126  const char *name) :
127  RooAbsCollection(name)
128 {
129  add(var1); add(var2); add(var3);
131 }
132 
133 
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Constructor for set containing 4 initial objects
137 
138 RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2,
139  const RooAbsArg& var3, const RooAbsArg& var4,
140  const char *name) :
141  RooAbsCollection(name)
142 {
143  add(var1); add(var2); add(var3); add(var4);
145 }
146 
147 
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Constructor for set containing 5 initial objects
151 
153  const RooAbsArg& var2, const RooAbsArg& var3,
154  const RooAbsArg& var4, const RooAbsArg& var5,
155  const char *name) :
156  RooAbsCollection(name)
157 {
158  add(var1); add(var2); add(var3); add(var4); add(var5);
160 }
161 
162 
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Constructor for set containing 6 initial objects
166 
167 RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2,
168  const RooAbsArg& var3, const RooAbsArg& var4,
169  const RooAbsArg& var5, const RooAbsArg& var6,
170  const char *name) :
171  RooAbsCollection(name)
172 {
173  add(var1); add(var2); add(var3); add(var4); add(var5); add(var6);
175 }
176 
177 
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Constructor for set containing 7 initial objects
181 
182 RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2,
183  const RooAbsArg& var3, const RooAbsArg& var4,
184  const RooAbsArg& var5, const RooAbsArg& var6,
185  const RooAbsArg& var7,
186  const char *name) :
187  RooAbsCollection(name)
188 {
189  add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;
191 }
192 
193 
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Constructor for set containing 8 initial objects
197 
198 RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2,
199  const RooAbsArg& var3, const RooAbsArg& var4,
200  const RooAbsArg& var5, const RooAbsArg& var6,
201  const RooAbsArg& var7, const RooAbsArg& var8,
202  const char *name) :
203  RooAbsCollection(name)
204 {
205  add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;add(var8) ;
207 }
208 
209 
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// Constructor for set containing 9 initial objects
213 
214 RooArgList::RooArgList(const RooAbsArg& var1, const RooAbsArg& var2,
215  const RooAbsArg& var3, const RooAbsArg& var4,
216  const RooAbsArg& var5, const RooAbsArg& var6,
217  const RooAbsArg& var7, const RooAbsArg& var8,
218  const RooAbsArg& var9, const char *name) :
219  RooAbsCollection(name)
220 {
221  add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7); add(var8); add(var9);
223 }
224 
225 
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Constructor from a root TCollection. Elements in the collection that
229 /// do not inherit from RooAbsArg will be skipped. A warning message
230 /// will be printed for every skipped item.
231 
232 RooArgList::RooArgList(const TCollection& tcoll, const char* name) :
233  RooAbsCollection(name)
234 {
235  TIterator* iter = tcoll.MakeIterator() ;
236  TObject* obj ;
237  while((obj=iter->Next())) {
238  if (!dynamic_cast<RooAbsArg*>(obj)) {
239  coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName()
240  << " is not a RooAbsArg, ignored" << endl ;
241  continue ;
242  }
243  add(*(RooAbsArg*)obj) ;
244  }
245  delete iter ;
247 }
248 
249 
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 /// Copy constructor. Note that a copy of a list is always non-owning,
253 /// even the source list is owning. To create an owning copy of
254 /// a list (owning or not), use the snaphot() method.
255 
256 RooArgList::RooArgList(const RooArgList& other, const char *name)
257  : RooAbsCollection(other,name)
258 {
260 }
261 
262 
263 
264 ////////////////////////////////////////////////////////////////////////////////
265 /// Destructor
266 
268 {
270 }
271 
272 
273 
274 ////////////////////////////////////////////////////////////////////////////////
275 /// Array operator. Element in slot 'idx' must already exist, otherwise
276 /// code will abort.
277 ///
278 /// When used as lvalue in assignment operations, the element contained in
279 /// the list will not be changed, only the value of the existing element!
280 
282 {
283  RooAbsArg* arg = at(idx) ;
284  if (!arg) {
285  coutE(InputArguments) << "RooArgList::operator[](" << GetName() << ") ERROR: index "
286  << idx << " out of range (0," << getSize() << ")" << endl ;
288  }
289  return *arg ;
290 }
291 
292 
293 
294 ////////////////////////////////////////////////////////////////////////////////
295 /// Write the contents of the argset in ASCII form to given stream.
296 ///
297 /// All elements will be printed on a single line separated by a single
298 /// white space. The contents of each element is written by the arguments'
299 /// writeToStream() function
300 
301 void RooArgList::writeToStream(ostream& os, Bool_t compact)
302 {
303  if (!compact) {
304  coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << endl ;
305  return ;
306  }
307 
308  TIterator *iterat= createIterator();
309  RooAbsArg *next = 0;
310  while((0 != (next= (RooAbsArg*)iterat->Next()))) {
311  next->writeToStream(os,kTRUE) ;
312  os << " " ;
313  }
314  delete iterat;
315  os << endl ;
316 }
317 
318 
319 
320 ////////////////////////////////////////////////////////////////////////////////
321 /// Read the contents of the argset in ASCII form from given stream.
322 ///
323 /// A single line is read, and all elements are assumed to be separated
324 /// by white space. The value of each argument is read by the arguments
325 /// readFromStream function.
326 
328 {
329  if (!compact) {
330  coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << endl ;
331  return kTRUE ;
332  }
333 
334  TIterator *iterat= createIterator();
335  RooStreamParser parser(is) ;
336  RooAbsArg *next = 0;
337  while((0 != (next= (RooAbsArg*)iterat->Next()))) {
338  if (!next->getAttribute("Dynamic")) {
339  if (next->readFromStream(is,kTRUE,verbose)) {
340  parser.zapToEnd() ;
341 
342  delete iterat ;
343  return kTRUE ;
344  }
345  } else {
346  }
347  }
348 
349  if (!parser.atEOL()) {
350  TString rest = parser.readLine() ;
351  if (verbose) {
352  coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName()
353  << "): ignoring extra characters at end of line: '" << rest << "'" << endl ;
354  }
355  }
356 
357  delete iterat;
358  return kFALSE ;
359 }
360 
#define coutE(a)
Definition: RooMsgService.h:35
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
static void softAbort()
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
virtual ~RooArgList()
Destructor.
Definition: RooArgList.cxx:267
ClassImp(RooArgList)
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:327
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:34
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:288
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)=0
Iterator abstract base class.
Definition: TIterator.h:32
#define TRACE_CREATE
Definition: RooTrace.h:23
virtual void writeToStream(std::ostream &os, Bool_t compact)
Write the contents of the argset in ASCII form to given stream.
Definition: RooArgList.cxx:301
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
TIterator * createIterator(Bool_t dir=kIterForward) const
if on multiple lines(like in C++).**The" * configuration fragment. * * The "import myobject continue
Parses the configuration file.
Definition: HLFactory.cxx:368
return
Definition: TBase64.cxx:62
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const =0
Collection abstract base class.
Definition: TCollection.h:48
bool verbose
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...
virtual void writeToStream(std::ostream &os, Bool_t compact) const =0
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
#define TRACE_DESTROY
Definition: RooTrace.h:24
RooArgList()
Default constructor.
Definition: RooArgList.cxx:64
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
virtual TObject * Next()=0
Int_t getSize() const
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
Bool_t atEOL()
If true, parser is at end of line in stream.
RooAbsArg & operator[](Int_t idx) const
Array operator.
Definition: RooArgList.cxx:281
const char * GetName() const
Returns name of object.