]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpMotifMap.cxx
Work around for CINT bug in root 5.10/00, with gcc4.0.2
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifMap.cxx
index b6fed2da83c387752e1d8534ff212472b5173a85..4c393eee2d38445cef43acc7b9c3c58a2dd46afc 100755 (executable)
@@ -1,6 +1,22 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
 // $Id$
+// $MpId: AliMpMotifMap.cxx,v 1.13 2006/03/15 10:04:36 ivana Exp $
 // Category: motif
-//
+// -------------------
 // Class AliMpMotifMap
 // -------------------
 // Class describing the motif map container, where motifs are
 #include "AliMpMotifSpecial.h"
 #include "AliMpMotifType.h"
 #include "AliMpMotifPosition.h"
+#include "TArrayI.h"
 
 ClassImp(AliMpMotifMap)
 
+//_____________________________________________________________________________
+AliMpMotifMap::AliMpMotifMap(Bool_t /*standardConstructor*/) 
+  : TObject()
 #ifdef WITH_ROOT
-const Int_t AliMpMotifMap::fgkSeparator = 100;
-#endif
+    ,fMotifs(true),
+     fMotifTypes(true),
+     fMotifPositions(true),
+     fMotifPositions2(true)
+#endif 
+{
+/// Standard constructor
+  
+  //fMotifPositions2.SetOwner(false);
+}
 
 //_____________________________________________________________________________
 AliMpMotifMap::AliMpMotifMap() 
-  : TObject()
+  : TObject(),
+    fMotifs(),
+    fMotifTypes(),
+    fMotifPositions(),
+    fMotifPositions2()
 {
-//
+/// Default constructor
 }
 
 //_____________________________________________________________________________
