Commenting out the infamous speed eater = StdoutToAliDebug until a better solution...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSlatMotifMap.cxx
CommitLineData
dd4ea4ef 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
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**************************************************************************/
15
16///
17/// \class AliMpSlatMotifMap
18//
19/// Basically this class provide a garbage collection of AliMpMotif and
20/// AliMpMotifType objects.
21///
22///
23/// \author Laurent Aphecetche
24
25
26// $Id$
27
28#include "AliMpSlatMotifMap.h"
29
30#include "AliMpVMotif.h"
31#include "AliMpMotifType.h"
32#include "AliLog.h"
33#include "TList.h"
34#include "TObjString.h"
35#include "TString.h"
36#include "Riostream.h"
37
38ClassImp(AliMpSlatMotifMap)
39
40//_____________________________________________________________________________
41AliMpSlatMotifMap::AliMpSlatMotifMap()
42: TObject(),
43fMotifs(),
44fMotifTypes()
45{
46 /// ctor
47 fMotifs.SetOwner(kTRUE);
48 fMotifTypes.SetOwner(kTRUE);
49}
50
51//_____________________________________________________________________________
52AliMpSlatMotifMap::~AliMpSlatMotifMap()
53{
54 /// dtor
55 Reset();
56}
57
58//_____________________________________________________________________________
59void
60AliMpSlatMotifMap::Reset()
61{
62 /// Clear
63 fMotifs.DeleteAll();
64 fMotifTypes.DeleteAll();
65}
66
67//_____________________________________________________________________________
68Bool_t
69AliMpSlatMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
70{
71 /// Add a motif to the map
72 AliDebug(1,Form("Adding motif %s",motif->GetID().Data()));
73
74 AliMpVMotif* found = FindMotif(motif->GetID());
75 if (found) {
76 if (warn && found == motif)
77 {
78 AliWarning(Form("The motif %s is already in map",motif->GetID().Data()));
79 }
80 if (warn && found != motif)
81 {
82 AliError(Form("Another motif with the same ID=%s is already in map",
83 motif->GetID().Data()));
84 }
85 return false;
86 }
87
88 fMotifs.Add(new TObjString(motif->GetID()),motif);
89 return true;
90}
91
92//_____________________________________________________________________________
93Bool_t
94AliMpSlatMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
95{
96 /// Add a motif to the map
97
98 AliDebug(1,Form("Adding motifType %s",motifType->GetID().Data()));
99
100 AliMpMotifType* found = FindMotifType(motifType->GetID());
101 if (found) {
102 if (warn && found == motifType)
103 {
104 AliWarning(Form("The motifType %s is already in map",
105 motifType->GetID().Data()));
106 }
107 if (warn && found != motifType)
108 {
109 AliError(Form("Another motifType with the same ID=%s is already in map",
110 motifType->GetID().Data()));
111 }
112 return false;
113 }
114
115 fMotifTypes.Add(new TObjString(motifType->GetID()),motifType);
116 return true;
117
118}
119
120//_____________________________________________________________________________
121AliMpVMotif*
122AliMpSlatMotifMap::FindMotif(const TString& id) const
123{
124 /// Search a given motif in the map and returns it if it's there.
125
126 AliDebug(1,Form("Looking for motif %s",id.Data()));
127
128 TObject* object = fMotifs.GetValue(id.Data());
129
130 if (object)
131 {
132 AliMpVMotif* motif = static_cast<AliMpVMotif*>(object);
133 AliDebug(1,Form("Found : %p id=%s",motif,motif->GetID().Data()));
134 return motif;
135 }
136 AliDebug(1,"Not found");
137 return 0x0;
138}
139
140//_____________________________________________________________________________
141AliMpMotifType*
142AliMpSlatMotifMap::FindMotifType(const TString& id) const
143{
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()));
146
147 TObject* object = fMotifTypes.GetValue(id.Data());
148
149 if (object)
150 {
151 AliMpMotifType* motifType = static_cast<AliMpMotifType*>(object);
152 AliDebug(1,Form("Found : %p id=%s",motifType,motifType->GetID().Data()));
153 return motifType;
154 }
155 AliDebug(1,"Not found");
156 return 0x0;
157
158}
159
160//_____________________________________________________________________________
161void
162AliMpSlatMotifMap::Print(Option_t*) const
163{
164 /// printout
165 cout << "Motifs=" << endl;
166 TObject* key;
167 TIter next(&fMotifs);
168 while ( ( key = next() ) )
169 {
170 AliMpVMotif* motif = dynamic_cast<AliMpVMotif*>(fMotifs.GetValue(key));
171 if (motif) cout << motif->GetID() << endl;
172 }
173
174 cout << "MotifTypes=" << endl;
175 TIter tnext(&fMotifTypes);
176 while ( ( key = tnext() ) )
177 {
178 AliMpMotifType* motifType = dynamic_cast<AliMpMotifType*>(fMotifTypes.GetValue(key));
179 if (motifType) cout << motifType->GetID() << endl;
180 }
181
182}