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
21 // --------------------
22 // The container class for detection element objects
23 // Authors: Ivana Hrivnacova, IPN Orsay
24 // Laurent Aphecetche, Christian Finck, SUBATECH Nantes
26 #include "AliMpDEStore.h"
27 #include "AliMpDEManager.h"
28 #include "AliMpDetElement.h"
29 #include "AliMpConstants.h"
30 #include "AliMpFiles.h"
31 #include "AliMpHelper.h"
32 #include "AliMpIntPair.h"
33 #include "AliMpConstants.h"
37 #include <Riostream.h>
40 #include <TObjString.h>
41 #include <TObjArray.h>
45 ClassImp(AliMpDEStore)
48 AliMpDEStore* AliMpDEStore::fgInstance = 0;
49 const char AliMpDEStore::fgkCommentPrefix = '#';
55 //______________________________________________________________________________
56 AliMpDEStore* AliMpDEStore::Instance()
58 /// Create the DE store if it does not yet exist
59 /// and return its instance
62 fgInstance = new AliMpDEStore();
71 //______________________________________________________________________________
72 AliMpDEStore::AliMpDEStore()
76 /// Standard constructor
79 fDetElements.SetOwner(true);
81 // Create all detection elements
85 //______________________________________________________________________________
86 AliMpDEStore::AliMpDEStore(TRootIOCtor* /*ioCtor*/)
90 /// Constructor for IO
98 //______________________________________________________________________________
99 AliMpDEStore::~AliMpDEStore()
105 // Segmentations are deleted with fMpSegmentations
106 // El cards arrays are deleted with fElCardsMap
115 //______________________________________________________________________________
116 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
118 /// Return true if the planeTypeName corresponds to a valid plane type
120 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
121 planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
127 //______________________________________________________________________________
128 AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName)
130 /// Return plane type for the given planeTypeName \n
131 /// Fatal error if planeTypeName is wrong
133 if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) )
134 return AliMp::kBendingPlane;
136 if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
137 return AliMp::kNonBendingPlane;
139 // Should never reach this line
140 AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
141 return AliMp::kBendingPlane;
144 //______________________________________________________________________________
145 AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName)
147 /// Return station type for the given stationTypeName \n
148 /// Fatal error if stationTypeName is wrong
150 if ( stationTypeName == StationTypeName(AliMp::kStation1) )
151 return AliMp::kStation1;
153 if ( stationTypeName == StationTypeName(AliMp::kStation2) )
154 return AliMp::kStation2;
156 if ( stationTypeName == StationTypeName(AliMp::kStation345) )
157 return AliMp::kStation345;
159 if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) )
160 return AliMp::kStationTrigger;
162 // Should never reach this line
163 AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
164 return AliMp::kStation1;
167 //______________________________________________________________________________
168 Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement,
169 AliMp::StationType stationType)
171 /// Read manu serial numbers for the given detection element
172 static Int_t manuMask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane);
174 TString deName = detElement->GetDEName();
176 TString infile = AliMpFiles::ManuToSerialPath(deName, stationType);
177 ifstream in(infile, ios::in);
179 // Change to Error when all files available
180 //if ( !in.is_open() && stationType == AliMp::kStation345 ) {
181 // AliWarningStream() << "File " << infile << " not found." << endl;
187 while ( in.getline(line,80) ) {
189 if ( line[0] == '#' ) continue;
191 TString tmp(AliMpHelper::Normalize(line));
193 TObjArray* stringList = tmp.Tokenize(TString(" "));
195 Int_t manuId = atoi( ((TObjString*)stringList->At(0))->GetName());
196 Int_t manuSerial = atoi( ((TObjString*)stringList->At(2))->GetName());
198 TString sPlane = ((TObjString*)stringList->At(1))->GetString();
200 // filling manuId <> manuSerial
201 if (!sPlane.CompareTo(PlaneTypeName(AliMp::kBendingPlane)))
202 detElement->AddManuSerial(manuId, manuSerial);
204 detElement->AddManuSerial(manuId + manuMask, manuSerial);
213 //______________________________________________________________________________
215 AliMpDEStore::ReadDENames(AliMp::StationType station)
217 /// Read det element names for cath = 0 from the file specified by name
221 TString filePath = AliMpFiles::DENamesFilePath(station);
222 std::ifstream in(filePath);
224 AliErrorClassStream() << "Cannot open file " << filePath << endl;;
228 // Read plane types per cathods
232 TString cathName1, cathName2;
234 while ( ! in.eof() && cathName1.Length() == 0 ) {
235 if ( word[0] == '#' )
236 in.getline(line, 80);
244 Bool_t isCathNameDefined = false;
245 if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
246 isCathNameDefined = true;
251 TString name, name0, name1, name2;
252 AliMp::PlaneType planeForCathode[2];
256 if ( word[0] == '#' )
258 in.getline(line, 80);
262 detElemId = word.Atoi();
265 // warning : important to check non bending first (=nbp),
266 // as bp is contained within nbp...
267 if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
269 planeForCathode[0] = AliMp::kNonBendingPlane;
273 planeForCathode[0] = AliMp::kBendingPlane;
276 if ( !isCathNameDefined )
280 Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
281 name0 = name1(0,pos);
283 // Other cathode is other plane...
284 planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
288 name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
289 name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
290 if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
292 planeForCathode[1] = AliMp::kNonBendingPlane;
296 planeForCathode[1] = AliMp::kBendingPlane;
300 if ( planeForCathode[0]==planeForCathode[1] )
302 AliFatalClass(Form("Got the same cathode type for both planes"
303 " of DetElemId %d",detElemId));
306 AliMpDetElement* detElement
307 = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
308 if ( ! fDetElements.GetValue(detElemId) )
310 AliDebugClassStream(3)
311 << "Adding DE name " << detElemId << " " << name << endl;
312 fDetElements.Add(detElemId, detElement);
314 // Read manu serial numbers for this det element
315 ReadManuToSerialNbs(detElement, station);
319 AliWarningClassStream()
320 << "Det element " << detElemId << " " << name << " already defined." << endl;
332 //______________________________________________________________________________
333 void AliMpDEStore::FillDEs()
335 /// Fill DE names from files
337 Bool_t result1 = ReadDENames(AliMp::kStation1);
338 Bool_t result2 = ReadDENames(AliMp::kStation2);
339 Bool_t result3 = ReadDENames(AliMp::kStation345);
340 Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
342 Bool_t result = result1 && result2 && result3 && result4;
344 AliErrorClassStream() << "Error in reading DE names files" << endl;
353 //______________________________________________________________________________
354 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
356 /// Return det element for given detElemId
358 AliMpDetElement* detElement
359 = (AliMpDetElement*)fDetElements.GetValue(detElemId);
361 if ( ! detElement && warn ) {
362 AliErrorClassStream()
363 << "Detection element " << detElemId << " not defined." << endl;
369 //______________________________________________________________________________
370 AliMpIntPair AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const
372 /// Return the detElemId and manuId for given serial manu number
374 for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) {
376 AliMpDetElement* detElement
377 = (AliMpDetElement*)fDetElements.GetObject(i);
379 Int_t manuId = detElement->GetManuIdFromSerial(manuSerial);
380 if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId);
383 // manu with this serial number does not exist
384 return AliMpIntPair::Invalid();