ROOT  6.06/09
Reference Guide
TGeoBranchArray.h
Go to the documentation of this file.
1 // @(#):$Id$
2 // Author: Andrei Gheata 01/03/11
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_TGeoBranchArray
13 #define ROOT_TGeoBranchArray
14 
15 #ifndef ROOT_TObject
16 #include "TObject.h"
17 #endif
18 
19 #ifndef ROOT_TGeoMatrix
20 #include "TGeoMatrix.h"
21 #endif
22 
23 ////////////////////////////////////////////////////////////////////////////
24 // //
25 // TGeoBranchArray - An array of daughter indices making a geometry path. //
26 // Can be used to backup/restore a state. Allocated contiguously in //
27 // memory. //
28 // //
29 ////////////////////////////////////////////////////////////////////////////
30 
31 class TGeoNavigator;
32 class TGeoNode;
33 
34 class TGeoBranchArray : public TObject
35 {
36 protected:
37  Int_t fLevel; // Branch depth
38  Int_t fMaxLevel; // Array length
39  TGeoHMatrix fMatrix; // Global matrix (owned)
40  TGeoNode **fArray; //![fMaxLevel+1] Array of nodes
41  TGeoNode *fRealArray[1]; // Beginning address of the array of nodes
42 
43 private:
44  TGeoBranchArray(Int_t level); // not allowed
45  TGeoBranchArray(const TGeoBranchArray&); // not allowed
46 public:
47  enum EGeoBATypes {
48  kBASelfAlloc = BIT(14) // does self allocation or not
49  };
50  // This replaces the dummy constructor to make sure that I/O can be
51  // performed while the user is only allowed to use the static maker
52  TGeoBranchArray(TRootIOCtor*) : TObject(), fLevel(0), fMaxLevel(0), fMatrix(), fArray(0) {}
53 
54  // The static maker to be use to create an instance of the branch array
55  static TGeoBranchArray *MakeInstance(size_t maxlevel);
56 
57  // The static maker to be use to create an instance of the branch array
58  static TGeoBranchArray *MakeInstanceAt(size_t maxlevel, void *addr);
59 
60  // The equivalent of the copy constructor
61  static TGeoBranchArray *MakeCopy(const TGeoBranchArray &other);
62 
63  // The equivalent of the copy constructor
64  static TGeoBranchArray *MakeCopyAt(const TGeoBranchArray &other, void *addr);
65 
66  // The equivalent of the destructor
67  static void ReleaseInstance(TGeoBranchArray *obj);
68 
69  // Assignment allowed
71 
72  // Fast copy based on memcpy to destination array
74 
75  // Equivalent of sizeof function
76  static size_t SizeOf(size_t maxlevel)
77  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(maxlevel)); }
78 
79  // Equivalent of sizeof function
80  static size_t SizeOfInstance(size_t maxlevel)
81  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(maxlevel)); }
82 
83  inline size_t SizeOf() const
84  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(fMaxLevel)); }
85 
86  // The data start should point to the address of the first data member,
87  // after the virtual table
88  void *DataStart() const {return (void*)&fLevel;}
89 
90  // The actual size of the data for an instance, excluding the virtual table
91  size_t DataSize() const {return SizeOf()-size_t(&fLevel)+(size_t)this;}
92 
93  // Update the internal addresses of n contiguous branch array objects, starting
94  // with this one
95  void UpdateArray(size_t nobj);
96 
97  // Destructor. Release instance to be called instead
98  virtual ~TGeoBranchArray() {}
99 
100  Bool_t operator ==(const TGeoBranchArray& other) const;
101  Bool_t operator !=(const TGeoBranchArray& other) const;
102  Bool_t operator >(const TGeoBranchArray& other) const;
103  Bool_t operator <(const TGeoBranchArray& other) const;
104  Bool_t operator >=(const TGeoBranchArray& other) const;
105  Bool_t operator <=(const TGeoBranchArray& other) const;
106 
107  void AddLevel(Int_t dindex);
109  virtual Int_t Compare(const TObject *obj) const;
110  void CleanMatrix();
111  TGeoNode **GetArray() const {return fArray;}
112  size_t GetLevel() const {return fLevel;}
113  size_t GetMaxLevel() const {return fMaxLevel;}
114  const TGeoHMatrix
115  *GetMatrix() const {return &fMatrix;}
116  TGeoNode *GetNode(Int_t level) const {return fArray[level];}
117  TGeoNode *GetCurrentNode() const {return fArray[fLevel];}
118  void GetPath(TString &path) const;
119  void Init(TGeoNode **branch, TGeoMatrix *global, Int_t level);
120  void InitFromNavigator(TGeoNavigator *nav);
121  virtual Bool_t IsSortable() const {return kTRUE;}
122  Bool_t IsOutside() const {return (fLevel<0)?kTRUE:kFALSE;}
123  virtual void Print(Option_t *option="") const;
124  static void Sort(Int_t n, TGeoBranchArray **array, Int_t *index, Bool_t down=kTRUE);
125  void UpdateNavigator(TGeoNavigator *nav) const;
126 
128 };
129 
130 struct compareBAasc {
132  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) < **(fData+i2);}
134 };
135 
138  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) > **(fData+i2);}
140 };
141 
142 #endif
Bool_t operator<=(const TGeoBranchArray &other) const
Is equal operator.
Bool_t operator==(const TGeoBranchArray &other) const
Is equal operator.
size_t DataSize() const
virtual Int_t Compare(const TObject *obj) const
Compare with other object of same type.
long long Long64_t
Definition: RtypesCore.h:69
TGeoBranchArray ** fData
const TGeoHMatrix * GetMatrix() const
static void ReleaseInstance(TGeoBranchArray *obj)
Releases the space allocated for the object.
const char Option_t
Definition: RtypesCore.h:62
#define BIT(n)
Definition: Rtypes.h:120
static size_t SizeOf(size_t maxlevel)
bool operator()(Int_t i1, Int_t i2)
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TGeoHMatrix fMatrix
Bool_t operator<(const TGeoBranchArray &other) const
Is equal operator.
TGeoNode * GetNode(Int_t level) const
size_t
Definition: TBuffer.cxx:28
void InitFromNavigator(TGeoNavigator *nav)
Init the branch array from current navigator state.
size_t SizeOf() const
size_t GetLevel() const
#define ClassDef(name, id)
Definition: Rtypes.h:254
size_t GetMaxLevel() const
TGeoBranchArray(TRootIOCtor *)
TGeoNode * GetCurrentNode() const
static TGeoBranchArray * MakeCopy(const TGeoBranchArray &other)
Make a copy of a branch array at the location (if indicated)
bool operator()(Int_t i1, Int_t i2)
compareBAdesc(TGeoBranchArray **d)
Bool_t operator>(const TGeoBranchArray &other) const
Is equal operator.
Bool_t operator!=(const TGeoBranchArray &other) const
Not equal operator.
void UpdateArray(size_t nobj)
Updates the internal addresses for n contiguous objects which have the same fMaxLevel Updates the int...
void * DataStart() const
virtual ~TGeoBranchArray()
void CleanMatrix()
Garbage collect the stored matrix.
static TGeoBranchArray * MakeCopyAt(const TGeoBranchArray &other, void *addr)
Make a copy of a branch array at the location (if indicated)
virtual Bool_t IsSortable() const
static Long64_t BinarySearch(Long64_t n, const TGeoBranchArray **array, TGeoBranchArray *value)
Binary search in an array of n pointers to branch arrays, to locate value.
Bool_t operator>=(const TGeoBranchArray &other) const
Is equal operator.
void Init(TGeoNode **branch, TGeoMatrix *global, Int_t level)
Init the branch array from an array of nodes, the global matrix for the path and the level...
compareBAasc(TGeoBranchArray **d)
static TGeoBranchArray * MakeInstance(size_t maxlevel)
Make an instance of the class which allocates the node array.
void UpdateNavigator(TGeoNavigator *nav) const
Update the navigator to reflect the branch.
void AddLevel(Int_t dindex)
Add and extra daughter to the current path array. No validity check performed !
TGeoBranchArray & operator=(const TGeoBranchArray &)
Assignment. Not valid anymore. Use TGeoBranchArray::MakeCopy instead.
TGeoNode ** GetArray() const
Mother of all ROOT objects.
Definition: TObject.h:58
static size_t SizeOfInstance(size_t maxlevel)
virtual void Print(Option_t *option="") const
Print branch information.
#define dest(otri, vertexptr)
Definition: triangle.c:1040
static TGeoBranchArray * MakeInstanceAt(size_t maxlevel, void *addr)
Make an instance of the class which allocates the node array.
Bool_t IsOutside() const
void CopyTo(TGeoBranchArray *dest)
Raw memcpy of the branch array content to an existing destination.
TGeoBranchArray(Int_t level)
static void Sort(Int_t n, TGeoBranchArray **array, Int_t *index, Bool_t down=kTRUE)
Sorting of an array of branch array pointers.
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
float value
Definition: math.cpp:443
const Int_t n
Definition: legend1.C:16
void GetPath(TString &path) const
Fill path pointed by the array.
TGeoNode * fRealArray[1]
[fMaxLevel+1] Array of nodes
TGeoNode ** fArray
TGeoBranchArray ** fData