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"
45 #include "RooAbsCategoryLValue.h"
46 #include "RooTrace.h"
47 #include "RooMsgService.h"
48 
49 #include <stdexcept>
50 
51 using namespace std;
52 
54 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Default constructor
58 
61 {
63 }
64 
65 
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Constructor from a RooArgSet.
69 
71  RooAbsCollection(set.GetName())
72 {
73  add(set) ;
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 
94 RooArgList::RooArgList(const TCollection& tcoll, const char* name) :
96 {
97  TIterator* iter = tcoll.MakeIterator() ;
98  TObject* obj ;
99  while((obj=iter->Next())) {
100  if (!dynamic_cast<RooAbsArg*>(obj)) {
101  coutW(InputArguments) << "RooArgList::RooArgList(TCollection) element " << obj->GetName()
102  << " is not a RooAbsArg, ignored" << endl ;
103  continue ;
104  }
105  add(*(RooAbsArg*)obj) ;
106  }
107  delete iter ;
109 }
110 
111 
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Copy constructor. Note that a copy of a list is always non-owning,
115 /// even the source list is owning. To create an owning copy of
116 /// a list (owning or not), use the snaphot() method.
117 
118 RooArgList::RooArgList(const RooArgList& other, const char *name)
119  : RooAbsCollection(other,name)
120 {
122 }
123 
124 
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 /// Destructor
128 
130 {
132 }
133 
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Write the contents of the argset in ASCII form to given stream.
137 ///
138 /// All elements will be printed on a single line separated by a single
139 /// white space. The contents of each element is written by the arguments'
140 /// writeToStream() function
141 
142 void RooArgList::writeToStream(ostream& os, Bool_t compact)
143 {
144  if (!compact) {
145  coutE(InputArguments) << "RooArgList::writeToStream(" << GetName() << ") non-compact mode not supported" << endl ;
146  return ;
147  }
148 
149  for (const auto obj : _list) {
150  obj->writeToStream(os,kTRUE);
151  os << " " ;
152  }
153  os << endl ;
154 }
155 
156 
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// Read the contents of the argset in ASCII form from given stream.
160 ///
161 /// A single line is read, and all elements are assumed to be separated
162 /// by white space. The value of each argument is read by the arguments
163 /// readFromStream function.
164 
166 {
167  if (!compact) {
168  coutE(InputArguments) << "RooArgList::readFromStream(" << GetName() << ") non-compact mode not supported" << endl ;
169  return kTRUE ;
170  }
171 
172  RooStreamParser parser(is) ;
173  for (auto next : _list) {
174  if (!next->getAttribute("Dynamic")) {
175  if (next->readFromStream(is,kTRUE,verbose)) {
176  parser.zapToEnd() ;
177 
178  return kTRUE ;
179  }
180  } else {
181  }
182  }
183 
184  if (!parser.atEOL()) {
185  TString rest = parser.readLine() ;
186  if (verbose) {
187  coutW(InputArguments) << "RooArgSet::readFromStream(" << GetName()
188  << "): ignoring extra characters at end of line: '" << rest << "'" << endl ;
189  }
190  }
191 
192  return kFALSE ;
193 }
194 
RooStreamParser.h
RooStreamParser::zapToEnd
void zapToEnd(Bool_t inclContLines=kFALSE)
Eat all characters up to and including then end of the current line.
Definition: RooStreamParser.cxx:361
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
RooMsgService.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:61
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
coutE
#define coutE(a)
Definition: RooMsgService.h:33
coutW
#define coutW(a)
Definition: RooMsgService.h:32
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooStreamParser::atEOL
Bool_t atEOL()
If true, parser is at end of line in stream.
Definition: RooStreamParser.cxx:88
TString
Basic string class.
Definition: TString.h:136
RooAbsCollection::GetName
const char * GetName() const
Returns name of object.
Definition: RooAbsCollection.h:241
bool
TIterator
Iterator abstract base class.
Definition: TIterator.h:30
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
RooTrace.h
RooStreamParser
Definition: RooStreamParser.h:21
TRACE_DESTROY
#define TRACE_DESTROY
Definition: RooTrace.h:24
RooArgList::RooArgList
RooArgList()
Default constructor.
Definition: RooArgList.cxx:59
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooAbsCollection
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Definition: RooAbsCollection.h:31
TRACE_CREATE
#define TRACE_CREATE
Definition: RooTrace.h:23
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:451
TCollection::MakeIterator
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const =0
TIterator::Next
virtual TObject * Next()=0
RooStreamParser::readLine
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
Definition: RooStreamParser.cxx:309
RooArgList::writeToStream
virtual void writeToStream(std::ostream &os, Bool_t compact)
Write the contents of the argset in ASCII form to given stream.
Definition: RooArgList.cxx:142
RooArgList::~RooArgList
virtual ~RooArgList()
Destructor.
Definition: RooArgList.cxx:129
RooAbsCategoryLValue.h
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
name
char name[80]
Definition: TGX11.cxx:110
RooArgList::readFromStream
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:165
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
TCollection
Collection abstract base class.
Definition: TCollection.h:63
RooArgList.h
RooAbsRealLValue.h
RooAbsCollection::_list
Storage_t _list
Definition: RooAbsCollection.h:264
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33