+/**************************************************************************
+ * 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
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() << " "
//_____________________________________________________________________________
void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
{
-// Prints the motif type.
-// ---
+/// Print the motif type.
cout << motifType->GetID().Data() << " "
<< motifType->GetNofPadsX() << " "
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() << " "
//_____________________________________________________________________________
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()) {
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++ << " "
//_____________________________________________________________________________
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()) {
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++ << " "
#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()) {
#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;
//_____________________________________________________________________________
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()) {
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;
//_____________________________________________________________________________
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) {
#endif
#ifdef WITH_ROOT
- fMotifs.Add(GetIndex(motif->GetID()), (Long_t)motif);
+ fMotifs.Add(motif->GetID(), motif);
#endif
return true;
//_____________________________________________________________________________
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) {
#endif
#ifdef WITH_ROOT
- fMotifTypes.Add(GetIndex(motifType->GetID()), (Long_t)motifType);
+ fMotifTypes.Add(motifType->GetID(), motifType);
#endif
return true;
//_____________________________________________________________________________
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) {
#endif
#ifdef WITH_ROOT
- fMotifPositions.Add(motifPosition->GetID(), (Long_t)motifPosition);
+ fMotifPositions.Add(motifPosition->GetID(), motifPosition);
#endif
return true;
//_____________________________________________________________________________
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 ) {
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);
#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;
//_____________________________________________________________________________
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);
//_____________________________________________________________________________
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);
#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
}
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) {
//_____________________________________________________________________________
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);
#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
}
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);
#endif
#ifdef WITH_ROOT
- Long_t value = fMotifPositions.GetValue(motifPositionID);
- if (value)
- return (AliMpMotifPosition*)value;
- else
- return 0;
+ return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
#endif
}
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