]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEStore.cxx
Commenting out StdoutToAliDebug which is, with the current AliLog
[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 // Class AliMpDEStore
21 // --------------------
22 // The container class for detection element objects
23 // Authors: Ivana Hrivnacova, IPN Orsay
24 //          Laurent Aphecetche, Christian Finck, SUBATECH Nantes
25
26 #include "AliMpDEStore.h"
27 #include "AliMpDEManager.h"
28 #include "AliMpDetElement.h"
29 #include "AliMpConstants.h"
30 #include "AliMpFiles.h"
31 #include "AliMpHelper.h"
32 #include "AliMpIntPair.h"
33 #include "AliMpConstants.h"
34
35 #include "AliLog.h"
36
37 #include <Riostream.h>
38 #include <TClass.h>
39 #include <TSystem.h>
40 #include <TObjString.h>
41 #include <TMap.h>
42
43 /// \cond CLASSIMP
44 ClassImp(AliMpDEStore)
45 /// \endcond
46
47 AliMpDEStore* AliMpDEStore::fgInstance = 0;
48 const char    AliMpDEStore::fgkCommentPrefix = '#'; 
49
50 //
51 // static methods
52 //
53
54 //______________________________________________________________________________
55 AliMpDEStore* AliMpDEStore::Instance()
56 {
57 /// Create the DE store if it does not yet exist
58 /// and return its instance
59
60   if ( ! fgInstance )
61     fgInstance = new AliMpDEStore();
62     
63   return fgInstance;
64 }    
65
66 //
67 // ctors, dtor
68 //
69
70 //______________________________________________________________________________
71 AliMpDEStore::AliMpDEStore()
72 : TObject(),
73   fDetElements(true)
74 {  
75 /// Standard constructor
76
77   AliDebug(1,"");
78   fDetElements.SetOwner(true);
79
80   // Create all detection elements
81   FillDEs();
82 }
83
84 //______________________________________________________________________________
85 AliMpDEStore::AliMpDEStore(TRootIOCtor* /*ioCtor*/)
86 : TObject(),
87   fDetElements()
88 {  
89 /// Constructor for IO
90
91   AliDebug(1,"");
92
93   fgInstance = this;
94 }
95
96
97 //______________________________________________________________________________
98 AliMpDEStore::~AliMpDEStore()
99 {
100 /// Destructor
101
102   AliDebug(1,"");
103
104   // Segmentations are deleted with fMpSegmentations 
105   // El cards arrays are deleted with fElCardsMap
106   
107   fgInstance = 0;
108 }
109
110 //
111 // private methods
112 //
113
114 //______________________________________________________________________________
115 Bool_t AliMpDEStore::IsPlaneType(const TString& planeTypeName)
116 {
117 /// Return true if the planeTypeName corresponds to a valid plane type
118
119   if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ||
120        planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) 
121     return true;   
122
123   return false;
124 }  
125
126 //______________________________________________________________________________
127 AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName)
128 {
129 /// Return plane type for the given planeTypeName                            \n
130 /// Fatal error if planeTypeName is wrong 
131
132   if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) ) 
133     return AliMp::kBendingPlane;
134
135   if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) ) 
136     return AliMp::kNonBendingPlane;
137
138   // Should never reach this line
139   AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
140   return AliMp::kBendingPlane;
141 }       
142
143 //______________________________________________________________________________
144 AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName)
145 {
146 /// Return station type for the given stationTypeName                        \n
147 /// Fatal error if stationTypeName is wrong 
148
149   if ( stationTypeName == StationTypeName(AliMp::kStation1) )
150     return AliMp::kStation1;
151
152   if ( stationTypeName == StationTypeName(AliMp::kStation2) )
153     return AliMp::kStation2;
154
155   if ( stationTypeName == StationTypeName(AliMp::kStation345) )
156     return AliMp::kStation345;
157
158   if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) ) 
159     return AliMp::kStationTrigger;
160
161   // Should never reach this line
162   AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
163   return AliMp::kStation1;
164 }
165
166 //______________________________________________________________________________
167 Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement, 
168                                        AliMp::StationType stationType)
169 {
170 /// Read manu serial numbers for the given detection element
171   
172   TString deName = detElement->GetDEName();
173
174   TString infile = AliMpFiles::ManuToSerialPath(deName, stationType);
175   ifstream in(infile, ios::in);
176   
177   // Change to Error when all files available
178   //if ( !in.is_open() && stationType == AliMp::kStation345 ) {
179   //   AliWarningStream() << "File " << infile << " not found." << endl;
180   //  return false;
181   //}   
182        
183   char line[80];
184
185   while ( in.getline(line,80) ) {
186
187     if ( line[0] == '#' ) continue;
188
189     TString tmp(AliMpHelper::Normalize(line));
190
191     Int_t blankPos  = tmp.First(' ');
192
193     TString sManuId(tmp(0, blankPos));
194
195     Int_t manuId = atoi(sManuId.Data());
196
197     TString sManuSerial(tmp(blankPos + 1, tmp.Length()-blankPos));
198
199     Int_t manuSerial = atoi(sManuSerial.Data());
200       
201     // filling manuId <> manuSerial
202     detElement->AddManuSerial(manuId, manuSerial); 
203   }
204    
205   in.close();
206   return true;
207 }
208
209 //______________________________________________________________________________
210 Bool_t
211 AliMpDEStore::ReadDENames(AliMp::StationType station)
212
213 /// Read det element names for cath = 0 from the file specified by name
214 /// and fill the map 
215
216   // Open file
217   TString filePath = AliMpFiles::DENamesFilePath(station);
218   std::ifstream in(filePath);
219   if (!in.good()) {
220     AliErrorClassStream() << "Cannot open file " << filePath << endl;;
221     return false;
222   }
223   
224   // Read plane types per cathods
225   //
226   char line[80];
227   TString word;
228   TString cathName1, cathName2;
229   in >> word;
230   while ( ! in.eof() && cathName1.Length() == 0 ) {
231     if ( word[0] == '#' ) 
232       in.getline(line, 80);
233     else { 
234       cathName1 = word;
235       in >> cathName2;
236     }
237     in >> word;
238   }
239   
240   Bool_t isCathNameDefined = false;
241   if ( IsPlaneType(cathName1) &&  IsPlaneType(cathName2) )
242     isCathNameDefined = true;
243     
244   // Read DE names
245   //
246   Int_t detElemId;
247   TString name, name0, name1, name2;
248   AliMp::PlaneType planeForCathode[2];
249   
250   while ( ! in.eof() ) 
251   {
252     if ( word[0] == '#' ) 
253     {
254       in.getline(line, 80);
255     }
256     else 
257     {  
258       detElemId = word.Atoi();
259       in >> name;
260       in >> name0;
261       // warning : important to check non bending first (=nbp),
262       // as bp is contained within nbp...
263       if ( name0.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
264       {
265         planeForCathode[0] = AliMp::kNonBendingPlane;
266       }
267       else
268       {
269         planeForCathode[0] = AliMp::kBendingPlane;
270       }
271  
272       if ( !isCathNameDefined ) 
273       { 
274         in >> name2;
275         name1 = name0; 
276         Ssiz_t pos = name1.First(AliMpDetElement::GetNameSeparator());
277         name0 = name1(0,pos);
278
279         // Other cathode is other plane...
280         planeForCathode[1] = OtherPlaneType(planeForCathode[0]);
281       }
282       else 
283       {
284         name1 = name0 + AliMpDetElement::GetNameSeparator() + cathName1;
285         name2 = name0 + AliMpDetElement::GetNameSeparator() + cathName2;
286         if ( name2.Contains(PlaneTypeName(AliMp::kNonBendingPlane)) )
287         {
288           planeForCathode[1] = AliMp::kNonBendingPlane;
289         }
290         else
291         {
292           planeForCathode[1] = AliMp::kBendingPlane;
293         }        
294       }   
295
296       if ( planeForCathode[0]==planeForCathode[1] )
297       {
298         AliFatalClass(Form("Got the same cathode type for both planes"
299                       " of DetElemId %d",detElemId));
300       }
301       
302       AliMpDetElement* detElement 
303         = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
304       if ( ! fDetElements.GetValue(detElemId) ) 
305       {
306         AliDebugClassStream(3)  
307           << "Adding DE name "  << detElemId << "  " << name << endl;
308         fDetElements.Add(detElemId, detElement); 
309         
310         // Read manu serial numbers for this det element
311         ReadManuToSerialNbs(detElement, station);
312       } 
313       else 
314       {
315         AliWarningClassStream()
316           << "Det element "  << detElemId << "  " << name << " already defined." << endl;
317       } 
318     } 
319     in >> word;
320   }
321
322   // Close file
323   in.close();
324   
325   return true;
326 }
327
328 //______________________________________________________________________________
329 void AliMpDEStore::FillDEs()
330 {
331 /// Fill DE names from files
332   AliDebugClass(2,"");
333   Bool_t result1 = ReadDENames(AliMp::kStation1);
334   Bool_t result2 = ReadDENames(AliMp::kStation2);
335   Bool_t result3 = ReadDENames(AliMp::kStation345);
336   Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
337   
338   Bool_t result = result1 && result2 && result3 && result4;
339   if ( ! result ) {
340     AliErrorClassStream() << "Error in reading DE names files" << endl;
341   }  
342 }
343
344 //
345 // public methods
346 //
347
348
349 //______________________________________________________________________________
350 AliMpDetElement* AliMpDEStore::GetDetElement(Int_t detElemId, Bool_t warn) const
351 {
352 /// Return det element for given detElemId
353
354   AliMpDetElement* detElement
355     = (AliMpDetElement*)fDetElements.GetValue(detElemId);
356     
357   if ( ! detElement && warn ) {  
358     AliErrorClassStream() 
359         << "Detection element " << detElemId << " not defined." << endl;
360   }     
361
362   return detElement;
363 }    
364
365 //______________________________________________________________________________
366 AliMpIntPair  AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const
367 {
368 /// Return the detElemId and manuId for given serial manu number
369
370   for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) {
371     
372     AliMpDetElement* detElement 
373       = (AliMpDetElement*)fDetElements.GetObject(i);
374       
375     Int_t manuId = detElement->GetManuIdFromSerial(manuSerial);
376     if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId);
377   }    
378
379   // manu with this serial number does not exist
380   return AliMpIntPair::Invalid();
381 }