Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
23Named container for two doubles, two integers
24two object points and three string pointers that can be passed
25as generic named arguments to a variety of RooFit end user
26methods. To achieved the named syntax, RooCmdArg objects are
27created using global helper functions defined in RooGlobalFunc.h
28that create and fill these generic containers
29**/
30
31
32
33#include "RooCmdArg.h"
34#include "Riostream.h"
35#include "RooArgSet.h"
36
37#include "RooFitImplHelpers.h"
38
39#include <array>
40#include <sstream>
41#include <string>
42#include <iostream>
43
45
47
48
49////////////////////////////////////////////////////////////////////////////////
50/// Return reference to null argument
51
53{
54 return _none ;
55}
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Default constructor
60
62{
63 _o[0] = nullptr ;
64 _o[1] = nullptr ;
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
76RooCmdArg::RooCmdArg(const char* name, Int_t i1, Int_t i2, double d1, double 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) :
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] = const_cast<TObject*>(o1);
89 _o[1] = const_cast<TObject*>(o2);
90 _c = nullptr ;
91
92 if (c1||c2) _c = new RooArgSet[2] ;
93 if (c1) _c[0].add(*c1) ;
94 if (c2) _c[1].add(*c2) ;
95
96 _procSubArgs = true ;
97 _prefixSubArgs = true ;
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 = nullptr ;
126 }
127
128 _procSubArgs = other._procSubArgs ;
130 for (Int_t i=0 ; i<other._argList.GetSize() ; i++) {
131 _argList.Add(new RooCmdArg(static_cast<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(static_cast<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
188{
189 _argList.Add(new RooCmdArg(arg)) ;
190}
191
192
193
194////////////////////////////////////////////////////////////////////////////////
195/// Return RooArgSet stored in slot idx
196
198 return _c ? &_c[idx] : nullptr ;
199 }
200
201
202
203////////////////////////////////////////////////////////////////////////////////
204
206{
207 if (!_c) {
208 _c = new RooArgSet[2] ;
209 }
210 _c[idx].removeAll() ;
211 _c[idx].add(set) ;
212}
213
214std::string RooCmdArg::constructorCode() const
215{
216 std::array<bool, 13> needs;
217 needs[0] = true; // name
218 needs[1] = true; // i1
219 needs[2] = _i[1] != 0; // i2
220 needs[3] = _d[0] != 0; // d1
221 needs[4] = _d[1] != 0; // d2
222 needs[5] = !_s[0].empty(); // s1
223 needs[6] = !_s[1].empty(); // s2
224 needs[7] = _o[0]; // o1
225 needs[8] = _o[1]; // o2
226 needs[9] = !_argList.empty(); // ca
227 needs[10] = !_s[2].empty(); // s3
228 needs[11] = _c; // c1
229 needs[12] = _c && !_c[1].empty(); // c2
230
231 // figure out until which point we actually need to pass constructor
232 // arguments
233 bool b = false;
234 for (int i = needs.size() - 1; i >= 0; --i) {
235 b |= needs[i];
236 needs[i] = b;
237 }
238
239 std::stringstream ss;
240
241 // The first two arguments always need to be passed
242 ss << "RooCmdArg(\"" << GetName() << "\", " << _i[0];
243
244 if (needs[2])
245 ss << ", " << _i[1];
246 if (needs[3])
247 ss << ", " << _d[0];
248 if (needs[4])
249 ss << ", " << _d[1];
250 if (needs[5])
251 ss << ", " << (!_s[0].empty() ? "\"" + _s[0] + "\"" : "\"\"");
252 if (needs[6])
253 ss << ", " << (!_s[1].empty() ? "\"" + _s[1] + "\"" : "\"\"");
254 if (needs[7])
255 ss << ", " << (_o[0] ? "\"" + std::string(_o[0]->GetName()) + "\"" : "0");
256 if (needs[8])
257 ss << ", " << (_o[1] ? "\"" + std::string(_o[1]->GetName()) + "\"" : "0");
258 if (needs[9]) {
259 ss << ", ";
260 if (!_argList.empty()) {
261 ss << "{\n";
262 for (std::size_t i = 0; i < _argList.size(); ++i) {
263 if (auto *cmdArg = dynamic_cast<RooCmdArg *>(_argList.At(i))) {
264 ss << cmdArg->constructorCode() << "\n";
265 }
266 }
267 ss << "}\n";
268 } else {
269 ss << 0;
270 }
271 }
272 if (needs[10])
273 ss << ", " << (!_s[2].empty() ? "\"" + _s[2] + "\"" : "\"\"");
274 if (needs[11])
275 ss << ", RooArgSet(" << RooHelpers::getColonSeparatedNameString(_c[0], ',') << ")";
276 if (needs[12])
277 ss << ", RooArgSet(" << RooHelpers::getColonSeparatedNameString(_c[1], ',') << ")";
278 ss << ")";
279
280 return ss.str();
281}
282
283////////////////////////////////////////////////////////////////////////////////
284// Print contents
285void RooCmdArg::Print(const char *opts) const
286{
287 TString o{opts};
288 if (o.Contains("v")) {
289 std::cout << constructorCode() << std::endl;
290 return;
291 }
292
293 std::cout << GetName() << ":\ndoubles\t" << _d[0] << " " << _d[1] << "\nints\t" << _i[0] << " " << _i[1]
294 << "\nstrings\t" << _s[0] << " " << _s[1] << " " << _s[2] << "\nobjects\t" << _o[0] << " " << _o[1]
295 << std::endl;
296}
#define b(i)
Definition RSha256.hxx:100
#define s1(x)
Definition RSha256.hxx:91
#define ClassImp(name)
Definition Rtypes.h:382
char name[80]
Definition TGX11.cxx:110
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
RooArgSet * _c
Payload RooArgSets.
Definition RooCmdArg.h:123
void Print(const char *="") const override
This method must be overridden when a class wants to print itself.
RooLinkedList _argList
Payload sub-arguments.
Definition RooCmdArg.h:124
void addArg(const RooCmdArg &arg)
Utility function to add nested RooCmdArg to payload of this RooCmdArg.
Int_t _i[2]
Payload integers.
Definition RooCmdArg.h:119
RooCmdArg & operator=(const RooCmdArg &other)
Assignment operator.
static const RooCmdArg & none()
Return reference to null argument.
Definition RooCmdArg.cxx:52
std::string constructorCode() const
void setSet(Int_t idx, const RooArgSet &set)
std::string _s[3]
Payload strings.
Definition RooCmdArg.h:120
bool _procSubArgs
If true argument requires recursive processing.
Definition RooCmdArg.h:122
RooCmdArg()
Default constructor.
Definition RooCmdArg.cxx:61
TObject * _o[2]
Payload objects.
Definition RooCmdArg.h:121
static const RooCmdArg _none
Static instance of null object.
Definition RooCmdArg.h:115
double _d[2]
Payload doubles.
Definition RooCmdArg.h:118
bool _prefixSubArgs
Prefix sub-arguments with container name?
Definition RooCmdArg.h:125
~RooCmdArg() override
Destructor.
Int_t GetSize() const
TObject * At(int index) const
Return object stored in sequential position given by index.
bool empty() const
std::size_t size() const
void Delete(Option_t *o=nullptr) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
return c1
Definition legend1.C:41
return c2
Definition legend2.C:14
std::string getColonSeparatedNameString(RooArgSet const &argSet, char delim=':')