]>
Commit | Line | Data |
---|---|---|
f0c62051 | 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 | // $MpId: AliMpDEStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $ | |
18 | // Category: management | |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
f0c62051 | 21 | // Class AliMpDEStore |
22 | // -------------------- | |
23 | // The container class for detection element objects | |
24 | // Authors: Ivana Hrivnacova, IPN Orsay | |
25 | // Laurent Aphecetche, Christian Finck, SUBATECH Nantes | |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
f0c62051 | 27 | |
b09247a2 | 28 | #include <cstdlib> |
f0c62051 | 29 | #include "AliMpDEStore.h" |
30 | #include "AliMpDEManager.h" | |
31 | #include "AliMpDetElement.h" | |
32 | #include "AliMpConstants.h" | |
33 | #include "AliMpFiles.h" | |
228fd720 | 34 | #include "AliMpDataStreams.h" |
f0c62051 | 35 | #include "AliMpHelper.h" |
f0c62051 | 36 | #include "AliMpConstants.h" |
630711ed | 37 | #include "AliMpExMapIterator.h" |
f0c62051 | 38 | |
39 | #include "AliLog.h" | |
40 | ||
41 | #include <Riostream.h> | |
a1e17193 | 42 | #include <TClass.h> |
f0c62051 | 43 | #include <TSystem.h> |
44 | #include <TObjString.h> | |
5954bf20 | 45 | #include <TObjArray.h> |
f0c62051 | 46 | #include <TMap.h> |
47 | ||
48 | /// \cond CLASSIMP | |
49 | ClassImp(AliMpDEStore) | |
50 | /// \endcond | |
51 | ||
52 | AliMpDEStore* AliMpDEStore::fgInstance = 0; | |
53 | const char AliMpDEStore::fgkCommentPrefix = '#'; | |
54 | ||
55 | // | |
56 | // static methods | |
57 | // | |
58 | ||
59 | //______________________________________________________________________________ | |
ac17c583 | 60 | AliMpDEStore* AliMpDEStore::Instance(Bool_t warn) |
f0c62051 | 61 | { |
62 | /// Create the DE store if it does not yet exist | |
63 | /// and return its instance | |
64 | ||
ac17c583 | 65 | if ( ! fgInstance && warn ) { |
66 | AliWarningClass("DE Store has not been loaded"); | |
67 | } | |
68 | ||
69 | return fgInstance; | |
70 | } | |
71 | ||
72 | //______________________________________________________________________________ | |
ab167304 | 73 | AliMpDEStore* AliMpDEStore::ReadData(const AliMpDataStreams& dataStreams, |
74 | Bool_t warn) | |
ac17c583 | 75 | { |
76 | /// Load the DE store data from ASCII data files | |
77 | /// and return its instance | |
78 | ||
79 | if ( fgInstance ) { | |
80 | if ( warn ) | |
81 | AliWarningClass("DE Store has been already loaded"); | |
82 | return fgInstance; | |
83 | } | |
84 | ||
ab167304 | 85 | if ( dataStreams.GetReadFromFiles() ) |
228fd720 | 86 | AliInfoClass("Reading DE Store from ASCII files."); |
ac17c583 | 87 | |
ab167304 | 88 | fgInstance = new AliMpDEStore(dataStreams); |
f0c62051 | 89 | return fgInstance; |
90 | } | |
91 | ||
92 | // | |
93 | // ctors, dtor | |
94 | // | |
95 | ||
96 | //______________________________________________________________________________ | |
ab167304 | 97 | AliMpDEStore::AliMpDEStore(const AliMpDataStreams& dataStreams) |
f0c62051 | 98 | : TObject(), |
630711ed | 99 | fDetElements() |
f0c62051 | 100 | { |
101 | /// Standard constructor | |
102 | ||
103 | AliDebug(1,""); | |
104 | fDetElements.SetOwner(true); | |
105 | ||
106 | // Create all detection elements | |
21027e5a | 107 | FillDEs(dataStreams); |
f0c62051 | 108 | } |
109 | ||
110 | //______________________________________________________________________________ | |
630711ed | 111 | AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor) |
f0c62051 | 112 | : TObject(), |
630711ed | 113 | fDetElements(ioCtor) |
f0c62051 | 114 | { |
115 | /// Constructor for IO | |
116 | ||
117 | AliDebug(1,""); | |
118 | ||
119 | fgInstance = this; | |
120 | } | |
121 | ||
122 | ||
123 | //______________________________________________________________________________ | |
124 | AliMpDEStore::~AliMpDEStore() | |
125 | { | |
126 | /// Destructor | |
127 | ||
128 | AliDebug(1,""); | |
129 | ||
130 | // Segmentations are deleted with fMpSegmentations | |
131 | // El cards arrays are deleted with fElCardsMap | |
132 | ||
133 | fgInstance = 0; | |
134 | } | |
135 | ||
136 | // | |
137 | // private methods | |
138 | // | |
139 | ||
140 | //______________________________________________________________________________ | |
141 | Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName) | |
142 | { | |
143 | /// Return true if the planeTypeName corresponds to a valid plane type | |
144 | ||
145 | if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) || | |
146 | planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) | |
147 | return true; | |
148 | ||
149 | return false; | |
150 | } | |
151 | ||
f0c62051 | 152 | //______________________________________________________________________________ |
153 | Bool_t | |
21027e5a | 154 | AliMpDEStore::ReadDENames(const AliMpDataStreams& dataStreams, |
155 | AliMp::StationType station, | |
4e51cfd2 | 156 | AliMq::Station12Type station12) |
f0c62051 | 157 | { |
158 | /// Read det element names for cath = 0 from the file specified by name | |
159 | /// and fill the map | |
160 | ||
228fd720 | 161 | // Open stream |
162 | istream& in | |
21027e5a | 163 | = dataStreams. |
4e51cfd2 | 164 | CreateDataStream(AliMpFiles::DENamesFilePath(station, station12)); |
f0c62051 | 165 | |
166 | // Read plane types per cathods | |
167 | // | |
168 | char line[80]; | |
169 | TString word; | |
170 | TString cathName1, cathName2; | |
171 | in >> word; | |
172 | while ( ! in.eof() && cathName1.Length() == 0 ) { | |
173 | if ( word[0] == '#' ) | |
174 | in.getline(line, 80); | |
175 | else { | |
176 | cathName1 = word; | |
177 | in >> cathName2; | |
178 | } | |
179 | in >> word; | |
180 | } | |
181 | ||
182 | Bool_t isCathNameDefined = false; | |
183 | if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) ) | |
184 | isCathNameDefined = true; | |
185 | ||
186 | // Read DE names | |
187 | // | |
188 | Int_t detElemId; | |
189 | TString name, name0, name1, name2; | |
190 | AliMp::PlaneType planeForCathode[2]; | |
191 | ||
192 | while ( ! in.eof() ) | |
193 | { | |
194 | if ( word[0] == '#' ) | |
195 | { | |
196 | in.getline(line, 80); | |
197 | } | |
198 | else | |
199 | { | |
200 | detElemId = word.Atoi(); | |
201 | in >> name; | |
202 | in >> name0; | |
203 | // warning : important to check non bending first (=nbp), | |
204 | // as bp is contained within nbp... | |
205 | if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) ) | |
206 | { | |
207 | planeForCathode[0] = AliMp::kNonBendingPlane; | |
208 | } | |
209 | else | |
210 | { | |
211 | planeForCathode[0] = AliMp::kBendingPlane; | |
212 | } | |
213 | ||
214 | if ( !isCathNameDefined ) | |
215 | { | |
216 | in >> name2; | |
217 | name1 = name0; | |
218 | Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator()); | |
219 | name0 = name1(0,pos); | |
220 | ||
221 | // Other cathode is other plane... | |
222 | planeForCathode[1] = OtherPlaneType(planeForCathode[0]); | |
223 | } | |
224 | else | |
225 | { | |
226 | name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1; | |
227 | name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2; | |
228 | if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) ) | |
229 | { | |
230 | planeForCathode[1] = AliMp::kNonBendingPlane; | |
231 | } | |
232 | else | |
233 | { | |
234 | planeForCathode[1] = AliMp::kBendingPlane; | |
235 | } | |
236 | } | |
237 | ||
238 | if ( planeForCathode[0]==planeForCathode[1] ) | |
239 | { | |
240 | AliFatalClass(Form("Got the same cathode type for both planes" | |
241 | " of DetElemId %d",detElemId)); | |
242 | } | |
243 | ||
630711ed | 244 | AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]); |
245 | ||
f0c62051 | 246 | if ( ! fDetElements.GetValue(detElemId) ) |
247 | { | |
248 | AliDebugClassStream(3) | |
249 | << "Adding DE name " << detElemId << " " << name << endl; | |
250 | fDetElements.Add(detElemId, detElement); | |
f0c62051 | 251 | } |
252 | else | |
253 | { | |
254 | AliWarningClassStream() | |
255 | << "Det element " << detElemId << " " << name << " already defined." << endl; | |
256 | } | |
257 | } | |
258 | in >> word; | |
259 | } | |
f0c62051 | 260 | |
228fd720 | 261 | delete ∈ |
262 | ||
f0c62051 | 263 | return true; |
264 | } | |
265 | ||
266 | //______________________________________________________________________________ | |
21027e5a | 267 | void AliMpDEStore::FillDEs(const AliMpDataStreams& dataStreams) |
f0c62051 | 268 | { |
269 | /// Fill DE names from files | |
270 | AliDebugClass(2,""); | |
21027e5a | 271 | Bool_t result1 = ReadDENames(dataStreams, AliMp::kStation12, AliMq::kStation1); |
272 | Bool_t result2 = ReadDENames(dataStreams, AliMp::kStation12, AliMq::kStation2); | |
273 | Bool_t result3 = ReadDENames(dataStreams, AliMp::kStation345); | |
274 | Bool_t result4 = ReadDENames(dataStreams, AliMp::kStationTrigger); | |
f0c62051 | 275 | |
276 | Bool_t result = result1 && result2 && result3 && result4; | |
277 | if ( ! result ) { | |
278 | AliErrorClassStream() << "Error in reading DE names files" << endl; | |
279 | } | |
183279c1 | 280 | AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize())); |
f0c62051 | 281 | } |
282 | ||
283 | // | |
284 | // public methods | |
285 | // | |
286 | ||
287 | ||
288 | //______________________________________________________________________________ | |
289 | AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const | |
290 | { | |
291 | /// Return det element for given detElemId | |
292 | ||
293 | AliMpDetElement* detElement | |
294 | = (AliMpDetElement*)fDetElements.GetValue(detElemId); | |
295 | ||
296 | if ( ! detElement && warn ) { | |
297 | AliErrorClassStream() | |
298 | << "Detection element " << detElemId << " not defined." << endl; | |
299 | } | |
300 | ||
301 | return detElement; | |
302 | } | |
303 | ||
2eee683c | 304 | //______________________________________________________________________________ |
305 | AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const | |
306 | { | |
307 | /// Return det element for given deName | |
308 | ||
630711ed | 309 | TIter next(fDetElements.CreateIterator()); |
310 | AliMpDetElement* detElement; | |
311 | ||
312 | while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) ) | |
313 | { | |
314 | ||
2eee683c | 315 | if (deName.CompareTo(detElement->GetDEName()) == 0) |
316 | ||
317 | return detElement; | |
318 | } | |
319 | ||
320 | if (warn) { | |
321 | AliErrorClassStream() | |
322 | << "Detection element with name" << deName.Data() << " not defined." << endl; | |
323 | } | |
324 | ||
325 | return 0x0; | |
326 | ||
327 | } |