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