Logo ROOT   6.21/01
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 
106 
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Copy constructor
110 
112  TNamed(other)
113 {
114  _i[0] = other._i[0] ;
115  _i[1] = other._i[1] ;
116  _d[0] = other._d[0] ;
117  _d[1] = other._d[1] ;
118  _s[0] = other._s[0] ;
119  _s[1] = other._s[1] ;
120  _s[2] = other._s[2] ;
121  _o[0] = other._o[0] ;
122  _o[1] = other._o[1] ;
123  if (other._c) {
124  _c = new RooArgSet[2] ;
125  _c[0].add(other._c[0]) ;
126  _c[1].add(other._c[1]) ;
127  } else {
128  _c = 0 ;
129  }
130 
131  _procSubArgs = other._procSubArgs ;
133  for (Int_t i=0 ; i<other._argList.GetSize() ; i++) {
134  _argList.Add(new RooCmdArg((RooCmdArg&)*other._argList.At(i))) ;
135  }
136 }
137 
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Assignment operator
141 
143 {
144  if (&other==this) return *this ;
145 
146  SetName(other.GetName()) ;
147  SetTitle(other.GetTitle()) ;
148 
149  _i[0] = other._i[0] ;
150  _i[1] = other._i[1] ;
151  _d[0] = other._d[0] ;
152  _d[1] = other._d[1] ;
153  _s[0] = other._s[0] ;
154  _s[1] = other._s[1] ;
155  _s[2] = other._s[2] ;
156  _o[0] = other._o[0] ;
157  _o[1] = other._o[1] ;
158  if (!_c) _c = new RooArgSet[2] ;
159  if (other._c) {
160  _c[0].removeAll() ; _c[0].add(other._c[0]) ;
161  _c[1].removeAll() ; _c[1].add(other._c[1]) ;
162  }
163 
164  _procSubArgs = other._procSubArgs ;
166 
167  for (Int_t i=0 ; i<other._argList.GetSize() ; i++) {
168  _argList.Add(new RooCmdArg((RooCmdArg&)*other._argList.At(i))) ;
169  }
170 
171  return *this ;
172 }
173 
174 
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Destructor
178 
180 {
181  _argList.Delete() ;
182  if (_c) delete[] _c ;
183 }
184 
185 
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// Utility function to add nested RooCmdArg to payload of this RooCmdArg
189 
190 void RooCmdArg::addArg(const RooCmdArg& arg)
191 {
192  _argList.Add(new RooCmdArg(arg)) ;
193 }
194 
195 
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Return RooArgSet stored in slot idx
199 
200 const RooArgSet* RooCmdArg::getSet(Int_t idx) const {
201  return _c ? &_c[idx] : 0 ;
202  }
203 
204 
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 
208 void RooCmdArg::setSet(Int_t idx,const RooArgSet& set)
209 {
210  if (!_c) {
211  _c = new RooArgSet[2] ;
212  }
213  _c[idx].removeAll() ;
214  _c[idx].add(set) ;
215 }
216 
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Print contents
220 void RooCmdArg::Print(const char*) const {
221  std::cout << GetName()
222  << ":\ndoubles\t" << _d[0] << " " << _d[1]
223  << "\nints\t" << _i[0] << " " << _i[1]
224  << "\nstrings\t" << _s[0] << " " << _s[1] << " " << _s[2]
225  << "\nobjects\t" << _o[0] << " " << _o[1] << std::endl;
226 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Double_t _d[2]
Definition: RooCmdArg.h:112
void Print(const char *="") const
Print contents.
Definition: RooCmdArg.cxx:220
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
void setSet(Int_t idx, const RooArgSet &set)
Definition: RooCmdArg.cxx:208
virtual ~RooCmdArg()
Destructor.
Definition: RooCmdArg.cxx:179
return c1
Definition: legend1.C:41
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
int Int_t
Definition: RtypesCore.h:41
STL namespace.
Int_t GetSize() const
Definition: RooLinkedList.h:61
TObject * _o[2]
Definition: RooCmdArg.h:115
RooLinkedList _argList
Definition: RooCmdArg.h:118
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:52
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:29
RooCmdArg & operator=(const RooCmdArg &other)
Assignment operator.
Definition: RooCmdArg.cxx:142
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:63
Int_t _i[2]
Definition: RooCmdArg.h:113
std::string _s[3]
Definition: RooCmdArg.h:114
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
#define s1(x)
Definition: RSha256.hxx:91
RooArgSet * _c
Definition: RooCmdArg.h:117
const Bool_t kFALSE
Definition: RtypesCore.h:88
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...
#define ClassImp(name)
Definition: Rtypes.h:365
RooCmdArg()
Default constructor.
Definition: RooCmdArg.cxx:61
double Double_t
Definition: RtypesCore.h:55
Bool_t _prefixSubArgs
Definition: RooCmdArg.h:119
void addArg(const RooCmdArg &arg)
Utility function to add nested RooCmdArg to payload of this RooCmdArg.
Definition: RooCmdArg.cxx:190
Mother of all ROOT objects.
Definition: TObject.h:37
static const RooCmdArg _none
Definition: RooCmdArg.h:104
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
const Bool_t kTRUE
Definition: RtypesCore.h:87
Bool_t _procSubArgs
Definition: RooCmdArg.h:116
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
Definition: RooCmdArg.cxx:200
char name[80]
Definition: TGX11.cxx:109
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:28