]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpMotifMap.cxx
Adding functions for iterating over motif positions
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifMap.cxx
index 4c393eee2d38445cef43acc7b9c3c58a2dd46afc..4267649d240e0de661bc21ba374f0343d3cf7448 100755 (executable)
@@ -14,7 +14,7 @@
  **************************************************************************/
 
 // $Id$
-// $MpId: AliMpMotifMap.cxx,v 1.13 2006/03/15 10:04:36 ivana Exp $
+// $MpId: AliMpMotifMap.cxx,v 1.16 2006/05/24 13:58:41 ivana Exp $
 // Category: motif
 // -------------------
 // Class AliMpMotifMap
 // Included in AliRoot: 2003/05/02
 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
 
-#include <Riostream.h>
-#include <TVector2.h>
-
 #include "AliMpMotifMap.h"
 #include "AliMpVMotif.h"
 #include "AliMpMotif.h"
 #include "AliMpMotifSpecial.h"
 #include "AliMpMotifType.h"
 #include "AliMpMotifPosition.h"
-#include "TArrayI.h"
 
+#include "AliLog.h"
+
+#include <Riostream.h>
+#include <TVector2.h>
+#include <TArrayI.h>
+
+/// \cond CLASSIMP
 ClassImp(AliMpMotifMap)
+/// \endcond
 
 //_____________________________________________________________________________
 AliMpMotifMap::AliMpMotifMap(Bool_t /*standardConstructor*/) 
@@ -95,7 +99,6 @@ AliMpMotifMap::~AliMpMotifMap()
 void  AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
 {
 /// Print the motif.
-// ---
 
   cout << motif->GetID().Data() << "  "
        << motif->GetMotifType()->GetID() << "    "
@@ -255,9 +258,46 @@ AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
 #endif  
 }
 
