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