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)
101 /// Standard constructor
104 fDetElements.SetOwner(true);
106 // Create all detection elements
107 FillDEs(dataStreams);
110 //______________________________________________________________________________
111 AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
115 /// Constructor for IO
123 //______________________________________________________________________________
124 AliMpDEStore::~AliMpDEStore()
130 // Segmentations are deleted with fMpSegmentations
131 // El cards arrays are deleted with fElCardsMap
140 //______________________________________________________________________________
141 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
143 /// Return true if the planeTypeName corresponds to a valid plane type
145 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
146 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
152 //______________________________________________________________________________
154 AliMpDEStore::ReadDENames(const AliMpDataStreams& dataStreams,
155 AliMp::StationType station,
156 AliMq::Station12Type station12)
158 /// Read det element names for cath = 0 from the file specified by name
164 CreateDataStream(AliMpFiles::DENamesFilePath(station, station12));
166 // Read plane types per cathods
170 TString cathName1, cathName2;
172 while ( ! in.eof() && cathName1.Length() == 0 ) {
173 if ( word[0] == '#' )
174 in.getline(line, 80);
182 Bool_t isCathNameDefined = false;
183 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
184 isCathNameDefined = true;
189 TString name, name0, name1, name2;
190 AliMp::PlaneType planeForCathode[2];
194 if ( word[0] == '#' )
196 in.getline(line, 80);
200 detElemId = word.Atoi();
203 // warning : important to check non bending first (=nbp),
204 // as bp is contained within nbp...
205 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
207 planeForCathode[0] = AliMp::kNonBendingPlane;
211 planeForCathode[0] = AliMp::kBendingPlane;
214 if ( !isCathNameDefined )
218 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
219 name0 = name1(0,pos);
221 // Other cathode is other plane...
222 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
226 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
227 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
228 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
230 planeForCathode[1] = AliMp::kNonBendingPlane;
234 planeForCathode[1] = AliMp::kBendingPlane;
238 if ( planeForCathode[0]==planeForCathode[1] )
240 AliFatalClass(Form("Got the same cathode type for both planes"
241 " of DetElemId %d",detElemId));
244 AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
246 if ( ! fDetElements.GetValue(detElemId) )
248 AliDebugClassStream(3)
249 << "Adding DE name " << detElemId << " " << name << endl;
250 fDetElements.Add(detElemId, detElement);
254 AliWarningClassStream()
255 << "Det element " << detElemId << " " << name << " already defined." << endl;
266 //______________________________________________________________________________
267 void AliMpDEStore::FillDEs(const AliMpDataStreams& dataStreams)
269 /// Fill DE names from files
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);
276 Bool_t result = result1 && result2 && result3 && result4;
278 AliErrorClassStream() << "Error in reading DE names files" << endl;
280 AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize()));
288 //______________________________________________________________________________
289 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
291 /// Return det element for given detElemId
293 AliMpDetElement* detElement
294 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
296 if ( ! detElement && warn ) {
297 AliErrorClassStream()
298 << "Detection element " << detElemId << " not defined." << endl;
304 //______________________________________________________________________________
305 AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
307 /// Return det element for given deName
309 TIter next(fDetElements.CreateIterator());
310 AliMpDetElement* detElement;
312 while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
315 if (deName.CompareTo(detElement->GetDEName()) == 0)
321 AliErrorClassStream()
322 << "Detection element with name" << deName.Data() << " not defined." << endl;