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 //-----------------------------------------------------------------------------
18 /// \class AliMpSlatMotifMap
20 /// Basically this class provide a garbage collection of AliMpMotif and
21 /// AliMpMotifType objects.
24 /// \author Laurent Aphecetche
25 //-----------------------------------------------------------------------------
30 #include "AliMpSlatMotifMap.h"
32 #include "AliMpVMotif.h"
33 #include "AliMpMotifType.h"
36 #include "TObjString.h"
38 #include "Riostream.h"
43 ClassImp(AliMpSlatMotifMap)
46 //_____________________________________________________________________________
47 AliMpSlatMotifMap::AliMpSlatMotifMap()
53 fMotifs.SetOwner(kTRUE);
54 fMotifTypes.SetOwner(kTRUE);
57 //_____________________________________________________________________________
58 AliMpSlatMotifMap::~AliMpSlatMotifMap()
64 //_____________________________________________________________________________
66 AliMpSlatMotifMap::Reset()
70 fMotifTypes.DeleteAll();
73 //_____________________________________________________________________________
75 AliMpSlatMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
77 /// Add a motif to the map
78 AliDebug(1,Form("Adding motif %s",motif->GetID().Data()));
80 AliMpVMotif* found = FindMotif(motif->GetID());
82 if (warn && found == motif)
84 AliWarning(Form("The motif %s is already in map",motif->GetID().Data()));
86 if (warn && found != motif)
88 AliError(Form("Another motif with the same ID=%s is already in map",
89 motif->GetID().Data()));
94 fMotifs.Add(new TObjString(motif->GetID()),motif);
98 //_____________________________________________________________________________
100 AliMpSlatMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
102 /// Add a motif to the map
104 AliDebug(1,Form("Adding motifType %s",motifType->GetID().Data()));
106 AliMpMotifType* found = FindMotifType(motifType->GetID());
108 if (warn && found == motifType)
110 AliWarning(Form("The motifType %s is already in map",
111 motifType->GetID().Data()));
113 if (warn && found != motifType)
115 AliError(Form("Another motifType with the same ID=%s is already in map",
116 motifType->GetID().Data()));
121 fMotifTypes.Add(new TObjString(motifType->GetID()),motifType);
126 //_____________________________________________________________________________
128 AliMpSlatMotifMap::FindMotif(const TString& id) const
130 /// Search a given motif in the map and returns it if it's there.
132 AliDebug(1,Form("Looking for motif %s",id.Data()));
134 TObject* object = fMotifs.GetValue(id.Data());
138 AliMpVMotif* motif = static_cast<AliMpVMotif*>(object);
139 AliDebug(1,Form("Found : %p id=%s",motif,motif->GetID().Data()));
142 AliDebug(1,"Not found");
146 //_____________________________________________________________________________
148 AliMpSlatMotifMap::FindMotifType(const TString& id) const
150 /// Search a given motifType in the map and returns it if it's there.
151 AliDebug(1,Form("Looking for motifType %s",id.Data()));
153 TObject* object = fMotifTypes.GetValue(id.Data());
157 AliMpMotifType* motifType = static_cast<AliMpMotifType*>(object);
158 AliDebug(1,Form("Found : %p id=%s",motifType,motifType->GetID().Data()));
161 AliDebug(1,"Not found");
166 //_____________________________________________________________________________
168 AliMpSlatMotifMap::Print(Option_t*) const
171 cout << "Motifs=" << endl;
173 TIter next(&fMotifs);
174 while ( ( key = next() ) )
176 AliMpVMotif* motif = dynamic_cast<AliMpVMotif*>(fMotifs.GetValue(key));
177 if (motif) cout << motif->GetID() << endl;
180 cout << "MotifTypes=" << endl;
181 TIter tnext(&fMotifTypes);
182 while ( ( key = tnext() ) )
184 AliMpMotifType* motifType = dynamic_cast<AliMpMotifType*>(fMotifTypes.GetValue(key));
185 if (motifType) cout << motifType->GetID() << endl;