-AliMpMotifMap::~AliMpMotifMap() {
-//  
+AliMpMotifMap::~AliMpMotifMap() 
+{
+/// Destructor  
 
   // Delete all registered motifs, motif types, motif positions
   
@@ -52,84 +85,16 @@ AliMpMotifMap::~AliMpMotifMap() {
     delete ip->second;
   }  
 #endif  
-  
-#ifdef WITH_ROOT
-  MotifMapIterator im(&fMotifs);
-  Long_t mkey, mvalue;
-  while ( im.Next(mkey, mvalue) ) delete (AliMpMotif*)mvalue;
-
-  MotifMapIterator it(&fMotifTypes);
-  Long_t tkey, tvalue;
-  while ( it.Next(tkey, tvalue) ) delete (AliMpMotifType*)tvalue;
-
-  MotifMapIterator ip(&fMotifPositions);
-  Long_t pkey, pvalue;
-  while ( it.Next(pkey, pvalue) ) delete (AliMpMotifPosition*)pvalue;
-#endif  
 }
 
 // 
 // private methods
 //
 
-#ifdef WITH_ROOT
-//_____________________________________________________________________________
-Int_t  AliMpMotifMap::GetIndex(const TString& s) const 
-{
-// Converts the TString to integer.
-// ---
-
-  if (s.Length() > 5) {
-    Fatal("GetIndex", "String too long.");
-    return 0;
-  }  
-
-  Int_t index = 0;
-  for (Int_t i=s.Length(); i>=0; --i)  index = index*100 + int(s(i));
-  return index;
-}
-
-//______________________________________________________________________________
-Int_t  AliMpMotifMap::GetIndex(const AliMpIntPair& pair) const
-{
-// Converts the pair of integers to integer.
-// ---
-
-  if (pair.GetFirst() >= fgkSeparator || pair.GetSecond() >= fgkSeparator)
-    Fatal("GetIndex", "Index out of limit.");
-      
-  return pair.GetFirst()*fgkSeparator + pair.GetSecond() + 1;
-}  
-
-//_____________________________________________________________________________
-TString  AliMpMotifMap::GetString(Int_t index) const
-{
-// Converts the integer index to the string.
-// ---
-
-  TString s;
-  while (index >0) {
-    Char_t c = index%100;
-    s += c;
-    index = index/100;
-  }
-  return s;
-}
-
-//______________________________________________________________________________
-AliMpIntPair  AliMpMotifMap::GetPair(Int_t index) const
-{
-// Converts the integer index to the pair of integers.
-// ---
-
-  return AliMpIntPair((index-1)/fgkSeparator, (index-1)%fgkSeparator);
-}  
-#endif
-
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
 {
-// Prints the motif.
+/// Print the motif.
 // ---
 
   cout << motif->GetID().Data() << "  "
@@ -141,8 +106,7 @@ void  AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
 {
-// Prints the motif type.
-// ---
+/// Print the motif type.
 
   cout << motifType->GetID().Data() << "  "
        << motifType->GetNofPadsX() << "  " 
@@ -153,21 +117,19 @@ void  AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
 void  AliMpMotifMap::PrintMotifPosition(
                           const AliMpMotifPosition* motifPosition) const
 {
-// Prints the motif position.
-// ---
+/// Print the motif position.
 
-  cout << motifPosition->GetID() << "  "
-       << motifPosition->GetMotif()->GetID() << "  " 
-       << motifPosition->Position().X() << "  "
-       << motifPosition->Position().Y() << "    ";
+  cout << " ID " << motifPosition->GetID() << "  "
+       << " Motif ID " << motifPosition->GetMotif()->GetID() << "  " 
+       << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
+       << motifPosition->Position().Y() << ")";
 }
 
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotifPosition2(
                           const AliMpMotifPosition* motifPosition) const
 {
-// Prints the motif position.
-// ---
+/// Print the motif position.
 
   cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << "  "
        << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << "  "
@@ -179,9 +141,8 @@ void  AliMpMotifMap::PrintMotifPosition2(
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotifs() const
 {
-// Prints all the motifs and their motif types 
-// for all motifs in the motifs map.
-// ---
+/// Print all the motifs and their motif types 
+/// for all motifs in the motifs map.
 
 #ifdef WITH_STL
   if (fMotifs.size()) {
@@ -203,10 +164,10 @@ void  AliMpMotifMap::PrintMotifs() const
   if (fMotifs.GetSize()) {
     cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
     Int_t counter = 0;        
-    MotifMapIterator i(&fMotifs);
+    TExMapIter i = fMotifs.GetIterator();
     Long_t key, value;
     while ( i.Next(key, value) ) {
-      TString id  = GetString(key);
+      TString id  = fMotifs.AliMpExMap::GetString(key);
       AliMpVMotif* motif = (AliMpVMotif*)value;
       cout << "Map element " 
            << setw(3) << counter++ << "   " 
@@ -222,9 +183,8 @@ void  AliMpMotifMap::PrintMotifs() const
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotifTypes() const
 {
-// Prints all the the motifs types and their motif dimensions
-// for all motif types in the motif types map.
-// ---
+/// Print all the the motifs types and their motif dimensions
+/// for all motif types in the motif types map.
 
 #ifdef WITH_STL
   if (fMotifTypes.size()) {
@@ -246,10 +206,10 @@ void  AliMpMotifMap::PrintMotifTypes() const
   if (fMotifTypes.GetSize()) {
     cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
     Int_t counter = 0;        
-    MotifTypeMapIterator i(&fMotifTypes);
+    TExMapIter i = fMotifTypes.GetIterator();
     Long_t key, value;
     while ( i.Next(key, value) ) {
-      TString id  = GetString(key);
+      TString id  = AliMpExMap::GetString(key);
       AliMpMotifType* motifType = (AliMpMotifType*)value;
       cout << "Map element " 
            << setw(3) << counter++ << "   " 
@@ -262,11 +222,69 @@ void  AliMpMotifMap::PrintMotifTypes() const
 #endif  
 }
 
+//_____________________________________________________________________________
+void 
+AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
+{
+/// Fill the given array with all motif positions IDs (electronic card numbers)
+/// defined in the map
+
+#ifdef WITH_STL
+  ecn.Set(fMotifPositions.size());  
+  Int_t i(0);
+  MotifPositionMapIterator it;
+  for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
+    AliMpMotifPosition* motifPosition = (*it).second;
+    ecn[i++] = motifPosition->GetID();
+  }
+#endif
+  
+#ifdef WITH_ROOT  
+  ecn.Set(fMotifPositions.GetSize());
+  TExMapIter it = fMotifPositions.GetIterator();
+  Long_t key, value;
+  Int_t i(0);
+  
+  while ( it.Next(key, value) ) 
+  {
+    AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
+    ecn[i] = motifPosition->GetID();
+    ++i;
+  }
+  
+#endif  
+}
+
+//_____________________________________________________________________________
+Int_t AliMpMotifMap::CalculateNofPads() const 
+{
+  Int_t nofPads = 0;
+
+#ifdef WITH_STL
+  MotifPositionMapIterator it;
+  for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
+    AliMpMotifPosition* motifPosition = (*it).second;
+    nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
+  }
+#endif
+  
+#ifdef WITH_ROOT  
+  TExMapIter it = fMotifPositions.GetIterator();
+  Long_t key, value;
+  
+  while ( it.Next(key, value) ) {
+    AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
+    nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
+  }
+#endif  
+
+  return nofPads;
+}
+
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotifPositions() const
 {
-// Prints all the the motifs positions.
-// ---
+/// Print all the the motifs positions.
 
 #ifdef WITH_STL
   if (fMotifPositions.size()) {
@@ -286,9 +304,9 @@ void  AliMpMotifMap::PrintMotifPositions() const
 
 #ifdef WITH_ROOT
   if (fMotifPositions.GetSize()) {
-    cout << "Dump of Motif Type Map - " << fMotifPositions.GetSize() << " entries:" << endl;
+    cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
     Int_t counter = 0;        
-    MotifPositionMapIterator i(&fMotifPositions);
+    TExMapIter i = fMotifPositions.GetIterator();
     Long_t key, value;
     while ( i.Next(key, value) ) {
       AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
@@ -305,9 +323,8 @@ void  AliMpMotifMap::PrintMotifPositions() const
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintMotifPositions2() const
 {
-// Prints all the the motifs positions from the second map
-// (by global indices)
-// ---
+/// Print all the the motifs positions from the second map
+/// (by global indices)
 
 #ifdef WITH_STL
   if (fMotifPositions2.size()) {
@@ -329,7 +346,7 @@ void  AliMpMotifMap::PrintMotifPositions2() const
   if (fMotifPositions2.GetSize()) {
     cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
     Int_t counter = 0;        
-    MotifPositionMapIterator i(&fMotifPositions2);
+    TExMapIter i = fMotifPositions2.GetIterator();
     Long_t key, value;
     while ( i.Next(key, value) ) {
       AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
@@ -350,9 +367,8 @@ void  AliMpMotifMap::PrintMotifPositions2() const
 //_____________________________________________________________________________
 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
 {
-// Adds the specified motif 
-// if the motif with this ID is not yet present.
-// ---
+/// Add the specified motif 
+/// if the motif with this ID is not yet present.
 
   AliMpVMotif* found = FindMotif(motif->GetID());
   if (found) {    
@@ -368,7 +384,7 @@ Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
 #endif
 
 #ifdef WITH_ROOT
-  fMotifs.Add(GetIndex(motif->GetID()), (Long_t)motif);
+  fMotifs.Add(motif->GetID(), motif);
 #endif
 
   return true;
@@ -377,9 +393,8 @@ Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
 //_____________________________________________________________________________
 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
 {
-// Adds the specified motif type
-// if the motif with this ID is not yet present.
-// ---
+/// Add the specified motif type
+/// if the motif with this ID is not yet present.
 
   AliMpMotifType* found = FindMotifType(motifType->GetID());
   if (found) {    
@@ -396,7 +411,7 @@ Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
 #endif
 
 #ifdef WITH_ROOT
-  fMotifTypes.Add(GetIndex(motifType->GetID()), (Long_t)motifType);
+  fMotifTypes.Add(motifType->GetID(), motifType);
 #endif
 
   return true;
@@ -405,9 +420,8 @@ Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
 //_____________________________________________________________________________
 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
 {
-// Adds the specified motif position
-// if this position is not yet present.
-// ---
+/// Add the specified motif position
+/// if this position is not yet present.
 
   AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
   if (found) { 
@@ -432,7 +446,7 @@ Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t
 #endif
 
 #ifdef WITH_ROOT
-  fMotifPositions.Add(motifPosition->GetID(), (Long_t)motifPosition);
+  fMotifPositions.Add(motifPosition->GetID(), motifPosition);
 #endif
 
   return true;
@@ -441,8 +455,7 @@ Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t
 //_____________________________________________________________________________
 void AliMpMotifMap::FillMotifPositionMap2()
 {
-// Fills the second map (by global indices) of motif positions.
-// ---
+/// Fill the second map (by global indices) of motif positions.
 
 #ifdef WITH_STL
   if (fMotifPositions2.size() > 0 ) {
@@ -463,34 +476,35 @@ void AliMpMotifMap::FillMotifPositionMap2()
     return;
   }  
 
-  MotifPositionMapIterator i(&fMotifPositions);
+  TExMapIter i = fMotifPositions.GetIterator();
   Long_t key, value;
   while ( i.Next(key, value) ) {
     AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
-    fMotifPositions2.Add(GetIndex(motifPosition->GetLowIndicesLimit()),
-                         (Long_t)motifPosition);
+    fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
   }
 #endif
 
 }
 
 //_____________________________________________________________________________
-void  AliMpMotifMap::Print(const char* /*option*/) const
+void  AliMpMotifMap::Print(const char* opt) const
 {
-// Prints the motifs and motif types maps.
-// ---
+/// Print the motifs and motif types maps.
 
-  PrintMotifs();
-  PrintMotifTypes();
-  PrintMotifPositions();
-  PrintMotifPositions2();
+  TString sopt(opt);
+  
+  sopt.ToUpper();
+  
+  if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
+  if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
+  if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
+  if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
 }
 
 //_____________________________________________________________________________
 void  AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
 {
-// Prints all the motifs positions and their global indices.
-// ---
+/// Print all the motifs positions and their global indices.
 
   ofstream out(fileName, ios::out);
 
@@ -511,7 +525,7 @@ void  AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
 
 #ifdef WITH_ROOT
   if (fMotifPositions.GetSize()) {
-    MotifPositionMapIterator i(&fMotifPositions);
+    TExMapIter i = fMotifPositions.GetIterator();
     Long_t key, value;
     while ( i.Next(key, value) ) {
       AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
@@ -528,9 +542,8 @@ void  AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
 //_____________________________________________________________________________
 void  AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
 {
-// Updates the motifs positions global indices
-// from the file.
-// ---
+/// Updates the motifs positions global indices
+/// from the file.
 
   ifstream in(fileName, ios::in);
 
@@ -572,8 +585,7 @@ void  AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
 //_____________________________________________________________________________
 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
 {
-// Finds the motif with the specified ID.
-// ---
+/// Finds the motif with the specified ID.
   
 #ifdef WITH_STL
   MotifMapIterator i = fMotifs.find(motifID);
@@ -584,11 +596,7 @@ AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
 #endif
 
 #ifdef WITH_ROOT
-  Long_t value = fMotifs.GetValue(GetIndex(motifID));
-  if (value) 
-    return (AliMpVMotif*)value;
-  else
-    return 0;  
+  return (AliMpVMotif*)fMotifs.GetValue(motifID);
 #endif
 }
 
@@ -597,12 +605,11 @@ AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
                                       const TString& motifTypeID,
                                      const TVector2& padDimensions ) const
 {
-// Finds 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.
-// ---
-  
+/// Finds 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.
   AliMpVMotif* motif = FindMotif(motifID);
 
   if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
@@ -640,8 +647,7 @@ AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
 //_____________________________________________________________________________
 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
 {
-// Finds the motif type with the specified motif type ID.
-// ---
+/// Find the motif type with the specified motif type ID.
   
 #ifdef WITH_STL
   MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
@@ -652,11 +658,7 @@ AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
 #endif
 
 #ifdef WITH_ROOT
-  Long_t value = fMotifTypes.GetValue(GetIndex(motifTypeID));
-  if (value) 
-    return (AliMpMotifType*)value;
-  else
-    return 0;  
+  return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
 #endif
 }
 
@@ -664,8 +666,7 @@ AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
 AliMpMotifPosition* 
 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
 {
-// Finds the motif position with the specified motif position ID.
-// ---
+/// Find the motif position with the specified motif position ID.
   
 #ifdef WITH_STL
   MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
@@ -676,11 +677,7 @@ AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
 #endif
 
 #ifdef WITH_ROOT
-  Long_t value = fMotifPositions.GetValue(motifPositionID);
-  if (value) 
-    return (AliMpMotifPosition*)value;
-  else
-    return 0;  
+  return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
 #endif
 }
 
@@ -689,9 +686,8 @@ AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
 AliMpMotifPosition* 
 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
 {
-// Finds the last motif position which has the global indices (low limit)
-// less then the indices specified.
-// ---
+/// Find the last motif position which has the global indices (low limit)
+/// less then the indices specified.
 
 #ifdef WITH_STL
   MotifPositionMap2Iterator found