KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVUniqueNameList Class Reference

Detailed Description

Optimised list in which named objects can only be placed once.

Created by KVClassFactory on Thu Dec 3 15:49:33 2009 Author: John Frankland,,,

Use this list when you need to check as each object is added that it is not already in the list (assuming that objects are the same if they have the same name), in order to avoid the same object being added several times.

Using a standard TList or KVList, implementing such a check can become very time-consuming as the list becomes longer, because for each new object we add we have to perform a sequential scan of all objects in the list and check the name of each one. However, using a KVHashList based on object names, the number of objects to check is kept small, even as the list becomes very long, thanks to automatic rehashing of the list.

By default, if an object with the same name is already in the list, the 'new' object is not added (no warning, no error).

If option 'replace' is used, then adding an object with the same name as an existing object will replace the previous object with the new one.

In addition, if the list owns its objects and 'replace' is used, the previous object will be deleted as well as being replaced.

After calling Add(TObject*), you can call method ObjectAdded() to know if the object was effectively added to the list or not.

EXAMPLES

TNamed* a = new TNamed("A1", "an object");
TNamed* b = new TNamed("B1", "another object");
TNamed* c = a;
TNamed* d = new TNamed("A1", "an object with the same name as another");
=== Example 0 - normal TList
TList aList;
aList.Add(a);
aList.Add(b);
aList.Add(c);
aList.Add(d);
aList.ls();
OBJ: TList TList Doubly linked list : 0
OBJ: TNamed A1 an object : 0 at: 0x6c21770
OBJ: TNamed B1 another object : 0 at: 0x6c0fc40
OBJ: TNamed A1 an object : 0 at: 0x6c21770
OBJ: TNamed A1 an object with the same name as another : 0 at: 0x6c0acf0
=== Example 1 - unique name list, no replace
UNlist1.Add(a);
UNlist1.Add(b);
UNlist1.Add(c);
UNlist1.Add(d);
UNlist1.ls();
OBJ: KVUniqueNameList KVUniqueNameList Optimised list in which objects can only be placed once : 0
OBJ: TNamed A1 an object : 0 at: 0x6c21770
OBJ: TNamed B1 another object : 0 at: 0x6c0fc40//
=== Example 2 - unique name list, with replace
KVUniqueNameList UNlist2(kTRUE);
UNlist2.Add(a);
UNlist2.Add(b);
UNlist2.Add(c);
UNlist2.Add(d);
UNlist2.ls();
OBJ: KVUniqueNameList KVUniqueNameList Optimised list in which objects can only be placed once : 0
OBJ: TNamed B1 another object : 0 at: 0x6c0fc40
OBJ: TNamed A1 an object with the same name as another : 0 at: 0x6c0acf0
=== Example 3 - unique name list which owns its objects, with replace
KVUniqueNameList UNlist3(kTRUE);
UNlist3.Add(a);
UNlist3.Add(b);
UNlist3.Add(d);
UNlist3.ls();
OBJ: KVUniqueNameList KVUniqueNameList Optimised list in which objects can only be placed once : 0
OBJ: TNamed B1 another object : 0 at: 0x6c0fc40
OBJ: TNamed A1 an object with the same name as another : 0 at: 0x6c0acf0
a->ls();
Break *** segmentation violation (1st object "A1" has been deleted)
#define d(i)
#define c(i)
void Break(const char *location, const char *msgfmt,...)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
char name[80]
Optimised list in which named objects can only be placed once.
virtual void Add(TObject *obj)
void ls(Option_t *option="") const override
void Add(TObject *obj) override
TMatrixT< Double_t > as(SEXP)
TArc a

N.B.: in the last example we do NOT do UNlist3.Add(c) which would have deleted the object pointed to by both a and c, and then tried to add this deleted object back in to the list

Definition at line 101 of file KVUniqueNameList.h.

#include <KVUniqueNameList.h>

Inheritance diagram for KVUniqueNameList:

