]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSegFactory.cxx
- Reordering includes and/or
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSegFactory.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 purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 ////////////////////////////////////////////////////////////
17 //  Factory for muon chambers, segmentations and response //
18 ////////////////////////////////////////////////////////////
19
20 /* $Id$ */
21
22 #include "AliMpSegFactory.h"
23
24 #include "AliLog.h"
25 #include "AliMpDEManager.h"
26 #include "AliMpExMap.h"
27 #include "AliMpSector.h"
28 #include "AliMpSectorReader.h"
29 #include "AliMpSectorSegmentation.h"
30 #include "AliMpSlat.h"
31 #include "AliMpSlatSegmentation.h"
32 #include "AliMpSt345Reader.h"
33 #include "AliMpTrigger.h"
34 #include "AliMpTriggerReader.h"
35 #include "AliMpTriggerSegmentation.h"
36 #include <Riostream.h>
37 #include <TMap.h>
38 #include <TObjString.h>
39 #include <TSystem.h>
40
41 ClassImp(AliMpSegFactory)
42
43 //______________________________________________________________________________
44 AliMpSegFactory::AliMpSegFactory()
45 : TObject(),
46   fMpSegmentations(),
47   fMpMap(new AliMpExMap(true))
48 {  
49     /// Standard constructor
50     AliDebug(1,"");
51     fMpMap->SetOwner(true);
52 }
53
54 //______________________________________________________________________________
55 AliMpSegFactory::AliMpSegFactory(const AliMpSegFactory& rhs)
56  : TObject(rhs)
57 {
58 /// Protected copy constructor
59
60   AliFatal("Not implemented.");
61 }
62
63 //______________________________________________________________________________
64
65 AliMpSegFactory::~AliMpSegFactory()
66 {
67 /// Destructor
68
69   // The segmentations is supposed to be deleted in the client code
70   AliDebug(1,"");
71 }
72
73 //______________________________________________________________________________
74 AliMpSegFactory&  AliMpSegFactory::operator=(const AliMpSegFactory& rhs)
75 {
76   // Protected assignement operator
77
78   if (this == &rhs) return *this;
79
80   AliFatal("Not implemented.");
81     
82   return *this;  
83 }    
84           
85 //
86 // public methods
87 //
88
89 //______________________________________________________________________________
90 AliMpVSegmentation* 
91 AliMpSegFactory::CreateMpSegmentation(Int_t detElemId, Int_t cath)
92 {
93 /// Create mapping segmentation for given detElemId and cath
94 /// or return it if it was already built
95
96   // Check detElemId & cath  
97   if ( ! AliMpDEManager::IsValid(detElemId, cath, true) ) return 0;
98
99   // If segmentation is already built, just return it
100   //
101   TString deName = AliMpDEManager::GetDEName(detElemId, cath);
102   TObject* object = fMpSegmentations.Get(deName);
103   if ( object ) return (AliMpVSegmentation*)object;
104
105   AliDebug(1,Form("Creating segmentation for detElemId=%d cath=%d",
106                   detElemId,cath));
107   
108   // Read mapping data and create segmentation
109   //
110   AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
111   AliMpPlaneType planeType = AliMpDEManager::GetPlaneType(detElemId, cath);
112   TString deTypeName = AliMpDEManager::GetDETypeName(detElemId, cath);
113
114   AliMpVSegmentation* mpSegmentation = 0;
115
116   if ( stationType == kStation1 || stationType == kStation2 ) {
117     AliMpSectorReader reader(stationType, planeType);
118     AliMpSector* sector = reader.BuildSector();
119     mpSegmentation = new AliMpSectorSegmentation(sector);
120   }
121   else if ( stationType == kStation345 ) { 
122     AliMpSlat* slat = AliMpSt345Reader::ReadSlat(deTypeName, planeType);
123     mpSegmentation =  new AliMpSlatSegmentation(slat);
124   }
125   else if ( stationType == kStationTrigger ) {
126     AliMpTrigger* trigger = AliMpTriggerReader::ReadSlat(deTypeName, planeType);
127     mpSegmentation = new AliMpTriggerSegmentation(trigger);
128   }
129   else   
130     AliErrorStream() << "Unknown station type" << endl;
131
132   fMpSegmentations.Add(deName, mpSegmentation); 
133   return mpSegmentation;
134
135
136 //_____________________________________________________________________________
137 AliMpVSegmentation* 
138 AliMpSegFactory::CreateMpSegmentationByElectronics(Int_t detElemId,
139                                                    Int_t FEMId)
140 {
141   AliMpExMap* m = static_cast<AliMpExMap*>(fMpMap->GetValue(detElemId));
142   
143   if (!m)
144   {
145     m = FillMpMap(detElemId);
146   }
147   
148   return static_cast<AliMpVSegmentation*>(m->GetValue(FEMId));
149 }
150     
151 //______________________________________________________________________________
152 void AliMpSegFactory::DeleteSegmentations()
153 {
154 /// Delete all segmentations created with this manager
155   AliDebug(1,"deleting mpSegmentations");
156   fMpSegmentations.Clear();
157   AliDebug(1,"deleting mpMap");
158   delete fMpMap;
159   fMpMap = 0; 
160   AliDebug(1,"done");
161 }
162
163 //_____________________________________________________________________________
164 AliMpExMap*
165 AliMpSegFactory::FillMpMap(Int_t detElemId)
166 {
167   AliDebug(1,Form("detElemId=%d",detElemId));
168   
169   AliMpExMap* mde = new AliMpExMap(true);
170   mde->SetOwner(kFALSE);
171   fMpMap->Add(detElemId,mde);
172   
173   AliMpVSegmentation* seg[2];
174   TArrayI ecn[2];
175   
176   // Do it in 2 steps to be able to set the AliMpExMap size once for all,
177   // to avoid annoying warning message in case of dynamical resizing.
178   // (not critical).
179   for ( Int_t cathode = 0; cathode < 2; ++cathode )
180   {
181     seg[cathode] = CreateMpSegmentation(detElemId,cathode);
182     seg[cathode]->GetAllElectronicCardIDs(ecn[cathode]);
183   }
184   
185   mde->SetSize(ecn[0].GetSize()+ecn[1].GetSize());
186   
187   for ( Int_t cathode = 0; cathode < 2; ++ cathode )
188   {
189     for ( Int_t i = 0; i < ecn[cathode].GetSize(); ++i )
190     {
191       mde->Add(ecn[cathode][i],const_cast<AliMpVSegmentation*>(seg[cathode]));
192     }
193   }
194   
195   return mde;
196 }