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 "RooMsgService.h"
46#include "RooConstVar.h"
47
48#include <stdexcept>
49
50using std::endl, std::istream, std::ostream;
51
52
53
54////////////////////////////////////////////////////////////////////////////////
55/// Default constructor
56
60
61
62
63////////////////////////////////////////////////////////////////////////////////
64/// Constructor from another RooAbsCollection.
65
71
72
73
74////////////////////////////////////////////////////////////////////////////////
75/// Empty list constructor
76
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Constructor from a root TCollection. Elements in the collection that
85/// do not inherit from RooAbsArg will be skipped. A warning message
86/// will be printed for every skipped item.
87
90{
91 for(TObject * obj : tcoll) {
92 if (!dynamic_cast<RooAbsArg*>(obj)) {
93 coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName()
94 << " is not a RooAbsArg, ignored" << std::endl ;
95 continue ;
96 }
97 add(*static_cast<RooAbsArg*>(obj)) ;
98 }
99}
100
101
102
103////////////////////////////////////////////////////////////////////////////////
104/// Copy constructor. Note that a copy of a list is always non-owning,
105/// even the source list is owning. To create an owning copy of
106/// a list (owning or not), use the snapshot() method.
107
112
113
114
115////////////////////////////////////////////////////////////////////////////////
116/// Destructor
117
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Write the contents of the argset in ASCII form to given stream.
125///
126/// All elements will be printed on a single line separated by a single
127/// white space. The contents of each element is written by the arguments'
128/// writeToStream() function
129
130void RooArgList::writeToStream(ostream& os, bool compact)
131{
132 if (!compact) {
133 coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << std::endl ;
134 return ;
135 }
136
137 for (const auto obj : _list) {
138 obj->writeToStream(os,true);
139 os << " " ;
140 }
141 os << std::endl ;
142}
143
144
145
146////////////////////////////////////////////////////////////////////////////////
147/// Read the contents of the argset in ASCII form from given stream.
148///
149/// A single line is read, and all elements are assumed to be separated
150/// by white space. The value of each argument is read by the arguments
151/// readFromStream function.
152
153bool RooArgList::readFromStream(istream& is, bool compact, bool verbose)
154{
155 if (!compact) {
156 coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << std::endl ;
157 return true ;
158 }
159
161 for (auto next : _list) {
162 if (!next->getAttribute("Dynamic")) {
163 if (next->readFromStream(is,true,verbose)) {
164 parser.zapToEnd() ;
165
166 return true ;
167 }
168 } else {
169 }
170 }
171
172 if (!parser.atEOL()) {
173 TString rest = parser.readLine() ;
174 if (verbose) {
175 coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName()
176 << "): ignoring extra characters at end of line: '" << rest << "'" << std::endl ;
177 }
178 }
179
180 return false ;
181}
182
183
#define coutW(a)
#define coutE(a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:142
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
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.
Collection abstract base class.
Definition TCollection.h:65
Mother of all ROOT objects.
Definition TObject.h:42
Basic string class.
Definition TString.h:137
RooConstVar & RooConst(double val)