ROOT » CORE » CONT » TObjArray

class TObjArray: public TSeqCollection


TObjArray

 An array of TObjects. The array expands automatically when
 objects are added (shrinking can be done by hand using Expand(),
 how nice to have meaningful names -:)).
 Use operator[] to have "real" array behaviour.

 Note on ownership and copy:
 By default the TObjArray does not own the objects it points to and
 will not delete them unless explicitly asked (via a call to the
 Delete member function).   To assign ownership of the content to
 the array, call:
     myarr->SetOwner(kTRUE);
 When the array owns its content a call to Clear or the deletion of
 the array itself will lead to the deletion of its contents.

 You can either make a shallow copy of the array:
     otherarr = new TObjArray(*myarr);
    *otherarr = *myarr;
 in which case ownership (if any) is not transfered but the other
 array points to the same object as the original array.  Note that
 if the content of either array is deleted the other array is not
 notified in any way (i.e. still points to the now deleted objects).

 You can also make a deep copy of the array:
     otherarr = (TObjArray*)myarr->Clone();
 in which case the array and the content are both duplicated (i.e.
 otherarr and myarr do not point to the same objects).  If myarr
 is set to the be the owner of its content, otherarr will also be
 set to the owner of its own conent.


/* */


Function Members (Methods)

public:
virtual~TObjArray()
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 idx) const
virtual TObject*Before(const TObject* obj) const
TIterTCollection::begin() 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*TCollection::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()
TIterTCollection::end() const
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*FindObject(const char* name) const
virtual TObject*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
virtual Int_tGetLast() const
virtual const char*TCollection::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
TObject**GetObjectRef() const
virtual TObject**GetObjectRef(const TObject* obj) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual Int_tTCollection::GetSize() const
virtual const char*TObject::GetTitle() 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)
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
voidTObject::operator delete(void* ptr)
voidTObject::operator delete(void* ptr, void* vp)
voidTObject::operator delete[](void* ptr)
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
TObjArray&operator=(const TObjArray&)
virtual TObject*&operator[](Int_t i)
virtual TObject*operator[](Int_t i) const
virtual voidTCollection::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTCollection::Print(Option_t* option = "") const
virtual voidTCollection::Print(Option_t* option, Int_t recurse) const
virtual voidTCollection::Print(Option_t* option, const char* wildcard, Int_t recurse = 1) const
virtual voidTCollection::Print(Option_t* option, TPRegexp& regexp, Int_t recurse = 1) 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)
static voidTSeqCollection::QSort(TObject** a, Int_t nBs, TObject*** b, Int_t first, Int_t last)
virtual voidRandomize(Int_t ntimes = 1)
virtual Int_tTObject::Read(const char* name)
virtual voidRecursiveRemove(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()
virtual voidRemoveRange(Int_t idx1, Int_t idx2)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& 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) const
virtual voidSort(Int_t upto = kMaxInt)
static voidTCollection::StartGarbageCollection()
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_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
TObjArray(const TObjArray& a)
TObjArray(Int_t s = TCollection::kInitCapacity, Int_t lowerBound = 0)
TObject*UncheckedAt(Int_t i) 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
virtual const char*TCollection::GetCollectionEntryName(TObject* entry) const
voidInit(Int_t s, Int_t lowerBound)
voidTObject::MakeZombie()
Bool_tOutOfBoundsError(const char* where, Int_t i) const
virtual voidTCollection::PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const
virtual voidTCollection::PrintCollectionHeader(Option_t* option) const

Data Members

