1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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.
24 // Author: Ivana Hrivnacova, IPN Orsay
26 #include <Riostream.h>
27 #include <TGeoMatrix.h>
31 #include "AliMUONGeometryStore.h"
33 const Int_t AliMUONGeometryStore::fgkInitSize = 100;
34 const Int_t AliMUONGeometryStore::fgkCoefficient = 100;
37 ClassImp(AliMUONGeometryStore)
44 //______________________________________________________________________________
45 Int_t AliMUONGeometryStore::GetModuleId(Int_t detElemId)
47 /// Get module Id from detection element Id
49 return detElemId/fgkCoefficient - 1;
53 // Constructor/destructor
56 //______________________________________________________________________________
57 AliMUONGeometryStore::AliMUONGeometryStore(Bool_t isOwner)
61 /// Standard constructor
63 fObjects.SetOwner(isOwner);
64 for (Int_t i=0; i<fgkInitSize; i++) fObjects[i] = 0;
67 //______________________________________________________________________________
68 AliMUONGeometryStore::AliMUONGeometryStore()
72 /// Default constructor
75 //______________________________________________________________________________
76 AliMUONGeometryStore::~AliMUONGeometryStore()
86 //______________________________________________________________________________
87 Int_t AliMUONGeometryStore::GetDEIndex(Int_t detElemId) const
89 /// Return the index of detector element specified by detElemId
91 return detElemId - detElemId/fgkCoefficient*fgkCoefficient;
98 //______________________________________________________________________________
99 void AliMUONGeometryStore::Add(Int_t objectId, TObject* object)
101 /// Add detection element in the array
102 /// if detection element with the same Id is not yet present.
104 // Expand array if the init size has been reached
105 Int_t index = GetDEIndex(objectId);
106 while ( index >= fObjects.GetSize() ) {
107 Int_t size = fObjects.GetSize();
108 fObjects.Expand(size + fgkInitSize);
109 for (Int_t i=size; i<fObjects.GetSize(); i++) fObjects[i] = 0;
113 if ( !Get(objectId, false) )
114 fObjects.AddAt(object, index);
116 AliWarning(Form("The detection element %d is already present", objectId));
119 //______________________________________________________________________________
121 AliMUONGeometryStore::Get(Int_t objectId, Bool_t warn) const
123 /// Return the object for the specified detector element Id
125 Int_t index = GetDEIndex(objectId);
127 if ( index >= 0 && index < fObjects.GetEntriesFast() )
128 return (TObject*) fObjects.At(index);
130 if (warn) AliWarning(Form("Index %d out of limits", index));
135 //______________________________________________________________________________
136 Int_t AliMUONGeometryStore::GetNofEntries() const
138 /// Return number of entries.
139 /// \todo Add check if the array is already filled
141 return fObjects.GetEntriesFast();
145 //______________________________________________________________________________
147 AliMUONGeometryStore::GetEntry(Int_t index) const
149 /// Return entry at specified index.
150 /// \todo Add check if the array is already filled
152 return (TObject*) fObjects.At(index);