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 
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 }
RooCmdArg
Definition: RooCmdArg.h:27
RooCmdArg::_argList
RooLinkedList _argList
Definition: RooCmdArg.h:117
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooCmdArg::getSet
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
Definition: RooCmdArg.cxx:200
RooCmdArg::operator=
RooCmdArg & operator=(const RooCmdArg &other)
Assignment operator.
Definition: RooCmdArg.cxx:142
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:179
RooArgSet.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
RooCmdArg::addArg
void addArg(const RooCmdArg &arg)
Utility function to add nested RooCmdArg to payload of this RooCmdArg.
Definition: RooCmdArg.cxx:190
RooLinkedList::GetSize
Int_t GetSize() const
Definition: RooLinkedList.h:60
RooCmdArg::_procSubArgs
Bool_t _procSubArgs
Definition: RooCmdArg.h:115
RooLinkedList::At
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
Definition: RooLinkedList.cxx:496
RooCmdArg::_c
RooArgSet * _c
Definition: RooCmdArg.h:116
RooCmdArg::_prefixSubArgs
Bool_t _prefixSubArgs
Definition: RooCmdArg.h:118
RooArgSet::add
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
RooCmdArg::_none
static const RooCmdArg _none
Definition: RooCmdArg.h:103
RooCmdArg::none
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:52
RooCmdArg::_d
Double_t _d[2]
Definition: RooCmdArg.h:111
RooCmdArg::setSet
void setSet(Int_t idx, const RooArgSet &set)
Definition: RooCmdArg.cxx:208
RooCmdArg::RooCmdArg
RooCmdArg()
Default constructor.
Definition: RooCmdArg.cxx:61
RooCmdArg::_i
Int_t _i[2]
Definition: RooCmdArg.h:112
TNamed
Definition: TNamed.h:29
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
s1
#define s1(x)
Definition: RSha256.hxx:109
RooLinkedList::Add
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
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:220
RooCmdArg::_s
std::string _s[3]
Definition: RooCmdArg.h:113
Double_t
double Double_t
Definition: RtypesCore.h:59
RooCmdArg::_o
TObject * _o[2]
Definition: RooCmdArg.h:114
TObject
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:53
RooAbsCollection::removeAll
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Definition: RooAbsCollection.cxx:643
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:587
RooArgSet
Definition: RooArgSet.h:28
int
c1
return c1
Definition: legend1.C:41