]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEStore.cxx
New macro to keep track of timing performances of the segmentation methods (Laurent)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEStore.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 // $Id$
17 // $MpId: AliMpDEStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpDEStore
22 // --------------------
23 // The container class for detection element objects
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 //          Laurent Aphecetche, Christian Finck, SUBATECH Nantes
26 //-----------------------------------------------------------------------------
27
28 #include <cstdlib>
29 #include "AliMpDEStore.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpDetElement.h"
32 #include "AliMpConstants.h"
33 #include "AliMpFiles.h"
34 #include "AliMpDataStreams.h"
35 #include "AliMpHelper.h"
36 #include "AliMpIntPair.h"
37 #include "AliMpConstants.h"
38 #include "AliMpExMapIterator.h"
39
40 #include "AliLog.h"
41
42 #include <Riostream.h>
43 #include <TClass.h>
44 #include <TSystem.h>
45 #include <TObjString.h>
46 #include <TObjArray.h>
47 #include <TMap.h>
48
49 /// \cond CLASSIMP
50 ClassImp(AliMpDEStore)
51 /// \endcond
52
53 AliMpDEStore* AliMpDEStore::fgInstance = 0;
54 const char    AliMpDEStore::fgkCommentPrefix = '#'; 
55
56 //
57 // static methods
58 //
59
60 //______________________________________________________________________________
61 AliMpDEStore* AliMpDEStore::Instance(Bool_t warn)
62 {
63 /// Create the DE store if it does not yet exist
64 /// and return its instance
65
66   if ( ! fgInstance && warn  ) {
67     AliWarningClass("DE Store has not been loaded");
68   }  
69      
70   return fgInstance;
71 }    
72
73 //______________________________________________________________________________
74 AliMpDEStore* AliMpDEStore::ReadData(const AliMpDataStreams& dataStreams, 
75                                      Bool_t warn)
76 {
77 /// Load the DE store data from ASCII data files
78 /// and return its instance
79
80   if ( fgInstance ) {
81     if ( warn )
82       AliWarningClass("DE Store has been already loaded");
83     return fgInstance;
84   }  
85   
86   if ( dataStreams.GetReadFromFiles() )
87     AliInfoClass("Reading DE Store from ASCII files.");
88
89   fgInstance = new AliMpDEStore(dataStreams);
90   return fgInstance;
91 }    
92
93 //
94 // ctors, dtor
95 //
96
97 //______________________________________________________________________________
98 AliMpDEStore::AliMpDEStore(const AliMpDataStreams& dataStreams)
99 : TObject(),
100   fkDataStreams(dataStreams),
101   fDetElements()
102 {  
103 /// Standard constructor
104
105   AliDebug(1,"");
106   fDetElements.SetOwner(true);
107
108   // Create all detection elements
109   FillDEs();
110 }
111
112 //______________________________________________________________________________
113 AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
114 : TObject(),
115   fkDataStreams(ioCtor),
116   fDetElements(ioCtor)
117 {  
118 /// Constructor for IO
119
120   AliDebug(1,"");
121
122   fgInstance = this;
123 }
124
125
126 //______________________________________________________________________________
127 AliMpDEStore::~AliMpDEStore()
128 {
129 /// Destructor
130
131   AliDebug(1,"");
132
133   // Segmentations are deleted with fMpSegmentations 
134   // El cards arrays are deleted with fElCardsMap
135   
136   fgInstance = 0;
137 }
138
139 //
140 // private methods
141 //
142
143 //______________________________________________________________________________
144 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
145 {
146 /// Return true if the planeTypeName corresponds to a valid plane type
147
148   if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
149        planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) 
150     return true;   
151
152   return false;
153 }  
154
155 //______________________________________________________________________________
156 Bool_t
157 AliMpDEStore::ReadDENames(AliMp::StationType station, 
158                           AliMq::Station12Type station12)
159
160 /// Read det element names for cath = 0 from the file specified by name
161 /// and fill the map 
162
163   // Open stream
164   istream& in 
165     = fkDataStreams.
166         CreateDataStream(AliMpFiles::DENamesFilePath(station, station12));
167   
168   // Read plane types per cathods
169   //
170   char line[80];
171   TString word;
172   TString cathName1, cathName2;
173   in >> word;
174   while ( ! in.eof() && cathName1.Length() == 0 ) {
175     if ( word[0] == '#' ) 
176       in.getline(line, 80);
177     else { 
178       cathName1 = word;
179       in >> cathName2;
180     }
181     in >> word;
182   }
183   
184   Bool_t isCathNameDefined = false;
185   if ( IsPlaneType(cathName1) &&  IsPlaneType(cathName2) )
186     isCathNameDefined = true;
187     
188   // Read DE names
189   //
190   Int_t detElemId;
191   TString name, name0, name1, name2;
192   AliMp::PlaneType planeForCathode[2];
193   
194   while ( ! in.eof() ) 
195   {
196     if ( word[0] == '#' ) 
197     {
198       in.getline(line, 80);
199     }
200     else 
201     {  
202       detElemId = word.Atoi();
203       in >> name;
204       in >> name0;
205       // warning : important to check non bending first (=nbp),
206       // as bp is contained within nbp...
207       if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
208       {
209         planeForCathode[0] = AliMp::kNonBendingPlane;
210       }
211       else
212       {
213         planeForCathode[0] = AliMp::kBendingPlane;
214       }
215  
216       if ( !isCathNameDefined ) 
217       { 
218         in >> name2;
219         name1 = name0; 
220         Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
221         name0 = name1(0,pos);
222
223         // Other cathode is other plane...
224         planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
225       }
226       else 
227       {
228         name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
229         name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
230         if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
231         {
232           planeForCathode[1] = AliMp::kNonBendingPlane;
233         }
234         else
235         {
236           planeForCathode[1] = AliMp::kBendingPlane;
237         }        
238       }   
239
240       if ( planeForCathode[0]==planeForCathode[1] )
241       {
242         AliFatalClass(Form("Got the same cathode type for both planes"
243                       " of DetElemId %d",detElemId));
244       }
245       
246       AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
247       
248       if ( ! fDetElements.GetValue(detElemId) ) 
249       {
250         AliDebugClassStream(3)  
251           << "Adding DE name "  << detElemId << "  " << name << endl;
252         fDetElements.Add(detElemId, detElement); 
253       } 
254       else 
255       {
256         AliWarningClassStream()
257           << "Det element "  << detElemId << "  " << name << " already defined." << endl;
258       } 
259     } 
260     in >> word;
261   }
262   
263   delete &in;
264
265   return true;
266 }
267
268 //______________________________________________________________________________
269 void AliMpDEStore::FillDEs()
270 {
271 /// Fill DE names from files
272   AliDebugClass(2,"");
273   Bool_t result1 = ReadDENames(AliMp::kStation12, AliMq::kStation1);
274   Bool_t result2 = ReadDENames(AliMp::kStation12, AliMq::kStation2);
275   Bool_t result3 = ReadDENames(AliMp::kStation345);
276   Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
277   
278   Bool_t result = result1 && result2 && result3 && result4;
279   if ( ! result ) {
280     AliErrorClassStream() << "Error in reading DE names files" << endl;
281   }  
282   AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize()));
283 }
284
285 //
286 // public methods
287 //
288
289
290 //______________________________________________________________________________
291 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
292 {
293 /// Return det element for given detElemId
294
295   AliMpDetElement* detElement
296     = (AliMpDetElement*)fDetElements.GetValue(detElemId);
297     
298   if ( ! detElement && warn ) {  
299     AliErrorClassStream() 
300         << "Detection element " << detElemId << " not defined." << endl;
301   }     
302
303   return detElement;
304 }    
305
306 //______________________________________________________________________________
307 AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
308 {
309 /// Return det element for given deName
310
311   TIter next(fDetElements.CreateIterator());
312   AliMpDetElement* detElement;
313   
314   while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
315   {
316              
317     if (deName.CompareTo(detElement->GetDEName()) == 0) 
318
319       return detElement;
320   }
321
322   if (warn) {  
323     AliErrorClassStream() 
324         << "Detection element with name" << deName.Data() << " not defined." << endl;
325   }     
326
327   return 0x0;   
328
329 }