Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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"
45#include "RooTrace.h"
46#include "RooMsgService.h"
47#include "RooConstVar.h"
48
49#include <stdexcept>
50
51using std::endl, std::istream, std::ostream;
52
54
55
56////////////////////////////////////////////////////////////////////////////////
57/// Default constructor
58
60{
62}
63
64
65
66////////////////////////////////////////////////////////////////////////////////
67/// Constructor from another RooAbsCollection.
68
70 RooAbsCollection(coll.GetName())
71{
72 add(coll) ;
74}
75
76
77
78////////////////////////////////////////////////////////////////////////////////
79/// Empty list constructor
80
83{
85}
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// Constructor from a root TCollection. Elements in the collection that
90/// do not inherit from RooAbsArg will be skipped. A warning message
91/// will be printed for every skipped item.
92
93RooArgList::RooArgList(const TCollection& tcoll, const char* name) :
95{
96 for(TObject * obj : tcoll) {
97 if (!dynamic_cast<RooAbsArg*>(obj)) {
98 coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName()
99 << " is not a RooAbsArg, ignored" << endl ;
100 continue ;
101 }
102 add(*static_cast<RooAbsArg*>(obj)) ;
103 }
105}
106
107
108
109////////////////////////////////////////////////////////////////////////////////
110/// Copy constructor. Note that a copy of a list is always non-owning,
111/// even the source list is owning. To create an owning copy of
112/// a list (owning or not), use the snapshot() method.
113
114RooArgList::RooArgList(const RooArgList& other, const char *name)
115 : RooAbsCollection(other,name)
116{
118}
119
120
121
122////////////////////////////////////////////////////////////////////////////////
123/// Destructor
124
126{
128}
129
130
131////////////////////////////////////////////////////////////////////////////////
132/// Write the contents of the argset in ASCII form to given stream.
133///
134/// All elements will be printed on a single line separated by a single
135/// white space. The contents of each element is written by the arguments'
136/// writeToStream() function
137
138void RooArgList::writeToStream(ostream& os, bool compact)
139{
140 if (!compact) {
141 coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << endl ;
142 return ;
143 }
144
145 for (const auto obj : _list) {
146 obj->writeToStream(os,true);
147 os << " " ;
148 }
149 os << endl ;
150}
151
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Read the contents of the argset in ASCII form from given stream.
156///
157/// A single line is read, and all elements are assumed to be separated
158/// by white space. The value of each argument is read by the arguments
159/// readFromStream function.
160
161bool RooArgList::readFromStream(istream& is, bool compact, bool verbose)
162{
163 if (!compact) {
164 coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << endl ;
165 return true ;
166 }
167
168 RooStreamParser parser(is) ;
169 for (auto next : _list) {
170 if (!next->getAttribute("Dynamic")) {
171 if (next->readFromStream(is,true,verbose)) {
172 parser.zapToEnd() ;
173
174 return true ;
175 }
176 } else {
177 }
178 }
179
180 if (!parser.atEOL()) {
181 TString rest = parser.readLine() ;
182 if (verbose) {
183 coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName()
184 << "): ignoring extra characters at end of line: '" << rest << "'" << endl ;
185 }
186 }
187
188 return false ;
189}
190
191
#define coutW(a)
#define coutE(a)
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
#define ClassImp(name)
Definition Rtypes.h:377
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
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Abstract container object that can hold multiple RooAbsArg objects.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t _list
Actual object storage.
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.
RooArgList()
Default constructor.
void processArg(const RooAbsArg &arg)
Definition RooArgList.h:138
~RooArgList() override
Destructor.
virtual bool readFromStream(std::istream &is, bool compact, bool verbose=false)
Read the contents of the argset in ASCII form from given stream.
bool atEOL()
If true, parser is at end of line in stream.
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
void zapToEnd(bool inclContLines=false)
Eat all characters up to and including then end of the current line.
Collection abstract base class.
Definition TCollection.h:65
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
RooConstVar & RooConst(double val)