Logo ROOT   6.12/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 #include "TObject.h"
16 
17 #include "TGeoMatrix.h"
18 
19 class TGeoNavigator;
20 class TGeoNode;
21 
22 class TGeoBranchArray : public TObject
23 {
24 protected:
25  Int_t fLevel; // Branch depth
26  Int_t fMaxLevel; // Array length
27  TGeoHMatrix fMatrix; // Global matrix (owned)
28  TGeoNode **fArray; //![fMaxLevel+1] Array of nodes
29  TGeoNode *fRealArray[1]; // Beginning address of the array of nodes
30 
31 private:
32  TGeoBranchArray(Int_t level); // not allowed
33  TGeoBranchArray(const TGeoBranchArray&); // not allowed
34 public:
35  enum EGeoBATypes {
36  kBASelfAlloc = BIT(14) // does self allocation or not
37  };
38  // This replaces the dummy constructor to make sure that I/O can be
39  // performed while the user is only allowed to use the static maker
40  TGeoBranchArray(TRootIOCtor*) : TObject(), fLevel(0), fMaxLevel(0), fMatrix(), fArray(0) { fRealArray[0] = nullptr; }
41 
42  // The static maker to be use to create an instance of the branch array
43  static TGeoBranchArray *MakeInstance(size_t maxlevel);
44 
45  // The static maker to be use to create an instance of the branch array
46  static TGeoBranchArray *MakeInstanceAt(size_t maxlevel, void *addr);
47 
48  // The equivalent of the copy constructor
49  static TGeoBranchArray *MakeCopy(const TGeoBranchArray &other);
50 
51  // The equivalent of the copy constructor
52  static TGeoBranchArray *MakeCopyAt(const TGeoBranchArray &other, void *addr);
53 
54  // The equivalent of the destructor
55  static void ReleaseInstance(TGeoBranchArray *obj);
56 
57  // Assignment allowed
59 
60  // Fast copy based on memcpy to destination array
62 
63  // Equivalent of sizeof function
64  static size_t SizeOf(size_t maxlevel)
65  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(maxlevel)); }
66 
67  // Equivalent of sizeof function
68  static size_t SizeOfInstance(size_t maxlevel)
69  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(maxlevel)); }
70 
71  inline size_t SizeOf() const
72  { return (sizeof(TGeoBranchArray)+sizeof(TGeoBranchArray*)*(fMaxLevel)); }
73 
74  // The data start should point to the address of the first data member,
75  // after the virtual table
76  void *DataStart() const {return (void*)&fLevel;}
77 
78  // The actual size of the data for an instance, excluding the virtual table
79  size_t DataSize() const {return SizeOf()-size_t(&fLevel)+(size_t)this;}
80 
81  // Update the internal addresses of n contiguous branch array objects, starting
82  // with this one
83  void UpdateArray(size_t nobj);
84 
85  // Destructor. Release instance to be called instead
86  virtual ~TGeoBranchArray() {}
87 
88  Bool_t operator ==(const TGeoBranchArray& other) const;
89  Bool_t operator !=(const TGeoBranchArray& other) const;
90  Bool_t operator >(const TGeoBranchArray& other) const;
91  Bool_t operator <(const TGeoBranchArray& other) const;
92  Bool_t operator >=(const TGeoBranchArray& other) const;
93  Bool_t operator <=(const TGeoBranchArray& other) const;
94 
95  void AddLevel(Int_t dindex);
96  static Long64_t BinarySearch(Long64_t n, const TGeoBranchArray **array, TGeoBranchArray *value);
97  virtual Int_t Compare(const TObject *obj) const;
98  void CleanMatrix();
99  TGeoNode **GetArray() const {return fArray;}
100  size_t GetLevel() const {return fLevel;}
101  size_t GetMaxLevel() const {return fMaxLevel;}
102  const TGeoHMatrix
103  *GetMatrix() const {return &fMatrix;}
104  TGeoNode *GetNode(Int_t level) const {return fArray[level];}
105  TGeoNode *GetCurrentNode() const {return fArray[fLevel];}
106  void GetPath(TString &path) const;
107  void Init(TGeoNode **branch, TGeoMatrix *global, Int_t level);
108  void InitFromNavigator(TGeoNavigator *nav);
109  virtual Bool_t IsSortable() const {return kTRUE;}
110  Bool_t IsOutside() const {return (fLevel<0)?kTRUE:kFALSE;}
111  virtual void Print(Option_t *option="") const;
112  static void Sort(Int_t n, TGeoBranchArray **array, Int_t *index, Bool_t down=kTRUE);
113  void UpdateNavigator(TGeoNavigator *nav) const;
114 
116 };
117 
118 struct compareBAasc {
119  compareBAasc(TGeoBranchArray **d) : fData(d) {}
120  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) < **(fData+i2);}
122 };
123 
125  compareBAdesc(TGeoBranchArray **d) : fData(d) {}
126  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) > **(fData+i2);}
128 };
129 
130 #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:78
static size_t SizeOf(size_t maxlevel)
size_t GetLevel() const
Basic string class.
Definition: TString.h:125
Matrix class used for computing global transformations Should NOT be used for node definition...
Definition: TGeoMatrix.h:420
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.
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.
TRObject operator()(const T1 &t1) const
const TGeoHMatrix * GetMatrix() const
#define ClassDef(name, id)
Definition: Rtypes.h:320
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
const Bool_t kFALSE
Definition: RtypesCore.h:88
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:33
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition: TGeoNode.h:39
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
TGeoNode * GetCurrentNode() const
const Bool_t kTRUE
Definition: RtypesCore.h:87
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