]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSt345Reader.cxx
Updated comments for Doxygen - corrected warnings
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSt345Reader.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 // $MpId: AliMpSt345Reader.cxx,v 1.11 2006/05/24 13:58:50 ivana Exp $
18
19 #include "AliMpSt345Reader.h"
20
21 #include "AliLog.h"
22 #include "AliMpMotifReader.h"
23 #include "AliMpFiles.h"
24 #include "AliMpMotifType.h"
25 #include "AliMpPCB.h"
26 #include "AliMpSlat.h"
27 #include "AliMpMotifMap.h"
28 #include "AliMpMotifPosition.h"
29 #include "AliMpMotif.h"
30 #include "AliMpHelper.h"
31 #include "AliMpConstants.h"
32
33 #include "Riostream.h"
34 #include "TClass.h"
35 #include "TObjString.h"
36 #include "TString.h"
37
38 #include <sstream>
39 #include <assert.h>
40
41 /// 
42 /// \class AliMpSt345Reader
43 //
44 /// Read slat and pcb ASCII files.
45 /// 
46 /// Basically this class provides 2 static methods :
47 /// - AliMpSlat* ReadSlat()
48 /// - AliMpPCB ReadPCB()
49 ///
50 /// \author Laurent Aphecetche
51
52 /// \cond CLASSIMP
53 ClassImp(AliMpSt345Reader)
54 /// \endcond
55
56 TMap AliMpSt345Reader::fgPCBMap;
57
58 //_____________________________________________________________________________
59 AliMpSt345Reader::AliMpSt345Reader() : TObject()
60 {
61   //
62   // Default ctor.
63   //
64
65
66 //_____________________________________________________________________________
67 AliMpSt345Reader::~AliMpSt345Reader()
68 {
69   //
70   // Dtor.
71   //
72   fgPCBMap.Delete();
73 }
74
75 //_____________________________________________________________________________
76 AliMpPCB*
77 AliMpSt345Reader::PCB(const char* pcbType)
78 {
79   //
80   // Get access to an AliMpPCB object, given its type (e.g. N1, SB2, etc...)
81   //
82   // Note that the returned object is either a new one (read from file) or a 
83   // reused one if it is already present in the internal map.
84   //
85   
86   TPair* pair = (TPair*)fgPCBMap.FindObject(pcbType);
87   if ( pair )
88   {
89     AliDebugClass(1,Form("Getting pcb %s from internal map",pcbType));
90     return (AliMpPCB*)pair->Value();
91   }
92   else
93   {
94     AliDebugClass(1,Form("Reading pcb %s from file",pcbType));
95     return ReadPCB(pcbType);
96   }
97 }
98
99 //_____________________________________________________________________________
100 AliMpPCB*
101 AliMpSt345Reader::ReadPCB(const char* pcbType)
102
103   //
104   // Create a new AliMpPCB object, by reading it from file.
105   //
106   
107   std::ifstream in(AliMpFiles::SlatPCBFilePath(kStation345,pcbType).Data());
108   if (!in.good()) 
109   {
110     AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
111     return 0;
112   }
113  
114   AliMpMotifReader reader(kStation345,kNonBendingPlane); 
115   // note that the nonbending
116   // parameter is of no use for station345, as far as reading motif is 
117   // concerned, as all motifs are supposed to be in the same directory
118   // (as they are shared by bending/non-bending planes).
119      
120   char line[80];
121   
122   const TString kSizeKeyword("SIZES");
123   const TString kMotifKeyword("MOTIF");
124   
125   AliMpPCB* pcb = 0;
126   
127   while ( in.getline(line,80) )
128   {
129     if ( line[0] == '#' ) continue;
130     
131     TString sline(line);
132     
133     if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
134     {
135       std::istringstream sin(sline(kSizeKeyword.Length(),
136                                    sline.Length()-kSizeKeyword.Length()).Data());
137       float padSizeX = 0.0;
138       float padSizeY = 0.0;
139       float pcbSizeX = 0.0;
140       float pcbSizeY = 0.0;
141       sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
142       assert(pcb==0);
143       pcb = new AliMpPCB(pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
144     }
145     
146     if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
147     {
148       std::istringstream sin(sline(kMotifKeyword.Length(),
149                                    sline.Length()-kMotifKeyword.Length()).Data());
150       TString sMotifType;
151       int ix;
152       int iy;
153       sin >> sMotifType >> ix >> iy;
154       
155       AliMpMotifType* motifType = 
156         reader.BuildMotifType(sMotifType.Data());
157       
158       assert(pcb!=0);
159       pcb->Add(motifType,ix,iy);
160     }
161   }
162   
163   in.close();
164   
165   fgPCBMap.Add(new TObjString(pcbType),pcb);
166   return pcb;
167 }
168
169 //_____________________________________________________________________________
170 AliMpSlat*
171 AliMpSt345Reader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
172 {
173   //
174   // Create a new AliMpSlat object, by reading it from file.
175   //
176   
177   std::ifstream in(AliMpFiles::SlatFilePath(kStation345,slatType,
178                                             planeType).Data());
179   if (!in.good()) 
180   {
181     AliErrorClass(Form("Cannot read slat from %s",
182                        AliMpFiles::SlatFilePath(kStation345,slatType,planeType).Data()));
183     return 0;
184   }
185   
186   char line[80];
187   
188   const TString kpcbKeyword("PCB");
189   
190   AliMpSlat* slat = new AliMpSlat(slatType, planeType);
191   
192   while ( in.getline(line,80) )
193   {
194     if ( line[0] == '#' ) continue;
195     
196     TString sline(AliMpHelper::Normalize(line));
197     
198     if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
199     {
200       TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
201       Ssiz_t blankPos = tmp.First(' ');
202       if ( blankPos < 0 )
203             {
204         AliErrorClass("Syntax error in PCB file, should get a list of "
205                       "manu ids after the pcbname");
206         delete slat;
207         return 0;
208             }
209       
210       TString pcbName(tmp(0,blankPos));
211       TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
212       
213       AliMpPCB* pcbType = PCB(pcbName.Data());    
214       if (!pcbType)
215             {
216         AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
217               delete slat;
218               return 0;
219             }      
220
221       TArrayI manuList;
222       AliMpHelper::DecodeName(manus,';',manuList);
223       if ( manuList.GetSize() != Int_t(pcbType->GetSize()) )
224             {
225         AliErrorClass(Form("Wrong number of manu ids for this PCB ("
226                            "%s) : %d out of %d",pcbName.Data(),
227                            manuList.GetSize(),pcbType->GetSize()));
228               delete slat;
229               return 0;
230       }
231
232       for ( Int_t i = 0; i < manuList.GetSize(); ++i )
233       {
234         manuList[i] |= AliMpConstants::ManuMask(planeType);
235       }
236       slat->Add(pcbType,manuList);
237     }
238   }
239   
240   in.close();
241   
242   return slat;
243 }
244