Logo ROOT  
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
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 {
120  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) < **(fData+i2);}
122 };
123 
126  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) > **(fData+i2);}
128 };
129 
130 #endif
TGeoBranchArray::MakeInstanceAt
static TGeoBranchArray * MakeInstanceAt(size_t maxlevel, void *addr)
Make an instance of the class which allocates the node array.
Definition: TGeoBranchArray.cxx:72
TGeoBranchArray::CopyTo
void CopyTo(TGeoBranchArray *dest)
Raw memcpy of the branch array content to an existing destination.
Definition: TGeoBranchArray.cxx:119
n
const Int_t n
Definition: legend1.C:16
TGeoBranchArray::UpdateNavigator
void UpdateNavigator(TGeoNavigator *nav) const
Update the navigator to reflect the branch.
Definition: TGeoBranchArray.cxx:388
TGeoBranchArray::SizeOf
static size_t SizeOf(size_t maxlevel)
Definition: TGeoBranchArray.h:64
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
TGeoBranchArray::fMaxLevel
Int_t fMaxLevel
Definition: TGeoBranchArray.h:26
TGeoBranchArray::operator=
TGeoBranchArray & operator=(const TGeoBranchArray &)
Assignment. Not valid anymore. Use TGeoBranchArray::MakeCopy instead.
Definition: TGeoBranchArray.cxx:173
TGeoBranchArray::MakeCopy
static TGeoBranchArray * MakeCopy(const TGeoBranchArray &other)
Make a copy of a branch array at the location (if indicated)
Definition: TGeoBranchArray.cxx:85
Option_t
const char Option_t
Definition: RtypesCore.h:66
TGeoBranchArray::SizeOf
size_t SizeOf() const
Definition: TGeoBranchArray.h:71
dest
#define dest(otri, vertexptr)
Definition: triangle.c:1040
TGeoBranchArray::DataSize
size_t DataSize() const
Definition: TGeoBranchArray.h:79
compareBAdesc::compareBAdesc
compareBAdesc(TGeoBranchArray **d)
Definition: TGeoBranchArray.h:125
TGeoBranchArray::operator==
Bool_t operator==(const TGeoBranchArray &other) const
Is equal operator.
Definition: TGeoBranchArray.cxx:210
TGeoBranchArray::InitFromNavigator
void InitFromNavigator(TGeoNavigator *nav)
Init the branch array from current navigator state.
Definition: TGeoBranchArray.cxx:334
Long64_t
long long Long64_t
Definition: RtypesCore.h:80
TGeoBranchArray::TGeoBranchArray
TGeoBranchArray(Int_t level)
Constructor. Allocates the array with a size given by level.
Definition: TGeoBranchArray.cxx:41
TGeoBranchArray::IsOutside
Bool_t IsOutside() const
Definition: TGeoBranchArray.h:110
Int_t
int Int_t
Definition: RtypesCore.h:45
TGeoBranchArray::TGeoBranchArray
TGeoBranchArray(TRootIOCtor *)
Definition: TGeoBranchArray.h:40
TGeoBranchArray::CleanMatrix
void CleanMatrix()
Garbage collect the stored matrix.
Definition: TGeoBranchArray.cxx:312
TGeoBranchArray::EGeoBATypes
EGeoBATypes
Definition: TGeoBranchArray.h:35
compareBAdesc::fData
TGeoBranchArray ** fData
Definition: TGeoBranchArray.h:127
TString
Basic string class.
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGeoNode
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition: TGeoNode.h:41
TGeoBranchArray::fMatrix
TGeoHMatrix fMatrix
Definition: TGeoBranchArray.h:27
compareBAdesc
Definition: TGeoBranchArray.h:124
compareBAasc
Definition: TGeoBranchArray.h:118
TGeoBranchArray::UpdateArray
void UpdateArray(size_t nobj)
Updates the internal addresses for n contiguous objects which have the same fMaxLevel Updates the int...
Definition: TGeoBranchArray.cxx:139
bool
TGeoBranchArray::operator!=
Bool_t operator!=(const TGeoBranchArray &other) const
Not equal operator.
Definition: TGeoBranchArray.cxx:220
compareBAasc::operator()
bool operator()(Int_t i1, Int_t i2)
Definition: TGeoBranchArray.h:120
TGeoBranchArray::GetNode
TGeoNode * GetNode(Int_t level) const
Definition: TGeoBranchArray.h:104
TGeoBranchArray::operator<
Bool_t operator<(const TGeoBranchArray &other) const
Is equal operator.
Definition: TGeoBranchArray.cxx:240
TGeoHMatrix
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition: TGeoMatrix.h:421
TGeoBranchArray::SizeOfInstance
static size_t SizeOfInstance(size_t maxlevel)
Definition: TGeoBranchArray.h:68
TGeoBranchArray::GetMaxLevel
size_t GetMaxLevel() const
Definition: TGeoBranchArray.h:101
TGeoBranchArray::Print
virtual void Print(Option_t *option="") const
Print branch information.
Definition: TGeoBranchArray.cxx:365
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
TRootIOCtor
Definition: TRootIOCtor.h:33
TGeoBranchArray::DataStart
void * DataStart() const
Definition: TGeoBranchArray.h:76
BIT
#define BIT(n)
Definition: Rtypes.h:85
TGeoBranchArray::MakeInstance
static TGeoBranchArray * MakeInstance(size_t maxlevel)
Make an instance of the class which allocates the node array.
Definition: TGeoBranchArray.cxx:55
TGeoBranchArray::operator<=
Bool_t operator<=(const TGeoBranchArray &other) const
Is equal operator.
Definition: TGeoBranchArray.cxx:260
TGeoBranchArray::GetArray
TGeoNode ** GetArray() const
Definition: TGeoBranchArray.h:99
TGeoBranchArray::GetMatrix
const TGeoHMatrix * GetMatrix() const
Definition: TGeoBranchArray.h:103
TGeoBranchArray::GetCurrentNode
TGeoNode * GetCurrentNode() const
Definition: TGeoBranchArray.h:105
TGeoBranchArray::AddLevel
void AddLevel(Int_t dindex)
Add and extra daughter to the current path array. No validity check performed !
Definition: TGeoBranchArray.cxx:185
TGeoBranchArray::fRealArray
TGeoNode * fRealArray[1]
[fMaxLevel+1] Array of nodes
Definition: TGeoBranchArray.h:29
TGeoMatrix.h
TGeoBranchArray::GetPath
void GetPath(TString &path) const
Fill path pointed by the array.
Definition: TGeoBranchArray.cxx:352
TGeoBranchArray::operator>=
Bool_t operator>=(const TGeoBranchArray &other) const
Is equal operator.
Definition: TGeoBranchArray.cxx:250
TGeoBranchArray::MakeCopyAt
static TGeoBranchArray * MakeCopyAt(const TGeoBranchArray &other, void *addr)
Make a copy of a branch array at the location (if indicated)
Definition: TGeoBranchArray.cxx:103
TGeoBranchArray::BinarySearch
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.
Definition: TGeoBranchArray.cxx:271
TGeoNavigator
Class providing navigation API for TGeo geometries.
Definition: TGeoNavigator.h:34
TGeoMatrix
Geometrical transformation package.
Definition: TGeoMatrix.h:41
TObject.h
compareBAasc::fData
TGeoBranchArray ** fData
Definition: TGeoBranchArray.h:121
TGeoBranchArray::IsSortable
virtual Bool_t IsSortable() const
Definition: TGeoBranchArray.h:109
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGeoBranchArray::Sort
static void Sort(Int_t n, TGeoBranchArray **array, Int_t *index, Bool_t down=kTRUE)
Sorting of an array of branch array pointers.
Definition: TGeoBranchArray.cxx:375
TGeoBranchArray::Compare
virtual Int_t Compare(const TObject *obj) const
Compare with other object of same type.
Definition: TGeoBranchArray.cxx:292
compareBAasc::compareBAasc
compareBAasc(TGeoBranchArray **d)
Definition: TGeoBranchArray.h:119
d
#define d(i)
Definition: RSha256.hxx:102
TGeoBranchArray::~TGeoBranchArray
virtual ~TGeoBranchArray()
Definition: TGeoBranchArray.h:86
TGeoBranchArray::fArray
TGeoNode ** fArray
Definition: TGeoBranchArray.h:28
compareBAdesc::operator()
bool operator()(Int_t i1, Int_t i2)
Definition: TGeoBranchArray.h:126
TGeoBranchArray::GetLevel
size_t GetLevel() const
Definition: TGeoBranchArray.h:100
TGeoBranchArray
An array of daughter indices making a geometry path.
Definition: TGeoBranchArray.h:23
TGeoBranchArray::kBASelfAlloc
@ kBASelfAlloc
Definition: TGeoBranchArray.h:36
TGeoBranchArray::operator>
Bool_t operator>(const TGeoBranchArray &other) const
Is equal operator.
Definition: TGeoBranchArray.cxx:230
TGeoBranchArray::fLevel
Int_t fLevel
Definition: TGeoBranchArray.h:25
int
TGeoBranchArray::ReleaseInstance
static void ReleaseInstance(TGeoBranchArray *obj)
Releases the space allocated for the object.
Definition: TGeoBranchArray.cxx:128
TGeoBranchArray::Init
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.
Definition: TGeoBranchArray.cxx:320