]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSt345Reader.cxx
Adding new libraries
[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 "AliMpSlatMotifMap.h"
23 #include "AliMpMotifReader.h"
24 #include "AliMpFiles.h"
25 #include "AliMpMotifType.h"
26 #include "AliMpPCB.h"
27 #include "AliMpSlat.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
40 /// 
41 /// \class AliMpSt345Reader
42 //
43 /// Read slat and pcb ASCII files.
44 /// 
45 /// Basically this class provides two methods :
46 /// - AliMpSlat* ReadSlat()
47 /// - AliMpPCB ReadPCB()
48 ///
49 /// \author Laurent Aphecetche
50
51 /// \cond CLASSIMP
52 ClassImp(AliMpSt345Reader)
53 /// \endcond
54
55 //_____________________________________________________________________________
56 AliMpSt345Reader::AliMpSt345Reader(AliMpSlatMotifMap& motifMap) 
57
58 TObject(),
59 fMotifMap(motifMap)
60 {
61   ///
62   /// Default ctor.
63   ///
64
65
66 //_____________________________________________________________________________
67 AliMpSt345Reader::~AliMpSt345Reader()
68 {
69   ///
70   /// Dtor.
71   ///
72 }
73
74 //_____________________________________________________________________________
75 AliMpPCB*
76 AliMpSt345Reader::ReadPCB(const char* pcbType)
77
78   ///
79   /// Create a new AliMpPCB object, by reading it from file.
80   /// The returned object must be deleted by the client
81   
82   std::ifstream in(AliMpFiles::SlatPCBFilePath(AliMp::kStation345,pcbType).Data());
83   if (!in.good()) 
84   {
85     AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
86     return 0;
87   }
88  
89   AliMpMotifReader reader(AliMp::kStation345,AliMp::kNonBendingPlane); 
90   // note that the nonbending
91   // parameter is of no use for station345, as far as reading motif is 
92   // concerned, as all motifs are supposed to be in the same directory
93   // (as they are shared by bending/non-bending planes).
94      
95   char line[80];
96   
97   const TString kSizeKeyword("SIZES");
98   const TString kMotifKeyword("MOTIF");
99   
100   AliMpPCB* pcb = 0;
101   
102   while ( in.getline(line,80) )
103   {
104     if ( line[0] == '#' ) continue;
105     
106     TString sline(line);
107     
108     if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
109     {
110       std::istringstream sin(sline(kSizeKeyword.Length(),
111                                    sline.Length()-kSizeKeyword.Length()).Data());
112       double padSizeX = 0.0;
113       double padSizeY = 0.0;
114       double pcbSizeX = 0.0;
115       double pcbSizeY = 0.0;
116       sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
117       if (pcb)
118       {
119         AliError("pcb not null as expected");
120       }
121       pcb = new AliMpPCB(&fMotifMap,pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
122     }
123     
124     if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
125     {
126       std::istringstream sin(sline(kMotifKeyword.Length(),
127                                    sline.Length()-kMotifKeyword.Length()).Data());
128       TString sMotifType;
129       int ix;
130       int iy;
131       sin >> sMotifType >> ix >> iy;
132       
133       AliMpMotifType* motifType = fMotifMap.FindMotifType(sMotifType);
134       if (!motifType)
135       {
136         AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data()));
137         motifType = reader.BuildMotifType(sMotifType.Data());
138         fMotifMap.AddMotifType(motifType);
139       }
140       else
141       {
142         AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data()));
143       }
144       
145       pcb->Add(motifType,ix,iy);
146     }
147   }
148   
149   in.close();
150   
151   return pcb;
152 }
153
154 //_____________________________________________________________________________
155 AliMpSlat*
156 AliMpSt345Reader::ReadSlat(const char* slatType, AliMp::PlaneType planeType)
157 {
158   ///
159   /// Create a new AliMpSlat object, by reading it from file.
160   /// The returned object must be deleted by the client.
161   
162   std::ifstream in(AliMpFiles::SlatFilePath(AliMp::kStation345,slatType,
163                                             planeType).Data());
164   if (!in.good()) 
165   {
166     AliErrorClass(Form("Cannot read slat from %s",
167                        AliMpFiles::SlatFilePath(AliMp::kStation345,slatType,planeType).Data()));
168     return 0;
169   }
170   
171   char line[80];
172   
173   const TString kpcbKeyword("PCB");
174   
175   AliMpSlat* slat = new AliMpSlat(slatType, planeType);
176   
177   while ( in.getline(line,80) )
178   {
179     if ( line[0] == '#' ) continue;
180     
181     TString sline(AliMpHelper::Normalize(line));
182     
183     if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
184     {
185       TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
186       Ssiz_t blankPos = tmp.First(' ');
187       if ( blankPos < 0 )
188             {
189         AliErrorClass("Syntax error in PCB file, should get a list of "
190                       "manu ids after the pcbname");
191         delete slat;
192         return 0;
193             }
194       
195       TString pcbName(tmp(0,blankPos));
196       TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
197       
198       AliMpPCB* pcbType = ReadPCB(pcbName.Data());        
199       if (!pcbType)
200             {
201         AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
202               delete slat;
203               return 0;
204             }      
205
206       TArrayI manuList;
207       AliMpHelper::DecodeName(manus,';',manuList);
208       if ( manuList.GetSize() != Int_t(pcbType->GetSize()) )
209             {
210         AliErrorClass(Form("Wrong number of manu ids for this PCB ("
211                            "%s) : %d out of %d",pcbName.Data(),
212                            manuList.GetSize(),pcbType->GetSize()));
213         delete pcbType;
214               delete slat;
215               return 0;
216       }
217
218       for ( Int_t i = 0; i < manuList.GetSize(); ++i )
219       {
220         manuList[i] |= AliMpConstants::ManuMask(planeType);
221       }
222       slat->Add(*pcbType,manuList);
223       delete pcbType;
224     }
225   }
226   
227   in.close();
228   
229   return slat;
230 }
231