Public Member Functions

 KVUniqueNameList (Bool_t R=kFALSE)
 Default constructor.
 
virtual ~KVUniqueNameList ()
 Destructor.
 
virtual void Add (TObject *obj)
 
virtual void AddAfter (const TObject *after, TObject *obj)
 
virtual void AddAt (TObject *obj, Int_t idx)
 
virtual void AddBefore (const TObject *before, TObject *obj)
 
virtual void AddFirst (TObject *obj)
 
virtual void AddLast (TObject *obj)
 
Bool_t ObjectAdded () const
 
void ReplaceObjects (Bool_t yes=kTRUE)
 
- Public Member Functions inherited from KVHashList
 KVHashList (Int_t capacity=TCollection::kInitHashTableCapacity, Int_t rehash=2)
 
virtual ~KVHashList ()
 Destructor.
 
Float_t AverageCollisions () const
 
template<typename T >
Bool_t ContainsObjectWithName (const T &o)
 
const TListGetListForObject (const char *name) const
 
const TListGetListForObject (const TObject *obj) const
 
void Rehash (Int_t newCapacity=0)
 
void Sort (Bool_t order=kSortAscending)
 
- Public Member Functions inherited from KVSeqCollection
 KVSeqCollection ()
 Default constructor.
 
 KVSeqCollection (const Char_t *collection_classname)
 
 KVSeqCollection (const KVSeqCollection &)
 
virtual ~KVSeqCollection ()
 
virtual TObjectAfter (const TObject *obj) const
 
virtual TObjectAt (Int_t idx) const
 
virtual TObjectBefore (const TObject *obj) const
 
virtual void Clear (Option_t *option="")
 
const Char_tCollectionClassName () const
 
virtual void Copy (TObject &obj) const
 
virtual void Delete (Option_t *option="")
 
virtual void Execute (const char *method, const char *params, Int_t *error=0)
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=0)
 
virtual TObjectFindObject (const char *name) const
 
virtual TObjectFindObject (const TObject *obj) const
 
virtual TObjectFindObjectAny (const Char_t *att, const Char_t *keys, Bool_t contains_all=kFALSE, Bool_t case_sensitive=kTRUE) const
 
TObjectFindObjectByClass (const Char_t *) const
 Return (first) object in embedded list with given class.
 
TObjectFindObjectByClass (const TClass *) const
 Return (first) object in embedded list with given class.
 
virtual TObjectFindObjectByLabel (const Char_t *) const
 
virtual TObjectFindObjectByName (const Char_t *name) const
 
virtual TObjectFindObjectByNumber (UInt_t num) const
 
virtual TObjectFindObjectByTitle (const Char_t *) const
 Will return object with given title (value of TObject::GetTitle() method).
 
virtual TObjectFindObjectByType (const Char_t *) const
 
virtual TObjectFindObjectWithMethod (const Char_t *retvalue, const Char_t *method) const
 
virtual TObjectFindObjectWithNameAndType (const Char_t *name, const Char_t *type) const
 
virtual TObjectFirst () const
 
template<typename T >
Tget_object (const TString &name) const
 
TSeqCollectionGetCollection () const
 
virtual TObject ** GetObjectRef (const TObject *obj) const
 Return reference to object.
 
virtual Int_t GetSize () const
 
KVSeqCollectionGetSubListWithClass (const Char_t *class_name) const
 
KVSeqCollectionGetSubListWithClass (const TClass *_class) const
 
KVSeqCollectionGetSubListWithLabel (const Char_t *retvalue) const
 
KVSeqCollectionGetSubListWithMethod (const Char_t *retvalue, const Char_t *method) const
 
KVSeqCollectionGetSubListWithName (const Char_t *retvalue) const
 
KVSeqCollectionGetSubListWithType (const Char_t *retvalue) const
 
virtual Bool_t IsCleanup () const
 
virtual Bool_t IsSendingModifiedSignals () const
 
virtual Bool_t IsSortable () const
 
