Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
43 ClassImp(RooCmdArg);
44  ;
45 
46 const RooCmdArg RooCmdArg::_none ;
47 
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Return reference to null argument
51 
52 const RooCmdArg& RooCmdArg::none()
53 {
54  return _none ;
55 }
56 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Default constructor
60 
61 RooCmdArg::RooCmdArg() : TNamed("","")
62 {
63  _procSubArgs = kFALSE ;
64  _prefixSubArgs = kTRUE ;
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) :
82  TNamed(name,name)
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 
99  _procSubArgs = kTRUE ;
100  _prefixSubArgs = kTRUE ;
101  if (ca) {
102  _argList.Add(new RooCmdArg(*ca)) ;
103  }
104 }
105 
106 
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Copy constructor
110 
111 RooCmdArg::RooCmdArg(const RooCmdArg& other) :
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 ;
132  _prefixSubArgs = other._prefixSubArgs ;
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 
142 RooCmdArg& RooCmdArg::operator=(const RooCmdArg& other)
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 ;
165  _prefixSubArgs = other._prefixSubArgs ;
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 
179 RooCmdArg::~RooCmdArg()
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 }