1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpSt345Reader.cxx,v 1.11 2006/05/24 13:58:50 ivana Exp $
19 #include "AliMpSt345Reader.h"
22 #include "AliMpSlatMotifMap.h"
23 #include "AliMpMotifReader.h"
24 #include "AliMpFiles.h"
25 #include "AliMpMotifType.h"
27 #include "AliMpSlat.h"
28 #include "AliMpMotifPosition.h"
29 #include "AliMpMotif.h"
30 #include "AliMpHelper.h"
31 #include "AliMpConstants.h"
33 #include "Riostream.h"
35 #include "TObjString.h"
41 /// \class AliMpSt345Reader
43 /// Read slat and pcb ASCII files.
45 /// Basically this class provides two methods :
46 /// - AliMpSlat* ReadSlat()
47 /// - AliMpPCB ReadPCB()
49 /// \author Laurent Aphecetche
52 ClassImp(AliMpSt345Reader)
55 //_____________________________________________________________________________
56 AliMpSt345Reader::AliMpSt345Reader(AliMpSlatMotifMap& motifMap)
66 //_____________________________________________________________________________
67 AliMpSt345Reader::~AliMpSt345Reader()
74 //_____________________________________________________________________________
76 AliMpSt345Reader::ReadPCB(const char* pcbType)
79 /// Create a new AliMpPCB object, by reading it from file.
80 /// The returned object must be deleted by the client
82 std::ifstream in(AliMpFiles::SlatPCBFilePath(AliMp::kStation345,pcbType).Data());
85 AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
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).
97 const TString kSizeKeyword("SIZES");
98 const TString kMotifKeyword("MOTIF");
102 while ( in.getline(line,80) )
104 if ( line[0] == '#' ) continue;
108 if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
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;
119 AliError("pcb not null as expected");
121 pcb = new AliMpPCB(&fMotifMap,pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
124 if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
126 std::istringstream sin(sline(kMotifKeyword.Length(),
127 sline.Length()-kMotifKeyword.Length()).Data());
131 sin >> sMotifType >> ix >> iy;
133 AliMpMotifType* motifType = fMotifMap.FindMotifType(sMotifType);
136 AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data()));
137 motifType = reader.BuildMotifType(sMotifType.Data());
138 fMotifMap.AddMotifType(motifType);
142 AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data()));
145 pcb->Add(motifType,ix,iy);
154 //_____________________________________________________________________________
156 AliMpSt345Reader::ReadSlat(const char* slatType, AliMp::PlaneType planeType)
159 /// Create a new AliMpSlat object, by reading it from file.
160 /// The returned object must be deleted by the client.
162 std::ifstream in(AliMpFiles::SlatFilePath(AliMp::kStation345,slatType,
166 AliErrorClass(Form("Cannot read slat from %s",
167 AliMpFiles::SlatFilePath(AliMp::kStation345,slatType,planeType).Data()));
173 const TString kpcbKeyword("PCB");
175 AliMpSlat* slat = new AliMpSlat(slatType, planeType);
177 while ( in.getline(line,80) )
179 if ( line[0] == '#' ) continue;
181 TString sline(AliMpHelper::Normalize(line));
183 if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
185 TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
186 Ssiz_t blankPos = tmp.First(' ');
189 AliErrorClass("Syntax error in PCB file, should get a list of "
190 "manu ids after the pcbname");
195 TString pcbName(tmp(0,blankPos));
196 TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
198 AliMpPCB* pcbType = ReadPCB(pcbName.Data());
201 AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
207 AliMpHelper::DecodeName(manus,';',manuList);
208 if ( manuList.GetSize() != Int_t(pcbType->GetSize()) )
210 AliErrorClass(Form("Wrong number of manu ids for this PCB ("
211 "%s) : %d out of %d",pcbName.Data(),
212 manuList.GetSize(),pcbType->GetSize()));
218 for ( Int_t i = 0; i < manuList.GetSize(); ++i )
220 manuList[i] |= AliMpConstants::ManuMask(planeType);
222 slat->Add(*pcbType,manuList);