class TRefArray: public TSeqCollection


TRefArray

An array of references to TObjects. The array expands automatically
 when  objects are added (shrinking can be done by hand using Expand() )

The TRefArray can be filled with:
array.Add(obj)
array.AddAt(obj,i)
but not array[i] = obj  !!!

The array elements can be retrieved with:
TObject *obj = array.At(i);

By default the TRefArray 'points' to the current process and can only
receive object that have been created in this process.
To point the TRefArray to a different process do:
TRefArray array( processId );

For example, if 'obj' is an instance that was created in the different
process and you do:
TRefArray array( TProcessID::GetProcessWithUID( obj ) );
Then
array.Add(obj);
is correct (obj comes from the process the array is pointed to
while
TObject *nobj = new TObject;
array.Add(nobj);
is incorrect since 'nobj' was created in a different process than the
one the array is pointed to. In this case you will see error message:
Error in <TRefArray::AddAtAndExpand>: The object at 0x... is not
registered in the process the TRefArray point to
(pid = ProcessID../....)

When a TRefArray is Streamed, only the pointer unique id is written,
not the referenced object. TRefArray may be assigned to different
branches of one Tree or several Trees.
The branch containing the TRefArray can be read before or after the
array (eg TClonesArray, STL vector,..) of the referenced objects.

See an example in $ROOTSYS/test/Event.h

RESTRICTIONS when using TRefArray

- Elements in a TRefArray cannot point to a TFile or TDirectory.
- All elements of a TRefArray must be set in the same process,
In particular, one cannot modify some elements of the array in
a different process.
Use an array of TRef when one of the above restrictions is met.


Function Members (Methods)

public:
TRefArray(TProcessID* pid = 0)
TRefArray(const TRefArray& a)
TRefArray(Int_t s, TProcessID* pid)
TRefArray(Int_t s, Int_t lowerBound = 0, TProcessID* pid = 0)
virtual~TRefArray()
voidTObject::AbstractMethod(const char* method) const
virtual voidAdd(TObject* obj)
virtual voidAddAfter(const TObject* after, TObject* obj)
virtual voidTCollection::AddAll(const TCollection* col)
virtual voidAddAt(TObject* obj, Int_t idx)
virtual voidAddAtAndExpand(TObject* obj, Int_t idx)
virtual Int_tAddAtFree(TObject* obj)
virtual voidAddBefore(const TObject* before, TObject* obj)
virtual voidAddFirst(TObject* obj)
virtual voidAddLast(TObject* obj)
voidTCollection::AddVector(TObject* obj1)
virtual TObject*After(const TObject* obj) const
virtual voidTObject::AppendPad(Option_t* option = "")
Bool_tTCollection::AssertClass(TClass* cl) const
virtual TObject*At(Int_t at) const
virtual TObject*Before(const TObject* obj) const
virtual Int_tBinarySearch(TObject* obj, Int_t upto = kMaxInt)
virtual voidTCollection::Browse(TBrowser* b)
Int_tTCollection::Capacity() const
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidClear(Option_t* option = "")
virtual TObject*TObject::Clone(const char* newname = "") const
virtual Int_tTCollection::Compare(const TObject* obj) const
virtual voidCompress()
Bool_tTCollection::Contains(const char* name) const
Bool_tTCollection::Contains(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
virtual voidDelete(Option_t* option = "")
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTCollection::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTCollection::Dump() const
static voidTCollection::EmptyGarbageCollection()
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidExpand(Int_t newSize)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual TObject*TCollection::FindObject(const char* name) const
virtual TObject*TCollection::FindObject(const TObject* obj) const
virtual TObject*First() const
static voidTCollection::GarbageCollect(TObject* obj)
static TCollection*TCollection::GetCurrentCollection()
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual Int_tGetEntries() const
Int_tGetEntriesFast() const
virtual const char*TObject::GetIconName() const
Int_tGetLast() const
virtual const char*TCollection::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
virtual TObject**GetObjectRef(const TObject* obj) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
TProcessID*GetPID() const
virtual Int_tTCollection::GetSize() const
virtual const char*TObject::GetTitle() const
UInt_tGetUID(Int_t at) const
virtual UInt_tTObject::GetUniqueID() const
virtual Int_tTCollection::GrowBy(Int_t delta) const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTCollection::Hash() const
virtual Int_tIndexOf(const TObject* obj) const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
Bool_tTCollection::IsArgNull(const char* where, const TObject* obj) const
virtual Bool_tIsEmpty() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTCollection::IsFolder() const
Bool_tTObject::IsOnHeap() const
Bool_tTCollection::IsOwner() const
virtual Bool_tTCollection::IsSortable() const
virtual Bool_tTSeqCollection::IsSorted() const
Bool_tTObject::IsZombie() const
virtual TObject*Last() const
Int_tTSeqCollection::LastIndex() const
Int_tLowerBound() const
virtual voidTCollection::ls(Option_t* option = "") const
virtual TIterator*MakeIterator(Bool_t dir = kIterForward) const
virtual TIterator*TCollection::MakeReverseIterator() const
voidTObject::MayNotUse(const char* method) const
Long64_tTSeqCollection::Merge(TCollection* list)
virtual Bool_tTObject::Notify()
static Int_tTSeqCollection::ObjCompare(TObject* a, TObject* b)
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
TObject*TCollection::operator()(const char* name) const
TRefArray&operator=(const TRefArray& a)
virtual TObject*operator[](Int_t at) const
virtual voidTCollection::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTCollection::Print(Option_t* wildcard = "") const
virtual voidTCollection::Print(Option_t* wildcard, Option_t* option) const
static voidTSeqCollection::QSort(TObject** a, Int_t first, Int_t last)
static voidTSeqCollection::QSort(TObject** a, TObject** b, Int_t first, Int_t last)
virtual Int_tTObject::Read(const char* name)
virtual voidTCollection::RecursiveRemove(TObject* obj)
virtual TObject*Remove(TObject* obj)
virtual voidTSeqCollection::RemoveAfter(TObject* after)
voidTCollection::RemoveAll()
virtual voidTCollection::RemoveAll(TCollection* col)
virtual TObject*RemoveAt(Int_t idx)
virtual voidTSeqCollection::RemoveBefore(TObject* before)
virtual voidTSeqCollection::RemoveFirst()
virtual voidTSeqCollection::RemoveLast()
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(basic_ostream<char,char_traits<char> >& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
voidTCollection::SetCurrentCollection()
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
voidSetLast(Int_t last)
voidTCollection::SetName(const char* name)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidTCollection::SetOwner(Bool_t enable = kTRUE)
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp, char* parent)
virtual voidSort(Int_t upto = kMaxInt)
static voidTCollection::StartGarbageCollection()
virtual voidStreamer(TBuffer& b)
voidStreamerNVirtual(TBuffer& b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
voidTSeqCollection::UnSort()
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTCollection::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTCollection::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
Bool_tBoundsOk(const char* where, Int_t at) const
virtual voidTSeqCollection::Changed()
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
Int_tGetAbsLast() const
TObject*GetFromTable(Int_t idx) const
voidInit(Int_t s, Int_t lowerBound)
voidTObject::MakeZombie()
Bool_tOutOfBoundsError(const char* where, Int_t i) const

Data Members

public:
enum TCollection::[unnamed] { kIsOwner
kInitCapacity
kInitHashTableCapacity
};
enum TObject::EStatusBits { kCanDelete
kMustCleanup
kObjInCanvas
kIsReferenced
kHasUUID
kCannotPick
kNoContextMenu
kInvalidObject
};
enum TObject::[unnamed] { kIsOnHeap
kNotDeleted
kZombie
kBitMask
kSingleKey
kOverwrite
kWriteDelete
};
protected:
Int_tfLastLast element in array containing an object
Int_tfLowerBoundLower bound of the array
TStringTCollection::fNamename of the collection
TProcessID*fPIDPointer to Process Unique Identifier
Int_tTCollection::fSizenumber of elements in collection
Bool_tTSeqCollection::fSortedtrue if collection has been sorted
UInt_t*fUIDs[fSize] To store uids of referenced objects

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TRefArray(TProcessID *pid)
 default constructor
TRefArray(Int_t s, TProcessID* pid)
 Create an object array. Using s one can set the array size
 and lowerBound can be used to set the array lowerbound
 index (default is 0).
TRefArray(Int_t s, Int_t lowerBound = 0, TProcessID* pid = 0)
 Create an object array. Using s one can set the array size
 and lowerBound can be used to set the array lowerbound
 index (default is 0).
TRefArray(const TRefArray &a)
 Create a copy of TRefArray a.
TRefArray& operator=(const TRefArray& a)
 Assignment operator.
~TRefArray()
 Delete an array. Objects are not deleted unless the TRefArray is the
 owner (set via SetOwner()).
void AddFirst(TObject* obj)
 Add object in the first slot of the array. This will overwrite the
 first element that might have been there. To have insertion semantics
 use either a TList or a TOrdCollection.
void AddLast(TObject* obj)
 Add object in the next empty slot in the array. Expand the array
 if necessary.
void AddBefore(const TObject* before, TObject* obj)
 Add object in the slot before object before. If before=0 add object
 in the first slot. Note that this will overwrite any object that
 might have already been in this slot. For insertion semantics use
 either a TList or a TOrdCollection.
void AddAfter(const TObject* after, TObject* obj)
 Add object in the slot after object after. If after=0 add object in
 the last empty slot. Note that this will overwrite any object that
 might have already been in this slot. For insertion semantics use
 either a TList or a TOrdCollection.
void AddAtAndExpand(TObject* obj, Int_t idx)
 Add object at position idx. If idx is larger than the current size
 of the array, expand the array (double its size).
void AddAt(TObject* obj, Int_t idx)
 Add object at position ids. Give an error when idx is out of bounds
 (i.e. the array is not expanded).
Int_t AddAtFree(TObject* obj)
 Return the position of the new object.
 Find the first empty cell or AddLast if there is no empty cell
TObject * After(const TObject* obj) const
 Return the object after obj. Returns 0 if obj is last object.
TObject * Before(const TObject* obj) const
 Return the object before obj. Returns 0 if obj is first object.
void Clear(Option_t* option = "")
 Remove all objects from the array. Does not delete the objects
 unless the TRefArray is the owner (set via SetOwner()).
void Compress()
 Remove empty slots from array.
void Delete(Option_t* option = "")
 Remove all objects from the array.
void Expand(Int_t newSize)
 Expand or shrink the array to newSize elements.
TObject * GetFromTable(Int_t idx) const
the reference may be in the TRefTable
void Streamer(TBuffer& b)
 Stream all objects in the array to or from the I/O buffer.
TObject * First()
 Return the object in the first slot.
TObject * Last()
 Return the object in the last filled slot. Returns 0 if no entries.
Int_t GetEntries()
 Return the number of objects in array (i.e. number of non-empty slots).
 Attention: use this method ONLY if you want to know the number of
 non-empty slots. This function loops over the complete array and
 is therefore very slow when applied in a loop. Most of the time you
 better use GetLast()+1.
Int_t GetAbsLast()
 Return absolute index to last object in array. Returns -1 in case
 array is empty.
Int_t GetLast()
 Return index of last object in array. Returns lowerBound-1 in case
 array is empty.
TObject ** GetObjectRef(const TObject* obj) const
 Return address of pointer obj.
UInt_t GetUID(Int_t at) const
 Return UID of element at.
Int_t IndexOf(const TObject* obj) const
 obj != 0 Return index of object in array.
          Returns lowerBound-1 in case array doesn't contain the obj.

 obj == 0 Return the index of the first empty slot.
          Returns lowerBound-1 in case array doesn't contain any empty slot.
void Init(Int_t s, Int_t lowerBound)
 Initialize a TRefArray.
TIterator * MakeIterator(Bool_t dir = kIterForward) const
 Returns an array iterator.
Bool_t OutOfBoundsError(const char* where, Int_t i) const
 Generate an out-of-bounds error. Always returns false.
TObject * RemoveAt(Int_t idx)
 Remove object at index idx.
TObject * Remove(TObject* obj)
 Remove object from array.
void SetLast(Int_t last)
 Set index of last object in array, effectively truncating the
 array. Use carefully since whenever last position has to be
 recalculated, e.g. after a Remove() or Sort() it will be reset
 to the last non-empty slot. If last is -2 this will force the
 recalculation of the last used slot.
void Sort(Int_t upto = kMaxInt)
 If objects in array are sortable (i.e. IsSortable() returns true
 for all objects) then sort array.
Int_t BinarySearch(TObject* obj, Int_t upto = kMaxInt)
 Find object using a binary search. Array must first have been sorted.
 Search can be limited by setting upto to desired index.
Bool_t BoundsOk(const char* where, Int_t at) const
TObject * operator[](Int_t at) const
TObject * At(Int_t at) const
 Return the object at position i. Returns 0 if i is out of bounds.
Int_t GetEntriesFast()
TProcessID * GetPID()
{return fPID;}
Bool_t IsEmpty()
{ return GetAbsLast() == -1; }
void Add(TObject* obj)
{ AddLast(obj); }
Int_t LowerBound()
{ return fLowerBound; }

Author: Rene Brun 02/10/2001
Last change: root/cont:$Id: TRefArray.h 23530 2008-04-24 16:22:51Z rdm $
Last generated: 2008-06-25 08:52
Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.