Fixing Doxygen warnings
[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"
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
49ClassImp(AliMpDEStore)
50/// \endcond
51
52AliMpDEStore* AliMpDEStore::fgInstance = 0;
53const char AliMpDEStore::fgkCommentPrefix = '#';
54
55//
56// static methods
57//
58
59//______________________________________________________________________________
ac17c583 60AliMpDEStore* 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 73AliMpDEStore* 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 97AliMpDEStore::AliMpDEStore(const AliMpDataStreams& dataStreams)
f0c62051 98: TObject(),
7d5d0cc5 99 fkDataStreams(dataStreams),
630711ed 100 fDetElements()
f0c62051 101{
102/// Standard constructor
103
104 AliDebug(1,"");
105 fDetElements.SetOwner(true);
106
107 // Create all detection elements
108 FillDEs();
109}
110
111//______________________________________________________________________________
630711ed 112AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
f0c62051 113: TObject(),
7d5d0cc5 114 fkDataStreams(ioCtor),
630711ed 115 fDetElements(ioCtor)
f0c62051 116{
117/// Constructor for IO
118
119 AliDebug(1,"");
120
121 fgInstance = this;
122}
123
124
125//______________________________________________________________________________
126AliMpDEStore::~AliMpDEStore()
127{
128/// Destructor
129
130 AliDebug(1,"");
131
132 // Segmentations are deleted with fMpSegmentations
133 // El cards arrays are deleted with fElCardsMap
134
135 fgInstance = 0;
136}
137
138//
139// private methods
140//
141
142//______________________________________________________________________________
143Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
144{
145/// Return true if the planeTypeName corresponds to a valid plane type
146
147 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
148 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
149 return true;
150
151 return false;
152}
153
154//______________________________________________________________________________
f0c62051 155Bool_t
4e51cfd2 156AliMpDEStore::ReadDENames(AliMp::StationType station,
157 AliMq::Station12Type station12)
f0c62051 158{
159/// Read det element names for cath = 0 from the file specified by name
160/// and fill the map
161
228fd720 162 // Open stream
163 istream& in
7d5d0cc5 164 = fkDataStreams.
4e51cfd2 165 CreateDataStream(AliMpFiles::DENamesFilePath(station, station12));
f0c62051 166
167 // Read plane types per cathods
168 //
169 char line[80];
170 TString word;
171 TString cathName1, cathName2;
172 in >> word;
173 while ( ! in.eof() && cathName1.Length() == 0 ) {
174 if ( word[0] == '#' )
175 in.getline(line, 80);
176 else {
177 cathName1 = word;
178 in >> cathName2;
179 }
180 in >> word;
181 }
182
183 Bool_t isCathNameDefined = false;
184 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
185 isCathNameDefined = true;
186
187 // Read DE names
188 //
189 Int_t detElemId;
190 TString name, name0, name1, name2;
191 AliMp::PlaneType planeForCathode[2];
192
193 while ( ! in.eof() )
194 {
195 if ( word[0] == '#' )
196 {
197 in.getline(line, 80);
198 }
199 else
200 {
201 detElemId = word.Atoi();
202 in >> name;
203 in >> name0;
204 // warning : important to check non bending first (=nbp),
205 // as bp is contained within nbp...
206 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
207 {
208 planeForCathode[0] = AliMp::kNonBendingPlane;
209 }
210 else
211 {
212 planeForCathode[0] = AliMp::kBendingPlane;
213 }
214
215 if ( !isCathNameDefined )
216 {
217 in >> name2;
218 name1 = name0;
219 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
220 name0 = name1(0,pos);
221
222 // Other cathode is other plane...
223 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
224 }
225 else
226 {
227 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
228 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
229 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
230 {
231 planeForCathode[1] = AliMp::kNonBendingPlane;
232 }
233 else
234 {
235 planeForCathode[1] = AliMp::kBendingPlane;
236 }
237 }
238
239 if ( planeForCathode[0]==planeForCathode[1] )
240 {
241 AliFatalClass(Form("Got the same cathode type for both planes"
242 " of DetElemId %d",detElemId));
243 }
244
630711ed 245 AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
246
f0c62051 247 if ( ! fDetElements.GetValue(detElemId) )
248 {
249 AliDebugClassStream(3)
250 << "Adding DE name " << detElemId << " " << name << endl;
251 fDetElements.Add(detElemId, detElement);
f0c62051 252 }
253 else
254 {
255 AliWarningClassStream()
256 << "Det element " << detElemId << " " << name << " already defined." << endl;
257 }
258 }
259 in >> word;
260 }
f0c62051 261
228fd720 262 delete &in;
263
f0c62051 264 return true;
265}
266
267//______________________________________________________________________________
268void AliMpDEStore::FillDEs()
269{
270/// Fill DE names from files
271 AliDebugClass(2,"");
4e51cfd2 272 Bool_t result1 = ReadDENames(AliMp::kStation12, AliMq::kStation1);
273 Bool_t result2 = ReadDENames(AliMp::kStation12, AliMq::kStation2);
f0c62051 274 Bool_t result3 = ReadDENames(AliMp::kStation345);
275 Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
276
277 Bool_t result = result1 && result2 && result3 && result4;
278 if ( ! result ) {
279 AliErrorClassStream() << "Error in reading DE names files" << endl;
280 }
183279c1 281 AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize()));
f0c62051 282}
283
284//
285// public methods
286//
287
288
289//______________________________________________________________________________
290AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
291{
292/// Return det element for given detElemId
293
294 AliMpDetElement* detElement
295 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
296
297 if ( ! detElement && warn ) {
298 AliErrorClassStream()
299 << "Detection element " << detElemId << " not defined." << endl;
300 }
301
302 return detElement;
303}
304
305//______________________________________________________________________________
2eee683c 306AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
307{
308/// Return det element for given deName
309
630711ed 310 TIter next(fDetElements.CreateIterator());
311 AliMpDetElement* detElement;
312
313 while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
314 {
315
2eee683c 316 if (deName.CompareTo(detElement->GetDEName()) == 0)
317
318 return detElement;
319 }
320
321 if (warn) {
322 AliErrorClassStream()
323 << "Detection element with name" << deName.Data() << " not defined." << endl;
324 }
325
326 return 0x0;
327
328}