1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpDEStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
20 //-----------------------------------------------------------------------------
22 // --------------------
23 // The container class for detection element objects
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 // Laurent Aphecetche, Christian Finck, SUBATECH Nantes
26 //-----------------------------------------------------------------------------
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"
41 #include <Riostream.h>
44 #include <TObjString.h>
45 #include <TObjArray.h>
49 ClassImp(AliMpDEStore)
52 AliMpDEStore* AliMpDEStore::fgInstance = 0;
53 const char AliMpDEStore::fgkCommentPrefix = '#';
59 //______________________________________________________________________________
60 AliMpDEStore* AliMpDEStore::Instance(Bool_t warn)
62 /// Create the DE store if it does not yet exist
63 /// and return its instance
65 if ( ! fgInstance && warn ) {
66 AliWarningClass("DE Store has not been loaded");
72 //______________________________________________________________________________
73 AliMpDEStore* AliMpDEStore::ReadData(const AliMpDataStreams& dataStreams,
76 /// Load the DE store data from ASCII data files
77 /// and return its instance
81 AliWarningClass("DE Store has been already loaded");
85 if ( dataStreams.GetReadFromFiles() )
86 AliInfoClass("Reading DE Store from ASCII files.");
88 fgInstance = new AliMpDEStore(dataStreams);
96 //______________________________________________________________________________
97 AliMpDEStore::AliMpDEStore(const AliMpDataStreams& dataStreams)
99 fkDataStreams(dataStreams),
102 /// Standard constructor
105 fDetElements.SetOwner(true);
107 // Create all detection elements
111 //______________________________________________________________________________
112 AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
114 fkDataStreams(ioCtor),
117 /// Constructor for IO
125 //______________________________________________________________________________
126 AliMpDEStore::~AliMpDEStore()
132 // Segmentations are deleted with fMpSegmentations
133 // El cards arrays are deleted with fElCardsMap
142 //______________________________________________________________________________
143 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
145 /// Return true if the planeTypeName corresponds to a valid plane type
147 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
148 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
154 //______________________________________________________________________________
156 AliMpDEStore::ReadDENames(AliMp::StationType station,
157 AliMq::Station12Type station12)
159 /// Read det element names for cath = 0 from the file specified by name
165 CreateDataStream(AliMpFiles::DENamesFilePath(station, station12));
167 // Read plane types per cathods
171 TString cathName1, cathName2;
173 while ( ! in.eof() && cathName1.Length() == 0 ) {
174 if ( word[0] == '#' )
175 in.getline(line, 80);
183 Bool_t isCathNameDefined = false;
184 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
185 isCathNameDefined = true;
190 TString name, name0, name1, name2;
191 AliMp::PlaneType planeForCathode[2];
195 if ( word[0] == '#' )
197 in.getline(line, 80);
201 detElemId = word.Atoi();
204 // warning : important to check non bending first (=nbp),
205 // as bp is contained within nbp...
206 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
208 planeForCathode[0] = AliMp::kNonBendingPlane;
212 planeForCathode[0] = AliMp::kBendingPlane;
215 if ( !isCathNameDefined )
219 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
220 name0 = name1(0,pos);
222 // Other cathode is other plane...
223 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
227 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
228 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
229 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
231 planeForCathode[1] = AliMp::kNonBendingPlane;
235 planeForCathode[1] = AliMp::kBendingPlane;
239 if ( planeForCathode[0]==planeForCathode[1] )
241 AliFatalClass(Form("Got the same cathode type for both planes"
242 " of DetElemId %d",detElemId));
245 AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
247 if ( ! fDetElements.GetValue(detElemId) )
249 AliDebugClassStream(3)
250 << "Adding DE name " << detElemId << " " << name << endl;
251 fDetElements.Add(detElemId, detElement);
255 AliWarningClassStream()
256 << "Det element " << detElemId << " " << name << " already defined." << endl;
267 //______________________________________________________________________________
268 void AliMpDEStore::FillDEs()
270 /// Fill DE names from files
272 Bool_t result1 = ReadDENames(AliMp::kStation12, AliMq::kStation1);
273 Bool_t result2 = ReadDENames(AliMp::kStation12, AliMq::kStation2);
274 Bool_t result3 = ReadDENames(AliMp::kStation345);
275 Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
277 Bool_t result = result1 && result2 && result3 && result4;
279 AliErrorClassStream() << "Error in reading DE names files" << endl;
281 AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize()));
289 //______________________________________________________________________________
290 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
292 /// Return det element for given detElemId
294 AliMpDetElement* detElement
295 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
297 if ( ! detElement && warn ) {
298 AliErrorClassStream()
299 << "Detection element " << detElemId << " not defined." << endl;
305 //______________________________________________________________________________
306 AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
308 /// Return det element for given deName
310 TIter next(fDetElements.CreateIterator());
311 AliMpDetElement* detElement;
313 while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
316 if (deName.CompareTo(detElement->GetDEName()) == 0)
322 AliErrorClassStream()
323 << "Detection element with name" << deName.Data() << " not defined." << endl;