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"
21 #include "AliMpSectorReader.h"
22 #include "AliMpSector.h"
23 #include "AliMpSectorSegmentation.h"
24 #include "AliMpSlat.h"
25 #include "AliMpSlatSegmentation.h"
26 #include "AliMpSt345Reader.h"
27 #include "AliMpTriggerReader.h"
28 #include "AliMpTriggerSegmentation.h"
29 #include "AliMpTrigger.h"
31 #include "Riostream.h"
36 #include "TObjString.h"
39 ClassImp(AliMUONSegmentationManager)
41 AliMpExMap AliMUONSegmentationManager::fgMap(kTRUE);
42 AliMpExMap AliMUONSegmentationManager::fgDetElemIdToNameMap(kTRUE);
43 AliMpExMap AliMUONSegmentationManager::fgLocalBoardMap(kTRUE);
47 //__________________________________________________________________________
48 TString DetElemIdToNamePath(AliMpStationType stationType)
50 /// Get the full path of the file containing the mapping detElemId <->
52 /// The bending parameter below is of no use in this case, but
53 /// we use it to re-use the PlaneDataDir() method untouched.
55 TString filename(gSystem->ExpandPathName("${ALICE_ROOT}/MUON/data/"));
56 filename += "denames_";
57 filename += StationTypeName(stationType);
63 //_____________________________________________________________________________
64 AliMUONSegmentationManager::AliMUONSegmentationManager() : TObject()
68 //_____________________________________________________________________________
69 AliMUONSegmentationManager::~AliMUONSegmentationManager()
73 //_____________________________________________________________________________
75 AliMUONSegmentationManager::FillLocalBoardMap(AliMpTriggerSegmentation* seg)
77 const AliMpTrigger* slat = seg->Slat();
78 for ( Int_t i = 0; i < slat->GetSize(); ++i )
81 slat->GetAllLocalBoardNumbers(lbn);
82 for ( Int_t j = 0; j < lbn.GetSize(); ++j )
84 TList* list = (TList*)fgLocalBoardMap.GetValue(lbn[j]);
88 fgLocalBoardMap.Add(lbn[j],list);
90 if ( list->FindObject(seg) == 0 )
98 //_____________________________________________________________________________
100 AliMUONSegmentationManager::IsValidDetElemId(Int_t detElemId)
102 return (DetElemName(detElemId) != 0);
105 //_____________________________________________________________________________
107 AliMUONSegmentationManager::ReadSegmentation(Int_t detElemId, AliMpPlaneType planeType)
109 AliMpStationType station = StationType(detElemId);
111 if (station==kStation345)
113 AliMpSlat* slat = AliMpSt345Reader::ReadSlat(DetElemName(detElemId),planeType);
114 return new AliMpSlatSegmentation(slat);
116 else if ( station==kStation1 || station==kStation2 )
118 AliMpSectorReader reader(station,planeType);
119 AliMpSector* sector = reader.BuildSector();
120 //FIXME: get this to be able to delete the sectors: fStore.push_back(sector);
121 return new AliMpSectorSegmentation(sector);
123 else if ( station == kStationTrigger )
125 AliMpTrigger* slat = AliMpTriggerReader::ReadSlat(DetElemName(detElemId),planeType);
126 return new AliMpTriggerSegmentation(slat);
131 //_____________________________________________________________________________
133 AliMUONSegmentationManager::ReadDetElemIdToName(AliMpStationType stationType)
135 std::ifstream in(DetElemIdToNamePath(stationType).Data());
138 AliErrorClass(Form("Cannot read file %s",DetElemIdToNamePath(stationType).Data()));
144 while ( in.getline(line,80) )
146 if ( !isdigit(line[0]) ) continue;
149 Ssiz_t pos = sline.First(' ');
150 int detelemid = TString(sline(0,pos)).Atoi();
151 TObject* o = fgDetElemIdToNameMap.GetValue(detelemid);
154 fgDetElemIdToNameMap.Add(detelemid,
155 new TObjString(sline(pos+1,sline.Length()-pos).Data()));
164 //_____________________________________________________________________________
166 AliMUONSegmentationManager::Segmentation(Int_t detElemId, AliMpPlaneType planeType)
168 TObject* it = fgMap.GetValue(detElemId);
172 TPair* p = (TPair*)(it);
174 if ( planeType == kBendingPlane )
176 return (AliMpVSegmentation*)p->Key();
178 else if ( planeType == kNonBendingPlane )
180 return (AliMpVSegmentation*)p->Value();
184 AliFatalClass("oups");
190 AliMpVSegmentation* b = ReadSegmentation(detElemId,kBendingPlane);
191 AliMpVSegmentation* nb = ReadSegmentation(detElemId,kNonBendingPlane);
194 AliErrorClass(Form("Could not get segmentations for detElemId=%d",detElemId));
197 fgMap.Add(detElemId,new TPair(b,nb));
198 return Segmentation(detElemId,planeType);
202 //_____________________________________________________________________________
204 AliMUONSegmentationManager::SegmentationList(Int_t localBoardNumber)
207 // Method specific to trigger chamber where a single local trigger board
208 // spans several detelemid.
209 // This method returns a list of AliMpVSegmentation that contains
210 // the given local board.
212 // Note that the returned TList is not the owner of its AliMpVSegmentation
215 // This method can only work if ALL trigger segmentation have been read in,
217 // FIXME: now I'm not so sure the following is the best way to achieve that.
218 // Maybe a global way to get the list of detelemid of a stationType would be
219 // best, and would avoid to hard-code detelemid range here.
221 if ( fgLocalBoardMap.GetSize() == 0 )
223 for ( Int_t detElemId = 1100; detElemId < 1500; ++detElemId )
225 if ( StationType(detElemId) == kStationTrigger )
227 AliMpTriggerSegmentation* seg =
228 (AliMpTriggerSegmentation*)Segmentation(detElemId,kNonBendingPlane);
229 FillLocalBoardMap(seg);
230 seg = (AliMpTriggerSegmentation*)Segmentation(detElemId,kBendingPlane);
231 FillLocalBoardMap(seg);
236 return (TList*)fgLocalBoardMap.GetValue(localBoardNumber);
239 //_____________________________________________________________________________
241 AliMUONSegmentationManager::DetElemName(int detelemid)
243 if ( ! fgDetElemIdToNameMap.GetSize() )
245 ReadDetElemIdToName(kStation345);
246 ReadDetElemIdToName(kStationTrigger);
247 ReadDetElemIdToName(kStation1);
248 ReadDetElemIdToName(kStation2);
251 TObject* rv = fgDetElemIdToNameMap.GetValue(detelemid);
255 return ((TObjString*)(rv))->String().Data();
263 //_____________________________________________________________________________
265 AliMUONSegmentationManager::StationType(Int_t detelemid)
267 if (!IsValidDetElemId(detelemid)) return kStationInvalid;
269 Int_t i = detelemid/100;
293 return kStationTrigger;
296 AliErrorClass(Form("%d is not a valid detelemeid\n",detelemid));
297 return kStationInvalid;