virtual Bool_t IsSorted () const
 
virtual TObjectLast () const
 
virtual TIteratorMakeIterator (Bool_t dir=kIterForward) const
 Make and return iterator for the list.
 
virtual void Modified ()
 
KVSeqCollectionoperator= (const KVSeqCollection &)
 
virtual void RecursiveRemove (TObject *obj)
 
virtual TObjectRemove (TObject *obj)
 Remove object from list.
 
virtual void SendModifiedSignals (Bool_t yes=kTRUE)
 
virtual void SetCleanup (Bool_t enable=kTRUE)
 
virtual void SetOwner (Bool_t enable=kTRUE)
 
- Public Member Functions inherited from TSeqCollection
virtual ~TSeqCollection ()
 
void Add (TObject *obj) override
 
virtual Int_t GetLast () const
 
virtual Int_t IndexOf (const TObject *obj) const
 
TClassIsA () const override
 
Int_t LastIndex () const
 
Long64_t Merge (TCollection *list)
 
virtual void RemoveAfter (TObject *after)
 
virtual TObjectRemoveAt (Int_t idx)
 
virtual void RemoveBefore (TObject *before)
 
virtual void RemoveFirst ()
 
virtual void RemoveLast ()
 
void Streamer (TBuffer &) override
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
void UnSort ()
 
- Public Member Functions inherited from TCollection
virtual ~TCollection ()
 
virtual void AddAll (const TCollection *col)
 
void AddVector (TObject *obj1,...)
 
Bool_t AssertClass (TClass *cl) const
 
TIter begin () const
 
void Browse (TBrowser *b) override
 
Int_t Capacity () const
 
TObjectClone (const char *newname="") const override
 
Int_t Compare (const TObject *obj) const override
 
Bool_t Contains (const char *name) const
 
Bool_t Contains (const TObject *obj) const
 
void Draw (Option_t *option="") override
 
void Dump () const override
 
TIter end () const
 
TObjectFindObject (const char *name) const override
 
TObjectFindObject (const TObject *obj) const override
 
virtual Int_t GetEntries () const
 
const char * GetName () const override
 
virtual Int_t GrowBy (Int_t delta) const
 
ULong_t Hash () const override
 
Bool_t IsArgNull (const char *where, const TObject *obj) const
 
virtual Bool_t IsEmpty () const
 
Bool_t IsFolder () const override
 
Bool_t IsOwner () const
 
Bool_t IsSortable () const override
 
R__ALWAYS_INLINE Bool_t IsUsingRWLock () const
 
void ls (Option_t *option="") const override
 
virtual TIteratorMakeReverseIterator () const
 
Bool_t Notify () override
 
TObjectoperator() (const char *name) const
 
void Paint (Option_t *option="") override
 
virtual void Print (Option_t *option, const char *wildcard, Int_t recurse=1) const
 
virtual void Print (Option_t *option, Int_t recurse) const
 
virtual void Print (Option_t *option, TPRegexp &regexp, Int_t recurse=1) const
 
void Print (Option_t *option="") const override
 
void RecursiveRemove (TObject *obj) override
 
void RemoveAll ()
 
virtual void RemoveAll (TCollection *col)
 
void SetCurrentCollection ()
 
void SetName (const char *name)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual bool UseRWLock (Bool_t enable=true)
 
Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
 
Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
 
- Public Member Functions inherited from TObject
 TObject ()
 
 TObject (const TObject &object)
 
virtual ~TObject ()
 
void AbstractMethod (const char *method) const
 
virtual void AppendPad (Option_t *option="")
 
ULong_t CheckedHash ()
 
virtual const char * ClassName () const
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 
virtual void DrawClass () const
 
virtual TObjectDrawClone (Option_t *option="") const
 
virtual void Error (const char *method, const char *msgfmt,...) const
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 
virtual Option_tGetDrawOption () const
 
virtual const char * GetIconName () const
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 
virtual Option_tGetOption () const
 
