]>
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 | |
28 | #include "AliMpDEStore.h" | |
29 | #include "AliMpDEManager.h" | |
30 | #include "AliMpDetElement.h" | |
31 | #include "AliMpConstants.h" | |
32 | #include "AliMpFiles.h" | |
33 | #include "AliMpHelper.h" | |
34 | #include "AliMpIntPair.h" | |
35 | #include "AliMpConstants.h" | |
36 | ||
37 | #include "AliLog.h" | |
38 | ||
39 | #include <Riostream.h> | |
a1e17193 | 40 | #include <TClass.h> |
f0c62051 | 41 | #include <TSystem.h> |
42 | #include <TObjString.h> | |
5954bf20 | 43 | #include <TObjArray.h> |
f0c62051 | 44 | #include <TMap.h> |
45 | ||
46 | /// \cond CLASSIMP | |
47 | ClassImp(AliMpDEStore) | |
48 | /// \endcond | |
49 | ||
50 | AliMpDEStore* AliMpDEStore::fgInstance = 0; | |
51 | const char AliMpDEStore::fgkCommentPrefix = '#'; | |
52 | ||
53 | // | |
54 | // static methods | |
55 | // | |
56 | ||
57 | //______________________________________________________________________________ | |
58 | AliMpDEStore* AliMpDEStore::Instance() | |
59 | { | |
60 | /// Create the DE store if it does not yet exist | |
61 | /// and return its instance | |
62 | ||
63 | if ( ! fgInstance ) | |
64 | fgInstance = new AliMpDEStore(); | |
65 | ||
66 | return fgInstance; | |
67 | } | |
68 | ||
69 | // | |
70 | // ctors, dtor | |
71 | // | |
72 | ||
73 | //______________________________________________________________________________ | |
74 | AliMpDEStore::AliMpDEStore() | |
75 | : TObject(), | |
76 | fDetElements(true) | |
77 | { | |
78 | /// Standard constructor | |
79 | ||
80 | AliDebug(1,""); | |
81 | fDetElements.SetOwner(true); | |
82 | ||
83 | // Create all detection elements | |
84 | FillDEs(); | |
85 | } | |
86 | ||
87 | //______________________________________________________________________________ | |
88 | AliMpDEStore::AliMpDEStore(TRootIOCtor* /*ioCtor*/) | |
89 | : TObject(), | |
90 | fDetElements() | |
91 | { | |
92 | /// Constructor for IO | |
93 | ||
94 | AliDebug(1,""); | |
95 | ||
96 | fgInstance = this; | |
97 | } | |
98 | ||
99 | ||
100 | //______________________________________________________________________________ | |
101 | AliMpDEStore::~AliMpDEStore() | |
102 | { | |
103 | /// Destructor | |
104 | ||
105 | AliDebug(1,""); | |
106 | ||
107 | // Segmentations are deleted with fMpSegmentations | |
108 | // El cards arrays are deleted with fElCardsMap | |
109 | ||
110 | fgInstance = 0; | |
111 | } | |
112 | ||
113 | // | |
114 | // private methods | |
115 | // | |
116 | ||
117 | //______________________________________________________________________________ | |
118 | Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName) | |
119 | { | |
120 | /// Return true if the planeTypeName corresponds to a valid plane type | |
121 | ||
122 | if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) || | |
123 | planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) | |
124 | return true; | |
125 | ||
126 | return false; | |
127 | } | |
128 | ||
129 | //______________________________________________________________________________ | |
130 | AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName) | |
131 | { | |
132 | /// Return plane type for the given planeTypeName \n | |
133 | /// Fatal error if planeTypeName is wrong | |
134 | ||
135 | if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ) | |
136 | return AliMp::kBendingPlane; | |
137 | ||
138 | if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) | |
139 | return AliMp::kNonBendingPlane; | |
140 | ||
141 | // Should never reach this line | |
142 | AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data())); | |
143 | return AliMp::kBendingPlane; | |
144 | } | |
145 | ||
146 | //______________________________________________________________________________ | |
147 | AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName) | |
148 | { | |
149 | /// Return station type for the given stationTypeName \n | |
150 | /// Fatal error if stationTypeName is wrong | |
151 | ||
152 | if ( stationTypeName == StationTypeName(AliMp::kStation1) ) | |
153 | return AliMp::kStation1; | |
154 | ||
155 | if ( stationTypeName == StationTypeName(AliMp::kStation2) ) | |
156 | return AliMp::kStation2; | |
157 | ||
158 | if ( stationTypeName == StationTypeName(AliMp::kStation345) ) | |
159 | return AliMp::kStation345; | |
160 | ||
161 | if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) ) | |
162 | return AliMp::kStationTrigger; | |
163 | ||
164 | // Should never reach this line | |
165 | AliFatalClass(Form("No station type defined for ", stationTypeName.Data())); | |
166 | return AliMp::kStation1; | |
167 | } | |
168 | ||
169 | //______________________________________________________________________________ | |
170 | Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement, | |
171 | AliMp::StationType stationType) | |
172 | { | |
173 | /// Read manu serial numbers for the given detection element | |
5954bf20 | 174 | static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane); |
175 | ||
f0c62051 | 176 | TString deName = detElement->GetDEName(); |
177 | ||
178 | TString infile = AliMpFiles::ManuToSerialPath(deName, stationType); | |
179 | ifstream in(infile, ios::in); | |
180 | ||
181 | // Change to Error when all files available | |
182 | //if ( !in.is_open() && stationType == AliMp::kStation345 ) { | |
183 | // AliWarningStream() << "File " << infile << " not found." << endl; | |
184 | // return false; | |
185 | //} | |
186 | ||
187 | char line[80]; | |
188 | ||
189 | while ( in.getline(line,80) ) { | |
190 | ||
191 | if ( line[0] == '#' ) continue; | |
192 | ||
193 | TString tmp(AliMpHelper::Normalize(line)); | |
194 | ||
5954bf20 | 195 | TObjArray* stringList = tmp.Tokenize(TString(" ")); |
f0c62051 | 196 | |
5954bf20 | 197 | Int_t manuId = atoi( ((TObjString*)stringList->At(0))->GetName()); |
198 | Int_t manuSerial = atoi( ((TObjString*)stringList->At(2))->GetName()); | |
f0c62051 | 199 | |
5954bf20 | 200 | TString sPlane = ((TObjString*)stringList->At(1))->GetString(); |
201 | ||
f0c62051 | 202 | // filling manuId <> manuSerial |
5954bf20 | 203 | if (!sPlane.CompareTo(PlaneTypeName(AliMp::kBendingPlane))) |
204 | detElement->AddManuSerial(manuId, manuSerial); | |
205 | else | |
206 | detElement->AddManuSerial(manuId + manuMask, manuSerial); | |
207 | ||
208 | delete stringList; | |
f0c62051 | 209 | } |
210 | ||
211 | in.close(); | |
212 | return true; | |
213 | } | |
214 | ||
215 | //______________________________________________________________________________ | |
216 | Bool_t | |
217 | AliMpDEStore::ReadDENames(AliMp::StationType station) | |
218 | { | |
219 | /// Read det element names for cath = 0 from the file specified by name | |
220 | /// and fill the map | |
221 | ||
222 | // Open file | |
223 | TString filePath = AliMpFiles::DENamesFilePath(station); | |
224 | std::ifstream in(filePath); | |
225 | if (!in.good()) { | |
226 | AliErrorClassStream() << "Cannot open file " << filePath << endl;; | |
227 | return false; | |
228 | } | |
229 | ||
230 | // Read plane types per cathods | |
231 | // | |
232 | char line[80]; | |
233 | TString word; | |
234 | TString cathName1, cathName2; | |
235 | in >> word; | |
236 | while ( ! in.eof() && cathName1.Length() == 0 ) { | |
237 | if ( word[0] == '#' ) | |
238 | in.getline(line, 80); | |
239 | else { | |
240 | cathName1 = word; | |
241 | in >> cathName2; | |
242 | } | |
243 | in >> word; | |
244 | } | |
245 | ||
246 | Bool_t isCathNameDefined = false; | |
247 | if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) ) | |
248 | isCathNameDefined = true; | |
249 | ||
250 | // Read DE names | |
251 | // | |
252 | Int_t detElemId; | |
253 | TString name, name0, name1, name2; | |
254 | AliMp::PlaneType planeForCathode[2]; | |
255 | ||
256 | while ( ! in.eof() ) | |
257 | { | |
258 | if ( word[0] == '#' ) | |
259 | { | |
260 | in.getline(line, 80); | |
261 | } | |
262 | else | |
263 | { | |
264 | detElemId = word.Atoi(); | |
265 | in >> name; | |
266 | in >> name0; | |
267 | // warning : important to check non bending first (=nbp), | |
268 | // as bp is contained within nbp... | |
269 | if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) ) | |
270 | { | |
271 | planeForCathode[0] = AliMp::kNonBendingPlane; | |
272 | } | |
273 | else | |
274 | { | |
275 | planeForCathode[0] = AliMp::kBendingPlane; | |
276 | } | |
277 | ||
278 | if ( !isCathNameDefined ) | |
279 | { | |
280 | in >> name2; | |
281 | name1 = name0; | |
282 | Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator()); | |
283 | name0 = name1(0,pos); | |
284 | ||
285 | // Other cathode is other plane... | |
286 | planeForCathode[1] = OtherPlaneType(planeForCathode[0]); | |
287 | } | |
288 | else | |
289 | { | |
290 | name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1; | |
291 | name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2; | |
292 | if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) ) | |
293 | { | |
294 | planeForCathode[1] = AliMp::kNonBendingPlane; | |
295 | } | |
296 | else | |
297 | { | |
298 | planeForCathode[1] = AliMp::kBendingPlane; | |
299 | } | |
300 | } | |
301 | ||
302 | if ( planeForCathode[0]==planeForCathode[1] ) | |
303 | { | |
304 | AliFatalClass(Form("Got the same cathode type for both planes" | |
305 | " of DetElemId %d",detElemId)); | |
306 | } | |
307 | ||
308 | AliMpDetElement* detElement | |
309 | = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]); | |
310 | if ( ! fDetElements.GetValue(detElemId) ) | |
311 | { | |
312 | AliDebugClassStream(3) | |
313 | << "Adding DE name " << detElemId << " " << name << endl; | |
314 | fDetElements.Add(detElemId, detElement); | |
315 | ||
316 | // Read manu serial numbers for this det element | |
317 | ReadManuToSerialNbs(detElement, station); | |
318 | } | |
319 | else | |
320 | { | |
321 | AliWarningClassStream() | |
322 | << "Det element " << detElemId << " " << name << " already defined." << endl; | |
323 | } | |
324 | } | |
325 | in >> word; | |
326 | } | |
327 | ||
328 | // Close file | |
329 | in.close(); | |
330 | ||
331 | return true; | |
332 | } | |
333 | ||
334 | //______________________________________________________________________________ | |
335 | void AliMpDEStore::FillDEs() | |
336 | { | |
337 | /// Fill DE names from files | |
338 | AliDebugClass(2,""); | |
339 | Bool_t result1 = ReadDENames(AliMp::kStation1); | |
340 | Bool_t result2 = ReadDENames(AliMp::kStation2); | |
341 | Bool_t result3 = ReadDENames(AliMp::kStation345); | |
342 | Bool_t result4 = ReadDENames(AliMp::kStationTrigger); | |
343 | ||
344 | Bool_t result = result1 && result2 && result3 && result4; | |
345 | if ( ! result ) { | |
346 | AliErrorClassStream() << "Error in reading DE names files" << endl; | |
347 | } | |
348 | } | |
349 | ||
350 | // | |
351 | // public methods | |
352 | // | |
353 | ||
354 | ||
355 | //______________________________________________________________________________ | |
356 | AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const | |
357 | { | |
358 | /// Return det element for given detElemId | |
359 | ||
360 | AliMpDetElement* detElement | |
361 | = (AliMpDetElement*)fDetElements.GetValue(detElemId); | |
362 | ||
363 | if ( ! detElement && warn ) { | |
364 | AliErrorClassStream() | |
365 | << "Detection element " << detElemId << " not defined." << endl; | |
366 | } | |
367 | ||
368 | return detElement; | |
369 | } | |
370 | ||
2eee683c | 371 | //______________________________________________________________________________ |
372 | AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const | |
373 | { | |
374 | /// Return det element for given deName | |
375 | ||
376 | for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) { | |
377 | ||
378 | AliMpDetElement* detElement | |
379 | = (AliMpDetElement*)fDetElements.GetObject(i); | |
380 | ||
381 | if (deName.CompareTo(detElement->GetDEName()) == 0) | |
382 | ||
383 | return detElement; | |
384 | } | |
385 | ||
386 | if (warn) { | |
387 | AliErrorClassStream() | |
388 | << "Detection element with name" << deName.Data() << " not defined." << endl; | |
389 | } | |
390 | ||
391 | return 0x0; | |
392 | ||
393 | } | |
f0c62051 | 394 | //______________________________________________________________________________ |
395 | AliMpIntPair AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const | |
396 | { | |
397 | /// Return the detElemId and manuId for given serial manu number | |
398 | ||
399 | for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) { | |
400 | ||
401 | AliMpDetElement* detElement | |
402 | = (AliMpDetElement*)fDetElements.GetObject(i); | |
403 | ||
404 | Int_t manuId = detElement->GetManuIdFromSerial(manuSerial); | |
405 | if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId); | |
406 | } | |
407 | ||
408 | // manu with this serial number does not exist | |
409 | return AliMpIntPair::Invalid(); | |
410 | } | |
2eee683c | 411 |