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