]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpTriggerReader.cxx
Coding conventions
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpTriggerReader.cxx
index 549a08d6a235477b0a311af1dd36d0ac2245597a..a7d433a93a7d9cc19450668765efc1c398f60493 100644 (file)
 **************************************************************************/
 
 // $Id$
-// $MpId$
+// $MpId: AliMpTriggerReader.cxx,v 1.4 2006/05/24 13:58:52 ivana Exp $
 
-#include <assert.h>
 #include "AliMpTriggerReader.h"
 
 #include "AliLog.h"
-#include "AliMpMotifReader.h"
+#include "AliMpConstants.h"
+#include "AliMpDataStreams.h"
 #include "AliMpFiles.h"
+#include "AliMpHelper.h"
+#include "AliMpMotif.h"
+#include "AliMpMotifPosition.h"
+#include "AliMpMotifReader.h"
+#include "AliMpMotifSpecial.h"
 #include "AliMpMotifType.h"
 #include "AliMpPCB.h"
 #include "AliMpSlat.h"
-#include "AliMpMotifMap.h"
-#include "AliMpMotifPosition.h"
-#include "AliMpMotif.h"
-#include "AliMpHelper.h"
+#include "AliMpSlatMotifMap.h"
+#include "AliMpSlatMotifMap.h"
 #include "AliMpSt345Reader.h"
 #include "AliMpTrigger.h"
-
 #include "Riostream.h"
-
 #include "TClass.h"
-#include "TObjString.h"
 #include "TList.h"
+#include "TObjString.h"
 #include "TString.h"
-
+#include <TArrayI.h>
+#include <cstdlib>
 #include <sstream>
 
+//-----------------------------------------------------------------------------
+/// \class AliMpTriggerReader
+/// Read trigger slat ASCII files
+/// Basically provides two methods:
+/// - AliMpTrigger* ReadSlat()
+/// - AliMpPCB* ReadPCB()
+///
+/// \author Laurent Aphecetche
+//-----------------------------------------------------------------------------
+
+/// \cond CLASSIMP
 ClassImp(AliMpTriggerReader)
+/// \endcond
 
-TMap AliMpTriggerReader::fgPCBMap;
-TMap AliMpTriggerReader::fgLocalBoardMap;
-
-namespace
-{
-  const TString KEYWORD_LAYER("LAYER");
-  const TString KEYWORD_SCALE("SCALE");
-  const TString KEYWORD_PCB("PCB");  
-  const TString KEYWORD_FLIPX("FLIP_X");
-  const TString KEYWORD_FLIPY("FLIP_Y");
-}
+const TString AliMpTriggerReader::fgkKeywordLayer("LAYER");
+const TString AliMpTriggerReader::fgkKeywordScale("SCALE");
+const TString AliMpTriggerReader::fgkKeywordPcb("PCB");  
+const TString AliMpTriggerReader::fgkKeywordFlipX("FLIP_X");
+const TString AliMpTriggerReader::fgkKeywordFlipY("FLIP_Y");
 
 //_____________________________________________________________________________
