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
44
46
47
48////////////////////////////////////////////////////////////////////////////////
49/// Return reference to null argument
50
52{
53 return _none ;
54}
55
56
57////////////////////////////////////////////////////////////////////////////////
58/// Default constructor
59
61{
62 _o[0] = nullptr ;
63 _o[1] = nullptr ;
64 _i[0] = 0 ;
65 _i[1] = 0 ;
66 _d[0] = 0 ;
67 _d[1] = 0 ;
68}
69
70
71////////////////////////////////////////////////////////////////////////////////
72/// Constructor with full specification of payload: two integers, two doubles,
73/// three string poiners, two object pointers and one RooCmdArg pointer
74
75RooCmdArg::RooCmdArg(const char* name, Int_t i1, Int_t i2, double d1, double d2,
76 const char* s1, const char* s2, const TObject* o1, const TObject* o2,
77 const RooCmdArg* ca, const char* s3, const RooArgSet* c1, const RooArgSet* c2) :
79{
80 _i[0] = i1 ;
81 _i[1] = i2 ;
82 _d[0] = d1 ;
83 _d[1] = d2 ;
84 if (s1) _s[0] = s1 ;
85 if (s2) _s[1] = s2 ;
86 if (s3) _s[2] = s3 ;
87 _o[0] = const_cast<TObject*>(o1);
88 _o[1] = const_cast<TObject*>(o2);
89 _c = nullptr ;
90
91 if (c1||c2) _c = new RooArgSet[2] ;
92 if (c1) _c[0].add(*c1) ;
93 if (c2) _c[1].add(*c2) ;
94
97 if (ca) {
98 _argList.Add(new RooCmdArg(*ca)) ;
99 }
100}
101
102
103
104////////////////////////////////////////////////////////////////////////////////
105/// Copy constructor
106
109{
110 _i[0] = other._i[0] ;
111 _i[1] = other._i[1] ;
112 _d[0] = other._d[0] ;
113 _d[1] = other._d[1] ;
114 _s[0] = other._s[0] ;
115 _s[1] = other._s[1] ;
116 _s[2] = other._s[2] ;
117 _o[0] = other._o[0] ;
118 _o[1] = other._o[1] ;
119 if (other._c) {
120 _c = new RooArgSet[2] ;
121 _c[0].add(other._c[0]) ;
122 _c[1].add(other._c[1]) ;
123 } else {
124 _c = nullptr ;
125 }
126
127 _procSubArgs = other._procSubArgs ;
128 _prefixSubArgs = other._prefixSubArgs ;
129 for (Int_t i=0 ; i<other._argList.GetSize() ; i++) {
130 _argList.Add(new RooCmdArg(static_cast<RooCmdArg&>(*other._argList.At(i)))) ;
131 }
132}
133
134
135////////////////////////////////////////////////////////////////////////////////
136/// Assignment operator
137
139{
140 if (&other==this) return *this ;
141
142 SetName(other.GetName()) ;
143 SetTitle(other.GetTitle()) ;
144
145 _i[0] = other._i[0] ;
146 _i[1] = other._i[1] ;
147 _d[0] = other._d[0] ;
148 _d[1] = other._d[1] ;
149 _s[0] = other._s[0] ;
150 _s[1] = other._s[1] ;
151 _s[2] = other._s[2] ;
152 _o[0] = other._o[0] ;
153 _o[1] = other._o[1] ;
154 if (!_c) _c = new RooArgSet[2] ;
155 if (other._c) {
156 _c[0].removeAll() ; _c[0].add(other._c[0]) ;
157 _c[1].removeAll() ; _c[1].add(other._c[1]) ;
158 }
159
160 _procSubArgs = other._procSubArgs ;
161 _prefixSubArgs = other._prefixSubArgs ;
162
163 for (Int_t i=0 ; i<other._argList.GetSize() ; i++) {
164 _argList.Add(new RooCmdArg(static_cast<RooCmdArg&>(*other._argList.At(i)))) ;
165 }
166
167 return *this ;
168}
169
170
171
172////////////////////////////////////////////////////////////////////////////////
173/// Destructor
174
176{
177 _argList.Delete() ;
178 if (_c) delete[] _c ;
179}
180
181
182
183////////////////////////////////////////////////////////////////////////////////
184/// Utility function to add nested RooCmdArg to payload of this RooCmdArg
185
187{
188 _argList.Add(new RooCmdArg(arg)) ;
189}
190
191
192
193////////////////////////////////////////////////////////////////////////////////
194/// Return RooArgSet stored in slot idx
195
197 return _c ? &_c[idx] : nullptr ;
198 }
199
200
201
202////////////////////////////////////////////////////////////////////////////////
203
205{
206 if (!_c) {
207 _c = new RooArgSet[2] ;
208 }
209 _c[idx].removeAll() ;
210 _c[idx].add(set) ;
211}
212
213std::string RooCmdArg::constructorCode() const
214{
215 std::array<bool, 13> needs;
216 needs[0] = true; // name
217 needs[1] = true; // i1
218 needs[2] = _i[1] != 0; // i2
219 needs[3] = _d[0] != 0; // d1
220 needs[4] = _d[1] != 0; // d2
221 needs[5] = !_s[0].empty(); // s1
222 needs[6] = !_s[1].empty(); // s2
223 needs[7] = _o[0]; // o1
224 needs[8] = _o[1]; // o2
225 needs[9] = !_argList.empty(); // ca
226 needs[10] = !_s[2].empty(); // s3
227 needs[11] = _c; // c1
228 needs[12] = _c && !_c[1].empty(); // c2
229
230 // figure out until which point we actually need to pass constructor
231 // arguments
232 bool b = false;
233 for (int i = needs.size() - 1; i >= 0; --i) {
234 b |= needs[i];
235 needs[i] = b;
236 }
237
238 std::stringstream ss;
239
240 // The first two arguments always need to be passed
241 ss << "RooCmdArg(\"" << GetName() << "\", " << _i[0];
242
243 if (needs[2])
244 ss << ", " << _i[1];
245 if (needs[3])
246 ss << ", " << _d[0];
247 if (needs[4])
248 ss << ", " << _d[1];
249 if (needs[5])
250 ss << ", " << (!_s[0].empty() ? "\"" + _s[0] + "\"" : "\"\"");
251 if (needs[6])
252 ss << ", " << (!_s[1].empty() ? "\"" + _s[1] + "\"" : "\"\"");
253 if (needs[7])
254 ss << ", " << (_o[0] ? "\"" + std::string(_o[0]->GetName()) + "\"" : "0");
255 if (needs[8])
256 ss << ", " << (_o[1] ? "\"" + std::string(_o[1]->GetName()) + "\"" : "0");
257 if (needs[9]) {
258 ss << ", ";
259 if (!_argList.empty()) {
260 ss << "{\n";
261 for (std::size_t i = 0; i < _argList.size(); ++i) {
262 if (auto *cmdArg = dynamic_cast<RooCmdArg *>(_argList.At(i))) {
263 ss << cmdArg->constructorCode() << "\n";
264 }
265 }
266 ss << "}\n";
267 } else {
268 ss << 0;
269 }
270 }
271 if (needs[10])
272 ss << ", " << (!_s[2].empty() ? "\"" + _s[2] + "\"" : "\"\"");
273 if (needs[11])
274 ss << ", RooArgSet(" << RooHelpers::getColonSeparatedNameString(_c[0], ',') << ")";
275 if (needs[12])
276 ss << ", RooArgSet(" << RooHelpers::getColonSeparatedNameString(_c[1], ',') << ")";
277 ss << ")";
278
279 return ss.str();
280}
281
282////////////////////////////////////////////////////////////////////////////////
283// Print contents
284void RooCmdArg::Print(const char *opts) const
285{
286 TString o{opts};
287 if (o.Contains("v")) {
288 std::cout << constructorCode() << std::endl;
289 return;
290 }
291
292 std::cout << GetName() << ":\ndoubles\t" << _d[0] << " " << _d[1] << "\nints\t" << _i[0] << " " << _i[1]
293 << "\nstrings\t" << _s[0] << " " << _s[1] << " " << _s[2] << "\nobjects\t" << _o[0] << " " << _o[1]
294 << std::endl;
295}
#define b(i)
Definition RSha256.hxx:100
#define s1(x)
Definition RSha256.hxx:91
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:51
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:60
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.
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:174
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:150
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=':')