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