public:
static TObject::(anonymous)TObject::kBitMask
static TObject::EStatusBitsTObject::kCanDelete
static TObject::EStatusBitsTObject::kCannotPick
static TObject::EStatusBitsTObject::kHasUUID
static TCollection::(anonymous)TCollection::kInitCapacity
static TCollection::(anonymous)TCollection::kInitHashTableCapacity
static TObject::EStatusBitsTObject::kInvalidObject
static TObject::(anonymous)TObject::kIsOnHeap
static TObject::EStatusBitsTObject::kIsReferenced
static TObject::EStatusBitsTObject::kMustCleanup
static TObject::EStatusBitsTObject::kNoContextMenu
static TObject::(anonymous)TObject::kNotDeleted
static TObject::EStatusBitsTObject::kObjInCanvas
static TObject::(anonymous)TObject::kOverwrite
static TObject::(anonymous)TObject::kSingleKey
static TObject::(anonymous)TObject::kWriteDelete
static TObject::(anonymous)TObject::kZombie
protected:
TObject**fCont!Array contents
Int_tfLastLast element in array containing an object
Int_tfLowerBoundLower bound of the array
TStringTCollection::fNamename of the collection
Int_tTCollection::fSizenumber of elements in collection
Bool_tTSeqCollection::fSortedtrue if collection has been sorted
static TCollection::(anonymous)TCollection::kIsOwner

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TObjArray(Int_t s = TCollection::kInitCapacity, Int_t lowerBound = 0)
 Create an object array. Using s one can set the array size (default is
 kInitCapacity=16) and lowerBound can be used to set the array lowerbound
 index (default is 0).
TObjArray(const TObjArray& a)
 Create a copy of TObjArray a. Note, does not copy the kIsOwner flag.
~TObjArray()
 Delete an array. Objects are not deleted unless the TObjArray is the
 owner (set via SetOwner()).
TObjArray& operator=(const TObjArray& )
 Assignment operator. Note, unsets the kIsOwner flag.
TObject *& operator[](Int_t i)
 Return the object at position i. Returns address at position 0
 if i is out of bounds. Result may be used as an lvalue.
TObject * operator[](Int_t i) const
 Return the object at position at. Returns 0 if i is out of bounds.
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 TObjArray is the owner (set via SetOwner()).
void Compress()
 Remove empty slots from array.
void Delete(Option_t* option = "")
 Remove all objects from the array AND delete all heap based objects.
void Expand(Int_t newSize)
 Expand or shrink the array to newSize elements.
TObject * FindObject(const char* name) const
 Find an object in this collection using its name. Requires a sequential
 scan till the object has been found. Returns 0 if object with specified
 name is not found.
TObject * FindObject(const TObject* obj) const
 Find an object in this collection using the object's IsEqual()
 member function. Requires a sequential scan till the object has
 been found. Returns 0 if object is not found.
 Typically this function is overridden by a more efficient version
 in concrete collection classes (e.g. THashTable).
void Streamer(TBuffer& )
 Stream all objects in the array to or from the I/O buffer.
TObject * First() const
 Return the object in the first slot.
TObject * Last() const
 Return the object in the last filled slot. Returns 0 if no entries.
Int_t GetEntries() const
 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 GetEntriesFast() (only in case when there are no empty slots).
Int_t GetAbsLast() const
 Return absolute index to last object in array. Returns -1 in case
 array is empty.
Int_t GetLast() const
 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. If obj is 0 returns address of container.
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 TObjArray.
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.
void RecursiveRemove(TObject* obj)
 Remove object from this collection and recursively remove the object
 from all other objects (and collections).
TObject * RemoveAt(Int_t idx)
 Remove object at index idx.
TObject * Remove(TObject* obj)
 Remove object from array.
void RemoveRange(Int_t idx1, Int_t idx2)
 Remove objects from index idx1 to idx2 included.
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.
 If last is -1, this effectively truncate the array completely.
void Randomize(Int_t ntimes = 1)
 Randomize objects inside the array, i.e. permute randomly objects.
 With fLast being the index of the last entry in the array, the following
 algorithm is applied to the array:
   - for each entry j between 0 and fLast, another entry k is chosen
     randomly between 0 and fLast.
   - the objects at j and k are swapped.
   - this process is repeated ntimes (ntimes = 1 by default).
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 * At(Int_t idx) const
 Return the object at position i. Returns 0 if i is out of bounds.
Int_t GetEntriesFast() const
TObject ** GetObjectRef() const
{ return fCont; }
Bool_t IsEmpty() const
{ return GetAbsLast() == -1; }
void Add(TObject* obj)
{ AddLast(obj); }
TObject * UncheckedAt(Int_t i) const
{ return fCont[i-fLowerBound]; }
Int_t LowerBound() const
{ return fLowerBound; }