-AliMpTriggerReader::AliMpTriggerReader() : TObject()
+AliMpTriggerReader::AliMpTriggerReader(const AliMpDataStreams& dataStreams, AliMpSlatMotifMap* motifMap) 
+: TObject(),
+  fkDataStreams(dataStreams),
+  fMotifMap(motifMap),
+  fLocalBoardMap()
 {
-  //
-  // Default ctor.
-  //
+  ///
+  /// Default ctor.
+  ///
+    fLocalBoardMap.SetOwner(kTRUE);
 } 
 
 //_____________________________________________________________________________
 AliMpTriggerReader::~AliMpTriggerReader()
 {
-  //
-  // Dtor.
-  //
-  fgPCBMap.Delete();
-  fgLocalBoardMap.Delete();
+  ///
+  /// Dtor.
+  ///
+  fLocalBoardMap.DeleteAll();
 }
 
 //_____________________________________________________________________________
 AliMpSlat*
 AliMpTriggerReader::BuildSlat(const char* slatName,
-                              AliMpPlaneType planeType,
+                              AliMp::PlaneType planeType,
                               const TList& lines,
                               Double_t scale)
 {
+  /// Construct a slat from the list of lines, taking into account
+  /// the scale factor. The returned pointer must be deleted by the client
+
+  AliDebug(1,Form("slat %s %s scale %e",
+                  slatName,PlaneTypeName(planeType).Data(),scale))
+  ;
+  
   AliMpSlat* slat = new AliMpSlat(slatName, planeType);
     
   TIter it(&lines);
+  
+//  StdoutToAliDebug(3,lines.Print(););
+  
   TObjString* osline;
   while ( ( osline = (TObjString*)it.Next() ) )
   {
@@ -93,7 +115,7 @@ AliMpTriggerReader::BuildSlat(const char* slatName,
     
     TString& keyword = ((TObjString*)tokens->At(0))->String();
     
-    if ( keyword == KEYWORD_PCB )
+    if ( keyword == fgkKeywordPcb )
     {
       if ( tokens->GetEntriesFast() != 3 )
       {
@@ -114,7 +136,7 @@ AliMpTriggerReader::BuildSlat(const char* slatName,
         pcbName = s.str().c_str();
       }
       
-      AliMpPCB* pcbType = PCB(pcbName.Data());   
+      AliMpPCB* pcbType = ReadPCB(pcbName.Data());       
       if (!pcbType)
       {
         AliErrorClass(Form("Cannot read pcbType=%s",pcbName.Data()));
@@ -151,9 +173,14 @@ AliMpTriggerReader::BuildSlat(const char* slatName,
           }
         }
       }
+      AliDebug(3,"Deleting tokens");
       delete tokens;
+      AliDebug(3,"Deleting localBoardList");
       delete localBoardList;
-      slat->Add(pcbType,allLocalBoards);
+      AliDebug(3,"Adding pcb to slat");
+      slat->Add(*pcbType,allLocalBoards);
+      AliDebug(3,Form("Deleting pcbType=%p %s",pcbType,pcbName.Data()));
+      delete pcbType;
     }
   }
   
@@ -168,13 +195,14 @@ AliMpTriggerReader::BuildSlat(const char* slatName,
 TString
 AliMpTriggerReader::GetBoardNameFromPCBLine(const TString& s)
 {
+  /// Decode the string to get the board name
   TString boardName;
   
   TObjArray* tokens = s.Tokenize(' ');
   
   TString& keyword = ((TObjString*)tokens->At(0))->String();
 
-  if ( keyword == KEYWORD_PCB &&
+  if ( keyword == fgkKeywordPcb &&
        tokens->GetEntriesFast() == 3 )
   {
     boardName = ((TObjString*)tokens->At(2))->String();
@@ -190,19 +218,17 @@ void
 AliMpTriggerReader::FlipLines(TList& lines, Bool_t flipX, Bool_t flipY,
                               Int_t srcLine, Int_t destLine)
 {
-  //
-  // Change the local board names contained in lines, 
-  // to go from right to left, and/or
-  // from top to bottom
-  //
+  ///
+  /// Change the local board names contained in lines, 
+  /// to go from right to left, and/or
+  /// from top to bottom
+  ///
  
-//  cout << "--- Original lines (flipX=" << flipX << " flipY=" << flipY
-//  << " srcLine=" << srcLine << " destLine=" << destLine << " : " << endl;
-//  lines.Print();
-//
+
   if ( flipX )
   {
-    // Simply swaps R(ight) and L(eft) in the first character of local board names
+    // Simply swaps R(ight) and L(eft) in the first character of 
+    // local board names
 
     TObjString* oline;
     TIter it(&lines);
@@ -222,9 +248,6 @@ AliMpTriggerReader::FlipLines(TList& lines, Bool_t flipX, Bool_t flipY,
     }
   }
   
-//  cout << "*** After flipX :" << endl;
-//  lines.Print();
-
   if ( flipY )
   {
     // Change line number, according to parameters srcLine and destLine
@@ -244,7 +267,7 @@ AliMpTriggerReader::FlipLines(TList& lines, Bool_t flipX, Bool_t flipY,
         
         TString& s = oline->String();
         
-        if ( !s.Contains(KEYWORD_PCB) ) 
+        if ( !s.Contains(fgkKeywordPcb) )
         {
           // Only consider PCB lines.
           continue;
@@ -310,15 +333,15 @@ AliMpTriggerReader::FlipLines(TList& lines, Bool_t flipX, Bool_t flipY,
       }    
     }
   }
-//  cout << "*** After flipY :" << endl;
-//  lines.Print();
 }
 
 //___________________________________________________________________________
 Int_t
 AliMpTriggerReader::IsLayerLine(const TString& sline)
 {
-  if ( sline.BeginsWith(KEYWORD_LAYER) )
+  /// Whether sline contains LAYER keyword
+
+  if ( sline.BeginsWith(fgkKeywordLayer) )
   {
     return 1;
   }
@@ -334,15 +357,17 @@ AliMpTriggerReader::DecodeFlipLine(const TString& sline,
                                    TString& slatType2,
                                    Bool_t& flipX, Bool_t& flipY)
 {
+  /// Decode a line containing FLIP_X and/or FLIP_Y keywords
+
   Ssiz_t blankPos = sline.First(' ');
   if ( blankPos < 0 ) return 0;
   
   TString keyword(sline(0,blankPos));
   
-  if ( keyword == KEYWORD_FLIPX ) 
+  if ( keyword == fgkKeywordFlipX )
   {
     flipX = kTRUE;
-  } else if ( keyword == KEYWORD_FLIPY ) 
+  } else if ( keyword == fgkKeywordFlipY )
   {
     flipY = kTRUE;
   }
@@ -360,10 +385,12 @@ Int_t
 AliMpTriggerReader::DecodeScaleLine(const TString& sline, 
                                     Double_t& scale, TString& slatType)
 {
-  if ( sline(0,KEYWORD_SCALE.Length()) == KEYWORD_SCALE )
+  /// Decode sline containing SCALE keyword
+
+  if ( sline(0,fgkKeywordScale.Length()) == fgkKeywordScale )
   {
-    TString tmp(sline(KEYWORD_SCALE.Length()+1,
-                      sline.Length()-KEYWORD_SCALE.Length()-1));
+    TString tmp(sline(fgkKeywordScale.Length()+1,
+                      sline.Length()-fgkKeywordScale.Length()-1));
     Ssiz_t blankPos = tmp.First(' ');
     if ( blankPos < 0 )
     {
@@ -386,12 +413,13 @@ AliMpTriggerReader::DecodeScaleLine(const TString& sline,
 Int_t
 AliMpTriggerReader::GetLine(const TString& slatType)
 {
-  //
-  // Assuming slatType is a 4 character string of the form XSLN
-  // where X=1,2,3 or 4
-  // S = R or L
-  // N is the line number
-  // returns N
+  ///
+  /// Assuming slatType is a 4 character string of the form XSLN
+  /// where X=1,2,3 or 4
+  /// S = R or L
+  /// N is the line number
+  /// returns N
+  
   if ( isdigit(slatType[0]) && 
        ( slatType[1] == 'R' || slatType[1] == 'L' ) &&
        slatType[2] == 'L' )
@@ -405,12 +433,14 @@ AliMpTriggerReader::GetLine(const TString& slatType)
 int
 AliMpTriggerReader::LocalBoardNumber(const char* localBoardName)
 {
-  if ( !fgLocalBoardMap.GetSize() ) 
+  /// From local board name to local board number
+
+  if ( !fLocalBoardMap.GetSize() ) 
   {
     ReadLocalBoardMapping();
   }
   
-  TPair* pair = (TPair*)fgLocalBoardMap.FindObject(localBoardName);
+  TPair* pair = (TPair*)fLocalBoardMap.FindObject(localBoardName);
   
   if (pair)
   {
@@ -419,50 +449,28 @@ AliMpTriggerReader::LocalBoardNumber(const char* localBoardName)
   return -1;
 }
 
-//_____________________________________________________________________________
-AliMpPCB*
-AliMpTriggerReader::PCB(const char* pcbType)
-{
-  //
-  // Get access to an AliMpPCB object, given its type (e.g. N1, SB2, etc...)
-  //
-  // Note that the returned object is either a new one (read from file) or a 
-  // reused one if it is already present in the internal map.
-  //
-  
-  TPair* pair = (TPair*)fgPCBMap.FindObject(pcbType);
-  if ( pair )
-  {
-    AliDebugClass(1,Form("Getting pcb %s from internal map",pcbType));
-    return (AliMpPCB*)pair->Value();
-  }
-  else
-  {
-    AliDebugClass(1,Form("Reading pcb %s from file",pcbType));
-    return ReadPCB(pcbType);
-  }
-}
-
 //_____________________________________________________________________________
 void 
 AliMpTriggerReader::ReadLines(const char* slatType,
-                              AliMpPlaneType planeType,
+                              AliMp::PlaneType planeType,
                               TList& lines,
                               Double_t& scale,
                               Bool_t& flipX, Bool_t& flipY,
                               Int_t& srcLine, Int_t& destLine)
 {
-  AliDebugClass(1,Form("SlatType %s Scale %e FlipX %d FlipY %d srcLine %d"
+  ///
+  /// Reads in lines from file for a given slat
+  /// Returns the list of lines (lines), together with some global
+  /// information as the scale, whether to flip the lines, etc...
+  ///
+  AliDebugClass(2,Form("SlatType %s Scale %e FlipX %d FlipY %d srcLine %d"
                        " destLine %d\n",slatType,scale,flipX,flipY,
                        srcLine,destLine));
   
-  TString filename(AliMpFiles::SlatFilePath(kStationTrigger,slatType,
-                                            planeType).Data());
-  std::ifstream in(filename.Data());
-  if (!in.good()) 
-  {
-    AliErrorClass(Form("Cannot read slat from %s",filename.Data()));
-  }
+  istream& in 
+    = fkDataStreams.
+        CreateDataStream(AliMpFiles::SlatFilePath(
+                             AliMp::kStationTrigger,slatType, planeType));
   
   char line[80];
   
@@ -473,10 +481,11 @@ AliMpTriggerReader::ReadLines(const char* slatType,
     if ( sline.Length() == 0 || sline[0] == '#' ) continue;
     
     Bool_t isKeywordThere = 
-      sline.Contains(KEYWORD_PCB) || 
-      sline.Contains(KEYWORD_LAYER) ||
-      sline.Contains(KEYWORD_SCALE) || 
-      sline.Contains(KEYWORD_FLIPY) || sline.Contains(KEYWORD_FLIPX);
+      sline.Contains(fgkKeywordPcb) || 
+      sline.Contains(fgkKeywordLayer) ||
+      sline.Contains(fgkKeywordScale) || 
+      sline.Contains(fgkKeywordFlipX) || 
+      sline.Contains(fgkKeywordFlipY);
     
     if ( !isKeywordThere ) 
     {
@@ -494,7 +503,7 @@ AliMpTriggerReader::ReadLines(const char* slatType,
 
     if ( isScaleLine < 0 )
     {
-      AliFatalClass(Form("Syntax error near %s keyword\n",KEYWORD_SCALE.Data()));
+      AliFatalClass(Form("Syntax error near %s keyword\n",fgkKeywordScale.Data()));
     }
     else if ( isScaleLine > 0 && slatType2 != slatType )
     {
@@ -523,53 +532,71 @@ AliMpTriggerReader::ReadLines(const char* slatType,
     }
   }
   
-  in.close();
+  delete &in;
 }
                                         
 //_____________________________________________________________________________
 void
 AliMpTriggerReader::ReadLocalBoardMapping()
 {
-  TString filename(AliMpFiles::LocalTriggerBoardMapping());
-  
-  AliDebugClass(1,Form("Reading from %s\n",filename.Data()));
+  /// Reads the file that contains the mapping local board name <-> number
 
-  fgLocalBoardMap.Delete();
+  fLocalBoardMap.DeleteAll();
   
-  ifstream in(filename.Data());
-  if (!in.good())
-  {
-    AliErrorClass(Form("Cannot read file %s\n",filename.Data()));    
-  }
-  else
+  UShort_t mask;
+  
+  istream& in 
+    = fkDataStreams.
+        CreateDataStream(AliMpFiles::LocalTriggerBoardMapping());
+
+  char line[80];
+  Char_t localBoardName[20];
+  Int_t j,localBoardId;
+  UInt_t switches;
+  Int_t nofBoards;
+
+  while (!in.eof())
   {
-    char line[80];
-    
-    while ( in.getline(line,80) )
-    {
-      if ( line[0] == '#' ) continue;
-      
-      TString sline(line);
-      TObjArray* tokens = sline.Tokenize(' ');
-      TString& number = ((TObjString*)(tokens->At(0)))->String();
-      TString& name = ((TObjString*)(tokens->At(1)))->String();
-      fgLocalBoardMap.Add(new TObjString(name), new TObjString(number));
-      AliDebugClass(10,Form("Board %s has number %s\n",name.Data(),number.Data()));
-      delete tokens;
-    }      
+    for (Int_t i = 0; i < 4; ++i)
+      if (!in.getline(line,80)) continue; //skip 4 first lines
+    // read mask
+    if (!in.getline(line,80)) break;
+    sscanf(line,"%hx",&mask);
+   // read # boards
+    if (!in.getline(line,80)) break;
+    sscanf(line,"%d",&nofBoards);
+   
+    for ( Int_t i = 0; i < nofBoards; ++i ) 
+    {      
+  
+      if (!in.getline(line,80)) break; 
+      sscanf(line,"%02d %s %03d %03x", &j, localBoardName, &localBoardId, &switches);
+      if (localBoardId <= AliMpConstants::NofLocalBoards()) 
+      {
+       fLocalBoardMap.Add(new TObjString(localBoardName), new TObjString(Form("%d",localBoardId)));
+       AliDebugClass(10,Form("Board %s has number %d\n", localBoardName, localBoardId));
+      }
+      // skip 2 following lines
+      if (!in.getline(line,80)) break; 
+      if (!in.getline(line,80)) break; 
+       
+    }
   }
-  in.close();
+  
+  delete &in;      
 }
 
 //_____________________________________________________________________________
 AliMpPCB*
 AliMpTriggerReader::ReadPCB(const char* pcbType)
 { 
-  //
-  // Create a new AliMpPCB object, by reading it from file.
-  //
+  ///
+  /// Create a new AliMpPCB object, by reading it from file.
+  /// Returned pointer must be deleted by client.
   
-  AliDebugClass(1,Form("pcbType=%s\n",pcbType));
+  AliDebugClass(2,Form("pcbType=%s\n",pcbType));
   
   TString pcbName(pcbType);
   
@@ -583,14 +610,13 @@ AliMpTriggerReader::ReadPCB(const char* pcbType)
     pcbName = pcbName(0,pos);
   }
   
-  std::ifstream in(AliMpFiles::SlatPCBFilePath(kStationTrigger,pcbName).Data());
-  if (!in.good()) 
-  {
-    AliErrorClass(Form("Cannot open file for PCB %s",pcbName.Data()));
-    return 0;
-  }
+  istream& in 
+    = fkDataStreams.
+        CreateDataStream(AliMpFiles::SlatPCBFilePath(
+                             AliMp::kStationTrigger,pcbName));
  
-  AliMpMotifReader reader(kStationTrigger,kNonBendingPlane); 
+  AliMpMotifReader reader(fkDataStreams,
+                          AliMp::kStationTrigger, AliMq::kNotSt12, AliMp::kNonBendingPlane); 
   // note that the nonbending
   // parameter is of no use for trigger, as far as reading motif is 
   // concerned, as all motifs are supposed to be in the same directory
@@ -598,11 +624,11 @@ AliMpTriggerReader::ReadPCB(const char* pcbType)
      
   char line[80];
   
-  const TString sizeKeyword("SIZES");
-  const TString motifKeyword("MOTIF");
-  const TString motifSpecialKeyword("SPECIAL_MOTIF");
+  const TString kSizeKeyword("SIZES");
+  const TString kMotifKeyword("MOTIF");
+  const TString kMotifSpecialKeyword("SPECIAL_MOTIF");
   
-  AliMpPCB* pcb = 0;
+  AliMpPCB* pcb(0x0);
   
   while ( in.getline(line,80) )
   {
@@ -610,70 +636,109 @@ AliMpTriggerReader::ReadPCB(const char* pcbType)
     
     TString sline(line);
     
-    if ( sline(0,sizeKeyword.Length()) == sizeKeyword )
+    if ( sline(0,kSizeKeyword.Length()) == kSizeKeyword )
     {
-      std::istringstream sin(sline(sizeKeyword.Length(),
-                                   sline.Length()-sizeKeyword.Length()-1).Data());
+      std::istringstream sin(sline(kSizeKeyword.Length(),
+                                   sline.Length()-kSizeKeyword.Length()-1).Data());
       float padSizeX = 0.0;
       float padSizeY = 0.0;
       float pcbSizeX = 0.0;
       float pcbSizeY = 0.0;
       sin >> padSizeX >> padSizeY >> pcbSizeX >> pcbSizeY;
-      assert(pcb==0);
-      pcb = new AliMpPCB(pcbType,padSizeX*scale,padSizeY*scale,
+      if (pcb)
+      {
+        AliError("pcb not null as expected");
+      }
+      pcb = new AliMpPCB(fMotifMap,pcbType,padSizeX*scale,padSizeY*scale,
                          pcbSizeX*scale,pcbSizeY*scale);
     }
     
-    if ( sline(0,motifSpecialKeyword.Length()) == motifSpecialKeyword )
+    if ( sline(0,kMotifSpecialKeyword.Length()) == kMotifSpecialKeyword )
     {
-      std::istringstream sin(sline(motifSpecialKeyword.Length(),
-                                   sline.Length()-motifSpecialKeyword.Length()).Data());
+      std::istringstream sin(sline(kMotifSpecialKeyword.Length(),
+                                   sline.Length()-kMotifSpecialKeyword.Length()).Data());
       TString sMotifSpecial;
       TString sMotifType;
       sin >> sMotifSpecial >> sMotifType;
       
-      AliMpMotifType* motifType = reader.BuildMotifType(sMotifType);
-      AliMpMotifSpecial* specialMotif = 
-        reader.BuildMotifSpecial(sMotifSpecial,motifType,scale);
+      TString id = reader.MotifSpecialName(sMotifSpecial,scale);
       
-      assert(pcb==0);      
+      AliMpMotifSpecial* specialMotif =
+        dynamic_cast<AliMpMotifSpecial*>(fMotifMap->FindMotif(id));
+      if (!specialMotif)
+      {
+        AliDebug(1,Form("Reading motifSpecial %s (%s) from file",
+                        sMotifSpecial.Data(),id.Data()));
+        AliMpMotifType* motifType = fMotifMap->FindMotifType(sMotifType.Data());
+        if ( !motifType)
+        {
+          AliDebug(1,Form("Reading motifType %s (%s) from file",
+                          sMotifType.Data(),id.Data()));
+          motifType = reader.BuildMotifType(sMotifType.Data());
+          fMotifMap->AddMotifType(motifType);
+        }
+        else
+        {
+          AliDebug(1,Form("Got motifType %s (%s) from motifMap",
+                          sMotifType.Data(),id.Data()));        
+        }
+        specialMotif = reader.BuildMotifSpecial(sMotifSpecial,motifType,scale);
+        fMotifMap->AddMotif(specialMotif);
+      }
+      else
+      {
+        AliDebug(1,Form("Got motifSpecial %s from motifMap",sMotifSpecial.Data()));
+      }
+      if (pcb)
+      {
+        AliError("pcb not null as expected");
+      }
       pcb = new AliMpPCB(pcbType,specialMotif);
     }
     
-    if ( sline(0,motifKeyword.Length()) == motifKeyword )
+    if ( sline(0,kMotifKeyword.Length()) == kMotifKeyword )
     {
-      std::istringstream sin(sline(motifKeyword.Length(),
-                                   sline.Length()-motifKeyword.Length()).Data());
+      std::istringstream sin(sline(kMotifKeyword.Length(),
+                                   sline.Length()-kMotifKeyword.Length()).Data());
       TString sMotifType;
       int ix;
       int iy;
       sin >> sMotifType >> ix >> iy;
       
-      AliMpMotifType* motifType = reader.BuildMotifType(sMotifType.Data());
+      AliMpMotifType* motifType = fMotifMap->FindMotifType(sMotifType.Data());
+      if ( !motifType)
+      {
+        AliDebug(1,Form("Reading motifType %s from file",sMotifType.Data()));
+        motifType = reader.BuildMotifType(sMotifType.Data());
+        fMotifMap->AddMotifType(motifType);
+      }
+      else
+      {
+        AliDebug(1,Form("Got motifType %s from motifMap",sMotifType.Data()));        
+      }
       
-      assert(pcb!=0);
       pcb->Add(motifType,ix,iy);
     }
   }
   
-  in.close();
+  delete &in;
   
-  fgPCBMap.Add(new TObjString(pcbType),pcb);
   return pcb;
 }
 
 //_____________________________________________________________________________
 AliMpTrigger*
-AliMpTriggerReader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
+AliMpTriggerReader::ReadSlat(const char* slatType, AliMp::PlaneType planeType)
 {
-  //
-  // Create a new AliMpTrigger object, by reading it from file.
-  //
+  ///
+  /// Create a new AliMpTrigger object, by reading it from file.
+  /// Returned object must be deleted by client.
 
   Double_t scale = 1.0;
   Bool_t flipX = kFALSE;
   Bool_t flipY = kFALSE;
   TList lines;
+  lines.SetOwner(kTRUE);
   Int_t srcLine(-1);
   Int_t destLine(-1);
   
@@ -688,7 +753,7 @@ AliMpTriggerReader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
   if ( !IsLayerLine(firstLine) ) 
   {
     std::ostringstream s;
-    s << KEYWORD_LAYER;
+    s << fgkKeywordLayer;
     lines.AddFirst(new TObjString(s.str().c_str()));
   }
   
@@ -699,6 +764,7 @@ AliMpTriggerReader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
   // Now splits the lines in packets corresponding to different layers 
   // (if any), and create sub-slats.
   TObjArray layers;
+  layers.SetOwner(kTRUE);
   Int_t ilayer(-1);
   TIter it(&lines);
   TObjString* osline;
@@ -708,7 +774,9 @@ AliMpTriggerReader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
     TString& s = osline->String();
     if ( IsLayerLine(s) )
     {
-      layers.Add(new TList);
+      TList* list = new TList;
+      list->SetOwner(kTRUE);
+      layers.Add(list);
       ++ilayer;
     }
     else
@@ -721,15 +789,45 @@ AliMpTriggerReader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
 
   AliMpTrigger* triggerSlat = new AliMpTrigger(slatType, planeType);
     
-  for ( Int_t ilayer = 0; ilayer < layers.GetEntriesFast(); ++ilayer )
+  for ( ilayer = 0; ilayer < layers.GetEntriesFast(); ++ilayer )
   {
-    TList& lines = *((TList*)layers.At(ilayer));
+    TList& lines1 = *((TList*)layers.At(ilayer));
     std::ostringstream slatName;
     slatName << slatType << "-LAYER" << ilayer;
-    AliMpSlat* slat = BuildSlat(slatName.str().c_str(),planeType,lines,scale);
+    AliMpSlat* slat = BuildSlat(slatName.str().c_str(),planeType,lines1,scale);
     if ( slat )
     {
-      triggerSlat->AdoptLayer(slat);
+      Bool_t ok = triggerSlat->AdoptLayer(slat);
+      if (!ok)
+      {
+        StdoutToAliError(cout << "could not add slat=" << endl;
+                         slat->Print();
+                         cout << "to the triggerSlat=" << endl;
+                         triggerSlat->Print();
+                         );
+        AliError("Slat is=");
+        for ( Int_t i = 0; i < slat->GetSize(); ++i )
+        {
+          AliMpPCB* pcb = slat->GetPCB(i);
+          AliError(Form("ERR pcb %d size %e,%e (unscaled is %e,%e)",
+                                i,pcb->DX()*2,pcb->DY()*2,
+                                pcb->DX()*2/scale,pcb->DY()*2/scale));
+        }
+        AliError("TriggerSlat is=");
+        for ( Int_t j = 0; j < triggerSlat->GetSize(); ++j )
+        {
+          AliMpSlat* slat1 = triggerSlat->GetLayer(j);
+          AliError(Form("Layer %d",j));
+          for ( Int_t i = 0; i < slat1->GetSize(); ++i )
+          {
+            AliMpPCB* pcb = slat1->GetPCB(i);
+            AliError(Form("ERR pcb %d size %e,%e (unscaled is %e,%e)",
+                          i,pcb->DX()*2,pcb->DY()*2,
+                          pcb->DX()*2/scale,pcb->DY()*2/scale));
+          }
+        } 
+        StdoutToAliError(fMotifMap->Print(););
+      }
     }
     else
     {
@@ -739,15 +837,5 @@ AliMpTriggerReader::ReadSlat(const char* slatType, AliMpPlaneType planeType)
     }
   }
   
-  layers.SetOwner(kTRUE);
-  layers.Delete();
-  
   return triggerSlat;
 }
-
-//_____________________________________________________________________________
-void
-AliMpTriggerReader::Reset()
-{
-  fgPCBMap.Delete();
-}