+//_____________________________________________________________________________
+UInt_t  AliMpMotifMap::GetNofMotifPositions() const
+{
+/// Return the number of all motif positions IDs (electronic card numbers)
+
+#ifdef WITH_STL
+  return fMotifPositions.size();  
+#endif
+  
+#ifdef WITH_ROOT  
+  return fMotifPositions.GetSize();
+#endif 
+} 
+
+//_____________________________________________________________________________
+AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
+{
+/// Return the motif position which is in the map on the index-th position
+
+  if ( index >= GetNofMotifPositions() ) {
+    AliErrorStream() << "Index " << index << " outside limits." << endl;
+    return 0;
+  }   
+
+#ifdef WITH_STL
+  MotifPositionMapIterator it = fMotifPositions.begin();
+  std::advance(it, index);
+  return it->second;
+#endif
+  
+#ifdef WITH_ROOT  
+  return (AliMpMotifPosition*)fMotifPositions.GetObject(index);
+#endif 
+}
+
 //_____________________________________________________________________________
 Int_t AliMpMotifMap::CalculateNofPads() const 
 {
+/// Calculate total number of pads in the map
+
   Int_t nofPads = 0;
 
 #ifdef WITH_STL
@@ -284,7 +324,7 @@ Int_t AliMpMotifMap::CalculateNofPads() const
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotifPositions() const
 {
-/// Print all the the motifs positions.
+/// Print all motif positions.
 
 #ifdef WITH_STL
   if (fMotifPositions.size()) {
@@ -323,7 +363,7 @@ void  AliMpMotifMap::PrintMotifPositions() const
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotifPositions2() const
 {
-/// Print all the the motifs positions from the second map
+/// Print all motif positions from the second map
 /// (by global indices)
 
 #ifdef WITH_STL
@@ -373,9 +413,12 @@ Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
   AliMpVMotif* found = FindMotif(motif->GetID());
   if (found) {    
     if (warn && found == motif) 
-      Warning("AddMotif", "The motif is already in map.");
-    if (warn && found != motif) 
-      Warning("AddMotif", "Another motif with the same ID is already in map.");      
+      AliWarningStream() << "The motif is already in map." << endl;
+
+    if (warn && found != motif) {
+      AliWarningStream() 
+        << "Another motif with the same ID is already in map." << endl; 
+    }       
     return false;
   }  
 
@@ -399,10 +442,12 @@ Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
   AliMpMotifType* found = FindMotifType(motifType->GetID());
   if (found) {    
     if (warn && found == motifType) 
-      Warning("AddMotifType", "The motif type is already in map.");
-    if (warn && found != motifType) 
-      Warning("AddMotifType", 
-              "Another motif type with the same ID is already in map.");      
+      AliWarningStream() << "The motif type is already in map." << endl;
+      
+    if (warn && found != motifType) { 
+      AliWarningStream() 
+        << "Another motif type with the same ID is already in map." << endl;
+    }       
     return false;
   }  
 
@@ -426,18 +471,22 @@ Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t
   AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
   if (found) { 
     if (warn && found == motifPosition) {
-      cerr << "ID: " << motifPosition->GetID() 
+      AliWarningStream()
+           << "ID: " << motifPosition->GetID() 
            << "  found: " << found 
-          << "  new:   " << motifPosition << endl;   
-      Warning("AddMotifPosition", "This motif position is already in map.");
+          << "  new:   " << motifPosition << endl
+          << "This motif position is already in map." << endl;
     }  
+    
     if (warn && found != motifPosition) { 
-      cerr << "ID: " << motifPosition->GetID() 
+      AliWarningStream()
+           << "ID: " << motifPosition->GetID() 
            << "  found: " << found 
-          << "  new:   " << motifPosition << endl;   
-      Warning("AddMotifposition", 
-              "Another motif position with the same ID is already in map.");
-    }              
+          << "  new:   " << motifPosition << endl
+          << "Another motif position with the same ID is already in map."
+          << endl;
+    }
+                   
     return false;
   }  
 
@@ -459,7 +508,7 @@ void AliMpMotifMap::FillMotifPositionMap2()
 
 #ifdef WITH_STL
   if (fMotifPositions2.size() > 0 ) {
-    Warning("FillMotifPositionMap2", "Map has been already filled.");
+    AliWarningStream() << "Map has been already filled." << endl;
     return;
   }  
 
@@ -472,7 +521,7 @@ void AliMpMotifMap::FillMotifPositionMap2()
 
 #ifdef WITH_ROOT
   if (fMotifPositions2.GetSize() > 0 ) {
-    Warning("FillMotifPositionMap2", "Map has been already filled.");
+    AliWarningStream() <<"Map has been already filled." << endl;
     return;
   }  
 
@@ -504,7 +553,7 @@ void  AliMpMotifMap::Print(const char* opt) const
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
 {
-/// Print all the motifs positions and their global indices.
+/// Print all motif positions and their global indices.
 
   ofstream out(fileName, ios::out);
 
@@ -542,8 +591,7 @@ void  AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
 //_____________________________________________________________________________
 void  AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
 {
-/// Updates the motifs positions global indices
-/// from the file.
+/// Update the motif positions global indices from the file.
 
   ifstream in(fileName, ios::in);
 
@@ -560,7 +608,8 @@ void  AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
     AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
          
     if (motifPosition) {
-       cout << "Processing " 
+       AliDebugStream(1) 
+            << "Processing " 
             << motifPosition->GetID() << " " << offx << " " << offy << endl; 
 
        motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
@@ -574,8 +623,8 @@ void  AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
        motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
     }
     else {   
-       cerr <<"Motif position " << motifPositionId << endl;
-       Warning("UpdateGlobalIndices", "Motif position not found !!!");
+       AliWarningStream()
+         << "Motif position " << motifPositionId << " not found" << endl;
     }
   }    
   while (!in.eof());
@@ -585,7 +634,7 @@ void  AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
 //_____________________________________________________________________________
 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
 {
-/// Finds the motif with the specified ID.
+/// Find the motif with the specified ID.
   
 #ifdef WITH_STL
   MotifMapIterator i = fMotifs.find(motifID);
@@ -605,7 +654,7 @@ AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
                                       const TString& motifTypeID,
                                      const TVector2& padDimensions ) const
 {
-/// Finds the motif with the specified ID and returns it
+/// Find the motif with the specified ID and returns it
 /// only if its motif type and motif dimensions agree
 /// with the given motifTypeID and motifDimensions.
 /// Disagreement causes fatal error.