virtual const char * GetTitle () const
 
virtual UInt_t GetUniqueID () const
 
virtual Bool_t HandleTimer (TTimer *timer)
 
Bool_t HasInconsistentHash () const
 
virtual void Info (const char *method, const char *msgfmt,...) const
 
virtual Bool_t InheritsFrom (const char *classname) const
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 
virtual void Inspect () const
 
void InvertBit (UInt_t f)
 
Bool_t IsDestructed () const
 
virtual Bool_t IsEqual (const TObject *obj) const
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
void MayNotUse (const char *method) const
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 
void operator delete (void *ptr)
 
void operator delete (void *ptr, void *vp)
 
void operator delete[] (void *ptr)
 
void operator delete[] (void *ptr, void *vp)
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 
virtual void Pop ()
 
virtual Int_t Read (const char *name)
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 
void SetBit (UInt_t f)
 
void SetBit (UInt_t f, Bool_t set)
 
virtual void SetDrawOption (Option_t *option="")
 
virtual void SetUniqueID (UInt_t uid)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 

Private Member Functions

Bool_t checkObjInList (TObject *obj)
 

Private Attributes

Bool_t fLastCheck
 return value of last call to checkobj
 
Bool_t fReplace
 if kTRUE, objects with same name are replaced
 

Additional Inherited Members

- Public Types inherited from TObject
enum  EDeprecatedStatusBits
 
enum  EStatusBits
 
- Static Public Member Functions inherited from KVSeqCollection
static KVSeqCollectionMakeListFromFile (TFile *file)
 
static KVSeqCollectionMakeListFromFileWithClass (TFile *file, const Char_t *class_name)
 
static KVSeqCollectionMakeListFromFileWithClass (TFile *file, const TClass *_class)
 
static KVSeqCollectionMakeListFromFileWithMethod (TFile *file, const Char_t *retvalue, const Char_t *method)
 
static void RehashCleanupList ()
 
- Static Public Member Functions inherited from TSeqCollection
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Int_t ObjCompare (TObject *a, TObject *b)
 
static void QSort (TObject **a, Int_t first, Int_t last)
 
static void QSort (TObject **a, Int_t nBs, TObject ***b, Int_t first, Int_t last)
 
static void QSort (TObject **a, TObject **b, Int_t first, Int_t last)
 
- Static Public Member Functions inherited from TCollection
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static void EmptyGarbageCollection ()
 
static void GarbageCollect (TObject *obj)
 
static TCollectionGetCurrentCollection ()
 
static void StartGarbageCollection ()
 
- Static Public Member Functions inherited from TObject
static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 
static Longptr_t GetDtorOnly ()
 
static Bool_t GetObjectStat ()
 
static void SetDtorOnly (void *obj)
 
static void SetObjectStat (Bool_t stat)
 
- Public Attributes inherited from TCollection
 kInitCapacity
 
 kInitHashTableCapacity
 
- Public Attributes inherited from TObject
 kBitMask
 
 kCanDelete
 
 kCannotPick
 
 kHasUUID
 
 kInconsistent
 
 kInvalidObject
 
 kIsOnHeap
 
 kIsReferenced
 
 kMustCleanup
 
 kNoContextMenu
 
 kNotDeleted
 
 kObjInCanvas
 
 kOverwrite
 
 kSingleKey
 
 kWriteDelete
 
 kZombie
 
- Protected Types inherited from TCollection
enum  EStatusBits
 
- Protected Member Functions inherited from TSeqCollection
 TSeqCollection ()
 
- Protected Member Functions inherited from TCollection
 TCollection ()
 
virtual const char * GetCollectionEntryName (TObject *entry) const
 
virtual void PrintCollectionEntry (TObject *entry, Option_t *option, Int_t recurse) const
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 
void MakeZombie ()
 
- Protected Attributes inherited from TSeqCollection
Bool_t fSorted
 
