]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpMotifReader.cxx
Coding conventions
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifReader.cxx
index 87f51f2020bc645aa83d80b4c816c93a1b90bf4d..e909e8d6205b70d0abfebdc41a88b92f73f06227 100644 (file)
 // $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"
@@ -31,7 +34,6 @@
 #include "AliMpMotifType.h"
 #include "AliMpConnection.h"
 #include "AliMpIntPair.h"
-#include "AliMpDirection.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<maskName>.dat
+/// The streams mentioned are named padPos<maskName>.dat
 /// and connect<maskName>.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(2) << "Opening file " << padPosFileName << endl;
+  AliMpMotifType*  motifType = new AliMpMotifType(motifTypeId);        
 
   PadMapType 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;
@@ -120,25 +127,18 @@ AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId)
     positions.Add( AliMpExMap::GetIndex(key), 
                    AliMpExMap::GetIndex(AliMpIntPair(i,j)) ); 
 #endif
-  } while (!padPos.eof());
-
-  padPos.close();
-
-  TString bergToGCFileName
-    = AliMpFiles::BergToGCFilePath(fStationType);
-  AliDebugStream(2) << "Opening file " << bergToGCFileName << endl;
+  } while (!padPosStream.eof());
 
-  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];
   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 ...");
@@ -146,13 +146,7 @@ AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId)
     }
     gassiChannel[bergNum-1]= atoi(gcStr);
   }
-  bergToGCFile.close();
   
-  TString motifTypeFileName(AliMpFiles::MotifFilePath(fStationType, 
-                                                      fPlaneType, motifTypeId));
-  ifstream motif(motifTypeFileName);
-  AliDebugStream(2) << "Opening file " << motifTypeFileName << endl;
-
   Int_t nofPadsX=0;
   Int_t nofPadsY=0;
 
@@ -161,8 +155,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();
@@ -212,8 +206,8 @@ AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId)
     if (iter==positions.end()) {
       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;
     }
 
@@ -226,49 +220,36 @@ AliMpMotifType* AliMpMotifReader::BuildMotifType(const TString& motifTypeId)
     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, AliMpIntPair(ix,iy));
+    
+    motifType->AddConnection(AliMpIntPair(ix,iy),connection);
+                  
     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;
 }
 
-//_____________________________________________________________________________
-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;
-}
-
 //_____________________________________________________________________________
 AliMpMotifSpecial*  
 AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
@@ -278,15 +259,12 @@ AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
 /// Build a special motif by reading the file motifSpecial<motifId>.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));
 
   TString id = MotifSpecialName(motifID,scale);
   
@@ -301,7 +279,26 @@ AliMpMotifReader::BuildMotifSpecial(const TString& motifID,
   }
   res->CalculateDimensions();
   
-  in.close();
+  delete &in;
+  
   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;
+}
+