Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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
58  TGeoBranchArray& operator=(const TGeoBranchArray&);
59 
60  // Fast copy based on memcpy to destination array
61  void CopyTo(TGeoBranchArray *dest);
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 
115  ClassDef(TGeoBranchArray, 4)
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);}
121  TGeoBranchArray **fData;
122 };
123 
124 struct compareBAdesc {
125  compareBAdesc(TGeoBranchArray **d) : fData(d) {}
126  bool operator ()(Int_t i1, Int_t i2) {return **(fData+i1) > **(fData+i2);}
127  TGeoBranchArray **fData;
128 };
129 
130 #endif