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 namespace std;
52
54
55
56////////////////////////////////////////////////////////////////////////////////
57/// Default constructor
58
61{
63}
64
65
66
67////////////////////////////////////////////////////////////////////////////////
68/// Constructor from another RooAbsCollection.
69
71 RooAbsCollection(coll.GetName())
72{
73 add(coll) ;
75}
76
77
78
79////////////////////////////////////////////////////////////////////////////////
80/// Empty list constructor
81
84{
86}
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Constructor from a root TCollection. Elements in the collection that
91/// do not inherit from RooAbsArg will be skipped. A warning message
92/// will be printed for every skipped item.
93
94RooArgList::RooArgList(const TCollection& tcoll, const char* name) :
96{
97 for(TObject * obj : tcoll) {
98 if (!dynamic_cast<RooAbsArg*>(obj)) {
99 coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName()
100 << " is not a RooAbsArg, ignored" << endl ;
101 continue ;
102 }
103 add(*(RooAbsArg*)obj) ;
104 }
106}
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Copy constructor. Note that a copy of a list is always non-owning,
112/// even the source list is owning. To create an owning copy of
113/// a list (owning or not), use the snaphot() method.
114
115RooArgList::RooArgList(const RooArgList& other, const char *name)
116 : RooAbsCollection(other,name)
117{
119}
120
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Destructor
125
127{
129}
130
131
132////////////////////////////////////////////////////////////////////////////////
133/// Write the contents of the argset in ASCII form to given stream.
134///
135/// All elements will be printed on a single line separated by a single
136/// white space. The contents of each element is written by the arguments'
137/// writeToStream() function
138
139void RooArgList::writeToStream(ostream& os, bool compact)
140{
141 if (!compact) {
142 coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << endl ;
143 return ;
144 }
145
146 for (const auto obj : _list) {
147 obj->writeToStream(os,true);
148 os << " " ;
149 }
150 os << endl ;
151}
152
153
154
155////////////////////////////////////////////////////////////////////////////////
156/// Read the contents of the argset in ASCII form from given stream.
157///
158/// A single line is read, and all elements are assumed to be separated
159/// by white space. The value of each argument is read by the arguments
160/// readFromStream function.
161
162bool RooArgList::readFromStream(istream& is, bool compact, bool verbose)
163{
164 if (!compact) {
165 coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << endl ;
166 return true ;
167 }
168
169 RooStreamParser parser(is) ;
170 for (auto next : _list) {
171 if (!next->getAttribute("Dynamic")) {
172 if (next->readFromStream(is,true,verbose)) {
173 parser.zapToEnd() ;
174
175 return true ;
176 }
177 } else {
178 }
179 }
180
181 if (!parser.atEOL()) {
182 TString rest = parser.readLine() ;
183 if (verbose) {
184 coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName()
185 << "): ignoring extra characters at end of line: '" << rest << "'" << endl ;
186 }
187 }
188
189 return false ;
190}
191
192
#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
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:74
RooAbsCollection is an 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)