]>
Commit | Line | Data |
---|---|---|
e118b27e | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | // | |
18 | // Class AliMUONGeometryStore | |
19 | // ------------------------------------- | |
20 | // The class contains the array of the detection elements, | |
21 | // which are sorted using the AliMUONVGeometryDEIndexing class. | |
22 | // The class provides fast access to detection element via DetElemId. | |
23 | // | |
24 | // Author: Ivana Hrivnacova, IPN Orsay | |
25 | ||
26 | #include <Riostream.h> | |
27 | #include <TGeoMatrix.h> | |
28 | ||
29 | #include "AliLog.h" | |
30 | ||
31 | #include "AliMUONGeometryStore.h" | |
e118b27e | 32 | |
33 | ClassImp(AliMUONGeometryStore) | |
34 | ||
35 | const Int_t AliMUONGeometryStore::fgkInitSize = 100; | |
984150e9 | 36 | const Int_t AliMUONGeometryStore::fgkCoefficient = 100; |
37 | ||
38 | // | |
39 | // static methods | |
40 | // | |
41 | ||
42 | //______________________________________________________________________________ | |
43 | Int_t AliMUONGeometryStore::GetModuleId(Int_t detElemId) | |
44 | { | |
45 | // Get module Id from detection element Id | |
46 | // --- | |
47 | ||
48 | return detElemId/fgkCoefficient - 1; | |
49 | } | |
50 | ||
51 | // | |
52 | // Constructor/destructor | |
53 | // | |
e118b27e | 54 | |
55 | //______________________________________________________________________________ | |
46829bae | 56 | AliMUONGeometryStore::AliMUONGeometryStore(Bool_t isOwner) |
e118b27e | 57 | : TObject(), |
46829bae | 58 | fObjects(fgkInitSize) |
e118b27e | 59 | { |
692de412 | 60 | /// Standard constructor |
e118b27e | 61 | |
62 | fObjects.SetOwner(isOwner); | |
63 | for (Int_t i=0; i<fgkInitSize; i++) fObjects[i] = 0; | |
64 | } | |
65 | ||
66 | //______________________________________________________________________________ | |
67 | AliMUONGeometryStore::AliMUONGeometryStore() | |
68 | : TObject(), | |
46829bae | 69 | fObjects() |
e118b27e | 70 | { |
692de412 | 71 | /// Default constructor |
e118b27e | 72 | } |
73 | ||
74 | //______________________________________________________________________________ | |
692de412 | 75 | AliMUONGeometryStore::AliMUONGeometryStore(const AliMUONGeometryStore& rhs) |
e118b27e | 76 | : TObject(rhs) |
77 | { | |
692de412 | 78 | /// Protected copy constructor |
79 | ||
e118b27e | 80 | AliFatal("Copy constructor is not implemented."); |
81 | } | |
82 | ||
83 | //______________________________________________________________________________ | |
b42a2af7 | 84 | AliMUONGeometryStore::~AliMUONGeometryStore() |
85 | { | |
692de412 | 86 | /// Destructor |
b42a2af7 | 87 | |
e118b27e | 88 | } |
89 | ||
90 | //______________________________________________________________________________ | |
91 | AliMUONGeometryStore& | |
92 | AliMUONGeometryStore::operator = (const AliMUONGeometryStore& rhs) | |
93 | { | |
692de412 | 94 | /// Protected assignment operator |
95 | ||
96 | // check assignement to self | |
e118b27e | 97 | if (this == &rhs) return *this; |
98 | ||
99 | AliFatal("Assignment operator is not implemented."); | |
100 | ||
101 | return *this; | |
102 | } | |
103 | ||
984150e9 | 104 | // |
105 | // private methods | |
106 | // | |
107 | ||
108 | //______________________________________________________________________________ | |
109 | Int_t AliMUONGeometryStore::GetDEIndex(Int_t detElemId) const | |
110 | { | |
111 | /// Returns the index of detector element specified by detElemId | |
112 | ||
113 | return detElemId - detElemId/fgkCoefficient*fgkCoefficient; | |
114 | } | |
115 | ||
e118b27e | 116 | // |
117 | // public methods | |
118 | // | |
119 | ||
120 | //______________________________________________________________________________ | |
121 | void AliMUONGeometryStore::Add(Int_t objectId, TObject* object) | |
122 | { | |
692de412 | 123 | /// Add detection element in the array |
124 | /// if detection element with the same Id is not yet present. | |
e118b27e | 125 | |
e118b27e | 126 | // Expand array if the init size has been reached |
984150e9 | 127 | Int_t index = GetDEIndex(objectId); |
e118b27e | 128 | while ( index >= fObjects.GetSize() ) { |
129 | Int_t size = fObjects.GetSize(); | |
130 | fObjects.Expand(size + fgkInitSize); | |
131 | for (Int_t i=size; i<fObjects.GetSize(); i++) fObjects[i] = 0; | |
132 | } | |
133 | ||
134 | // Add to the map | |
135 | if ( !Get(objectId, false) ) | |
136 | fObjects.AddAt(object, index); | |
137 | else | |
138 | AliWarning(Form("The detection element %d is already present", objectId)); | |
139 | } | |
140 | ||
141 | //______________________________________________________________________________ | |
142 | TObject* | |
143 | AliMUONGeometryStore::Get(Int_t objectId, Bool_t warn) const | |
144 | { | |
692de412 | 145 | /// Returns the object for the specified detector element Id |
e118b27e | 146 | |
984150e9 | 147 | Int_t index = GetDEIndex(objectId); |
e118b27e | 148 | |
149 | if ( index >= 0 && index < fObjects.GetEntriesFast() ) | |
150 | return (TObject*) fObjects.At(index); | |
151 | else { | |
152 | if (warn) AliWarning(Form("Index %d out of limits", index)); | |
153 | return 0; | |
154 | } | |
155 | } | |
156 | ||
157 | //______________________________________________________________________________ | |
158 | Int_t AliMUONGeometryStore::GetNofEntries() const | |
159 | { | |
692de412 | 160 | /// Return number of entries |
161 | /// Add check if the array is already filled | |
e118b27e | 162 | |
163 | return fObjects.GetEntriesFast(); | |
164 | } | |
165 | ||
166 | ||
167 | //______________________________________________________________________________ | |
168 | TObject* | |
169 | AliMUONGeometryStore::GetEntry(Int_t index) const | |
170 | { | |
692de412 | 171 | /// Return entry at specified index. |
172 | /// Add check if the array is already filled | |
e118b27e | 173 | |
174 | return (TObject*) fObjects.At(index); | |
175 | } |