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