1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 /// \class AliMpSlatMotifMap
19 /// Basically this class provide a garbage collection of AliMpMotif and
20 /// AliMpMotifType objects.
23 /// \author Laurent Aphecetche
28 #include "AliMpSlatMotifMap.h"
30 #include "AliMpVMotif.h"
31 #include "AliMpMotifType.h"
34 #include "TObjString.h"
36 #include "Riostream.h"
38 ClassImp(AliMpSlatMotifMap)
40 //_____________________________________________________________________________
41 AliMpSlatMotifMap::AliMpSlatMotifMap()
47 fMotifs.SetOwner(kTRUE);
48 fMotifTypes.SetOwner(kTRUE);
51 //_____________________________________________________________________________
52 AliMpSlatMotifMap::~AliMpSlatMotifMap()
58 //_____________________________________________________________________________
60 AliMpSlatMotifMap::Reset()
64 fMotifTypes.DeleteAll();
67 //_____________________________________________________________________________
69 AliMpSlatMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
71 /// Add a motif to the map
72 AliDebug(1,Form("Adding motif %s",motif->GetID().Data()));
74 AliMpVMotif* found = FindMotif(motif->GetID());
76 if (warn && found == motif)
78 AliWarning(Form("The motif %s is already in map",motif->GetID().Data()));
80 if (warn && found != motif)
82 AliError(Form("Another motif with the same ID=%s is already in map",
83 motif->GetID().Data()));
88 fMotifs.Add(new TObjString(motif->GetID()),motif);
92 //_____________________________________________________________________________
94 AliMpSlatMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
96 /// Add a motif to the map
98 AliDebug(1,Form("Adding motifType %s",motifType->GetID().Data()));
100 AliMpMotifType* found = FindMotifType(motifType->GetID());
102 if (warn && found == motifType)
104 AliWarning(Form("The motifType %s is already in map",
105 motifType->GetID().Data()));
107 if (warn && found != motifType)
109 AliError(Form("Another motifType with the same ID=%s is already in map",
110 motifType->GetID().Data()));
115 fMotifTypes.Add(new TObjString(motifType->GetID()),motifType);
120 //_____________________________________________________________________________
122 AliMpSlatMotifMap::FindMotif(const TString& id) const
124 /// Search a given motif in the map and returns it if it's there.
126 AliDebug(1,Form("Looking for motif %s",id.Data()));
128 TObject* object = fMotifs.GetValue(id.Data());
132 AliMpVMotif* motif = static_cast<AliMpVMotif*>(object);
133 AliDebug(1,Form("Found : %p id=%s",motif,motif->GetID().Data()));
136 AliDebug(1,"Not found");
140 //_____________________________________________________________________________
142 AliMpSlatMotifMap::FindMotifType(const TString& id) const
144 /// Search a given motifType in the map and returns it if it's there.
145 AliDebug(1,Form("Looking for motifType %s",id.Data()));
147 TObject* object = fMotifTypes.GetValue(id.Data());
151 AliMpMotifType* motifType = static_cast<AliMpMotifType*>(object);
152 AliDebug(1,Form("Found : %p id=%s",motifType,motifType->GetID().Data()));
155 AliDebug(1,"Not found");
160 //_____________________________________________________________________________
162 AliMpSlatMotifMap::Print(Option_t*) const
165 cout << "Motifs=" << endl;
167 TIter next(&fMotifs);
168 while ( ( key = next() ) )
170 AliMpVMotif* motif = dynamic_cast<AliMpVMotif*>(fMotifs.GetValue(key));
171 if (motif) cout << motif->GetID() << endl;
174 cout << "MotifTypes=" << endl;
175 TIter tnext(&fMotifTypes);
176 while ( ( key = tnext() ) )
178 AliMpMotifType* motifType = dynamic_cast<AliMpMotifType*>(fMotifTypes.GetValue(key));
179 if (motifType) cout << motifType->GetID() << endl;