- Protected Attributes inherited from TCollection
TString fName
 
Int_t fSize
 
 kIsOwner
 
 kUseRWLock
 
- Protected Attributes inherited from TObject
 kOnlyPrepStep
 

Constructor & Destructor Documentation

◆ KVUniqueNameList()

KVUniqueNameList::KVUniqueNameList ( Bool_t  R = kFALSE)

Default constructor.

Definition at line 14 of file KVUniqueNameList.cpp.

◆ ~KVUniqueNameList()

KVUniqueNameList::~KVUniqueNameList ( )
virtual

Destructor.

Definition at line 25 of file KVUniqueNameList.cpp.

Member Function Documentation

◆ Add()

virtual void KVUniqueNameList::Add ( TObject obj)
inlinevirtual

Add an object to the list if it is not already in it (no object with same name in list)

Reimplemented from KVSeqCollection.

Reimplemented in KVPartitionList, and KVGVList.

Definition at line 145 of file KVUniqueNameList.h.

◆ AddAfter()

virtual void KVUniqueNameList::AddAfter ( const TObject after,
TObject obj 
)
inlinevirtual

Add an object to the list if it is not already in it (no object with same name in list)

Reimplemented from KVSeqCollection.

Reimplemented in KVPartitionList.

Definition at line 131 of file KVUniqueNameList.h.

◆ AddAt()

virtual void KVUniqueNameList::AddAt ( TObject obj,
Int_t  idx 
)
inlinevirtual

Add an object to the list if it is not already in it (no object with same name in list)

Reimplemented from KVSeqCollection.

Reimplemented in KVPartitionList.

Definition at line 124 of file KVUniqueNameList.h.

◆ AddBefore()

virtual void KVUniqueNameList::AddBefore ( const TObject before,
TObject obj 
)
inlinevirtual

Add an object to the list if it is not already in it (no object with same name in list)

Reimplemented from KVSeqCollection.

Reimplemented in KVPartitionList.

Definition at line 138 of file KVUniqueNameList.h.

◆ AddFirst()

virtual void KVUniqueNameList::AddFirst ( TObject obj)
inlinevirtual

Add an object to the list if it is not already in it (no object with same name in list)

Reimplemented from KVSeqCollection.

Reimplemented in KVPartitionList, and KVGVList.

Definition at line 110 of file KVUniqueNameList.h.

◆ AddLast()

virtual void KVUniqueNameList::AddLast ( TObject obj)
inlinevirtual

Add an object to the list if it is not already in it (no object with same name in list)

Reimplemented from KVSeqCollection.

Reimplemented in KVPartitionList.

Definition at line 117 of file KVUniqueNameList.h.

◆ checkObjInList()

Bool_t KVUniqueNameList::checkObjInList ( TObject obj)
private

Return kTRUE if 'obj' can be added to list. If fReplace==kFALSE, there must be no object in the list with same name as obj->GetName(). If fReplace==kTRUE the previous object is removed from the list. If IsOwner()==kTRUE the previous object is removed AND deleted. In the latter two cases the new object can always be added (returns kTRUE)

Definition at line 40 of file KVUniqueNameList.cpp.

◆ ObjectAdded()

Bool_t KVUniqueNameList::ObjectAdded ( ) const
inline

returns kTRUE if the last (immediately previous) attempt ot add an object to the list was successful

Definition at line 153 of file KVUniqueNameList.h.

◆ ReplaceObjects()

void KVUniqueNameList::ReplaceObjects ( Bool_t  yes = kTRUE)
inline

Definition at line 162 of file KVUniqueNameList.h.

Member Data Documentation

◆ fLastCheck

Bool_t KVUniqueNameList::fLastCheck
mutableprivate

return value of last call to checkobj

Definition at line 103 of file KVUniqueNameList.h.

◆ fReplace

Bool_t KVUniqueNameList::fReplace
private

if kTRUE, objects with same name are replaced

Definition at line 102 of file KVUniqueNameList.h.