Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooLinkedList.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooLinkedList.h,v 1.15 2007/05/11 09:11:30 verkerke Exp $
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#ifndef ROO_LINKED_LIST
17#define ROO_LINKED_LIST
18
19#include "TObject.h"
20#include "RooLinkedListElem.h"
21#include "TString.h"
22
23#include <vector>
24#include <memory>
25#include <unordered_map>
26
29class RooFIter;
30class TIterator ;
31class RooAbsArg ;
32
33/// \cond ROOFIT_INTERNAL
34
35template<class T>
37
39 class Chunk;
40 class Pool;
41}
42
43/// \endcond
44
45class RooLinkedList : public TObject {
46public:
47 // Constructor
49
50 // Copy constructor
52
53 TObject* Clone(const char* =nullptr) const override {
54 return new RooLinkedList(*this) ;
55 }
56
57 // Assignment operator
59
61 // Return size of hash table
62 return _htableName ? _htableName->size() : 0 ;
63 }
64
66
67 // Destructor
68 ~RooLinkedList() override ;
69
70 Int_t GetSize() const { return _size ; }
71 std::size_t size() const { return _size ; }
72 bool empty() const { return _size == 0 ; }
73
74 virtual void Add(TObject* arg) { Add(arg,1) ; }
75 virtual bool Remove(TObject* arg) ;
76 TObject* At(int index) const ;
77 bool Replace(const TObject* oldArg, const TObject* newArg) ;
78 TIterator* MakeIterator(bool forward = true) const ;
79 RooLinkedListIter iterator(bool forward = true) const ;
80 RooFIter fwdIterator() const ;
85
86 void Clear(Option_t *o=nullptr) override ;
87 void Delete(Option_t *o=nullptr) override ;
88 TObject* find(const char* name) const ;
89 RooAbsArg* findArg(const RooAbsArg*) const ;
90 TObject* FindObject(const char* name) const override ;
91 TObject* FindObject(const TObject* obj) const override ;
92 Int_t IndexOf(const char* name) const ;
93 Int_t IndexOf(const TObject* arg) const ;
94 TObject* First() const {
95 return _first ? _first->_arg : nullptr ;
96 }
97
98 void RecursiveRemove(TObject *obj) override;
99
100 void Print(const char* opt) const override ;
101 void Sort(bool ascend=true) ;
102
103 // const char* GetName() const { return "" ; /*_name.Data() ; */ }
104 // void SetName(const char* /*name*/) { /*_name = name ; */ }
105 const char* GetName() const override { return _name.Data() ; }
106 void SetName(const char* name) { _name = name ; }
107
108 void useNptr(bool flag) { _useNptr = flag ; }
109 // needed for using it in THashList/THashTable
110
111 ULong_t Hash() const override { return _name.Hash(); }
112
113protected:
114
117
118 /// \cond ROOFIT_INTERNAL
119 template<class T> friend class RooSTLRefCountList;
120 /// \endcond
123
124 virtual void Add(TObject* arg, Int_t refCount) ;
125
126 RooLinkedListElem* findLink(const TObject* arg) const ;
127
128 Int_t _hashThresh ; ///< Size threshold for hashing
129 Int_t _size ; ///< Current size of list
130 RooLinkedListElem* _first ; ///<! Link to first element of list
131 RooLinkedListElem* _last ; ///<! Link to last element of list
132
133 using HashTableByName = std::unordered_map<std::string,TObject const*>;
134 using HashTableByLink = std::unordered_map<TObject const*,TObject const*>;
135 std::unique_ptr<HashTableByName> _htableName; ///<! Hash table by name
136 std::unique_ptr<HashTableByLink> _htableLink; ///<! Hash table by link pointer
137
139 bool _useNptr ; ///<!
140
141private:
142 template <bool ascending>
144 const unsigned sz, RooLinkedListElem** tail = nullptr);
145 /// memory pool for quick allocation of RooLinkedListElems
146 typedef RooLinkedListImplDetails::Pool Pool;
147 /// shared memory pool for allocation of RooLinkedListElems
148 static Pool* _pool; //!
149
150 std::vector<RooLinkedListElem *> _at; ///<! index list for quick index through ::At
151
152 ClassDefOverride(RooLinkedList,3) // Doubly linked list for storage of RooAbsArg objects
153};
154
155#endif
int Int_t
Definition RtypesCore.h:45
unsigned long ULong_t
Definition RtypesCore.h:55
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Definition TGX11.cxx:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Implementation of the GenericRooFIter interface for the RooLinkedList.
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
Link element for the RooLinkedList class.
TObject * _arg
Link to contents.
Implementation of the actual iterator on RooLinkedLists.
A wrapper around TIterator derivatives.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
Int_t GetSize() const
void SetName(const char *name)
RooLinkedListIterImpl rend() const
TObject * At(int index) const
Return object stored in sequential position given by index.
RooLinkedListIter iterator(bool forward=true) const
Create an iterator for this list.
static Pool * _pool
shared memory pool for allocation of RooLinkedListElems
~RooLinkedList() override
Destructor.
RooLinkedListIterImpl end() const
RooLinkedListImplDetails::Pool Pool
memory pool for quick allocation of RooLinkedListElems
bool empty() const
std::vector< RooLinkedListElem * > _at
! index list for quick index through At
const char * GetName() const override
Returns name of object.
std::unique_ptr< HashTableByName > _htableName
! Hash table by name
void RecursiveRemove(TObject *obj) override
If one of the TObject we have a referenced to is deleted, remove the reference.
std::unordered_map< std::string, TObject const * > HashTableByName
bool Replace(const TObject *oldArg, const TObject *newArg)
Replace object 'oldArg' in collection with new object 'newArg'.
RooLinkedList(Int_t htsize=0)
void Print(const char *opt) const override
Print contents of list, defers to Print() function of contained objects.
std::unique_ptr< HashTableByLink > _htableLink
! Hash table by link pointer
Int_t getHashTableSize() const
RooFIter fwdIterator() const
Create a one-time-use forward iterator for this list.
void deleteElement(RooLinkedListElem *)
RooLinkedListElem * findLink(const TObject *arg) const
Find the element link containing the given object.
std::unordered_map< TObject const *, TObject const * > HashTableByLink
void useNptr(bool flag)
RooLinkedListIterImpl rbegin() const
std::size_t size() const
Int_t _hashThresh
Size threshold for hashing.
RooLinkedListElem * createElement(TObject *obj, RooLinkedListElem *elem=nullptr)
std::cout << "RooLinkedList::createElem(" << this << ") obj = " << obj << " elem = " << elem << std::...
RooAbsArg * findArg(const RooAbsArg *) const
Return pointer to object with given name in collection.
void Delete(Option_t *o=nullptr) override
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
TObject * find(const char *name) const
Return pointer to object with given name in collection.
RooLinkedList & operator=(const RooLinkedList &other)
Assignment operator, copy contents from 'other'.
virtual void Add(TObject *arg)
Int_t _size
Current size of list.
RooLinkedListIterImpl begin() const
RooLinkedListElem * _last
! Link to last element of list
void setHashTableSize(Int_t size)
Change the threshold for hash-table use to given size.
TObject * FindObject(const char *name) const override
Return pointer to object with given name.
RooLinkedListElem * _first
! Link to first element of list
TIterator * MakeIterator(bool forward=true) const
Create a TIterator for this list.
void Clear(Option_t *o=nullptr) override
Remove all elements from collection.
static RooLinkedListElem * mergesort_impl(RooLinkedListElem *l1, const unsigned sz, RooLinkedListElem **tail=nullptr)
length 0, 1 lists are sorted
ULong_t Hash() const override
Return hash value for this object.
void Sort(bool ascend=true)
TObject * Clone(const char *=nullptr) const override
Make a clone of an object using the Streamer facility.
Int_t IndexOf(const char *name) const
Return position of given object in list.
virtual bool Remove(TObject *arg)
Remove object from collection.
TObject * First() const
Iterator abstract base class.
Definition TIterator.h:30
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition TString.cxx:677