]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegmentationManager.cxx
From Laurent:
[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 "AliMpFiles.h"
21 #include "AliLog.h"
22 #include "AliMpSectorReader.h"
23 #include "AliMpSector.h"
24 #include "AliMpSectorSegmentation.h"
25 #include "AliMpSlatSegmentation.h"
26 #include "AliMpSt345Reader.h"
27
28 #include "TObjString.h"
29 #include "TClass.h"
30
31 ClassImp(AliMUONSegmentationManager)
32
33 TExMap AliMUONSegmentationManager::fgMap;
34 TExMap AliMUONSegmentationManager::fgDetElemIdToSlatTypeMap;
35
36 //_____________________________________________________________________________
37 AliMUONSegmentationManager::AliMUONSegmentationManager() : TObject()
38 {
39 }
40
41 //_____________________________________________________________________________
42 AliMUONSegmentationManager::~AliMUONSegmentationManager()
43 {
44 }
45
46 //_____________________________________________________________________________
47 Bool_t 
48 AliMUONSegmentationManager::IsValidDetElemId(Int_t detElemId)
49 {
50   return (SlatType(detElemId) != 0);
51 }
52
53 //_____________________________________________________________________________
54 AliMpVSegmentation* 
55 AliMUONSegmentationManager::ReadSegmentation(Int_t detElemId, AliMpPlaneType planeType)
56 {
57   if ( detElemId >= 500 && detElemId <= 1025 )
58   {
59     AliMpSlat* slat = ReadSlat(detElemId,planeType);
60     return new AliMpSlatSegmentation(slat);
61   }     
62   else if ( detElemId < 500 )
63   {
64     AliMpStationType station(kStation2);
65     if ( detElemId < 200 )
66     { 
67       station = kStation1;
68     }   
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);
73   }
74   else
75   {
76     return 0x0;
77   }
78 }
79
80 //_____________________________________________________________________________
81 Bool_t
82 AliMUONSegmentationManager::ReadDetElemIdToSlatType()
83
84   std::ifstream in(AliMpFiles::Instance()->DetElemIdToSlatTypeFilePath().Data());
85   if (!in.good()) return false;
86   
87   fgDetElemIdToSlatTypeMap.Delete();
88   
89   char line[80];
90   
91   while ( in.getline(line,80) )
92   {    
93     if ( !isdigit(line[0]) ) continue;
94     TString sline(line);
95     
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())));
100   }
101   
102   in.close();
103   
104   return true;
105 }
106
107 //_____________________________________________________________________________
108 AliMpSlat*
109 AliMUONSegmentationManager::ReadSlat(Int_t detElemId, AliMpPlaneType planeType)
110 {
111         return AliMpSt345Reader::ReadSlat(SlatType(detElemId),planeType);
112 }
113
114
115 //_____________________________________________________________________________
116 AliMpVSegmentation* 
117 AliMUONSegmentationManager::Segmentation(Int_t detElemId, AliMpPlaneType planeType)
118 {
119         Long_t it = fgMap.GetValue((Long_t)detElemId);
120         
121   if ( it )
122   {
123     TPair* p = (TPair*)(it);
124   
125     if ( planeType == kBendingPlane )
126     {
127       return (AliMpVSegmentation*)p->Key();
128     }
129     else if ( planeType == kNonBendingPlane )
130     {
131       return (AliMpVSegmentation*)p->Value();
132     }           
133     else
134     {
135       AliFatalClass("oups");
136       return 0x0;
137     }
138   }
139   else
140   {
141     AliMpVSegmentation* b = ReadSegmentation(detElemId,kBendingPlane);
142     AliMpVSegmentation* nb = ReadSegmentation(detElemId,kNonBendingPlane);
143     if ( !b || !nb )
144     {
145       AliErrorClass(Form("Could not get segmentations for detElemId=%d",detElemId));
146       return 0x0;
147     } 
148     fgMap.Add((Long_t)(detElemId),(Long_t)(new TPair(b,nb)));
149     return Segmentation(detElemId,planeType);
150   }
151 }
152
153 //_____________________________________________________________________________
154 const char* 
155 AliMUONSegmentationManager::SlatType(int detelemid)
156 {
157   if ( ! fgDetElemIdToSlatTypeMap.GetSize() ) ReadDetElemIdToSlatType();
158   
159   Long_t rv = fgDetElemIdToSlatTypeMap.GetValue(detelemid);
160   
161   if ( rv )
162   {
163     return ((TObjString*)(rv))->String().Data();
164   }
165   else
166   {
167     return 0;
168   }
169 }
170