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