]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpMotifType.cxx
bugfix: stopwatches for HLT benchmarks had been resumed at wrong point and measuremen...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifType.cxx
index bb634e8cbf873aeb6f06d2e2d090c45521d37029..7d72904db097c61e30bf2149ab123f3fe944ad34 100755 (executable)
  **************************************************************************/
 
 // $Id$
-// $MpId: AliMpMotifType.cxx,v 1.9 2006/03/17 11:38:06 ivana Exp $
+// $MpId: AliMpMotifType.cxx,v 1.10 2006/05/24 13:58:41 ivana Exp $
 // Category: motif
-//
+
+//-----------------------------------------------------------------------------
 // Class AliMpMotifType
 // --------------------
 // Class that defines the motif properties.
 // Included in AliRoot: 2003/05/02
 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+//-----------------------------------------------------------------------------
 
+#include <cstdlib>
 #include "AliMpMotifType.h"
+
+#include "AliMpExMapIterator.h"
 #include "AliMpMotifTypePadIterator.h"
 #include "AliMpConnection.h"
 
+#include "AliLog.h"
+#include "AliMpFiles.h"
+#include "TSystem.h"
+
 #include <Riostream.h>
 
-#include <stdlib.h>
+/// \cond CLASSIMP
+ClassImp(AliMpMotifType)
+/// \endcond
 
 const Int_t AliMpMotifType::fgkPadNumForA = 65;
 
-ClassImp(AliMpMotifType)
-
 //______________________________________________________________________________
 AliMpMotifType::AliMpMotifType(const TString &id) 
   : TObject(),
     fID(id),
     fNofPadsX(0),   
     fNofPadsY(0),
-    fVerboseLevel(0),
-#ifdef WITH_STL
     fConnections()
-#endif
-#ifdef WITH_ROOT
-    fConnections(true)
-#endif
 {
-  /// Standard constructor
+  /// Standard constructor                                                   \n
+  /// Please note that id should be of the form %s for station 1,2,
+  //  %s-%e-%e for station345 and %sx%e for stationTrigger
+      
+      AliDebug(1,Form("this=%p id=%s",this,id.Data()));
 }
 
 //______________________________________________________________________________
-AliMpMotifType::AliMpMotifType() 
+AliMpMotifType::AliMpMotifType(TRootIOCtor* ioCtor
   : TObject(),
     fID(""),
     fNofPadsX(0),   
     fNofPadsY(0),
-    fVerboseLevel(0),
+#ifdef WITH_STL
     fConnections()
+#endif
+#ifdef WITH_ROOT
+    fConnections(ioCtor)
+#endif
 {
   /// Default constructor
+      AliDebug(1,Form("this=%p",this));
+}
+
+//______________________________________________________________________________
+AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
+: TObject(),
+  fID(""),
+  fNofPadsX(0),   
+  fNofPadsY(0),
+  fConnections()
+{
+  /// Copy constructor
+
+    AliDebug(1,Form("this=%p (copy ctor)",this));
+    rhs.Copy(*this);
+}
+
+//______________________________________________________________________________
+AliMpMotifType&
+AliMpMotifType::operator=(const AliMpMotifType& rhs)
+{
+  /// Assignment operator
+
+  TObject::operator=(rhs);
+  rhs.Copy(*this);
+  return *this;  
+}
+
+//______________________________________________________________________________
+TObject*
+AliMpMotifType::Clone(const char* /*newname*/) const 
+{
+  /// Returns a full copy of this object
+  return new AliMpMotifType(*this);
+}
+
+//______________________________________________________________________________
+void
+AliMpMotifType::Copy(TObject& object) const
+{
+  /// Copy object
+
+  TObject::Copy(object);
+  AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
+  mt.fID = fID;
+  mt.fNofPadsX = fNofPadsX;
+  mt.fNofPadsY = fNofPadsY;
+  mt.fConnections = fConnections;
 }
 
 //______________________________________________________________________________
@@ -76,6 +135,9 @@ AliMpMotifType::~AliMpMotifType()
 
   fConnections.erase(fConnections.begin(),fConnections.end());
 #endif  
+  
+  AliDebug(1,Form("this=%p",this));
+//  StdoutToAliDebug(1,this->Print(););
 }
 
 //______________________________________________________________________________
