Logo ROOT  
Reference Guide
TClonesArray.h
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Rene Brun 11/02/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TClonesArray
13 #define ROOT_TClonesArray
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TClonesArray //
19 // //
20 // An array of clone TObjects. The array expands automatically when //
21 // adding elements (shrinking can be done explicitly). //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TObjArray.h"
26 
27 class TClass;
28 
29 class TClonesArray : public TObjArray {
30 
31 protected:
32  TClass *fClass; //!Pointer to the class of the elements
33  TObjArray *fKeep; //!Saved copies of pointers to objects
34 
35 public:
36  enum EStatusBits {
37  kBypassStreamer = BIT(12), // Class Streamer not called (default)
38  kForgetBits = BIT(15) // Do not create branches for fBits, fUniqueID
39  };
40 
41  TClonesArray();
42  TClonesArray(const char *classname, Int_t size = 1000, Bool_t call_dtor = kFALSE);
43  TClonesArray(const TClass *cl, Int_t size = 1000, Bool_t call_dtor = kFALSE);
44  TClonesArray(const TClonesArray& tc);
45  virtual ~TClonesArray();
47  virtual void Compress();
48  virtual void Clear(Option_t *option="");
49  virtual void Delete(Option_t *option="");
50  virtual void Expand(Int_t newSize);
51  virtual void ExpandCreate(Int_t n);
52  virtual void ExpandCreateFast(Int_t n);
53  TClass *GetClass() const { return fClass; }
54  virtual void SetOwner(Bool_t enable = kTRUE);
55 
56  void AddFirst(TObject *) { MayNotUse("AddFirst"); }
57  void AddLast(TObject *) { MayNotUse("AddLast"); }
58  void AddAt(TObject *, Int_t) { MayNotUse("AddAt"); }
59  void AddAtAndExpand(TObject *, Int_t) { MayNotUse("AddAtAndExpand"); }
60  Int_t AddAtFree(TObject *) { MayNotUse("AddAtFree"); return 0; }
61  void AddAfter(const TObject *, TObject *) { MayNotUse("AddAfter"); }
62  void AddBefore(const TObject *, TObject *) { MayNotUse("AddBefore"); }
63  void BypassStreamer(Bool_t bypass=kTRUE);
66  TObject *ConstructedAt(Int_t idx, Option_t *clear_options);
67  void SetClass(const char *classname,Int_t size=1000);
68  void SetClass(const TClass *cl,Int_t size=1000);
69 
70  void AbsorbObjects(TClonesArray *tc);
71  void AbsorbObjects(TClonesArray *tc, Int_t idx1, Int_t idx2);
72  void MultiSort(Int_t nTCs, TClonesArray** tcs, Int_t upto = kMaxInt);
73  virtual TObject *RemoveAt(Int_t idx);
74  virtual TObject *Remove(TObject *obj);
75  virtual void RemoveRange(Int_t idx1, Int_t idx2);
76  virtual void Sort(Int_t upto = kMaxInt);
77 
78  TObject *New(Int_t idx);
79  TObject *AddrAt(Int_t idx);
80  TObject *&operator[](Int_t idx);
81  TObject *operator[](Int_t idx) const;
82 
83  ClassDef(TClonesArray,4) //An array of clone objects
84 };
85 
87 {
88  return operator[](idx);
89 }
90 
91 #endif
n
const Int_t n
Definition: legend1.C:16
TClonesArray::CanBypassStreamer
Bool_t CanBypassStreamer() const
Definition: TClonesArray.h:64
TClonesArray::fClass
TClass * fClass
Definition: TClonesArray.h:32
TClonesArray::AddFirst
void AddFirst(TObject *)
Add object in the first slot of the array.
Definition: TClonesArray.h:56
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
TObjArray
An array of TObjects.
Definition: TObjArray.h:37
Option_t
const char Option_t
Definition: RtypesCore.h:66
TClonesArray::Delete
virtual void Delete(Option_t *option="")
Clear the clones array.
Definition: TClonesArray.cxx:441
TClonesArray::~TClonesArray
virtual ~TClonesArray()
Delete a clones array.
Definition: TClonesArray.cxx:270
TClonesArray::New
TObject * New(Int_t idx)
Create an object of type fClass with the default ctor at the specified index.
Definition: TClonesArray.cxx:956
TClonesArray::fKeep
TObjArray * fKeep
Pointer to the class of the elements.
Definition: TClonesArray.h:33
TClonesArray::AddAfter
void AddAfter(const TObject *, TObject *)
Add object in the slot after object after.
Definition: TClonesArray.h:61
Int_t
int Int_t
Definition: RtypesCore.h:45
TObject::MayNotUse
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:943
TClonesArray::operator=
TClonesArray & operator=(const TClonesArray &tc)
Assignment operator.
Definition: TClonesArray.cxx:234
TClonesArray::Sort
virtual void Sort(Int_t upto=kMaxInt)
If objects in array are sortable (i.e.
Definition: TClonesArray.cxx:710
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TClonesArray::ExpandCreate
virtual void ExpandCreate(Int_t n)
Expand or shrink the array to n elements and create the clone objects by calling their default ctor.
Definition: TClonesArray.cxx:502
bool
TClonesArray::AddAtFree
Int_t AddAtFree(TObject *)
Return the position of the new object.
Definition: TClonesArray.h:60
TClonesArray::AddBefore
void AddBefore(const TObject *, TObject *)
Add object in the slot before object before.
Definition: TClonesArray.h:62
TClonesArray::BypassStreamer
void BypassStreamer(Bool_t bypass=kTRUE)
When the kBypassStreamer bit is set, the automatically generated Streamer can call directly TClass::W...
Definition: TClonesArray.cxx:310
TClonesArray::Remove
virtual TObject * Remove(TObject *obj)
Remove object from array.
Definition: TClonesArray.cxx:596
TClonesArray::AddAtAndExpand
void AddAtAndExpand(TObject *, Int_t)
Add object at position idx.
Definition: TClonesArray.h:59
TClonesArray::Compress
virtual void Compress()
Remove empty slots from array.
Definition: TClonesArray.cxx:321
TClonesArray::Expand
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Definition: TClonesArray.cxx:468
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TClonesArray::GetClass
TClass * GetClass() const
Definition: TClonesArray.h:53
BIT
#define BIT(n)
Definition: Rtypes.h:85
TClonesArray::AbsorbObjects
void AbsorbObjects(TClonesArray *tc)
Directly move the object pointers from tc without cloning (copying).
Definition: TClonesArray.cxx:980
TClonesArray::AddLast
void AddLast(TObject *)
Add object in the next empty slot in the array.
Definition: TClonesArray.h:57
TClonesArray::kForgetBits
@ kForgetBits
Definition: TClonesArray.h:38
TClonesArray::operator[]
TObject *& operator[](Int_t idx)
Return pointer to reserved area in which a new object of clones class can be constructed.
Definition: TClonesArray.cxx:908
TObjArray.h
TClonesArray::kBypassStreamer
@ kBypassStreamer
Definition: TClonesArray.h:37
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TClonesArray::AddAt
void AddAt(TObject *, Int_t)
Add object at position ids.
Definition: TClonesArray.h:58
kMaxInt
const Int_t kMaxInt
Definition: RtypesCore.h:103
TClonesArray::RemoveRange
virtual void RemoveRange(Int_t idx1, Int_t idx2)
Remove objects from index idx1 to idx2 included.
Definition: TClonesArray.cxx:619
TClonesArray::AddrAt
TObject * AddrAt(Int_t idx)
Definition: TClonesArray.h:86
TClonesArray::SetOwner
virtual void SetOwner(Bool_t enable=kTRUE)
A TClonesArray is always the owner of the object it contains.
Definition: TClonesArray.cxx:701
TClonesArray::TClonesArray
TClonesArray()
Default Constructor.
Definition: TClonesArray.cxx:177
TClonesArray::ConstructedAt
TObject * ConstructedAt(Int_t idx)
Get an object at index 'idx' that is guaranteed to have been constructed.
Definition: TClonesArray.cxx:366
TClonesArray
An array of clone (identical) objects.
Definition: TClonesArray.h:29
TClonesArray::RemoveAt
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
Definition: TClonesArray.cxx:572
TClonesArray::MultiSort
void MultiSort(Int_t nTCs, TClonesArray **tcs, Int_t upto=kMaxInt)
Sort multiple TClonesArrays simultaneously with this array.
Definition: TClonesArray.cxx:1049
TObject::EStatusBits
EStatusBits
Definition: TObject.h:57
TClonesArray::SetClass
void SetClass(const char *classname, Int_t size=1000)
see TClonesArray::SetClass(const TClass*)
Definition: TClonesArray.cxx:690
int
TClonesArray::ExpandCreateFast
virtual void ExpandCreateFast(Int_t n)
Expand or shrink the array to n elements and create the clone objects by calling their default ctor.
Definition: TClonesArray.cxx:546
TClonesArray::Clear
virtual void Clear(Option_t *option="")
Clear the clones array.
Definition: TClonesArray.cxx:409