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