ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifndef ROOT_TObjArray
26 #include "TObjArray.h"
27 #endif
28 
29 class TClass;
30 
31 
32 class TClonesArray : public TObjArray {
33 
34 protected:
35  TClass *fClass; //!Pointer to the class of the elements
36  TObjArray *fKeep; //!Saved copies of pointers to objects
37 
38 public:
39  enum {
40  kForgetBits = BIT(0), // Do not create branches for fBits, fUniqueID
41  kNoSplit = BIT(1), // Array not split by TTree::Branch
42  kBypassStreamer = BIT(12) // Class Streamer not called (default)
43  };
44 
45  TClonesArray();
46  TClonesArray(const char *classname, Int_t size = 1000, Bool_t call_dtor = kFALSE);
47  TClonesArray(const TClass *cl, Int_t size = 1000, Bool_t call_dtor = kFALSE);
48  TClonesArray(const TClonesArray& tc);
49  virtual ~TClonesArray();
51  virtual void Compress();
52  virtual void Clear(Option_t *option="");
53  virtual void Delete(Option_t *option="");
54  virtual void Expand(Int_t newSize);
55  virtual void ExpandCreate(Int_t n);
56  virtual void ExpandCreateFast(Int_t n);
57  TClass *GetClass() const { return fClass; }
58  virtual void SetOwner(Bool_t enable = kTRUE);
59 
60  void AddFirst(TObject *) { MayNotUse("AddFirst"); }
61  void AddLast(TObject *) { MayNotUse("AddLast"); }
62  void AddAt(TObject *, Int_t) { MayNotUse("AddAt"); }
63  void AddAtAndExpand(TObject *, Int_t) { MayNotUse("AddAtAndExpand"); }
64  Int_t AddAtFree(TObject *) { MayNotUse("AddAtFree"); return 0; }
65  void AddAfter(const TObject *, TObject *) { MayNotUse("AddAfter"); }
66  void AddBefore(const TObject *, TObject *) { MayNotUse("AddBefore"); }
67  void BypassStreamer(Bool_t bypass=kTRUE);
70  TObject *ConstructedAt(Int_t idx, Option_t *clear_options);
71  void SetClass(const char *classname,Int_t size=1000);
72  void SetClass(const TClass *cl,Int_t size=1000);
73 
74  void AbsorbObjects(TClonesArray *tc);
75  void AbsorbObjects(TClonesArray *tc, Int_t idx1, Int_t idx2);
76  void MultiSort(Int_t nTCs, TClonesArray** tcs, Int_t upto = kMaxInt);
77  virtual TObject *RemoveAt(Int_t idx);
78  virtual TObject *Remove(TObject *obj);
79  virtual void RemoveRange(Int_t idx1, Int_t idx2);
80  virtual void Sort(Int_t upto = kMaxInt);
81 
82  TObject *New(Int_t idx);
83  TObject *AddrAt(Int_t idx);
84  TObject *&operator[](Int_t idx);
85  TObject *operator[](Int_t idx) const;
86 
87  ClassDef(TClonesArray,4) //An array of clone objects
88 };
89 
91 {
92  return operator[](idx);
93 }
94 
95 #endif
void AddAt(TObject *, Int_t)
Add object at position ids.
Definition: TClonesArray.h:62
An array of TObjects.
Definition: TObjArray.h:39
void MultiSort(Int_t nTCs, TClonesArray **tcs, Int_t upto=kMaxInt)
Sort multiple TClonesArrays simultaneously with this array.
void AbsorbObjects(TClonesArray *tc)
Directly move the object pointers from tc without cloning (copying).
const char Option_t
Definition: RtypesCore.h:62
#define BIT(n)
Definition: Rtypes.h:120
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:971
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void AddFirst(TObject *)
Add object in the first slot of the array.
Definition: TClonesArray.h:60
virtual void RemoveRange(Int_t idx1, Int_t idx2)
Remove objects from index idx1 to idx2 included.
void AddBefore(const TObject *, TObject *)
Add object in the slot before object before.
Definition: TClonesArray.h:66
void BypassStreamer(Bool_t bypass=kTRUE)
When the kBypassStreamer bit is set, the automatically generated Streamer can call directly TClass::W...
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void SetOwner(Bool_t enable=kTRUE)
A TClonesArray is always the owner of the object it contains.
TObject * ConstructedAt(Int_t idx)
Get an object at index 'idx' that is guaranteed to have been constructed.
void AddAfter(const TObject *, TObject *)
Add object in the slot after object after.
Definition: TClonesArray.h:65
TObject * AddrAt(Int_t idx)
Definition: TClonesArray.h:90
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
Bool_t CanBypassStreamer() const
Definition: TClonesArray.h:68
virtual void Clear(Option_t *option="")
Clear the clones array.
void SetClass(const char *classname, Int_t size=1000)
see TClonesArray::SetClass(const TClass*)
virtual void Delete(Option_t *option="")
Clear the clones array.
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
TClass * GetClass() const
Definition: TClonesArray.h:57
TClonesArray & operator=(const TClonesArray &tc)
Assignment operator.
Mother of all ROOT objects.
Definition: TObject.h:58
const Int_t kMaxInt
Definition: Rtypes.h:103
An array of clone (identical) objects.
Definition: TClonesArray.h:32
TClass * fClass
Definition: TClonesArray.h:35
virtual void ExpandCreateFast(Int_t n)
Expand or shrink the array to n elements and create the clone objects by calling their default ctor...
virtual void Sort(Int_t upto=kMaxInt)
If objects in array are sortable (i.e.
Int_t AddAtFree(TObject *)
Return the position of the new object.
Definition: TClonesArray.h:64
void AddLast(TObject *)
Add object in the next empty slot in the array.
Definition: TClonesArray.h:61
TObject *& operator[](Int_t idx)
Return pointer to reserved area in which a new object of clones class can be constructed.
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * New(Int_t idx)
Create an object of type fClass with the default ctor at the specified index.
TObject * obj
virtual TObject * Remove(TObject *obj)
Remove object from array.
virtual void ExpandCreate(Int_t n)
Expand or shrink the array to n elements and create the clone objects by calling their default ctor...
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
const Int_t n
Definition: legend1.C:16
virtual void Compress()
Remove empty slots from array.
virtual ~TClonesArray()
Delete a clones array.
TObjArray * fKeep
Pointer to the class of the elements.
Definition: TClonesArray.h:36
void AddAtAndExpand(TObject *, Int_t)
Add object at position idx.
Definition: TClonesArray.h:63