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 "AliMpIntPair.h"
37 #include "AliMpConstants.h"
38 #include "AliMpExMapIterator.h"
42 #include <Riostream.h>
45 #include <TObjString.h>
46 #include <TObjArray.h>
50 ClassImp(AliMpDEStore)
53 AliMpDEStore* AliMpDEStore::fgInstance = 0;
54 const char AliMpDEStore::fgkCommentPrefix = '#';
60 //______________________________________________________________________________
61 AliMpDEStore* AliMpDEStore::Instance(Bool_t warn)
63 /// Create the DE store if it does not yet exist
64 /// and return its instance
66 if ( ! fgInstance && warn ) {
67 AliWarningClass("DE Store has not been loaded");
73 //______________________________________________________________________________
74 AliMpDEStore* AliMpDEStore::ReadData(const AliMpDataStreams& dataStreams,
77 /// Load the DE store data from ASCII data files
78 /// and return its instance
82 AliWarningClass("DE Store has been already loaded");
86 if ( dataStreams.GetReadFromFiles() )
87 AliInfoClass("Reading DE Store from ASCII files.");
89 fgInstance = new AliMpDEStore(dataStreams);
97 //______________________________________________________________________________
98 AliMpDEStore::AliMpDEStore(const AliMpDataStreams& dataStreams)
100 fkDataStreams(dataStreams),
103 /// Standard constructor
106 fDetElements.SetOwner(true);
108 // Create all detection elements
112 //______________________________________________________________________________
113 AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
115 fkDataStreams(ioCtor),
118 /// Constructor for IO
126 //______________________________________________________________________________
127 AliMpDEStore::~AliMpDEStore()
133 // Segmentations are deleted with fMpSegmentations
134 // El cards arrays are deleted with fElCardsMap
143 //______________________________________________________________________________
144 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
146 /// Return true if the planeTypeName corresponds to a valid plane type
148 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
149 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
155 //______________________________________________________________________________
157 AliMpDEStore::ReadDENames(AliMp::StationType station,
158 AliMq::Station12Type station12)
160 /// Read det element names for cath = 0 from the file specified by name
166 CreateDataStream(AliMpFiles::DENamesFilePath(station, station12));
168 // Read plane types per cathods
172 TString cathName1, cathName2;
174 while ( ! in.eof() && cathName1.Length() == 0 ) {
175 if ( word[0] == '#' )
176 in.getline(line, 80);
184 Bool_t isCathNameDefined = false;
185 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
186 isCathNameDefined = true;
191 TString name, name0, name1, name2;
192 AliMp::PlaneType planeForCathode[2];
196 if ( word[0] == '#' )
198 in.getline(line, 80);
202 detElemId = word.Atoi();
205 // warning : important to check non bending first (=nbp),
206 // as bp is contained within nbp...
207 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
209 planeForCathode[0] = AliMp::kNonBendingPlane;
213 planeForCathode[0] = AliMp::kBendingPlane;
216 if ( !isCathNameDefined )
220 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
221 name0 = name1(0,pos);
223 // Other cathode is other plane...
224 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
228 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
229 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
230 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
232 planeForCathode[1] = AliMp::kNonBendingPlane;
236 planeForCathode[1] = AliMp::kBendingPlane;
240 if ( planeForCathode[0]==planeForCathode[1] )
242 AliFatalClass(Form("Got the same cathode type for both planes"
243 " of DetElemId %d",detElemId));
246 AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
248 if ( ! fDetElements.GetValue(detElemId) )
250 AliDebugClassStream(3)
251 << "Adding DE name " << detElemId << " " << name << endl;
252 fDetElements.Add(detElemId, detElement);
256 AliWarningClassStream()
257 << "Det element " << detElemId << " " << name << " already defined." << endl;
268 //______________________________________________________________________________
269 void AliMpDEStore::FillDEs()
271 /// Fill DE names from files
273 Bool_t result1 = ReadDENames(AliMp::kStation12, AliMq::kStation1);
274 Bool_t result2 = ReadDENames(AliMp::kStation12, AliMq::kStation2);
275 Bool_t result3 = ReadDENames(AliMp::kStation345);
276 Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
278 Bool_t result = result1 && result2 && result3 && result4;
280 AliErrorClassStream() << "Error in reading DE names files" << endl;
282 AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize()));
290 //______________________________________________________________________________
291 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
293 /// Return det element for given detElemId
295 AliMpDetElement* detElement
296 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
298 if ( ! detElement && warn ) {
299 AliErrorClassStream()
300 << "Detection element " << detElemId << " not defined." << endl;
306 //______________________________________________________________________________
307 AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
309 /// Return det element for given deName
311 TIter next(fDetElements.CreateIterator());
312 AliMpDetElement* detElement;
314 while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
317 if (deName.CompareTo(detElement->GetDEName()) == 0)
323 AliErrorClassStream()
324 << "Detection element with name" << deName.Data() << " not defined." << endl;