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 purpeateose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include "AliMUONSegmentationManager.h"
20 #include "AliMpFiles.h"
22 #include "AliMpSectorReader.h"
23 #include "AliMpSector.h"
24 #include "AliMpSectorSegmentation.h"
25 #include "AliMpSlatSegmentation.h"
26 #include "AliMpSt345Reader.h"
28 #include "TObjString.h"
31 ClassImp(AliMUONSegmentationManager)
33 TExMap AliMUONSegmentationManager::fgMap;
34 TExMap AliMUONSegmentationManager::fgDetElemIdToSlatTypeMap;
36 //_____________________________________________________________________________
37 AliMUONSegmentationManager::AliMUONSegmentationManager() : TObject()
41 //_____________________________________________________________________________
42 AliMUONSegmentationManager::~AliMUONSegmentationManager()
46 //_____________________________________________________________________________
48 AliMUONSegmentationManager::IsValidDetElemId(Int_t detElemId)
50 return (SlatType(detElemId) != 0);
53 //_____________________________________________________________________________
55 AliMUONSegmentationManager::ReadSegmentation(Int_t detElemId, AliMpPlaneType planeType)
57 if ( detElemId >= 500 && detElemId <= 1025 )
59 AliMpSlat* slat = ReadSlat(detElemId,planeType);
60 return new AliMpSlatSegmentation(slat);
62 else if ( detElemId < 500 )
64 AliMpStationType station(kStation2);
65 if ( detElemId < 200 )
69 AliMpSectorReader reader(station,planeType);
70 AliMpSector* sector = reader.BuildSector();
71 //FIXME: get this to be able to delete the sectors: fStore.push_back(sector);
72 return new AliMpSectorSegmentation(sector);
80 //_____________________________________________________________________________
82 AliMUONSegmentationManager::ReadDetElemIdToSlatType()
84 std::ifstream in(AliMpFiles::Instance()->DetElemIdToSlatTypeFilePath().Data());
85 if (!in.good()) return false;
87 fgDetElemIdToSlatTypeMap.Delete();
91 while ( in.getline(line,80) )
93 if ( !isdigit(line[0]) ) continue;
96 Ssiz_t pos = sline.First(' ');
97 int detelemid = TString(sline(0,pos)).Atoi();
98 fgDetElemIdToSlatTypeMap.Add((Long_t)detelemid,
99 (Long_t)(new TObjString(sline(pos+1,sline.Length()-pos).Data())));
107 //_____________________________________________________________________________
109 AliMUONSegmentationManager::ReadSlat(Int_t detElemId, AliMpPlaneType planeType)
111 return AliMpSt345Reader::ReadSlat(SlatType(detElemId),planeType);
115 //_____________________________________________________________________________
117 AliMUONSegmentationManager::Segmentation(Int_t detElemId, AliMpPlaneType planeType)
119 Long_t it = fgMap.GetValue((Long_t)detElemId);
123 TPair* p = (TPair*)(it);
125 if ( planeType == kBendingPlane )
127 return (AliMpVSegmentation*)p->Key();
129 else if ( planeType == kNonBendingPlane )
131 return (AliMpVSegmentation*)p->Value();
135 AliFatalClass("oups");
141 AliMpVSegmentation* b = ReadSegmentation(detElemId,kBendingPlane);
142 AliMpVSegmentation* nb = ReadSegmentation(detElemId,kNonBendingPlane);
145 AliErrorClass(Form("Could not get segmentations for detElemId=%d",detElemId));
148 fgMap.Add((Long_t)(detElemId),(Long_t)(new TPair(b,nb)));
149 return Segmentation(detElemId,planeType);
153 //_____________________________________________________________________________
155 AliMUONSegmentationManager::SlatType(int detelemid)
157 if ( ! fgDetElemIdToSlatTypeMap.GetSize() ) ReadDetElemIdToSlatType();
159 Long_t rv = fgDetElemIdToSlatTypeMap.GetValue(detelemid);
163 return ((TObjString*)(rv))->String().Data();