@@ -148,13 +210,14 @@ AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
 #endif
 
 #ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* connection = (AliMpConnection*)value;
-    if (connection->GetPadNum()==padNum) return connection;
-  }  
- return 0;
+ TIter next(fConnections.CreateIterator());
+ AliMpConnection* connection;
+ while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
+ {
+   if (connection->GetPadNum()==padNum) return connection;
+ }
+ return 0x0;
 #endif
 }
 
@@ -191,13 +254,14 @@ AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
 #endif
 
 #ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* connection = (AliMpConnection*)value;
-    if (connection->GetGassiNum()==gassiNum) return connection;
-  }  
- return 0;
+ TIter next(fConnections.CreateIterator());
+ AliMpConnection* connection;
+ while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
+ {
+   if (connection->GetGassiNum()==gassiNum) return connection;
+ }
+ return 0x0;
 #endif
 }
 
@@ -214,13 +278,14 @@ AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) cons
 #endif
 
 #ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* connection = (AliMpConnection*)value;
-    if (connection->GetKaptonNum()==kaptonNum) return connection;
-  }  
- return 0;
+ TIter next(fConnections.CreateIterator());
+ AliMpConnection* connection;
+ while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
+ {
+   if (connection->GetKaptonNum()==kaptonNum) return connection;
+ }
+ return 0x0;
 #endif
 }
 //______________________________________________________________________________
@@ -236,41 +301,24 @@ AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
 #endif
 
 #ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* connection = (AliMpConnection*)value;
-    if (connection->GetBergNum()==bergNum) return connection;
-  }  
-  return 0;
+ TIter next(fConnections.CreateIterator());
+ AliMpConnection* connection;
+ while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
+ {
+   if (connection->GetBergNum()==bergNum) return connection;
+ }
+ return 0x0;
 #endif
 }
 
 
 //______________________________________________________________________________
-AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
-                                 const AliMpConnection* connection) const
+AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(const AliMpConnection* connection) const
 {
-  /// Retrieve the pad position from the connection pointer.
-  /// Not to be used widely, since it use a search in the
-  /// connection list...
+  /// Reurn the pad position from the connection pointer.
 
-#ifdef WITH_STL
- for(ConnectionMapCIterator i = fConnections.begin();
-  i!=fConnections.end();++i)
-   if (i->second==connection) return i->first;
-#endif
-
-#ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* aConnection = (AliMpConnection*)value;
-    if (aConnection == connection) return AliMpExMap::GetPair(key);
-  }  
-#endif
-
-  return AliMpIntPair::Invalid();
+  return connection->LocalIndices();
 }
 
 //______________________________________________________________________________
@@ -285,12 +333,13 @@ AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
 #endif
    
 #ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* connection = (AliMpConnection*)value;
-    if (connection->GetPadNum() == padNum) return AliMpExMap::GetPair(key);
-  }  
+  TIter next(fConnections.CreateIterator());
+  AliMpConnection* connection;
+  
+  while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
+  {
+    if (connection->GetPadNum()==padNum) return connection->LocalIndices();
+  }
 #endif
  return AliMpIntPair::Invalid();
 }
@@ -307,12 +356,13 @@ AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
 #endif
    
 #ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* connection = (AliMpConnection*)value;
-    if (connection->GetGassiNum()==gassiNum) return AliMpExMap::GetPair(key);
-  }  
+  TIter next(fConnections.CreateIterator());
+  AliMpConnection* connection;
+  
+  while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
+  {
+    if (connection->GetGassiNum()==gassiNum) return connection->LocalIndices();
+  }
 #endif
    
  return AliMpIntPair::Invalid();
@@ -330,12 +380,13 @@ AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
 #endif
    
 #ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* connection = (AliMpConnection*)value;
-    if (connection->GetKaptonNum()==kaptonNum) return AliMpExMap::GetPair(key);
-  }  
+  TIter next(fConnections.CreateIterator());
+  AliMpConnection* connection;
+  
+  while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
+  {
+    if (connection->GetKaptonNum()==kaptonNum) return connection->LocalIndices();
+  }
 #endif
    
  return AliMpIntPair::Invalid();
