Logo ROOT  
Reference Guide
RooCmdArg.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/**
19\file RooCmdArg.cxx
20\class RooCmdArg
21\ingroup Roofitcore
22
23RooCmdArg is a named container for two doubles, two integers
24two object points and three string pointers that can be passed
25as generic named arguments to a variety of RooFit end user
26methods. To achieved the named syntax, RooCmdArg objects are
27created using global helper functions defined in RooGlobalFunc.h
28that create and fill these generic containers
29**/
30
31
32
33#include "RooCmdArg.h"
34#include "Riostream.h"
35#include "RooArgSet.h"
36
37#include <string>
38#include <iostream>
39
40using namespace std;
41
43 ;
44
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Return reference to null argument
50
52{
53 return _none ;
54}
55
56
57////////////////////////////////////////////////////////////////////////////////
58/// Default constructor
59
61{
62 _procSubArgs = false ;
63 _prefixSubArgs = true ;
64 _c = 0 ;
65 _o[0] = 0 ;
66 _o[1] = 0 ;
67 _i[0] = 0 ;
68 _i[1] = 0 ;
69 _d[0] = 0 ;
70 _d[1] = 0 ;
71}
72
73
74////////////////////////////////////////////////////////////////////////////////
75/// Constructor with full specification of payload: two integers, two doubles,
76/// three string poiners, two object pointers and one RooCmdArg pointer
77
78RooCmdArg::RooCmdArg(const char* name, Int_t i1, Int_t i2, double d1, double d2,
79 const char* s1, const char* s2, const TObject* o1, const TObject* o2,
80 const RooCmdArg* ca, const char* s3, const RooArgSet* c1, const RooArgSet* c2) :
82{
83 _i[0] = i1 ;
84 _i[1] = i2 ;
85 _d[0] = d1 ;
86 _d[1] = d2 ;
87 if (s1) _s[0] = s1 ;
88 if (s2) _s[1] = s2 ;
89 if (s3) _s[2] = s3 ;
90 _o[0] = (TObject*) o1 ;
91 _o[1] = (TObject*) o2 ;
92 _c = 0 ;
93
94 if (c1||c2) _c = new RooArgSet[2] ;
95 if (c1) _c[0].add(*c1) ;
96 if (c2) _c[1].add(*c2) ;
97
98 _procSubArgs = true ;
99 _prefixSubArgs = true ;
100 if (ca) {
101 _argList.Add(new RooCmdArg(*ca)) ;
102 }
103
104 _sharedData.reset(new DataCollection);
106}
107
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Copy constructor
112
114 TNamed(other),
115 _sharedData{other._sharedData}
116{
117 _i[0] = other._i[0] ;
118 _i[1] = other._i[1] ;
119 _d[0] = other._d[0] ;
120 _d[1] = other._d[1] ;
121 _s[0] = other._s[0] ;
122 _s[1] = other._s[1] ;
123 _s[2] = other._s[2] ;
124 _o[0] = other._o[0] ;
125 _o[1] = other._o[1] ;
126 if (other._c) {
127 _c = new RooArgSet[2] ;
128 _c[0].add(other._c[0]) ;
129 _c[1].add(other._c[1]) ;
130 } else {
131 _c = 0 ;
132 }
133
134 _procSubArgs = other._procSubArgs ;
136 for (Int_t i=0 ; i<other._argList.GetSize() ; i++) {
137 _argList.Add(new RooCmdArg((RooCmdArg&)*other._argList.At(i))) ;
138 }
139}
140
141
142////////////////////////////////////////////////////////////////////////////////
143/// Assignment operator
144
146{
147 if (&other==this) return *this ;
148
149 _sharedData = other._sharedData;
150
151 SetName(other.GetName()) ;
152 SetTitle(other.GetTitle()) ;
153
154 _i[0] = other._i[0] ;
155 _i[1] = other._i[1] ;
156 _d[0] = other._d[0] ;
157 _d[1] = other._d[1] ;
158 _s[0] = other._s[0] ;
159 _s[1] = other._s[1] ;
160 _s[2] = other._s[2] ;
161 _o[0] = other._o[0] ;
162 _o[1] = other._o[1] ;
163 if (!_c) _c = new RooArgSet[2] ;
164 if (other._c) {
165 _c[0].removeAll() ; _c[0].add(other._c[0]) ;
166 _c[1].removeAll() ; _c[1].add(other._c[1]) ;
167 }
168
169 _procSubArgs = other._procSubArgs ;
171
172 for (Int_t i=0 ; i<other._argList.GetSize() ; i++) {
173 _argList.Add(new RooCmdArg((RooCmdArg&)*other._argList.At(i))) ;
174 }
175
176 return *this ;
177}
178
179
180
181////////////////////////////////////////////////////////////////////////////////
182/// Destructor
183
185{
186 _argList.Delete() ;
187 if (_c) delete[] _c ;
188}
189
190
191
192////////////////////////////////////////////////////////////////////////////////
193/// Utility function to add nested RooCmdArg to payload of this RooCmdArg
194
196{
197 _argList.Add(new RooCmdArg(arg)) ;
198}
199
200
201
202////////////////////////////////////////////////////////////////////////////////
203/// Return RooArgSet stored in slot idx
204
206 return _c ? &_c[idx] : 0 ;
207 }
208
209
210
211////////////////////////////////////////////////////////////////////////////////
212
214{
215 if (!_c) {
216 _c = new RooArgSet[2] ;
217 }
218 _c[idx].removeAll() ;
219 _c[idx].add(set) ;
220}
221
222
223////////////////////////////////////////////////////////////////////////////////
224/// Print contents
225void RooCmdArg::Print(const char*) const {
226 std::cout << GetName()
227 << ":\ndoubles\t" << _d[0] << " " << _d[1]
228 << "\nints\t" << _i[0] << " " << _i[1]
229 << "\nstrings\t" << _s[0] << " " << _s[1] << " " << _s[2]
230 << "\nobjects\t" << _o[0] << " " << _o[1] << std::endl;
231}
232
234
#define s1(x)
Definition: RSha256.hxx:91
#define ClassImp(name)
Definition: Rtypes.h:375
char name[80]
Definition: TGX11.cxx:110
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
Definition: RooCmdArg.cxx:205
RooArgSet * _c
Payload RooArgSets.
Definition: RooCmdArg.h:126
void Print(const char *="") const override
Print contents.
Definition: RooCmdArg.cxx:225
RooLinkedList _argList
Payload sub-arguments.
Definition: RooCmdArg.h:127
void addArg(const RooCmdArg &arg)
Utility function to add nested RooCmdArg to payload of this RooCmdArg.
Definition: RooCmdArg.cxx:195
std::shared_ptr< DataCollection > _sharedData
!
Definition: RooCmdArg.h:131
Int_t _i[2]
Payload integers.
Definition: RooCmdArg.h:122
RooCmdArg & operator=(const RooCmdArg &other)
Assignment operator.
Definition: RooCmdArg.cxx:145
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:51
static DataCollection _nextSharedData
Definition: RooCmdArg.h:134
void setSet(Int_t idx, const RooArgSet &set)
Definition: RooCmdArg.cxx:213
std::string _s[3]
Payload strings.
Definition: RooCmdArg.h:123
bool _procSubArgs
If true argument requires recursive processing.
Definition: RooCmdArg.h:125
RooCmdArg()
Default constructor.
Definition: RooCmdArg.cxx:60
TObject * _o[2]
Payload objects.
Definition: RooCmdArg.h:124
static const RooCmdArg _none
Static instance of null object.
Definition: RooCmdArg.h:118
double _d[2]
Payload doubles.
Definition: RooCmdArg.h:121
std::vector< std::unique_ptr< TObject > > DataCollection
Definition: RooCmdArg.h:130
bool _prefixSubArgs
Prefix sub-arguments with container name?
Definition: RooCmdArg.h:128
~RooCmdArg() override
Destructor.
Definition: RooCmdArg.cxx:184
static DataCollection & getNextSharedData()
Definition: RooCmdArg.cxx:235
Int_t GetSize() const
Definition: RooLinkedList.h:63
TObject * At(int index) const
Return object stored in sequential position given by index.
void Delete(Option_t *o=0) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:67
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
Mother of all ROOT objects.
Definition: TObject.h:37
return c1
Definition: legend1.C:41
return c2
Definition: legend2.C:14