Logo ROOT  
Reference Guide
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
34 class Chunk;
35 class Pool;
36}
37
38class RooLinkedList : public TObject {
39public:
40 // Constructor
41 RooLinkedList(Int_t htsize=0) ;
42
43 // Copy constructor
44 RooLinkedList(const RooLinkedList& other) ;
45
46 virtual TObject* Clone(const char* =0) const {
47 return new RooLinkedList(*this) ;
48 }
49
50 // Assignment operator
52
54 // Return size of hash table
55 return _htableName ? _htableName->size() : 0 ;
56 }
57
59
60 // Destructor
61 virtual ~RooLinkedList() ;
62
63 Int_t GetSize() const { return _size ; }
64 std::size_t size() const { return _size ; }
65 bool empty() const { return _size == 0 ; }
66
67 virtual void Add(TObject* arg) { Add(arg,1) ; }
68 virtual Bool_t Remove(TObject* arg) ;
69 TObject* At(int index) const ;
70 Bool_t Replace(const TObject* oldArg, const TObject* newArg) ;
73 RooFIter fwdIterator() const ;
78
79 void Clear(Option_t *o=0) ;
80 void Delete(Option_t *o=0) ;
81 TObject* find(const char* name) const ;
82 RooAbsArg* findArg(const RooAbsArg*) const ;
83 TObject* FindObject(const char* name) const ;
84 TObject* FindObject(const TObject* obj) const ;
85 Int_t IndexOf(const char* name) const ;
86 Int_t IndexOf(const TObject* arg) const ;
87 TObject* First() const {
88 return _first?_first->_arg:0 ;
89 }
90
91 virtual void RecursiveRemove(TObject *obj);
92
93 void Print(const char* opt) const ;
94 void Sort(Bool_t ascend=kTRUE) ;
95
96 // const char* GetName() const { return "" ; /*_name.Data() ; */ }
97 // void SetName(const char* /*name*/) { /*_name = name ; */ }
98 const char* GetName() const { return _name.Data() ; }
99 void SetName(const char* name) { _name = name ; }
100
101 void useNptr(Bool_t flag) { _useNptr = flag ; }
102 // needed for using it in THashList/THashTable
103
104 ULong_t Hash() const { return _name.Hash(); }
105 //ULong_t Hash() const { return TString().Hash(); }
106
107protected:
108
111
112
115
116 virtual void Add(TObject* arg, Int_t refCount) ;
117
118 RooLinkedListElem* findLink(const TObject* arg) const ;
119
120 Int_t _hashThresh ; // Size threshold for hashing
121 Int_t _size ; // Current size of list
122 RooLinkedListElem* _first ; //! Link to first element of list
123 RooLinkedListElem* _last ; //! Link to last element of list
124
125 using HashTableByName = std::unordered_map<std::string,TObject const*>;
126 using HashTableByLink = std::unordered_map<TObject const*,TObject const*>;
127 std::unique_ptr<HashTableByName> _htableName; //! Hash table by name
128 std::unique_ptr<HashTableByLink> _htableLink; //! Hash table by link pointer
129
132
133private:
134 template <bool ascending>
136 const unsigned sz, RooLinkedListElem** tail = 0);
137 /// memory pool for quick allocation of RooLinkedListElems
139 /// shared memory pool for allocation of RooLinkedListElems
140 static Pool* _pool; //!
141
142 std::vector<RooLinkedListElem *> _at; //! index list for quick index through ::At
143
144 ClassDef(RooLinkedList,3) // Doubly linked list for storage of RooAbsArg objects
145};
146
147#endif
int Int_t
Definition: RtypesCore.h:45
unsigned long ULong_t
Definition: RtypesCore.h:55
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassDef(name, id)
Definition: Rtypes.h:325
char name[80]
Definition: TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
Implementation of the GenericRooFIter interface for the RooLinkedList.
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooLinkedListElem is an link element for the RooLinkedList class.
a chunk of memory in a pool for quick allocation of RooLinkedListElems
Implementation of the actual iterator on RooLinkedLists.
A wrapper around TIterator derivatives.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:38
Int_t GetSize() const
Definition: RooLinkedList.h:63
void SetName(const char *name)
Definition: RooLinkedList.h:99
RooLinkedListIterImpl rend() const
TObject * At(int index) const
Return object stored in sequential position given by index.
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
static Pool * _pool
shared memory pool for allocation of RooLinkedListElems
TString _name
Hash table by link pointer.
RooLinkedListIterImpl end() const
RooLinkedListImplDetails::Pool Pool
memory pool for quick allocation of RooLinkedListElems
bool empty() const
Definition: RooLinkedList.h:65
std::vector< RooLinkedListElem * > _at
RooLinkedListIter iterator(Bool_t forward=kTRUE) const
Create an iterator for this list.
const char * GetName() const
Returns name of object.
Definition: RooLinkedList.h:98
std::unique_ptr< HashTableByName > _htableName
std::unordered_map< std::string, TObject const * > HashTableByName
Link to last element of list.
RooLinkedListElem * createElement(TObject *obj, RooLinkedListElem *elem=0)
cout << "RooLinkedList::createElem(" << this << ") obj = " << obj << " elem = " << elem << endl ;
RooLinkedList(Int_t htsize=0)
std::unique_ptr< HashTableByLink > _htableLink
Hash table by name.
void Sort(Bool_t ascend=kTRUE)
Int_t getHashTableSize() const
Definition: RooLinkedList.h:53
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 Print(const char *opt) const
Print contents of list, defers to Print() function of contained objects.
RooLinkedListIterImpl rbegin() const
std::size_t size() const
Definition: RooLinkedList.h:64
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
virtual TObject * Clone(const char *=0) const
Make a clone of an object using the Streamer facility.
Definition: RooLinkedList.h:46
ULong_t Hash() const
Return hash value for this object.
static RooLinkedListElem * mergesort_impl(RooLinkedListElem *l1, const unsigned sz, RooLinkedListElem **tail=0)
length 0, 1 lists are sorted
RooAbsArg * findArg(const RooAbsArg *) const
Return pointer to object with given name in collection.
void Delete(Option_t *o=0)
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 RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:67
void useNptr(Bool_t flag)
RooLinkedListIterImpl begin() const
RooLinkedListElem * _last
Link to first element of list.
void setHashTableSize(Int_t size)
Change the threshold for hash-table use to given size.
void Clear(Option_t *o=0)
Remove all elements from collection.
Bool_t Replace(const TObject *oldArg, const TObject *newArg)
Replace object 'oldArg' in collection with new object 'newArg'.
RooLinkedListElem * _first
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
Int_t IndexOf(const char *name) const
Return position of given object in list.
virtual ~RooLinkedList()
Destructor.
TObject * First() const
Definition: RooLinkedList.h:87
Iterator abstract base class.
Definition: TIterator.h:30
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:136
const char * Data() const
Definition: TString.h:369
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:662
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN
Definition: NeuralNet.icc:546