X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2Fmapping%2FAliMpMotifReader.cxx;h=d1e8d811c835ac749d0a490366de64f12314fec0;hb=8980e5a2cf018365f77ac335cd497bbe19e0ca51;hp=1d10bbb6beebefedd9562f035e3fe0f4cfd8467d;hpb=13e7956b8ab5b88a4cd989fa7a730705350b26b6;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/mapping/AliMpMotifReader.cxx b/MUON/mapping/AliMpMotifReader.cxx index 1d10bbb6bee..d1e8d811c83 100644 --- a/MUON/mapping/AliMpMotifReader.cxx +++ b/MUON/mapping/AliMpMotifReader.cxx @@ -16,22 +16,24 @@ // $Id$ // $MpId: AliMpMotifReader.cxx,v 1.10 2006/05/24 13:58:41 ivana Exp $ // Category: sector -// + +//----------------------------------------------------------------------------- // Class AliMpMotifReader // ------------------- // Class that takes care of reading the sector data. // Included in AliRoot: 2003/05/02 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay +//----------------------------------------------------------------------------- #include "AliMpFiles.h" +#include "AliMpDataStreams.h" #include "AliMpMotifReader.h" #include "AliMpMotifMap.h" #include "AliMpMotif.h" #include "AliMpMotifSpecial.h" #include "AliMpMotifType.h" #include "AliMpConnection.h" -#include "AliMpIntPair.h" -#include "AliMpDirection.h" +#include "AliMpEncodePair.h" #include "AliLog.h" @@ -49,24 +51,19 @@ ClassImp(AliMpMotifReader) /// \endcond //_____________________________________________________________________________ -AliMpMotifReader::AliMpMotifReader(AliMpStationType station, - AliMpPlaneType plane) +AliMpMotifReader::AliMpMotifReader(const AliMpDataStreams& dataStreams, + AliMp::StationType station, + AliMq::Station12Type station12, + AliMp::PlaneType plane) : TObject(), + fkDataStreams(dataStreams), fStationType(station), + fStation12Type(station12), fPlaneType(plane) { /// Standard constructor } -//_____________________________________________________________________________ -AliMpMotifReader::AliMpMotifReader() - : TObject(), - fStationType(kStation1), - fPlaneType(kBendingPlane) -{ -/// Default constructor -} - //_____________________________________________________________________________ AliMpMotifReader::~AliMpMotifReader() { @@ -80,24 +77,34 @@ AliMpMotifReader::~AliMpMotifReader() //_____________________________________________________________________________ AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId) { -/// Read the files describing a motif in the "$MINSTALL/data" directory +/// Read the streams describing a motif in the "$MINSTALL/data" directory /// and fill the AliMpMotifType structure with. -/// The files mentioned are are named padPos.dat +/// The streams mentioned are named padPos.dat /// and connect.dat - AliMpMotifType* motifType = new AliMpMotifType(motifTypeId); + // Open streams + // + istream& padPosStream + = fkDataStreams. + CreateDataStream(AliMpFiles::PadPosFilePath( + fStationType, fStation12Type, fPlaneType, motifTypeId)); + istream& bergToGCStream + = fkDataStreams. + CreateDataStream(AliMpFiles::BergToGCFilePath(fStationType, fStation12Type)); + + istream& motifTypeStream + = fkDataStreams. + CreateDataStream(AliMpFiles::MotifFilePath( + fStationType, fStation12Type, fPlaneType, motifTypeId)); - TString padPosFileName(AliMpFiles::PadPosFilePath(fStationType, - fPlaneType, motifTypeId)); - ifstream padPos(padPosFileName); - AliDebugStream(1) << "Opening file " << padPosFileName << endl; + AliMpMotifType* motifType = new AliMpMotifType(motifTypeId); - PadMapType positions; + TExMap positions; char line[256]; do { - padPos.getline(line,255); - if (!padPos) break; + padPosStream.getline(line,255); + if (!padPosStream) break; #if defined (__HP_aCC) || (__alpha) strstream strline; @@ -112,47 +119,36 @@ AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId) int i,j; strline>>i>>j; -#ifdef WITH_STL - positions[key].first=i; - positions[key].second=j; -#endif -#ifdef WITH_ROOT positions.Add( AliMpExMap::GetIndex(key), - AliMpExMap::GetIndex(AliMpIntPair(i,j)) ); -#endif - } while (!padPos.eof()); + AliMp::Pair(i,j) + 1 ); + // we have to add 1 to the AliMp::Pair in order to + // its value always != 0, as the TExMap returns 0 value + // if given key does not exists + } while (!padPosStream.eof()); - padPos.close(); - - TString bergToGCFileName - = AliMpFiles::BergToGCFilePath(fStationType); - AliDebugStream(1) << "Opening file " << bergToGCFileName << endl; - - ifstream bergToGCFile(bergToGCFileName); const Int_t knbergpins = - (fStationType == kStation1 || fStationType == kStation2 ) ? 80 : 100; + (fStationType == AliMp::kStation12 ) ? 80 : 100; // Station1 & 2 Bergstak connectors have 80 pins, while for stations // 3, 4 and 5 they have 100 pins. Int_t gassiChannel[100]; + for (Int_t i=0; i<100; ++i) gassiChannel[i] = 0; while(1) { Int_t bergNum; TString gcStr; - bergToGCFile>>bergNum>>gcStr; - if (!bergToGCFile.good()) break; + bergToGCStream>>bergNum>>gcStr; + if (!bergToGCStream.good()) break; if (gcStr=="GND") continue; if (bergNum>knbergpins) { Fatal("BuildMotifType","Berg number > 80 ..."); continue; } + if ( bergNum <= 0 || bergNum >= 101 ) { + AliErrorStream() << "Wrong bergNum: " << bergNum << endl; + return 0; + } gassiChannel[bergNum-1]= atoi(gcStr); } - bergToGCFile.close(); - TString motifTypeFileName(AliMpFiles::MotifFilePath(fStationType, - fPlaneType, motifTypeId)); - ifstream motif(motifTypeFileName); - AliDebugStream(1) << "Opening file " << motifTypeFileName << endl; - Int_t nofPadsX=0; Int_t nofPadsY=0; @@ -161,8 +157,8 @@ AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId) Int_t ix,iy,numBerg,numKapton,padNum,gassiNum; TString lineStr,token; - lineStr.ReadLine(motif); - if (!motif.good()) break; + lineStr.ReadLine(motifTypeStream); + if (!motifTypeStream.good()) break; #if defined (__HP_aCC) || (__alpha) strstream tokenList; tokenList << lineStr.Data(); @@ -207,51 +203,43 @@ AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId) gassiNum = gassiChannel[numBerg-1]; -#ifdef WITH_STL - PadMapTypeIterator iter = positions.find(padName); - if (iter==positions.end()) { - AliWarningStream() - << "Problem: Pad number " << padNum - << " found in the file " << motifTypeFileName - << " but not in the file " << padPosFileName << endl; - continue; - } - - ix= iter->second.first; - iy= iter->second.second; -#endif - -#ifdef WITH_ROOT Long_t value = positions.GetValue(AliMpExMap::GetIndex(padName)); if (!value) { AliWarningStream() << "Problem: Pad number " << padNum - << " found in the file " << motifTypeFileName - << " but not in the file " << padPosFileName << endl; + << " for motif type " << motifTypeId.Data() + << " found in the motifType stream, but not in the padPos stream" << endl; continue; } - ix = AliMpExMap::GetPair(value).GetFirst(); - iy = AliMpExMap::GetPair(value).GetSecond(); -#endif - - motifType->AddConnection(AliMpIntPair(ix,iy), - new AliMpConnection(padNum,numBerg,numKapton,gassiNum)); - + AliMpConnection* connection + = new AliMpConnection(padNum,numBerg,numKapton,gassiNum, --value); + + Bool_t ok = motifType->AddConnection(connection); + + if (!ok) + { + AliFatal("Could not add connection"); + } + + ix = AliMp::PairFirst(value); + iy = AliMp::PairSecond(value); + if (ix>=nofPadsX) nofPadsX=ix+1; if (iy>=nofPadsY) nofPadsY=iy+1; - } while (!motif.eof()); + } while (!motifTypeStream.eof()); motifType->SetNofPads(nofPadsX, nofPadsY); - - motif.close(); + + delete &padPosStream; + delete &bergToGCStream; + delete &motifTypeStream; return motifType; } - //_____________________________________________________________________________ AliMpMotifSpecial* AliMpMotifReader::BuildMotifSpecial(const TString& motifID, @@ -261,28 +249,46 @@ AliMpMotifReader::BuildMotifSpecial(const TString& motifID, /// Build a special motif by reading the file motifSpecial.dat /// in the data directory - // Open the input file - TString motifSpecialFileName(AliMpFiles::MotifSpecialFilePath(fStationType, - fPlaneType, motifID)); - ifstream in(motifSpecialFileName); - if (!in) { - AliErrorStream() - << "File " << motifSpecialFileName.Data() << " not found." << endl; - return 0; - } + // Open streams + // + istream& in + = fkDataStreams. + CreateDataStream(AliMpFiles::MotifSpecialFilePath( + fStationType, fStation12Type, fPlaneType, motifID)); - AliMpMotifSpecial* res = new AliMpMotifSpecial(motifID,motifType); + TString id = MotifSpecialName(motifID,scale); + + AliMpMotifSpecial* res = new AliMpMotifSpecial(id,motifType); Int_t i,j; Double_t x,y; in >> i; while (!in.eof()){ in >>j >>x >> y; - res->SetPadDimensions(AliMpIntPair(i,j),TVector2(x*scale/2.,y*scale/2.)); + res->SetPadDimensions(i,j,x*scale/2.,y*scale/2.); in >> i; } res->CalculateDimensions(); - in.close(); + delete ∈ + return res; } +//_____________________________________________________________________________ +TString +AliMpMotifReader::MotifSpecialName(const TString& motifID, Double_t scale) +{ + /// Build the name taking into the scale, if not 1.0 + TString id; + + if ( scale != 1.0 ) + { + id = Form("%s-%e",motifID.Data(),scale); + } + else + { + id = motifID; + } + return id; +} +