]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegmentationManager.cxx
- Changed internal TExMap to AliMpExMap to allow persistency
[u/mrichter/AliRoot.git] / MUON / AliMUONSegmentationManager.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
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 **************************************************************************/
15
16 /* $Id$ */
17
18 #include "AliMUONSegmentationManager.h"
19
20 #include "AliLog.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"
30
31 #include "Riostream.h"
32
33 #include "TArrayI.h"
34 #include "TClass.h"
35 #include "TList.h"
36 #include "TObjString.h"
37 #include "TSystem.h"
38
39 ClassImp(AliMUONSegmentationManager)
40
41 AliMpExMap AliMUONSegmentationManager::fgMap(kTRUE);
42 AliMpExMap AliMUONSegmentationManager::fgDetElemIdToNameMap(kTRUE);
43 AliMpExMap AliMUONSegmentationManager::fgLocalBoardMap(kTRUE);
44
45 namespace
46 {
47   //__________________________________________________________________________
48   TString DetElemIdToNamePath(AliMpStationType stationType)
49   {
50     /// Get the full path of the file containing the mapping detElemId <->
51     /// SlatType.
52     /// The bending parameter below is of no use in this case, but
53     /// we use it to re-use the PlaneDataDir() method untouched.
54     
55     TString filename(gSystem->ExpandPathName("${ALICE_ROOT}/MUON/data/"));
56     filename += "denames_";
57     filename += StationTypeName(stationType);
58     filename += ".dat";
59     return filename;
60   }
61 }
62
63 //_____________________________________________________________________________
64 AliMUONSegmentationManager::AliMUONSegmentationManager() : TObject()
65 {
66 }
67
68 //_____________________________________________________________________________
69 AliMUONSegmentationManager::~AliMUONSegmentationManager()
70 {
71 }
72
73 //_____________________________________________________________________________
74 void
75 AliMUONSegmentationManager::FillLocalBoardMap(AliMpTriggerSegmentation* seg)
76 {
77   const AliMpTrigger* slat = seg->Slat();
78   for ( Int_t i = 0; i < slat->GetSize(); ++i )
79   {
80     TArrayI lbn;
81     slat->GetAllLocalBoardNumbers(lbn);
82     for ( Int_t j = 0; j < lbn.GetSize(); ++j )
83     {
84       TList* list = (TList*)fgLocalBoardMap.GetValue(lbn[j]);
85       if (!list)
86       {
87         list = new TList;
88         fgLocalBoardMap.Add(lbn[j],list);
89       }
90       if ( list->FindObject(seg) == 0 )
91       {
92         list->Add(seg);
93       }
94     }
95   }
96 }
97
98 //_____________________________________________________________________________
99 Bool_t 
100 AliMUONSegmentationManager::IsValidDetElemId(Int_t detElemId)
101 {
102   return (DetElemName(detElemId) != 0);
103 }
104
105 //_____________________________________________________________________________
106 AliMpVSegmentation* 
107 AliMUONSegmentationManager::ReadSegmentation(Int_t detElemId, AliMpPlaneType planeType)
108 {
109   AliMpStationType station = StationType(detElemId);
110   
111   if (station==kStation345)
112   {
113     AliMpSlat* slat = AliMpSt345Reader::ReadSlat(DetElemName(detElemId),planeType);
114     return new AliMpSlatSegmentation(slat);
115   }
116   else if ( station==kStation1 || station==kStation2 )
117   {
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);
122   }
123   else if ( station == kStationTrigger )
124   {
125     AliMpTrigger* slat = AliMpTriggerReader::ReadSlat(DetElemName(detElemId),planeType);
126     return new AliMpTriggerSegmentation(slat);
127   }
128   return 0x0;
129 }
130
131 //_____________________________________________________________________________
132 Bool_t
133 AliMUONSegmentationManager::ReadDetElemIdToName(AliMpStationType stationType)
134
135   std::ifstream in(DetElemIdToNamePath(stationType).Data());
136   if (!in.good()) 
137   {
138     AliErrorClass(Form("Cannot read file %s",DetElemIdToNamePath(stationType).Data()));
139     return false;
140   }
141   
142   char line[80];
143   
144   while ( in.getline(line,80) )
145   {    
146     if ( !isdigit(line[0]) ) continue;
147     TString sline(line);
148     
149     Ssiz_t pos = sline.First(' ');
150     int detelemid = TString(sline(0,pos)).Atoi();
151     TObject* o = fgDetElemIdToNameMap.GetValue(detelemid);
152     if (!o)
153     {
154       fgDetElemIdToNameMap.Add(detelemid,
155                                new TObjString(sline(pos+1,sline.Length()-pos).Data()));
156     }
157   }
158   
159   in.close();
160   
161   return true;
162 }
163
164 //_____________________________________________________________________________
165 AliMpVSegmentation* 
166 AliMUONSegmentationManager::Segmentation(Int_t detElemId, AliMpPlaneType planeType)
167 {
168         TObject* it = fgMap.GetValue(detElemId);
169         
170   if ( it )
171   {
172     TPair* p = (TPair*)(it);
173   
174     if ( planeType == kBendingPlane )
175     {
176       return (AliMpVSegmentation*)p->Key();
177     }
178     else if ( planeType == kNonBendingPlane )
179     {
180       return (AliMpVSegmentation*)p->Value();
181     }           
182     else
183     {
184       AliFatalClass("oups");
185       return 0x0;
186     }
187   }
188   else
189   {
190     AliMpVSegmentation* b = ReadSegmentation(detElemId,kBendingPlane);
191     AliMpVSegmentation* nb = ReadSegmentation(detElemId,kNonBendingPlane);
192     if ( !b || !nb )
193     {
194       AliErrorClass(Form("Could not get segmentations for detElemId=%d",detElemId));
195       return 0x0;
196     } 
197     fgMap.Add(detElemId,new TPair(b,nb));
198     return Segmentation(detElemId,planeType);
199   }
200 }
201
202 //_____________________________________________________________________________
203 TList* 
204 AliMUONSegmentationManager::SegmentationList(Int_t localBoardNumber)
205 {
206   //
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.
211   //
212   // Note that the returned TList is not the owner of its AliMpVSegmentation
213   // pointers.
214   
215   // This method can only work if ALL trigger segmentation have been read in,
216   // that's for sure.
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.
220   
221   if ( fgLocalBoardMap.GetSize() == 0 )
222   {
223     for ( Int_t detElemId = 1100; detElemId < 1500; ++detElemId )
224     {
225       if ( StationType(detElemId) == kStationTrigger )
226       {
227         AliMpTriggerSegmentation* seg = 
228         (AliMpTriggerSegmentation*)Segmentation(detElemId,kNonBendingPlane);
229         FillLocalBoardMap(seg);
230         seg = (AliMpTriggerSegmentation*)Segmentation(detElemId,kBendingPlane);
231         FillLocalBoardMap(seg);
232       }
233     }
234   }
235   
236   return (TList*)fgLocalBoardMap.GetValue(localBoardNumber);
237 }
238
239 //_____________________________________________________________________________
240 const char* 
241 AliMUONSegmentationManager::DetElemName(int detelemid)
242 {
243   if ( ! fgDetElemIdToNameMap.GetSize() ) 
244   {
245     ReadDetElemIdToName(kStation345);
246     ReadDetElemIdToName(kStationTrigger);
247     ReadDetElemIdToName(kStation1);
248     ReadDetElemIdToName(kStation2);    
249   }
250   
251   TObject* rv = fgDetElemIdToNameMap.GetValue(detelemid);
252   
253   if ( rv )
254   {
255     return ((TObjString*)(rv))->String().Data();
256   }
257   else
258   {
259     return 0;
260   }
261 }
262
263 //_____________________________________________________________________________
264 AliMpStationType
265 AliMUONSegmentationManager::StationType(Int_t detelemid)
266 {
267   if (!IsValidDetElemId(detelemid)) return kStationInvalid;
268   
269   Int_t i = detelemid/100;
270
271   switch (i)
272   {
273     case 1:
274     case 2:  
275       return kStation1;
276       break;
277     case 3:
278     case 4:  
279       return kStation2;
280       break;
281     case 5:
282     case 6:
283     case 7:
284     case 8:
285     case 9:
286     case 10:  
287       return kStation345;
288       break;
289     case 11:
290     case 12:
291     case 13:
292     case 14:  
293       return kStationTrigger;
294       break;
295     default:
296       AliErrorClass(Form("%d is not a valid detelemeid\n",detelemid));
297       return kStationInvalid;
298       break;
299   };
300 }