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