]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Define and implement Copy and Clone methods (Laurent)
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 12 Jan 2007 11:26:49 +0000 (11:26 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 12 Jan 2007 11:26:49 +0000 (11:26 +0000)
MUON/mapping/AliMpMotifType.cxx
MUON/mapping/AliMpMotifType.h

index c4b846992b405817317431844068ffd04869056e..87ab4d868f660197de6ba2791c184abdfdc8f951 100755 (executable)
 #include "AliMpMotifTypePadIterator.h"
 #include "AliMpConnection.h"
 
-#include <Riostream.h>
+#include "AliLog.h"
+#include "AliMpFiles.h"
+#include "TSystem.h"
 
-#include <stdlib.h>
+#include <Riostream.h>
 
 /// \cond CLASSIMP
 ClassImp(AliMpMotifType)
@@ -52,6 +54,7 @@ AliMpMotifType::AliMpMotifType(const TString &id)
 #endif
 {
   /// Standard constructor
+      AliDebug(1,Form("this=%p id=%s",this,id.Data()));
 }
 
 //______________________________________________________________________________
@@ -64,6 +67,50 @@ AliMpMotifType::AliMpMotifType()
     fConnections()
 {
   /// Default constructor
+      AliDebug(1,Form("this=%p",this));
+}
+
+//______________________________________________________________________________
+AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
+: TObject(),
+  fID(""),
+  fNofPadsX(0),   
+  fNofPadsY(0),
+  fVerboseLevel(0),
+  fConnections()
+{
+    AliDebug(1,Form("this=%p (copy ctor)",this));
+    rhs.Copy(*this);
+}
+
+//______________________________________________________________________________
+AliMpMotifType&
+AliMpMotifType::operator=(const AliMpMotifType& rhs)
+{
+  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
+{
+  TObject::Copy(object);
+  AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
+  mt.fID = fID;
+  mt.fNofPadsX = fNofPadsX;
+  mt.fNofPadsY = fNofPadsY;
+  mt.fVerboseLevel = fVerboseLevel;
+  mt.fConnections = fConnections;
 }
 
 //______________________________________________________________________________
@@ -78,6 +125,9 @@ AliMpMotifType::~AliMpMotifType()
 
   fConnections.erase(fConnections.begin(),fConnections.end());
 #endif  
+  
+  AliDebug(1,Form("this=%p",this));
+  StdoutToAliDebug(1,this->Print(););
 }
 
 //______________________________________________________________________________
@@ -430,21 +480,87 @@ 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
+{
+  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;
+}
+
+
+
index 7d5a8985681f1d32e90d3036eeeca7843159e99f..86f931235a09045be6ec7f09a4453dd2fa9ddf93 100755 (executable)
@@ -43,10 +43,17 @@ class AliMpMotifType : public TObject
 #endif    
 
   public:
+      /** Please note that id should be of the form %s for station 1,2,
+        %s-%e-%e for station345 and %sx%e for stationTrigger
+      */
     AliMpMotifType(const TString &id);
+    AliMpMotifType(const AliMpMotifType& rhs);
+    AliMpMotifType& operator=(const AliMpMotifType& rhs);
     AliMpMotifType();
     virtual ~AliMpMotifType();
 
+    TObject* Clone(const char* newname="") const;
+    
     virtual AliMpVPadIterator* CreateIterator() const;
 
     // find methods
@@ -82,7 +89,13 @@ class AliMpMotifType : public TObject
     TString PadName(Int_t padNum) const;
     Bool_t  HasPad(const AliMpIntPair& localIndices) const;
     Bool_t  IsFull() const;
+    
+    Bool_t Save(const char* motifName) const;
+    Bool_t Save() const;
 
+  private:
+      void Copy(TObject& o) const;
+    
   private:
     // static data members
     static const Int_t  fgkPadNumForA; ///< the pad number for the pad "A"