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 //-----------------------------------------------------------------------------
42 /// \class AliMpSt345Reader
44 /// Read slat and pcb ASCII files.
46 /// Basically this class provides two methods :
47 /// - AliMpSlat* ReadSlat()
48 /// - AliMpPCB ReadPCB()
50 /// \author Laurent Aphecetche
51 //-----------------------------------------------------------------------------
54 ClassImp(AliMpSt345Reader)
57 //_____________________________________________________________________________
58 AliMpSt345Reader::AliMpSt345Reader()
61 fMotifMap(AliMpSlatMotifMap::Instance())
68 //_____________________________________________________________________________
69 AliMpSt345Reader::~AliMpSt345Reader()
76 //_____________________________________________________________________________
78 AliMpSt345Reader::ReadPCB(const char* pcbType)
81 /// Create a new AliMpPCB object, by reading it from file.
82 /// The returned object must be deleted by the client
84 std::ifstream in(AliMpFiles::SlatPCBFilePath(AliMp::kStation345,pcbType).Data());
87 AliErrorClass(Form("Cannot open file for PCB %s",pcbType));
91 AliMpMotifReader reader(AliMp::kStation345,AliMp::kNonBendingPlane);
92 // note that the nonbending
93 // parameter is of no use for station345, as far as reading motif is
94 // concerned, as all motifs are supposed to be in the same directory
95 // (as they are shared by bending/non-bending planes).
99 const TString kSizeKeyword("SIZES");
100 const TString kMotifKeyword("MOTIF");
104 while ( in.getline(line,80) )
106 if ( line[0] == '#' ) continue;
110 if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
112 std::istringstream sin(sline(kSizeKeyword.Length(),
113 sline.Length()-kSizeKeyword.Length()).Data());
114 double padSizeX = 0.0;
115 double padSizeY = 0.0;
116 double pcbSizeX = 0.0;
117 double pcbSizeY = 0.0;
118 sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
121 AliError("pcb not null as expected");
123 pcb = new AliMpPCB(fMotifMap,pcbType,padSizeX,padSizeY,pcbSizeX,pcbSizeY);
126 if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
128 std::istringstream sin(sline(kMotifKeyword.Length(),
129 sline.Length()-kMotifKeyword.Length()).Data());
133 sin >> sMotifType >> ix >> iy;
135 AliMpMotifType* motifType = fMotifMap->FindMotifType(sMotifType);
138 AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data()));
139 motifType = reader.BuildMotifType(sMotifType.Data());
140 fMotifMap->AddMotifType(motifType);
144 AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data()));
147 pcb->Add(motifType,ix,iy);
156 //_____________________________________________________________________________
158 AliMpSt345Reader::ReadSlat(const char* slatType, AliMp::PlaneType planeType)
161 /// Create a new AliMpSlat object, by reading it from file.
162 /// The returned object must be deleted by the client.
164 std::ifstream in(AliMpFiles::SlatFilePath(AliMp::kStation345,slatType,
168 AliErrorClass(Form("Cannot read slat from %s",
169 AliMpFiles::SlatFilePath(AliMp::kStation345,slatType,planeType).Data()));
175 const TString kpcbKeyword("PCB");
177 AliMpSlat* slat = new AliMpSlat(slatType, planeType);
179 while ( in.getline(line,80) )
181 if ( line[0] == '#' ) continue;
183 TString sline(AliMpHelper::Normalize(line));
185 if ( sline(0,kpcbKeyword.Length()) == kpcbKeyword )
187 TString tmp(sline(kpcbKeyword.Length()+1,sline.Length()-kpcbKeyword.Length()));
188 Ssiz_t blankPos = tmp.First(' ');
191 AliErrorClass("Syntax error in PCB file, should get a list of "
192 "manu ids after the pcbname");
197 TString pcbName(tmp(0,blankPos));
198 TString manus(tmp(blankPos+1,tmp.Length()-blankPos));
200 AliMpPCB* pcbType = ReadPCB(pcbName.Data());
203 AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
209 AliMpHelper::DecodeName(manus,';',manuList);
210 if ( manuList.GetSize() != Int_t(pcbType->GetSize()) )
212 AliErrorClass(Form("Wrong number of manu ids for this PCB ("
213 "%s) : %d out of %d",pcbName.Data(),
214 manuList.GetSize(),pcbType->GetSize()));
220 for ( Int_t i = 0; i < manuList.GetSize(); ++i )
222 manuList[i] |= AliMpConstants::ManuMask(planeType);
224 slat->Add(*pcbType,manuList);