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 "RooArgList.h"
42
43#include "RooStreamParser.h"
44#include "RooAbsRealLValue.h"
46#include "RooTrace.h"
47#include "RooMsgService.h"
48#include "RooConstVar.h"
49
50#include <stdexcept>
51
52using namespace std;
53
55
56
57////////////////////////////////////////////////////////////////////////////////
58/// Default constructor
59
62{
64}
65
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// Constructor from another RooAbsCollection.
70
72 RooAbsCollection(coll.GetName())
73{
74 add(coll) ;
76}
77
78
79
80////////////////////////////////////////////////////////////////////////////////
81/// Empty list constructor
82
85{
87}
88
89
90////////////////////////////////////////////////////////////////////////////////
91/// Constructor from a root TCollection. Elements in the collection that
92/// do not inherit from RooAbsArg will be skipped. A warning message
93/// will be printed for every skipped item.
94
95RooArgList::RooArgList(const TCollection& tcoll, const char* name) :
97{
98 TIterator* iter = tcoll.MakeIterator() ;
99 TObject* obj ;
100 while((obj=iter->Next())) {
101 if (!dynamic_cast<RooAbsArg*>(obj)) {
102 coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName()
103 << " is not a RooAbsArg, ignored" << endl ;
104 continue ;
105 }
106 add(*(RooAbsArg*)obj) ;
107 }
108 delete iter ;
110}
111
112
113
114////////////////////////////////////////////////////////////////////////////////
115/// Copy constructor. Note that a copy of a list is always non-owning,
116/// even the source list is owning. To create an owning copy of
117/// a list (owning or not), use the snaphot() method.
118
119RooArgList::RooArgList(const RooArgList& other, const char *name)
120 : RooAbsCollection(other,name)
121{
123}
124
125
126
127////////////////////////////////////////////////////////////////////////////////
128/// Destructor
129
131{
133}
134
135
136////////////////////////////////////////////////////////////////////////////////
137/// Write the contents of the argset in ASCII form to given stream.
138///
139/// All elements will be printed on a single line separated by a single
140/// white space. The contents of each element is written by the arguments'
141/// writeToStream() function
142
143void RooArgList::writeToStream(ostream& os, Bool_t compact)
144{
145 if (!compact) {
146 coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << endl ;
147 return ;
148 }
149
150 for (const auto obj : _list) {
151 obj->writeToStream(os,kTRUE);
152 os << " " ;
153 }
154 os << endl ;
155}
156
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// Read the contents of the argset in ASCII form from given stream.
161///
162/// A single line is read, and all elements are assumed to be separated
163/// by white space. The value of each argument is read by the arguments
164/// readFromStream function.
165
167{
168 if (!compact) {
169 coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << endl ;
170 return kTRUE ;
171 }
172
173 RooStreamParser parser(is) ;
174 for (auto next : _list) {
175 if (!next->getAttribute("Dynamic")) {
176 if (next->readFromStream(is,kTRUE,verbose)) {
177 parser.zapToEnd() ;
178
179 return kTRUE ;
180 }
181 } else {
182 }
183 }
184
185 if (!parser.atEOL()) {
186 TString rest = parser.readLine() ;
187 if (verbose) {
188 coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName()
189 << "): ignoring extra characters at end of line: '" << rest << "'" << endl ;
190 }
191 }
192
193 return kFALSE ;
194}
195
196
#define coutW(a)
Definition: RooMsgService.h:32
#define coutE(a)
Definition: RooMsgService.h:33
#define TRACE_DESTROY
Definition: RooTrace.h:24
#define TRACE_CREATE
Definition: RooTrace.h:23
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:364
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:72
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
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:22
virtual void writeToStream(std::ostream &os, bool compact)
Write the contents of the argset in ASCII form to given stream.
Definition: RooArgList.cxx:143
virtual bool readFromStream(std::istream &is, bool compact, bool verbose=false)
Read the contents of the argset in ASCII form from given stream.
Definition: RooArgList.cxx:166
RooArgList()
Default constructor.
Definition: RooArgList.cxx:60
void processArg(const RooAbsArg &arg)
Definition: RooArgList.h:138
virtual ~RooArgList()
Destructor.
Definition: RooArgList.cxx:130
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:65
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:359
Basic string class.
Definition: TString.h:136
RooConstVar & RooConst(Double_t val)
@ InputArguments
Definition: RooGlobalFunc.h:61