@@ -353,12 +404,13 @@ AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
 #endif
    
 #ifdef WITH_ROOT
-  TExMapIter i = fConnections.GetIterator();
-  Long_t key, value;
-  while ( i.Next(key, value) ) {
-    AliMpConnection* connection = (AliMpConnection*)value;
-    if (connection->GetBergNum()==bergNum) return AliMpExMap::GetPair(key);
-  }  
+  TIter next(fConnections.CreateIterator());
+  AliMpConnection* connection;
+  
+  while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
+  {
+    if (connection->GetBergNum()==bergNum) return connection->LocalIndices();
+  }
 #endif
    
  return AliMpIntPair::Invalid();
@@ -381,7 +433,7 @@ Int_t  AliMpMotifType::GetNofPads() const
 //______________________________________________________________________________
 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
 {
-  /// Return true if the pad indexed by <localIndices> has a connection
+  /// Return true if the pad indexed by \a localIndices has a connection
   
   if (!localIndices.IsValid()) return false;
 
@@ -428,21 +480,89 @@ void AliMpMotifType::Print(Option_t *option) const
       AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
       TString str;
       if (connexion){
-       switch (option[0]){
-       case 'N':str=PadName(connexion->GetPadNum());
-         break;
-       case 'K':str=Form("%d",connexion->GetKaptonNum());
-         break;
-       case 'B':str=Form("%d",connexion->GetBergNum());
-         break;
-        case 'G':str=Form("%d",connexion->GetGassiNum());
-          break;
-       default:str= Form("%d",connexion->GetPadNum());
-       }
-       cout<<setw(2)<<str;
+        AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
+        
+        switch (option[0]){
+          case 'N':str=PadName(connexion->GetPadNum());
+            break;
+          case 'K':str=Form("%d",connexion->GetKaptonNum());
+            break;
+          case 'B':str=Form("%d",connexion->GetBergNum());
+            break;
+          case 'G':str=Form("%d",connexion->GetGassiNum());
+            break;
+          default:str= Form("%d",connexion->GetPadNum());
+        }
+        cout<<setw(2)<<str;
       } else cout<<setw(2)<<"--";
       cout<<" ";
     }
     cout<<endl;
   }
 }
+
+//_____________________________________________________________________________
+Bool_t
+AliMpMotifType::Save() const
+{
+/// Save this motif type
+
+  return Save(fID.Data());
+}
+
+//_____________________________________________________________________________
+Bool_t
+AliMpMotifType::Save(const char* motifName) const
+{
+  /// Generate the 2 files needed to describe the motif
+  
+  TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
+  
+  TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
+
+  // first a protection : do not allow overwriting existing files...
+  Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
+  if (test==kFALSE) // AccessPathName has a strange return value convention...
+  {
+    AliError("Cannot overwrite existing padPos file");
+    return kFALSE;
+  }
+  test = gSystem->AccessPathName(motifTypeFileName.Data());
+  if (test==kFALSE)
+  {
+    AliError("Cannot overwrite existing motifType file");
+    return kFALSE;    
+  }
+  
+  ofstream padPosFile(padPosFileName.Data());
+  ofstream motifFile(motifTypeFileName.Data());
+  
+  motifFile <<  "# Motif " << motifName << endl
+    << "#" << endl
+    << "#connecteur_berg kapton padname not_used" << endl
+    << "#for slats there's no kapton connector, so it's always 1" 
+    << " (zero make the reader" << endl
+    << "#abort, so it's not a valid value here)." << endl
+    << "#" << endl;
+  
+  for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix ) 
+  {
+    for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy ) 
+    {
+      AliMpConnection* con = FindConnectionByLocalIndices(AliMpIntPair(ix,iy));
+      if (con)
+      {
+        motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
+        padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;
+      }
+    }
+  }
+  
+  padPosFile.close();
+  motifFile.close();
+  
+  return kTRUE;
+}
+
+
+