Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsCollection.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\file RooAbsCollection.cxx
19\class RooAbsCollection
20\ingroup Roofitcore
21
22RooAbsCollection is an abstract container object that can hold
23multiple RooAbsArg objects. Collections are ordered and can
24contain multiple objects of the same name, (but a derived
25implementation can enforce unique names). The storage of objects is
26implemented using the container denoted by RooAbsCollection::Storage_t.
27**/
28
29#include "RooAbsCollection.h"
30
31#include "TClass.h"
32#include "TStopwatch.h"
33#include "TRegexp.h"
34#include "RooStreamParser.h"
35#include "RooFormula.h"
36#include "RooAbsRealLValue.h"
38#include "RooStringVar.h"
39#include "RooTrace.h"
40#include "RooArgList.h"
41#include "RooLinkedListIter.h"
42#include "RooCmdConfig.h"
43#include "RooRealVar.h"
44#include "RooGlobalFunc.h"
45#include "RooMsgService.h"
46#include <ROOT/RMakeUnique.hxx>
47#include "strlcpy.h"
48
49#include <algorithm>
50#include <iomanip>
51#include <iostream>
52#include <fstream>
53
54using std::endl;
55using std::vector;
56using std::string;
57using std::ostream;
58using std::cout;
59
60#if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3)
61char* operator+( streampos&, char* );
62#endif
63
65 ;
66
67////////////////////////////////////////////////////////////////////////////////
68/// Default constructor
69
71 _list(),
72 _ownCont(kFALSE),
73 _name(),
74 _allRRV(kTRUE),
75 _sizeThresholdForMapSearch(100)
76{
77 _list.reserve(8);
81
82////////////////////////////////////////////////////////////////////////////////
83/// Empty collection constructor
84
86 _list(),
87 _ownCont(kFALSE),
88 _name(name),
89 _allRRV(kTRUE),
90 _sizeThresholdForMapSearch(100)
91{
92 _list.reserve(8);
93}
94
95
96
97////////////////////////////////////////////////////////////////////////////////
98/// Copy constructor. Note that a copy of a collection is always non-owning,
99/// even the source collection is owning. To create an owning copy of
100/// a collection (owning or not), use the snapshot() method.
101
103 TObject(other),
104 RooPrintable(other),
105 _list(),
106 _ownCont(kFALSE),
107 _name(name),
108 _allRRV(other._allRRV),
109 _sizeThresholdForMapSearch(100)
110{
111 RooTrace::create(this) ;
112 if (!name) setName(other.GetName()) ;
113
114 _list.reserve(other._list.size());
115
116 for (auto item : other._list) {
117 add(*item);
118 }
119}
120
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Destructor
125
127{
128 // Delete all variables in our list if we own them
129 if(_ownCont){
131 }
132}
133
134
135////////////////////////////////////////////////////////////////////////////////
136/// Examine client server dependencies in list and
137/// delete contents in safe order: any client
138/// is deleted before a server is deleted
139
141{
142 _nameToItemMap = nullptr;
143
144 // Handle trivial case here
145 if (_list.size() > 1) {
146 std::vector<RooAbsArg*> tmp;
147 tmp.reserve(_list.size());
148 do {
149 tmp.clear();
150 for (auto arg : _list) {
151 // Check if arg depends on remainder of list
152 if (!arg->dependsOn(*this, arg)) tmp.push_back(arg);
153 }
154
155 // sort and uniquify, in case some elements occur more than once
156 std::sort(tmp.begin(), tmp.end());
157
158 tmp.erase(std::unique(tmp.begin(), tmp.end()), tmp.end());
159 // okay, can remove and delete what's in tmp
160 auto newEnd = _list.end();
161 for (auto item : tmp) {
162 newEnd = std::remove(_list.begin(), newEnd, item);
163 delete item;
164 }
165 _list.erase(newEnd, _list.end());
166 } while (!tmp.empty() && _list.size() > 1);
167
168 // Check if there are any remaining elements
169 if (_list.size() > 1) {
170 coutW(ObjectHandling) << "RooAbsCollection::safeDeleteList(" << GetName()
171 << ") WARNING: unable to delete following elements in client-server order " ;
172 Print("1") ;
173 }
174 }
175
176 // Built-in delete remaining elements
177 for (auto item : _list) {
178 delete item;
179 }
180 _list.clear();
181}
182
183
184
185////////////////////////////////////////////////////////////////////////////////
186/// Take a snap shot of current collection contents.
187/// An owning collection is returned containing clones of
188/// - Elements in this collection
189/// - External dependents of all elements and recursively any dependents of those dependents
190/// (if deepCopy flag is set)
191///
192/// This is useful to save the values of variables or parameters. It doesn't require
193/// deep copying if the parameters are direct members of the collection.
194///
195/// If deepCopy is specified, the client-server links between the cloned
196/// list elements and the cloned external dependents are reconnected to
197/// each other, making the snapshot a completely self-contained entity.
198///
199///
200
202{
203 // First create empty list
204 TString snapName ;
205 if (TString(GetName()).Length()>0) {
206 snapName.Append("Snapshot of ") ;
207 snapName.Append(GetName()) ;
208 }
210
211 Bool_t error = snapshot(*output,deepCopy) ;
212 if (error) {
213 delete output ;
214 return 0 ;
215 }
216
217 return output ;
218}
219
220
221
222////////////////////////////////////////////////////////////////////////////////
223/// Take a snap shot of current collection contents:
224/// A collection that owns its elements is returned containing clones of
225/// - Elements in this collection
226/// - External dependents of those elements
227/// and recursively any dependents of those dependents
228/// (if deepCopy flag is set)
229///
230/// If deepCopy is specified, the client-server links between the cloned
231/// list elements and the cloned external dependents are reconnected to
232/// each other, making the snapshot a completely self-contained entity.
233///
234///
235
237{
238 // Copy contents
239 output.reserve(_list.size());
240 for (auto orig : _list) {
241 RooAbsArg *copy= (RooAbsArg*)orig->Clone();
242 output.add(*copy);
243 }
244
245 // Add external dependents
246 Bool_t error(kFALSE) ;
247 if (deepCopy) {
248 // Recursively add clones of all servers
249 // Can only do index access because collection might reallocate when growing
250 for (Storage_t::size_type i = 0; i < output._list.size(); ++i) {
251 const auto var = output._list[i];
252 error |= output.addServerClonesToList(*var);
253 }
254 }
255
256 // Handle eventual error conditions
257 if (error) {
258 coutE(ObjectHandling) << "RooAbsCollection::snapshot(): Errors occurred in deep clone process, snapshot not created" << endl ;
259 output._ownCont = kTRUE ;
260 return kTRUE ;
261 }
262
263
264
265 // Redirect all server connections to internal list members
266 for (auto var : output) {
267 var->redirectServers(output,deepCopy);
268 }
269
270
271 // Transfer ownership of contents to list
272 output._ownCont = kTRUE ;
273 return kFALSE ;
274}
275
276
277
278////////////////////////////////////////////////////////////////////////////////
279/// Add clones of servers of given argument to end of list
280
282{
283 Bool_t ret(kFALSE) ;
284
285 // This can be a very heavy operation if existing elements depend on many others,
286 // so make sure that we have the hash map available for faster finding.
287 if (var.servers().size() > 20 || _list.size() > 30)
288 useHashMapForFind(true);
289
290 for (const auto server : var.servers()) {
291 RooAbsArg* tmp = find(*server) ;
292
293 if (!tmp) {
294 RooAbsArg* serverClone = (RooAbsArg*)server->Clone() ;
295 serverClone->setAttribute("SnapShot_ExtRefClone") ;
296 insert(serverClone);
297 ret |= addServerClonesToList(*server) ;
298 }
299 }
300
301 return ret ;
302}
303
304
305
306////////////////////////////////////////////////////////////////////////////////
307/// The assignment operator sets the value of any argument in our set
308/// that also appears in the other set.
309
311{
312 if (&other==this) return *this ;
313
314 for (auto elem : _list) {
315 auto theirs = other.find(*elem);
316 if(!theirs) continue;
317 theirs->syncCache() ;
318 elem->copyCache(theirs) ;
319 elem->setAttribute("Constant",theirs->isConstant()) ;
320 }
321 return *this;
322}
323
324
325
326////////////////////////////////////////////////////////////////////////////////
327/// The assignment operator sets the value of any argument in our set
328/// that also appears in the other set.
329
331{
332 if (&other==this) return *this ;
333
334 // Short cut for 1 element assignment
335 if (getSize()==1 && getSize()==other.getSize() && oneSafe) {
336 other.first()->syncCache() ;
337 first()->copyCache(other.first(),kTRUE) ;
338 return *this ;
339 }
340
341 for (auto elem : _list) {
342 auto theirs = other.find(*elem);
343 if(!theirs) continue;
344 theirs->syncCache() ;
345 elem->copyCache(theirs,kTRUE) ;
346 }
347 return *this;
348}
349
350
351
352////////////////////////////////////////////////////////////////////////////////
353/// Functional equivalent of operator=() but assumes this and other collection
354/// have same layout. Also no attributes are copied
355
357{
358 if (&other==this) return ;
359 assert(_list.size() == other._list.size());
360
361 auto iter2 = other._list.begin();
362 for (auto iter1 = _list.begin();
363 iter1 != _list.end() && iter2 != other._list.end();
364 ++iter1, ++iter2) {
365 // Identical size of iterators is documented assumption of method
366
367 if (_allRRV) {
368 // All contents are known to be RooRealVars - fast version of assignment
369 auto ours = static_cast<RooRealVar*>(*iter1);
370 auto theirs = static_cast<RooRealVar*>(*iter2);
371 ours->copyCacheFast(*theirs,setValDirty);
372 } else {
373 (*iter2)->syncCache() ;
374 (*iter1)->copyCache(*iter2,kTRUE,setValDirty) ;
375 }
376 }
377
378}
379
380
381
382////////////////////////////////////////////////////////////////////////////////
383/// Add the specified argument to list. Returns kTRUE if successful, or
384/// else kFALSE if a variable of the same name is already in the list.
385/// This method can only be called on a list that is flagged as owning
386/// all of its contents, or else on an empty list (which will force the
387/// list into that mode).
388
390{
391 // check that we own our variables or else are empty
392 if(!_ownCont && (getSize() > 0) && !silent) {
393 coutE(ObjectHandling) << ClassName() << "::" << GetName() << "::addOwned: can only add to an owned list" << endl;
394 return kFALSE;
395 }
397
398 insert(&var);
399
400 return kTRUE;
401}
402
403
404
405////////////////////////////////////////////////////////////////////////////////
406/// Add a clone of the specified argument to list. Returns a pointer to
407/// the clone if successful, or else zero if a variable of the same name
408/// is already in the list or the list does *not* own its variables (in
409/// this case, try add() instead.) Calling addClone() on an empty list
410/// forces it to take ownership of all its subsequent variables.
411
413{
414 // check that we own our variables or else are empty
415 if(!_ownCont && (getSize() > 0) && !silent) {
416 coutE(ObjectHandling) << ClassName() << "::" << GetName() << "::addClone: can only add to an owned list" << endl;
417 return 0;
418 }
420
421 // add a pointer to a clone of this variable to our list (we now own it!)
422 auto clone2 = static_cast<RooAbsArg*>(var.Clone());
423 assert(clone2);
424
425 insert(clone2);
426
427 return clone2;
428}
429
430
431
432////////////////////////////////////////////////////////////////////////////////
433/// Add the specified argument to list. Returns kTRUE if successful, or
434/// else kFALSE if a variable of the same name is already in the list
435/// or the list owns its variables (in this case, try addClone() or addOwned() instead).
436
438{
439 // check that this isn't a copy of a list
440 if(_ownCont && !silent) {
441 coutE(ObjectHandling) << ClassName() << "::" << GetName() << "::add: cannot add to an owned list" << endl;
442 return kFALSE;
443 }
444
445 // add a pointer to this variable to our list (we don't own it!)
446 insert(const_cast<RooAbsArg*>(&var)); //FIXME const_cast
447
448 return kTRUE;
449}
450
451
452
453////////////////////////////////////////////////////////////////////////////////
454/// Add a collection of arguments to this collection by calling add()
455/// for each element in the source collection
456
458{
459 Bool_t result(false) ;
460 _list.reserve(_list.size() + list._list.size());
461
462 for (auto item : list._list) {
463 result |= add(*item,silent);
464 }
465
466 return result;
467}
468
469
470
471////////////////////////////////////////////////////////////////////////////////
472/// Add a collection of arguments to this collection by calling addOwned()
473/// for each element in the source collection
474
476{
477 Bool_t result(false) ;
478 _list.reserve(_list.size() + list._list.size());
479
480 for (auto item : list._list) {
481 result |= addOwned(*item, silent) ;
482 }
483
484 return result;
485}
486
487
488
489////////////////////////////////////////////////////////////////////////////////
490/// Add a collection of arguments to this collection by calling addOwned()
491/// for each element in the source collection
492
494{
495 _list.reserve(_list.size() + list._list.size());
496
497 for (auto item : list._list) {
498 addClone(*item, silent);
499 }
500}
501
502
503
504////////////////////////////////////////////////////////////////////////////////
505/// Replace any args in our set with args of the same name from the other set
506/// and return kTRUE for success. Fails if this list is a copy of another.
507
509{
510 // check that this isn't a copy of a list
511 if(_ownCont) {
512 coutE(ObjectHandling) << "RooAbsCollection: cannot replace variables in a copied list" << endl;
513 return kFALSE;
514 }
515
516 // loop over elements in the other list
517 for (const auto * arg : other._list) {
518 // do we have an arg of the same name in our set?
519 auto found = find(*arg);
520 if (found) replace(*found,*arg);
521 }
522 return kTRUE;
523}
524
525
526
527////////////////////////////////////////////////////////////////////////////////
528/// Replace var1 with var2 and return kTRUE for success. Fails if
529/// this list is a copy of another, if var1 is not already in this set,
530/// or if var2 is already in this set. var1 and var2 do not need to have
531/// the same name.
532
534{
535 // check that this isn't a copy of a list
536 if(_ownCont) {
537 coutE(ObjectHandling) << "RooAbsCollection: cannot replace variables in a copied list" << endl;
538 return kFALSE;
539 }
540
541 // is var1 already in this list?
542 const char *name= var1.GetName();
543 auto var1It = std::find(_list.begin(), _list.end(), &var1);
544
545 if (var1It == _list.end()) {
546 coutE(ObjectHandling) << "RooAbsCollection: variable \"" << name << "\" is not in the list"
547 << " and cannot be replaced" << endl;
548 return kFALSE;
549 }
550
551
552 // is var2's name already in this list?
553 if (dynamic_cast<RooArgSet*>(this)) {
554 RooAbsArg *other = find(var2);
555 if(other != 0 && other != &var1) {
556 coutE(ObjectHandling) << "RooAbsCollection: cannot replace \"" << name
557 << "\" with already existing \"" << var2.GetName() << "\"" << endl;
558 return kFALSE;
559 }
560 }
561
562 // replace var1 with var2
563 if (_nameToItemMap) {
564 _nameToItemMap->erase((*var1It)->namePtr());
565 (*_nameToItemMap)[var2.namePtr()] = const_cast<RooAbsArg*>(&var2);
566 }
567 *var1It = const_cast<RooAbsArg*>(&var2); //FIXME try to get rid of const_cast
568
569 if (_allRRV && dynamic_cast<const RooRealVar*>(&var2)==0) {
571 }
572
573 return kTRUE;
574}
575
576
577
578////////////////////////////////////////////////////////////////////////////////
579/// Remove the specified argument from our list. Return kFALSE if
580/// the specified argument is not found in our list. An exact pointer
581/// match is required, not just a match by name.
582/// If `matchByNameOnly` is set, items will be looked up by name. In this case, if
583/// the collection also owns the item, it will delete it.
585{
586 // is var already in this list?
587 const auto sizeBefore = _list.size();
588
589 if (matchByNameOnly) {
590 const std::string name(var.GetName());
591 auto nameMatch = [&name](const RooAbsArg* elm) {
592 return elm->GetName() == name;
593 };
594 std::set<RooAbsArg*> toBeDeleted;
595
596 if (_ownCont) {
597 std::for_each(_list.begin(), _list.end(), [&toBeDeleted, nameMatch](RooAbsArg* elm){
598 if (nameMatch(elm)) {
599 toBeDeleted.insert(elm);
600 }
601 });
602 }
603
604 _list.erase(std::remove_if(_list.begin(), _list.end(), nameMatch), _list.end());
605
606 for (auto arg : toBeDeleted)
607 delete arg;
608 } else {
609 _list.erase(std::remove(_list.begin(), _list.end(), &var), _list.end());
610 }
611
612 if (_nameToItemMap && sizeBefore != _list.size()) {
613 _nameToItemMap->erase(var.namePtr());
614 }
615
616 return sizeBefore != _list.size();
617}
618
619
620
621////////////////////////////////////////////////////////////////////////////////
622/// Remove each argument in the input list from our list using remove(const RooAbsArg&).
623/// Return kFALSE in case of problems.
624
625Bool_t RooAbsCollection::remove(const RooAbsCollection& list, Bool_t silent, Bool_t matchByNameOnly)
626{
627
628 auto oldSize = _list.size();
629 for (auto item : list._list) {
630 remove(*item, silent, matchByNameOnly);
631 }
632
633 return oldSize != _list.size();
634}
635
636
637
638////////////////////////////////////////////////////////////////////////////////
639/// Remove all arguments from our set, deleting them if we own them.
640/// This effectively restores our object to the state it would have
641/// just after calling the RooAbsCollection(const char*) constructor.
642
644{
645 _nameToItemMap = nullptr;
646
647 if(_ownCont) {
650 }
651 else {
652 _list.clear();
653 }
654}
655
656
657
658////////////////////////////////////////////////////////////////////////////////
659/// Set given attribute in each element of the collection by
660/// calling each elements setAttribute() function.
661
663{
664 for (auto arg : _list) {
665 arg->setAttribute(name, value);
666 }
667}
668
669
670
671
672////////////////////////////////////////////////////////////////////////////////
673/// Create a subset of the current collection, consisting only of those
674/// elements with the specified attribute set. The caller is responsibe
675/// for deleting the returned collection
676
678{
679 TString selName(GetName()) ;
680 selName.Append("_selection") ;
681 RooAbsCollection *sel = (RooAbsCollection*) create(selName.Data()) ;
682
683 // Scan set contents for matching attribute
684 for (auto arg : _list) {
685 if (arg->getAttribute(name)==value)
686 sel->add(*arg) ;
687 }
688
689 return sel ;
690}
691
692
693
694
695////////////////////////////////////////////////////////////////////////////////
696/// Create a subset of the current collection, consisting only of those
697/// elements that are contained as well in the given reference collection.
698/// The caller is responsible for deleting the returned collection
699
701{
702 // Create output set
703 TString selName(GetName()) ;
704 selName.Append("_selection") ;
705 RooAbsCollection *sel = (RooAbsCollection*) create(selName.Data()) ;
706
707 // Scan set contents for matching attribute
708 for (auto arg : _list) {
709 if (refColl.find(*arg))
710 sel->add(*arg) ;
711 }
712
713 return sel ;
714}
715
716
717
718////////////////////////////////////////////////////////////////////////////////
719/// Create a subset of the current collection, consisting only of those
720/// elements with names matching the wildcard expressions in nameList,
721/// supplied as a comma separated list
722
723RooAbsCollection* RooAbsCollection::selectByName(const char* nameList, Bool_t verbose) const
724{
725 // Create output set
726 TString selName(GetName()) ;
727 selName.Append("_selection") ;
728 RooAbsCollection *sel = (RooAbsCollection*) create(selName.Data()) ;
729
730 const size_t bufSize = strlen(nameList) + 1;
731 char* buf = new char[bufSize] ;
732 strlcpy(buf,nameList,bufSize) ;
733 char* wcExpr = strtok(buf,",") ;
734 while(wcExpr) {
735 TRegexp rexp(wcExpr,kTRUE) ;
736 if (verbose) {
737 cxcoutD(ObjectHandling) << "RooAbsCollection::selectByName(" << GetName() << ") processing expression '" << wcExpr << "'" << endl ;
738 }
739
740 RooFIter iter = fwdIterator() ;
741 RooAbsArg* arg ;
742 while((arg=iter.next())) {
743 if (TString(arg->GetName()).Index(rexp)>=0) {
744 if (verbose) {
745 cxcoutD(ObjectHandling) << "RooAbsCollection::selectByName(" << GetName() << ") selected element " << arg->GetName() << endl ;
746 }
747 sel->add(*arg) ;
748 }
749 }
750 wcExpr = strtok(0,",") ;
751 }
752 delete[] buf ;
753
754 return sel ;
755}
756
757
758
759
760////////////////////////////////////////////////////////////////////////////////
761/// Check if this and other collection have identically-named contents
762
764{
765 // First check equal length
766 if (getSize() != otherColl.getSize()) return kFALSE ;
767
768 // Then check that each element of our list also occurs in the other list
769 auto compareByNamePtr = [](const RooAbsArg * left, const RooAbsArg * right) {
770 return left->namePtr() == right->namePtr();
771 };
772
773 return std::is_permutation(_list.begin(), _list.end(),
774 otherColl._list.begin(),
775 compareByNamePtr);
776}
777
778
779
780
781////////////////////////////////////////////////////////////////////////////////
782/// Check if this and other collection have common entries
783
785{
786 for (auto arg : _list) {
787 if (otherColl.find(*arg)) {
788 return kTRUE ;
789 }
790 }
791 return kFALSE ;
792}
793
794namespace {
795////////////////////////////////////////////////////////////////////////////////
796/// Linear search through list of stored objects.
797template<class Collection_t>
798RooAbsArg* findUsingNamePointer(const Collection_t& coll, const TNamed* ptr) {
799 auto findByNamePtr = [ptr](const RooAbsArg* elm) {
800 return ptr == elm->namePtr();
801 };
802
803 auto item = std::find_if(coll.begin(), coll.end(), findByNamePtr);
804
805 return item != coll.end() ? *item : nullptr;
806}
807}
808
809
810////////////////////////////////////////////////////////////////////////////////
811/// Find object with given name in list. A null pointer
812/// is returned if no object with the given name is found.
814{
815 if (!name)
816 return nullptr;
817
818 // If an object with such a name exists, its name has been registered.
819 const TNamed* nptr = RooNameReg::known(name);
820 if (!nptr) return nullptr;
821
822 RooAbsArg* item = tryFastFind(nptr);
823
824 return item ? item : findUsingNamePointer(_list, nptr);
825}
826
827
828
829////////////////////////////////////////////////////////////////////////////////
830/// Find object with given name in list. A null pointer
831/// is returned if no object with the given name is found.
833{
834 const auto nptr = arg.namePtr();
835 RooAbsArg* item = tryFastFind(nptr);
836
837 return item ? item : findUsingNamePointer(_list, nptr);
838}
839
840
841////////////////////////////////////////////////////////////////////////////////
842/// Return index of item with given name, or -1 in case it's not in the collection.
844 const std::string theName(name);
845 auto item = std::find_if(_list.begin(), _list.end(), [&theName](const RooAbsArg * elm){
846 return elm->GetName() == theName;
847 });
848 return item != _list.end() ? item - _list.begin() : -1;
849}
850
851
852////////////////////////////////////////////////////////////////////////////////
853/// Get value of a RooAbsReal stored in set with given name. If none is found, value of defVal is returned.
854/// No error messages are printed unless the verbose flag is set
855
856Double_t RooAbsCollection::getRealValue(const char* name, Double_t defVal, Bool_t verbose) const
857{
858 RooAbsArg* raa = find(name) ;
859 if (!raa) {
860 if (verbose) coutE(InputArguments) << "RooAbsCollection::getRealValue(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
861 return defVal ;
862 }
863 RooAbsReal* rar = dynamic_cast<RooAbsReal*>(raa) ;
864 if (!rar) {
865 if (verbose) coutE(InputArguments) << "RooAbsCollection::getRealValue(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsReal" << endl ;
866 return defVal ;
867 }
868 return rar->getVal() ;
869}
870
871
872
873////////////////////////////////////////////////////////////////////////////////
874/// Set value of a RooAbsRealLValye stored in set with given name to newVal
875/// No error messages are printed unless the verbose flag is set
876
878{
879 RooAbsArg* raa = find(name) ;
880 if (!raa) {
881 if (verbose) coutE(InputArguments) << "RooAbsCollection::setRealValue(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
882 return kTRUE ;
883 }
884 RooAbsRealLValue* rar = dynamic_cast<RooAbsRealLValue*>(raa) ;
885 if (!rar) {
886 if (verbose) coutE(InputArguments) << "RooAbsCollection::setRealValue(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsRealLValue" << endl ;
887 return kTRUE;
888 }
889 rar->setVal(newVal) ;
890 return kFALSE ;
891}
892
893
894
895////////////////////////////////////////////////////////////////////////////////
896/// Get state name of a RooAbsCategory stored in set with given name. If none is found, value of defVal is returned.
897/// No error messages are printed unless the verbose flag is set
898
899const char* RooAbsCollection::getCatLabel(const char* name, const char* defVal, Bool_t verbose) const
900{
901 RooAbsArg* raa = find(name) ;
902 if (!raa) {
903 if (verbose) coutE(InputArguments) << "RooAbsCollection::getCatLabel(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
904 return defVal ;
905 }
906 RooAbsCategory* rac = dynamic_cast<RooAbsCategory*>(raa) ;
907 if (!rac) {
908 if (verbose) coutE(InputArguments) << "RooAbsCollection::getCatLabel(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsCategory" << endl ;
909 return defVal ;
910 }
911 return rac->getCurrentLabel() ;
912}
913
914
915
916////////////////////////////////////////////////////////////////////////////////
917/// Set state name of a RooAbsCategoryLValue stored in set with given name to newVal.
918/// No error messages are printed unless the verbose flag is set
919
920Bool_t RooAbsCollection::setCatLabel(const char* name, const char* newVal, Bool_t verbose)
921{
922 RooAbsArg* raa = find(name) ;
923 if (!raa) {
924 if (verbose) coutE(InputArguments) << "RooAbsCollection::setCatLabel(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
925 return kTRUE ;
926 }
927 RooAbsCategoryLValue* rac = dynamic_cast<RooAbsCategoryLValue*>(raa) ;
928 if (!rac) {
929 if (verbose) coutE(InputArguments) << "RooAbsCollection::setCatLabel(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsCategory" << endl ;
930 return kTRUE ;
931 }
932 rac->setLabel(newVal) ;
933 return kFALSE ;
934}
935
936
937
938////////////////////////////////////////////////////////////////////////////////
939/// Get index value of a RooAbsCategory stored in set with given name. If none is found, value of defVal is returned.
940/// No error messages are printed unless the verbose flag is set
941
942Int_t RooAbsCollection::getCatIndex(const char* name, Int_t defVal, Bool_t verbose) const
943{
944 RooAbsArg* raa = find(name) ;
945 if (!raa) {
946 if (verbose) coutE(InputArguments) << "RooAbsCollection::getCatLabel(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
947 return defVal ;
948 }
949 RooAbsCategory* rac = dynamic_cast<RooAbsCategory*>(raa) ;
950 if (!rac) {
951 if (verbose) coutE(InputArguments) << "RooAbsCollection::getCatLabel(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsCategory" << endl ;
952 return defVal ;
953 }
954 return rac->getCurrentIndex() ;
955}
956
957
958
959////////////////////////////////////////////////////////////////////////////////
960/// Set index value of a RooAbsCategoryLValue stored in set with given name to newVal.
961/// No error messages are printed unless the verbose flag is set
962
964{
965 RooAbsArg* raa = find(name) ;
966 if (!raa) {
967 if (verbose) coutE(InputArguments) << "RooAbsCollection::setCatLabel(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
968 return kTRUE ;
969 }
970 RooAbsCategoryLValue* rac = dynamic_cast<RooAbsCategoryLValue*>(raa) ;
971 if (!rac) {
972 if (verbose) coutE(InputArguments) << "RooAbsCollection::setCatLabel(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsCategory" << endl ;
973 return kTRUE ;
974 }
975 rac->setIndex(newVal) ;
976 return kFALSE ;
977}
978
979
980
981////////////////////////////////////////////////////////////////////////////////
982/// Get string value of a RooStringVar stored in set with given name. If none is found, value of defVal is returned.
983/// No error messages are printed unless the verbose flag is set
984
985const char* RooAbsCollection::getStringValue(const char* name, const char* defVal, Bool_t verbose) const
986{
987 RooAbsArg* raa = find(name) ;
988 if (!raa) {
989 if (verbose) coutE(InputArguments) << "RooAbsCollection::getStringValue(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
990 return defVal ;
991 }
992 auto ras = dynamic_cast<const RooStringVar*>(raa) ;
993 if (!ras) {
994 if (verbose) coutE(InputArguments) << "RooAbsCollection::getStringValue(" << GetName() << ") ERROR object '" << name << "' is not of type RooStringVar" << endl ;
995 return defVal ;
996 }
997
998 return ras->getVal() ;
999}
1000
1001
1002
1003////////////////////////////////////////////////////////////////////////////////
1004/// Set string value of a RooStringVar stored in set with given name to newVal.
1005/// No error messages are printed unless the verbose flag is set
1006
1007Bool_t RooAbsCollection::setStringValue(const char* name, const char* newVal, Bool_t verbose)
1008{
1009 RooAbsArg* raa = find(name) ;
1010 if (!raa) {
1011 if (verbose) coutE(InputArguments) << "RooAbsCollection::setStringValue(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
1012 return kTRUE ;
1013 }
1014 auto ras = dynamic_cast<RooStringVar*>(raa);
1015 if (!ras) {
1016 if (verbose) coutE(InputArguments) << "RooAbsCollection::setStringValue(" << GetName() << ") ERROR object '" << name << "' is not of type RooStringVar" << endl ;
1017 return kTRUE ;
1018 }
1019 ras->setVal(newVal);
1020
1021 return false;
1022}
1023
1024////////////////////////////////////////////////////////////////////////////////
1025/// Return comma separated list of contained object names as STL string
1027{
1028 string retVal ;
1029 for (auto arg : _list) {
1030 retVal += arg->GetName();
1031 retVal += ",";
1032 }
1033
1034 retVal.erase(retVal.end()-1);
1035
1036 return retVal;
1037}
1038
1039
1040
1041////////////////////////////////////////////////////////////////////////////////
1042/// Return collection name
1043
1044void RooAbsCollection::printName(ostream& os) const
1045{
1046 os << GetName() ;
1047}
1048
1049
1050
1051////////////////////////////////////////////////////////////////////////////////
1052/// Return collection title
1053
1054void RooAbsCollection::printTitle(ostream& os) const
1055{
1056 os << GetTitle() ;
1057}
1058
1059
1060
1061////////////////////////////////////////////////////////////////////////////////
1062/// Return collection class name
1063
1065{
1066 os << IsA()->GetName() ;
1067}
1068
1069
1070
1071////////////////////////////////////////////////////////////////////////////////
1072/// Define default RooPrinable print options for given Print() flag string
1073/// For inline printing only show value of objects, for default print show
1074/// name,class name value and extras of each object. In verbose mode
1075/// also add object adress, argument and title
1076
1078{
1079 if (opt && TString(opt)=="I") {
1080 return kValue ;
1081 }
1082 if (opt && TString(opt).Contains("v")) {
1084 }
1085 return kName|kClassName|kValue ;
1086}
1087
1088
1089
1090
1091
1092////////////////////////////////////////////////////////////////////////////////
1093/// Print value of collection, i.e. a comma separated list of contained
1094/// object names
1095
1096void RooAbsCollection::printValue(ostream& os) const
1097{
1098 Bool_t first2(kTRUE) ;
1099 os << "(" ;
1100 for (auto arg : _list) {
1101 if (!first2) {
1102 os << "," ;
1103 } else {
1104 first2 = kFALSE ;
1105 }
1106 if (arg->IsA()->InheritsFrom(RooStringVar::Class())) {
1107 os << '\'' << ((RooStringVar *)arg)->getVal() << '\'';
1108 } else {
1109 os << arg->GetName();
1110 }
1111 }
1112 os << ")" ;
1113}
1114
1115
1116
1117////////////////////////////////////////////////////////////////////////////////
1118/// Implement multiline printing of collection, one line for each contained object showing
1119/// the requested content
1120
1121void RooAbsCollection::printMultiline(ostream&os, Int_t contents, Bool_t /*verbose*/, TString indent) const
1122{
1123 if (TString(GetName()).Length()>0 && (contents&kCollectionHeader)) {
1124 os << indent << ClassName() << "::" << GetName() << ":" << (_ownCont?" (Owning contents)":"") << endl;
1125 }
1126
1127 TString deeper(indent);
1128 deeper.Append(" ");
1129
1130 // Adjust the width of the name field to fit the largest name, if requested
1131 Int_t maxNameLen(1) ;
1132 Int_t nameFieldLengthSaved = RooPrintable::_nameLength ;
1133 if (nameFieldLengthSaved==0) {
1134 for (auto next : _list) {
1135 Int_t len = strlen(next->GetName()) ;
1136 if (len>maxNameLen) maxNameLen = len ;
1137 }
1138 RooPrintable::nameFieldLength(maxNameLen+1) ;
1139 }
1140
1141 unsigned int idx = 0;
1142 for (auto next : _list) {
1143 os << indent << std::setw(3) << ++idx << ") ";
1144 next->printStream(os,contents,kSingleLine,"");
1145 }
1146
1147 // Reset name field length, if modified
1148 RooPrintable::nameFieldLength(nameFieldLengthSaved) ;
1149}
1150
1151
1152
1153////////////////////////////////////////////////////////////////////////////////
1154/// Base contents dumper for debugging purposes
1155
1157{
1158 for (auto arg : _list) {
1159 cout << arg << " " << arg->IsA()->GetName() << "::" << arg->GetName() << " (" << arg->GetTitle() << ")" << endl ;
1160 }
1161}
1162
1163
1164
1165////////////////////////////////////////////////////////////////////////////////
1166/// Output content of collection as LaTex table. By default a table with two columns is created: the left
1167/// column contains the name of each variable, the right column the value.
1168///
1169/// The following optional named arguments can be used to modify the default behavior
1170/// <table>
1171/// <tr><th> Argument <th> Effect
1172/// <tr><td> `Columns(Int_t ncol)` <td> Fold table into multiple columns, i.e. ncol=3 will result in 3 x 2 = 6 total columns
1173/// <tr><td> `Sibling(const RooAbsCollection& other)` <td> Define sibling list.
1174/// The sibling list is assumed to have objects with the same
1175/// name in the same order. If this is not the case warnings will be printed. If a single
1176/// sibling list is specified, 3 columns will be output: the (common) name, the value of this
1177/// list and the value in the sibling list. Multiple sibling lists can be specified by
1178/// repeating the Sibling() command.
1179/// <tr><td> `Format(const char* str)` <td> Classic format string, provided for backward compatibility
1180/// <tr><td> `Format()` <td> Formatting arguments.
1181/// <table>
1182/// <tr><td> const char* what <td> Controls what is shown. "N" adds name, "E" adds error,
1183/// "A" shows asymmetric error, "U" shows unit, "H" hides the value
1184/// <tr><td> `FixedPrecision(int n)` <td> Controls precision, set fixed number of digits
1185/// <tr><td> `AutoPrecision(int n)` <td> Controls precision. Number of shown digits is calculated from error
1186/// and n specified additional digits (1 is sensible default)
1187/// <tr><td> `VerbatimName(Bool_t flag)` <td> Put variable name in a \\verb+ + clause.
1188/// </table>
1189/// <tr><td> `OutputFile(const char* fname)` <td> Send output to file with given name rather than standard output
1190///
1191/// </table>
1192///
1193/// Example use:
1194/// ```
1195/// list.printLatex(Columns(2), Format("NEU",AutoPrecision(1),VerbatimName()) );
1196/// ```
1197
1199 const RooCmdArg& arg3, const RooCmdArg& arg4,
1200 const RooCmdArg& arg5, const RooCmdArg& arg6,
1201 const RooCmdArg& arg7, const RooCmdArg& arg8) const
1202{
1203
1204
1205 // Define configuration for this method
1206 RooCmdConfig pc("RooAbsCollection::printLatex()") ;
1207 pc.defineInt("ncol","Columns",0,1) ;
1208 pc.defineString("outputFile","OutputFile",0,"") ;
1209 pc.defineString("format","Format",0,"NEYVU") ;
1210 pc.defineInt("sigDigit","Format",0,1) ;
1211 pc.defineObject("siblings","Sibling",0,0,kTRUE) ;
1212 pc.defineInt("dummy","FormatArgs",0,0) ;
1213 pc.defineMutex("Format","FormatArgs") ;
1214
1215 // Stuff all arguments in a list
1216 RooLinkedList cmdList;
1217 cmdList.Add(const_cast<RooCmdArg*>(&arg1)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg2)) ;
1218 cmdList.Add(const_cast<RooCmdArg*>(&arg3)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg4)) ;
1219 cmdList.Add(const_cast<RooCmdArg*>(&arg5)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg6)) ;
1220 cmdList.Add(const_cast<RooCmdArg*>(&arg7)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg8)) ;
1221
1222 // Process & check varargs
1223 pc.process(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
1224 if (!pc.ok(kTRUE)) {
1225 return ;
1226 }
1227
1228 const char* outFile = pc.getString("outputFile") ;
1229 if (outFile && strlen(outFile)) {
1230 std::ofstream ofs(outFile) ;
1231 if (pc.hasProcessed("FormatArgs")) {
1232 RooCmdArg* formatCmd = static_cast<RooCmdArg*>(cmdList.FindObject("FormatArgs")) ;
1233 formatCmd->addArg(RooFit::LatexTableStyle()) ;
1234 printLatex(ofs,pc.getInt("ncol"),0,0,pc.getObjectList("siblings"),formatCmd) ;
1235 } else {
1236 printLatex(ofs,pc.getInt("ncol"),pc.getString("format"),pc.getInt("sigDigit"),pc.getObjectList("siblings")) ;
1237 }
1238 } else {
1239 if (pc.hasProcessed("FormatArgs")) {
1240 RooCmdArg* formatCmd = static_cast<RooCmdArg*>(cmdList.FindObject("FormatArgs")) ;
1241 formatCmd->addArg(RooFit::LatexTableStyle()) ;
1242 printLatex(cout,pc.getInt("ncol"),0,0,pc.getObjectList("siblings"),formatCmd) ;
1243 } else {
1244 printLatex(cout,pc.getInt("ncol"),pc.getString("format"),pc.getInt("sigDigit"),pc.getObjectList("siblings")) ;
1245 }
1246 }
1247}
1248
1249
1250
1251
1252////////////////////////////////////////////////////////////////////////////////
1253/// Internal implementation function of printLatex
1254
1255void RooAbsCollection::printLatex(ostream& ofs, Int_t ncol, const char* option, Int_t sigDigit, const RooLinkedList& siblingList, const RooCmdArg* formatCmd) const
1256{
1257 // Count number of rows to print
1258 Int_t nrow = (Int_t) (getSize() / ncol + 0.99) ;
1259 Int_t i,j,k ;
1260
1261 // Sibling list do not need to print their name as it is supposed to be the same
1262 TString sibOption ;
1263 RooCmdArg sibFormatCmd ;
1264 if (option) {
1265 sibOption = option ;
1266 sibOption.ReplaceAll("N","") ;
1267 sibOption.ReplaceAll("n","") ;
1268 } else {
1269 sibFormatCmd = *formatCmd ;
1270 TString tmp = formatCmd->_s[0] ;
1271 tmp.ReplaceAll("N","") ;
1272 tmp.ReplaceAll("n","") ;
1273 static char buf[100] ;
1274 strlcpy(buf,tmp.Data(),100) ;
1275 sibFormatCmd._s[0] = buf ;
1276 }
1277
1278
1279 // Make list of lists ;
1280 RooLinkedList listList ;
1281 listList.Add((RooAbsArg*)this) ;
1282 RooFIter sIter = siblingList.fwdIterator() ;
1283 RooAbsCollection* col ;
1284 while((col=(RooAbsCollection*)sIter.next())) {
1285 listList.Add(col) ;
1286 }
1287
1288 RooLinkedList listListRRV ;
1289
1290 // Make list of RRV-only components
1291 RooFIter lIter = listList.fwdIterator() ;
1292 RooArgList* prevList = 0 ;
1293 while((col=(RooAbsCollection*)lIter.next())) {
1294 RooArgList* list = new RooArgList ;
1295 RooFIter iter = col->fwdIterator() ;
1296 RooAbsArg* arg ;
1297 while((arg=iter.next())) {
1298
1299 RooRealVar* rrv = dynamic_cast<RooRealVar*>(arg) ;
1300 if (rrv) {
1301 list->add(*rrv) ;
1302 } else {
1303 coutW(InputArguments) << "RooAbsCollection::printLatex: can only print RooRealVar in LateX, skipping non-RooRealVar object named "
1304 << arg->GetName() << endl ;
1305 }
1306 if (prevList && TString(rrv->GetName()).CompareTo(prevList->at(list->getSize()-1)->GetName())) {
1307 coutW(InputArguments) << "RooAbsCollection::printLatex: WARNING: naming and/or ordering of sibling list is different" << endl ;
1308 }
1309 }
1310 listListRRV.Add(list) ;
1311 if (prevList && list->getSize() != prevList->getSize()) {
1312 coutW(InputArguments) << "RooAbsCollection::printLatex: ERROR: sibling list(s) must have same length as self" << endl ;
1313 delete list ;
1314 listListRRV.Delete() ;
1315 return ;
1316 }
1317 prevList = list ;
1318 }
1319
1320 // Construct table header
1321 Int_t nlist = listListRRV.GetSize() ;
1322 TString subheader = "l" ;
1323 for (k=0 ; k<nlist ; k++) subheader += "c" ;
1324
1325 TString header = "\\begin{tabular}{" ;
1326 for (j=0 ; j<ncol ; j++) {
1327 if (j>0) header += "|" ;
1328 header += subheader ;
1329 }
1330 header += "}" ;
1331 ofs << header << endl ;
1332
1333
1334 // Print contents, delegating actual printing to RooRealVar::format()
1335 for (i=0 ; i<nrow ; i++) {
1336 for (j=0 ; j<ncol ; j++) {
1337 for (k=0 ; k<nlist ; k++) {
1338 RooRealVar* par = (RooRealVar*) ((RooArgList*)listListRRV.At(k))->at(i+j*nrow) ;
1339 if (par) {
1340 if (option) {
1341 TString* tmp = par->format(sigDigit,(k==0)?option:sibOption.Data()) ;
1342 ofs << *tmp ;
1343 delete tmp ;
1344 } else {
1345 TString* tmp = par->format((k==0)?*formatCmd:sibFormatCmd) ;
1346 ofs << *tmp ;
1347 delete tmp ;
1348 }
1349 }
1350 if (!(j==ncol-1 && k==nlist-1)) {
1351 ofs << " & " ;
1352 }
1353 }
1354 }
1355 ofs << "\\\\" << endl ;
1356 }
1357
1358 ofs << "\\end{tabular}" << endl ;
1359 listListRRV.Delete() ;
1360}
1361
1362
1363
1364
1365////////////////////////////////////////////////////////////////////////////////
1366/// Return true if all contained object report to have their
1367/// value inside the specified range
1368
1369Bool_t RooAbsCollection::allInRange(const char* rangeSpec) const
1370{
1371 if (!rangeSpec) return kTRUE ;
1372
1373 // Parse rangeSpec specification
1374 vector<string> cutVec ;
1375 if (rangeSpec && strlen(rangeSpec)>0) {
1376 if (strchr(rangeSpec,',')==0) {
1377 cutVec.push_back(rangeSpec) ;
1378 } else {
1379 const size_t bufSize = strlen(rangeSpec)+1;
1380 char* buf = new char[bufSize] ;
1381 strlcpy(buf,rangeSpec,bufSize) ;
1382 const char* oneRange = strtok(buf,",") ;
1383 while(oneRange) {
1384 cutVec.push_back(oneRange) ;
1385 oneRange = strtok(0,",") ;
1386 }
1387 delete[] buf ;
1388 }
1389 }
1390
1391 // Apply range based selection criteria
1392 Bool_t selectByRange = kTRUE ;
1393 for (auto arg : _list) {
1394 Bool_t selectThisArg = kFALSE ;
1395 UInt_t icut ;
1396 for (icut=0 ; icut<cutVec.size() ; icut++) {
1397 if (arg->inRange(cutVec[icut].c_str())) {
1398 selectThisArg = kTRUE ;
1399 break ;
1400 }
1401 }
1402 if (!selectThisArg) {
1403 selectByRange = kFALSE ;
1404 break ;
1405 }
1406 }
1407
1408 return selectByRange ;
1409}
1410
1411
1412
1413////////////////////////////////////////////////////////////////////////////////
1414
1416{
1417}
1418
1419
1420////////////////////////////////////////////////////////////////////////////////
1421
1423{
1424}
1425
1426////////////////////////////////////////////////////////////////////////////////
1427/// If one of the TObject we have a referenced to is deleted, remove the
1428/// reference.
1429
1431{
1432 if (obj && obj->InheritsFrom(RooAbsArg::Class())) remove(*(RooAbsArg*)obj,false,false);
1433}
1434
1435////////////////////////////////////////////////////////////////////////////////
1436/// Sort collection using std::sort and name comparison
1437
1439 //Windows seems to need an implementation where two different std::sorts are written
1440 //down in two different blocks. Switching between the two comparators using a ternary
1441 //operator does not compile on windows, although the signature is identical.
1442 if (reverse) {
1443 const auto cmpReverse = [](const RooAbsArg * l, const RooAbsArg * r) {
1444 return strcmp(l->GetName(), r->GetName()) > 0;
1445 };
1446
1447 std::sort(_list.begin(), _list.end(), cmpReverse);
1448 }
1449 else {
1450 const auto cmp = [](const RooAbsArg * l, const RooAbsArg * r) {
1451 return strcmp(l->GetName(), r->GetName()) < 0;
1452 };
1453
1454 std::sort(_list.begin(), _list.end(), cmp);
1455 }
1456}
1457
1458////////////////////////////////////////////////////////////////////////////////
1459/// Factory for legacy iterators.
1460
1461std::unique_ptr<RooAbsCollection::LegacyIterator_t> RooAbsCollection::makeLegacyIterator (bool forward) const {
1462 if (!forward)
1463 ccoutE(DataHandling) << "The legacy RooFit collection iterators don't support reverse iterations, any more. "
1464 << "Use begin() and end()" << endl;
1465 return std::make_unique<LegacyIterator_t>(_list);
1466}
1467
1468
1469////////////////////////////////////////////////////////////////////////////////
1470/// Insert an element into the owned collections.
1472 _list.push_back(item);
1473
1474 if (_allRRV && dynamic_cast<const RooRealVar*>(item)==0) {
1475 _allRRV= false;
1476 }
1477
1478 if (_nameToItemMap) {
1479 (*_nameToItemMap)[item->namePtr()] = item;
1480 }
1481}
1482
1483
1484////////////////////////////////////////////////////////////////////////////////
1485/// Install an internal hash map for fast finding of elements by name.
1487 if (!flag && _nameToItemMap){
1488 _nameToItemMap = nullptr;
1489 }
1490
1491 if (flag && !_nameToItemMap) {
1492 _nameToItemMap.reset(new std::unordered_map<const TNamed*, Storage_t::value_type>());
1493 for (const auto item : _list) {
1494 (*_nameToItemMap)[item->namePtr()] = item;
1495 }
1496 }
1497}
1498
1499
1500////////////////////////////////////////////////////////////////////////////////
1501/// Perform a search in a hash map.
1502/// This only happens if this collection is larger than _sizeThresholdForMapSearch.
1503/// This search is *not guaranteed* to find an existing
1504/// element because elements can be renamed while
1505/// being stored in the collection.
1508 useHashMapForFind(true);
1509 assert(_nameToItemMap);
1510 }
1511
1512 if (!_nameToItemMap) {
1513 return nullptr;
1514 }
1515
1516 auto item = _nameToItemMap->find(namePtr);
1517 if (item != _nameToItemMap->end()) {
1518 // Have an element. Check that it didn't get renamed.
1519 if (item->second->namePtr() == item->first) {
1520 return item->second;
1521 } else {
1522 // Item has been renamed / replaced.
1523 _nameToItemMap->erase(item);
1524 if (auto arg = findUsingNamePointer(_list, namePtr)) {
1525 (*_nameToItemMap)[arg->namePtr()] = arg;
1526 return arg;
1527 }
1528 }
1529 }
1530
1531 return nullptr;
1532}
ROOT::R::TRInterface & r
Definition Object.C:4
#define ccoutE(a)
#define cxcoutD(a)
#define coutW(a)
#define coutE(a)
int Int_t
Definition RtypesCore.h:45
char Text_t
Definition RtypesCore.h:62
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
Definition TString.cxx:1494
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
const TNamed * namePtr() const
Definition RooAbsArg.h:550
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:84
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValDirty=kTRUE)=0
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
const RefCountList_t & servers() const
List of all servers of this object.
Definition RooAbsArg.h:199
virtual void syncCache(const RooArgSet *nset=0)=0
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual bool setIndex(value_type index, bool printError=true)=0
Change category state by specifying the index code of the desired state.
virtual bool setLabel(const char *label, Bool_t printError=kTRUE)=0
Change category state by specifying a state name.
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
virtual value_type getCurrentIndex() const
Return index number of current state.
virtual const char * getCurrentLabel() const
Return label string of current state.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
Bool_t setCatLabel(const char *name, const char *newVal="", Bool_t verbose=kFALSE)
Set state name of a RooAbsCategoryLValue stored in set with given name to newVal.
virtual TObject * create(const char *newname) const =0
Bool_t setCatIndex(const char *name, Int_t newVal=0, Bool_t verbose=kFALSE)
Set index value of a RooAbsCategoryLValue stored in set with given name to newVal.
Int_t getCatIndex(const char *name, Int_t defVal=0, Bool_t verbose=kFALSE) const
Get index value of a RooAbsCategory stored in set with given name.
RooAbsCollection()
Default constructor.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, Bool_t oneSafe=kFALSE)
The assignment operator sets the value of any argument in our set that also appears in the other set.
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return kTRUE for success.
const char * getCatLabel(const char *name, const char *defVal="", Bool_t verbose=kFALSE) const
Get state name of a RooAbsCategory stored in set with given name.
Int_t getSize() const
RooAbsArg * tryFastFind(const TNamed *namePtr) const
Perform a search in a hash map.
void printLatex(const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg()) const
Output content of collection as LaTex table.
void sort(Bool_t reverse=false)
Sort collection using std::sort and name comparison.
Bool_t addServerClonesToList(const RooAbsArg &var)
Add clones of servers of given argument to end of list.
virtual void printName(std::ostream &os) const
Return collection name.
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
RooFIter fwdIterator() const
One-time forward iterator.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Bool_t setStringValue(const char *name, const char *newVal="", Bool_t verbose=kFALSE)
Set string value of a RooStringVar stored in set with given name to newVal.
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
virtual ~RooAbsCollection()
Destructor.
Bool_t setRealValue(const char *name, Double_t newVal=0, Bool_t verbose=kFALSE)
Set value of a RooAbsRealLValye stored in set with given name to newVal No error messages are printed...
RooAbsArg * first() const
void assignFast(const RooAbsCollection &other, Bool_t setValDirty=kTRUE)
Functional equivalent of operator=() but assumes this and other collection have same layout.
void reserve(Storage_t::size_type count)
RooAbsCollection * selectByName(const char *nameList, Bool_t verbose=kFALSE) const
Create a subset of the current collection, consisting only of those elements with names matching the ...
Bool_t overlaps(const RooAbsCollection &otherColl) const
Check if this and other collection have common entries.
Bool_t allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range.
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Implement multiline printing of collection, one line for each contained object showing the requested ...
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
std::unique_ptr< LegacyIterator_t > makeLegacyIterator(bool forward=true) const
Factory for legacy iterators.
std::size_t _sizeThresholdForMapSearch
void setAttribAll(const Text_t *name, Bool_t value=kTRUE)
Set given attribute in each element of the collection by calling each elements setAttribute() functio...
std::unique_ptr< std::unordered_map< const TNamed *, Storage_t::value_type > > _nameToItemMap
void dump() const
Base contents dumper for debugging purposes.
virtual void printTitle(std::ostream &os) const
Return collection title.
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
RooAbsCollection * selectByAttrib(const char *name, Bool_t value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
void useHashMapForFind(bool flag) const
Install an internal hash map for fast finding of elements by name.
const char * getStringValue(const char *name, const char *defVal="", Bool_t verbose=kFALSE) const
Get string value of a RooStringVar stored in set with given name.
const char * GetName() const
Returns name of object.
virtual void printClassName(std::ostream &os) const
Return collection class name.
std::string contentsString() const
Return comma separated list of contained object names as STL string.
void setName(const char *name)
RooAbsCollection & operator=(const RooAbsCollection &other)
The assignment operator sets the value of any argument in our set that also appears in the other set.
void safeDeleteList()
Examine client server dependencies in list and delete contents in safe order: any client is deleted b...
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
void insert(RooAbsArg *)
Insert an element into the owned collections.
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual void printValue(std::ostream &os) const
Print value of collection, i.e.
virtual Int_t defaultPrintContents(Option_t *opt) const
Define default RooPrinable print options for given Print() flag string For inline printing only show ...
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual void setVal(Double_t value)=0
Set the current value of the object. Needs to be overridden by implementations.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:61
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:21
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:70
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition RooCmdArg.h:27
void addArg(const RooCmdArg &arg)
Utility function to add nested RooCmdArg to payload of this RooCmdArg.
std::string _s[3]
Definition RooCmdArg.h:113
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Bool_t defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
void defineMutex(const char *argName1, const char *argName2)
Define arguments named argName1 and argName2 mutually exclusive.
Bool_t defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=0, Bool_t isArray=kFALSE)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
const char * getString(const char *name, const char *defaultValue="", Bool_t convEmptyToNull=kFALSE)
Return string property registered with name 'name'.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
const RooLinkedList & getObjectList(const char *name)
Return list of objects registered with name 'name'.
Bool_t defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", Bool_t appendMode=kFALSE)
Define Double_t property name 'name' mapped to Double_t in slot 'stringNum' in RooCmdArg with name ar...
Bool_t ok(Bool_t verbose) const
Return true of parsing was successful.
Bool_t process(const RooCmdArg &arg)
Process given RooCmdArg.
Bool_t hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooAbsArg * next()
Return next element or nullptr if at end.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Int_t GetSize() const
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
RooFIter fwdIterator() const
Create a one-time-use forward iterator for this list.
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
virtual void Add(TObject *arg)
static const TNamed * known(const char *stringPtr)
If the name is already known, return its TNamed pointer. Otherwise return 0 (don't register the name)...
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
static Int_t _nameLength
static void nameFieldLength(Int_t newLen)
Set length of field reserved from printing name of RooAbsArgs in multi-line collection printing to gi...
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
void copyCacheFast(const RooRealVar &other, Bool_t setValDirty=kTRUE)
Definition RooRealVar.h:133
std::size_t size() const
Number of contained objects (neglecting the ref count).
RooStringVar is a RooAbsArg implementing string values.
void setVal(const char *newVal)
const char * getVal() const
static void create(const TObject *obj)
Register creation of object 'obj'.
Definition RooTrace.cxx:68
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:130
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:403
Regular expression class.
Definition TRegexp.h:31
Basic string class.
Definition TString.h:136
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:438
const char * Data() const
Definition TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:692
TString & Append(const char *cs)
Definition TString.h:564
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:639
RooCmdArg LatexTableStyle(Bool_t flag=kTRUE)
auto * l
Definition textangle.C:4
static void output(int code)
Definition gifencode.c:226