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"
41 ClassImp(AliMpSlatMotifMap)
44 AliMpSlatMotifMap* AliMpSlatMotifMap::fgInstance = 0;
46 //______________________________________________________________________________
47 AliMpSlatMotifMap* AliMpSlatMotifMap::Instance()
49 /// Return its instance
52 fgInstance = new AliMpSlatMotifMap();
58 //_____________________________________________________________________________
59 AliMpSlatMotifMap::AliMpSlatMotifMap()
65 fMotifs.SetOwner(kTRUE);
66 fMotifTypes.SetOwner(kTRUE);
71 //_____________________________________________________________________________
72 AliMpSlatMotifMap::~AliMpSlatMotifMap()
79 //_____________________________________________________________________________
81 AliMpSlatMotifMap::Reset()
85 fMotifTypes.DeleteAll();
88 //_____________________________________________________________________________
90 AliMpSlatMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
92 /// Add a motif to the map
93 AliDebug(1,Form("Adding motif %s",motif->GetID().Data()));
95 AliMpVMotif* found = FindMotif(motif->GetID());
97 if (warn && found == motif)
99 AliWarning(Form("The motif %s is already in map",motif->GetID().Data()));
101 if (warn && found != motif)
103 AliError(Form("Another motif with the same ID=%s is already in map",
104 motif->GetID().Data()));
109 fMotifs.Add(new TObjString(motif->GetID()),motif);
113 //_____________________________________________________________________________
115 AliMpSlatMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
117 /// Add a motif to the map
119 AliDebug(1,Form("Adding motifType %s",motifType->GetID().Data()));
121 AliMpMotifType* found = FindMotifType(motifType->GetID());
123 if (warn && found == motifType)
125 AliWarning(Form("The motifType %s is already in map",
126 motifType->GetID().Data()));
128 if (warn && found != motifType)
130 AliError(Form("Another motifType with the same ID=%s is already in map",
131 motifType->GetID().Data()));
136 fMotifTypes.Add(new TObjString(motifType->GetID()),motifType);
141 //_____________________________________________________________________________
143 AliMpSlatMotifMap::FindMotif(const TString& id) const
145 /// Search a given motif in the map and returns it if it's there.
147 AliDebug(1,Form("Looking for motif %s",id.Data()));
149 TObject* object = fMotifs.GetValue(id.Data());
153 AliMpVMotif* motif = static_cast<AliMpVMotif*>(object);
154 AliDebug(1,Form("Found : %p id=%s",motif,motif->GetID().Data()));
157 AliDebug(1,"Not found");
161 //_____________________________________________________________________________
163 AliMpSlatMotifMap::FindMotifType(const TString& id) const
165 /// Search a given motifType in the map and returns it if it's there.
166 AliDebug(1,Form("Looking for motifType %s",id.Data()));
168 TObject* object = fMotifTypes.GetValue(id.Data());
172 AliMpMotifType* motifType = static_cast<AliMpMotifType*>(object);
173 AliDebug(1,Form("Found : %p id=%s",motifType,motifType->GetID().Data()));
176 AliDebug(1,"Not found");
181 //_____________________________________________________________________________
183 AliMpSlatMotifMap::Print(Option_t*) const
186 cout << "Motifs=" << endl;
188 TIter next(&fMotifs);
189 while ( ( key = next() ) )
191 AliMpVMotif* motif = dynamic_cast<AliMpVMotif*>(fMotifs.GetValue(key));
192 if (motif) cout << motif->GetID() << endl;
195 cout << "MotifTypes=" << endl;
196 TIter tnext(&fMotifTypes);
197 while ( ( key = tnext() ) )
199 AliMpMotifType* motifType = dynamic_cast<AliMpMotifType*>(fMotifTypes.GetValue(key));
200 if (motifType) cout << motifType->GetID() << endl;