Logo ROOT   6.08/07
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 class TGeoNavigator;
24 class TGeoNode;
25 
26 class TGeoBranchArray : public TObject
27 {
28 protected:
29  Int_t fLevel; // Branch depth
30  Int_t fMaxLevel; // Array length
31  TGeoHMatrix fMatrix; // Global matrix (owned)
32  TGeoNode **fArray; //![fMaxLevel+1] Array of nodes
33  TGeoNode *fRealArray[1]; // Beginning address of the array of nodes
34 
35 private:
36  TGeoBranchArray(Int_t level); // not allowed
37  TGeoBranchArray(const TGeoBranchArray&); // not allowed
38 public:
39  enum EGeoBATypes {
40  kBASelfAlloc = BIT(14) // does self allocation or not
41  };
42  // This replaces the dummy constructor to make sure that I/O can be
43  // performed while the user is only allowed to use the static maker
44  TGeoBranchArray(TRootIOCtor*) : TObject(), fLevel(0), fMaxLevel(0), fMatrix(), fArray(0) {}
45 
46  // The static maker to be use to create an instance of the branch array
47  static TGeoBranchArray *MakeInstance(size_t maxlevel);
48 
49  // The static maker to be use to create an instance of the branch array
50  static TGeoBranchArray *MakeInstanceAt(size_t maxlevel, void *addr);
51 
52  // The equivalent of the copy constructor
53  static TGeoBranchArray *MakeCopy(const TGeoBranchArray &other);
54 
55  // The equivalent of the copy constructor
56  static TGeoBranchArray *MakeCopyAt(const TGeoBranchArray &other, void *addr);
57 
58  // The equivalent of the destructor
59  static void ReleaseInstance(TGeoBranchArray *obj);
60 
61  // Assignment allowed
63 
64  // Fast copy based on memcpy to destination array
66 
67  // Equivalent of sizeof function
68  static size_t SizeOf(size_t maxlevel)
69  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(maxlevel)); }
70 
71  // Equivalent of sizeof function
72  static size_t SizeOfInstance(size_t maxlevel)
73  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(maxlevel)); }
74 
75  inline size_t SizeOf() const
76  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(fMaxLevel)); }
77 
78  // The data start should point to the address of the first data member,
79  // after the virtual table
80  void *DataStart() const {return (void*)&fLevel;}
81 
82  // The actual size of the data for an instance, excluding the virtual table
83  size_t DataSize() const {return SizeOf()-size_t(&fLevel)+(size_t)this;}
84 
85  // Update the internal addresses of n contiguous branch array objects, starting
86  // with this one
87  void UpdateArray(size_t nobj);
88 
89  // Destructor. Release instance to be called instead
90  virtual ~TGeoBranchArray() {}
91 
92  Bool_t operator ==(const TGeoBranchArray& other) const;
93  Bool_t operator !=(const TGeoBranchArray& other) const;
94  Bool_t operator >(const TGeoBranchArray& other) const;
95  Bool_t operator <(const TGeoBranchArray& other) const;
96  Bool_t operator >=(const TGeoBranchArray& other) const;
97  Bool_t operator <=(const TGeoBranchArray& other) const;
98 
99  void AddLevel(Int_t dindex);
100  static Long64_t BinarySearch(Long64_t n, const TGeoBranchArray **array, TGeoBranchArray *value);
101  virtual Int_t Compare(const TObject *obj) const;
102  void CleanMatrix();
103  TGeoNode **GetArray() const {return fArray;}
104  size_t GetLevel() const {return fLevel;}
105  size_t GetMaxLevel() const {return fMaxLevel;}
106  const TGeoHMatrix
107  *GetMatrix() const {return &fMatrix;}
108  TGeoNode *GetNode(Int_t level) const {return fArray[level];}
109  TGeoNode *GetCurrentNode() const {return fArray[fLevel];}
110  void GetPath(TString &path) const;
111  void Init(TGeoNode **branch, TGeoMatrix *global, Int_t level);
112  void InitFromNavigator(TGeoNavigator *nav);
113  virtual Bool_t IsSortable() const {return kTRUE;}
114  Bool_t IsOutside() const {return (fLevel<0)?kTRUE:kFALSE;}
115  virtual void Print(Option_t *option="") const;
116  static void Sort(Int_t n, TGeoBranchArray **array, Int_t *index, Bool_t down=kTRUE);
117  void UpdateNavigator(TGeoNavigator *nav) const;
118 
120 };
121 
122 struct compareBAasc {
123  compareBAasc(TGeoBranchArray **d) : fData(d) {}
124  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) < **(fData+i2);}
126 };
127 
129  compareBAdesc(TGeoBranchArray **d) : fData(d) {}
130  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) > **(fData+i2);}
132 };
133 
134 #endif
long long Long64_t
Definition: RtypesCore.h:69
TGeoBranchArray ** fData
static void ReleaseInstance(TGeoBranchArray *obj)
Releases the space allocated for the object.
const char Option_t
Definition: RtypesCore.h:62
Geometrical transformation package.
Definition: TGeoMatrix.h:40
Bool_t operator!=(const TGeoBranchArray &other) const
Not equal operator.
#define BIT(n)
Definition: Rtypes.h:120
static size_t SizeOf(size_t maxlevel)
size_t GetLevel() const
Basic string class.
Definition: TString.h:137
Matrix class used for computing global transformations Should NOT be used for node definition...
Definition: TGeoMatrix.h:410
int Int_t
Definition: RtypesCore.h:41
size_t GetMaxLevel() const
bool Bool_t
Definition: RtypesCore.h:59
Bool_t operator>(const TGeoBranchArray &other) const
Is equal operator.
const Bool_t kFALSE
Definition: Rtypes.h:92
size_t DataSize() const
TGeoHMatrix fMatrix
Bool_t operator==(const TGeoBranchArray &other) const
Is equal operator.
void InitFromNavigator(TGeoNavigator *nav)
Init the branch array from current navigator state.
const TGeoHMatrix * GetMatrix() const
#define ClassDef(name, id)
Definition: Rtypes.h:254
TGeoBranchArray(TRootIOCtor *)
Bool_t operator<(const TGeoBranchArray &other) const
Is equal operator.
static TGeoBranchArray * MakeCopy(const TGeoBranchArray &other)
Make a copy of a branch array at the location (if indicated)
compareBAdesc(TGeoBranchArray **d)
virtual void Print(Option_t *option="") const
Print branch information.
virtual Bool_t IsSortable() const
Bool_t operator<=(const TGeoBranchArray &other) const
Is equal operator.
void UpdateArray(size_t nobj)
Updates the internal addresses for n contiguous objects which have the same fMaxLevel Updates the int...
virtual ~TGeoBranchArray()
void GetPath(TString &path) const
Fill path pointed by the array.
Bool_t operator>=(const TGeoBranchArray &other) const
Is equal operator.
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)
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.
TGeoNode * GetNode(Int_t level) const
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.
TGeoNode ** GetArray() const
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.
Mother of all ROOT objects.
Definition: TObject.h:37
Class providing navigation API for TGeo geometries.
Definition: TGeoNavigator.h:37
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition: TGeoNode.h:51
static size_t SizeOfInstance(size_t maxlevel)
#define dest(otri, vertexptr)
Definition: triangle.c:1040
An array of daughter indices making a geometry path.
void * DataStart() const
static TGeoBranchArray * MakeInstanceAt(size_t maxlevel, void *addr)
Make an instance of the class which allocates the node array.
void CopyTo(TGeoBranchArray *dest)
Raw memcpy of the branch array content to an existing destination.
TGeoBranchArray(Int_t level)
Constructor. Allocates the array with a size given by level.
void UpdateNavigator(TGeoNavigator *nav) const
Update the navigator to reflect the branch.
static void Sort(Int_t n, TGeoBranchArray **array, Int_t *index, Bool_t down=kTRUE)
Sorting of an array of branch array pointers.
Bool_t IsOutside() const
const Bool_t kTRUE
Definition: Rtypes.h:91
TGeoNode * GetCurrentNode() const
virtual Int_t Compare(const TObject *obj) const
Compare with other object of same type.
const Int_t n
Definition: legend1.C:16
TGeoNode * fRealArray[1]
[fMaxLevel+1] Array of nodes
size_t SizeOf() const
TGeoNode ** fArray
TGeoBranchArray ** fData