AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpDEStore.cxx
Go to the documentation of this file.
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 //-----------------------------------------------------------------------------
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
26 //-----------------------------------------------------------------------------
27 
28 #include <cstdlib>
29 #include "AliMpDEStore.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpDetElement.h"
32 #include "AliMpConstants.h"
33 #include "AliMpFiles.h"
34 #include "AliMpDataStreams.h"
35 #include "AliMpHelper.h"
36 #include "AliMpConstants.h"
37 #include "AliMpExMapIterator.h"
38 
39 #include "AliLog.h"
40 
41 #include <Riostream.h>
42 #include <TClass.h>
43 #include <TSystem.h>
44 #include <TObjString.h>
45 #include <TObjArray.h>
46 #include <TMap.h>
47 
51 
52 AliMpDEStore* AliMpDEStore::fgInstance = 0;
53 const char AliMpDEStore::fgkCommentPrefix = '#';
54 
55 //
56 // static methods
57 //
58 
59 //______________________________________________________________________________
61 {
64 
65  if ( ! fgInstance && warn ) {
66  AliWarningClass("DE Store has not been loaded");
67  }
68 
69  return fgInstance;
70 }
71 
72 //______________________________________________________________________________
74  Bool_t warn)
75 {
78 
79  if ( fgInstance ) {
80  if ( warn )
81  AliWarningClass("DE Store has been already loaded");
82  return fgInstance;
83  }
84 
85  if ( dataStreams.GetReadFromFiles() )
86  AliInfoClass("Reading DE Store from ASCII files.");
87 
88  fgInstance = new AliMpDEStore(dataStreams);
89  return fgInstance;
90 }
91 
92 //
93 // ctors, dtor
94 //
95 
96 //______________________________________________________________________________
98 : TObject(),
99  fDetElements()
100 {
102 
103  AliDebug(1,"");
104  fDetElements.SetOwner(true);
105 
106  // Create all detection elements
107  FillDEs(dataStreams);
108 }
109 
110 //______________________________________________________________________________
111 AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
112 : TObject(),
113  fDetElements(ioCtor)
114 {
116 
117  AliDebug(1,"");
118 
119  fgInstance = this;
120 }
121 
122 
123 //______________________________________________________________________________
125 {
127 
128  AliDebug(1,"");
129 
130  // Segmentations are deleted with fMpSegmentations
131  // El cards arrays are deleted with fElCardsMap
132 
133  fgInstance = 0;
134 }
135 
136 //
137 // private methods
138 //
139 
140 //______________________________________________________________________________
141 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
142 {
144 
145  if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
146  planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
147  return true;
148 
149  return false;
150 }
151 
152 //______________________________________________________________________________
153 Bool_t
155  AliMp::StationType station,
156  AliMq::Station12Type station12)
157 {
160 
161  // Open stream
162  istream& in
163  = dataStreams.
164  CreateDataStream(AliMpFiles::DENamesFilePath(station, station12));
165 
166  // Read plane types per cathods
167  //
168  char line[80];
169  TString word;
170  TString cathName1, cathName2;
171  in >> word;
172  while ( ! in.eof() && cathName1.Length() == 0 ) {
173  if ( word[0] == '#' )
174  in.getline(line, 80);
175  else {
176  cathName1 = word;
177  in >> cathName2;
178  }
179  in >> word;
180  }
181 
182  Bool_t isCathNameDefined = false;
183  if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
184  isCathNameDefined = true;
185 
186  // Read DE names
187  //
188  Int_t detElemId;
189  TString name, name0, name1, name2;
190  AliMp::PlaneType planeForCathode[2];
191 
192  while ( ! in.eof() )
193  {
194  if ( word[0] == '#' )
195  {
196  in.getline(line, 80);
197  }
198  else
199  {
200  detElemId = word.Atoi();
201  in >> name;
202  in >> name0;
203  // warning : important to check non bending first (=nbp),
204  // as bp is contained within nbp...
205  if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
206  {
207  planeForCathode[0] = AliMp::kNonBendingPlane;
208  }
209  else
210  {
211  planeForCathode[0] = AliMp::kBendingPlane;
212  }
213 
214  if ( !isCathNameDefined )
215  {
216  in >> name2;
217  name1 = name0;
218  Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
219  name0 = name1(0,pos);
220 
221  // Other cathode is other plane...
222  planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
223  }
224  else
225  {
226  name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
227  name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
228  if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
229  {
230  planeForCathode[1] = AliMp::kNonBendingPlane;
231  }
232  else
233  {
234  planeForCathode[1] = AliMp::kBendingPlane;
235  }
236  }
237 
238  if ( planeForCathode[0]==planeForCathode[1] )
239  {
240  AliFatalClass(Form("Got the same cathode type for both planes"
241  " of DetElemId %d",detElemId));
242  }
243 
244  AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
245 
246  if ( ! fDetElements.GetValue(detElemId) )
247  {
248  AliDebugClassStream(3)
249  << "Adding DE name " << detElemId << " " << name << endl;
250  fDetElements.Add(detElemId, detElement);
251  }
252  else
253  {
254  AliWarningClassStream()
255  << "Det element " << detElemId << " " << name << " already defined." << endl;
256  }
257  }
258  in >> word;
259  }
260 
261  delete &in;
262 
263  return true;
264 }
265 
266 //______________________________________________________________________________
267 void AliMpDEStore::FillDEs(const AliMpDataStreams& dataStreams)
268 {
270  AliDebugClass(2,"");
271  Bool_t result1 = ReadDENames(dataStreams, AliMp::kStation12, AliMq::kStation1);
272  Bool_t result2 = ReadDENames(dataStreams, AliMp::kStation12, AliMq::kStation2);
273  Bool_t result3 = ReadDENames(dataStreams, AliMp::kStation345);
274  Bool_t result4 = ReadDENames(dataStreams, AliMp::kStationTrigger);
275 
276  Bool_t result = result1 && result2 && result3 && result4;
277  if ( ! result ) {
278  AliErrorClassStream() << "Error in reading DE names files" << endl;
279  }
280  AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize()));
281 }
282 
283 //
284 // public methods
285 //
286 
287 
288 //______________________________________________________________________________
289 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
290 {
292 
293  AliMpDetElement* detElement
294  = (AliMpDetElement*)fDetElements.GetValue(detElemId);
295 
296  if ( ! detElement && warn ) {
297  AliErrorClassStream()
298  << "Detection element " << detElemId << " not defined." << endl;
299  }
300 
301  return detElement;
302 }
303 
304 //______________________________________________________________________________
305 AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
306 {
308 
309  TIter next(fDetElements.CreateIterator());
310  AliMpDetElement* detElement;
311 
312  while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
313  {
314 
315  if (deName.CompareTo(detElement->GetDEName()) == 0)
316 
317  return detElement;
318  }
319 
320  if (warn) {
321  AliErrorClassStream()
322  << "Detection element with name" << deName.Data() << " not defined." << endl;
323  }
324 
325  return 0x0;
326 
327 }
station 1,2 (quadrants)
The container class for detection element objects.
Definition: AliMpDEStore.h:29
AliMp::PlaneType OtherPlaneType(AliMp::PlaneType planeType)
Return the other plane type.
static AliMpDEStore * Instance(Bool_t warn=true)
AliMpExMap fDetElements
Map between DE Ids and DE objects.
Definition: AliMpDEStore.h:68
void FillDEs(const AliMpDataStreams &dataStreams)
static AliMpDEStore * fgInstance
Singleton instance.
Definition: AliMpDEStore.h:64
Bool_t IsPlaneType(const TString &planeTypeName)
AliMpDEStore()
Not implemented.
station 3,4,5 (slats)
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
static char GetNameSeparator()
Return the name separator.
The class defines the electronics properties of detection element.
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Int_t GetSize() const
Definition: AliMpExMap.cxx:339
Bool_t ReadDENames(const AliMpDataStreams &dataStreams, AliMp::StationType stationType, AliMq::Station12Type station12Type=AliMq::kNotSt12)
static AliMpDEStore * ReadData(const AliMpDataStreams &dataStreams, Bool_t warn=true)
non-bending plane
TString PlaneTypeName(AliMp::PlaneType planeType)
Return name for given planeType.
TObject * GetValue(Int_t keyFirst, Int_t keySecond) const
Definition: AliMpExMap.cxx:364
void Add(Int_t keyFirst, Int_t keySecond, TObject *object)
Definition: AliMpExMap.cxx:291
void SetOwner(Bool_t owner)
Definition: AliMpExMap.cxx:331
bending plane
virtual ~AliMpDEStore()
trigger stations (slats)
static TString DENamesFilePath(AliMp::StationType stationType, AliMq::Station12Type station12Type)
Definition: AliMpFiles.cxx:327
Bool_t GetReadFromFiles() const
AliMpExMapIterator * CreateIterator() const
Definition: AliMpExMap.cxx:356
Mapping data streams provider.