AliRoot Core  3dc7879 (3dc7879)
AliMpSlatMotifMap.cxx
Go to the documentation of this file.
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 //-----------------------------------------------------------------------------
19 //
25 //-----------------------------------------------------------------------------
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 
40 using std::cout;
41 using std::endl;
43 ClassImp(AliMpSlatMotifMap)
45 
46 //_____________________________________________________________________________
48 : TObject(),
49 fMotifs(),
50 fMotifTypes()
51 {
53  fMotifs.SetOwner(kTRUE);
54  fMotifTypes.SetOwner(kTRUE);
55 }
56 
57 //_____________________________________________________________________________
59 {
61  Reset();
62 }
63 
64 //_____________________________________________________________________________
65 void
67 {
69  fMotifs.DeleteAll();
70  fMotifTypes.DeleteAll();
71 }
72 
73 //_____________________________________________________________________________
74 Bool_t
76 {
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 //_____________________________________________________________________________
99 Bool_t
101 {
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 //_____________________________________________________________________________
127 AliMpVMotif*
128 AliMpSlatMotifMap::FindMotif(const TString& id) const
129 {
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 //_____________________________________________________________________________
148 AliMpSlatMotifMap::FindMotifType(const TString& id) const
149 {
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 //_____________________________________________________________________________
167 void
168 AliMpSlatMotifMap::Print(Option_t*) const
169 {
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 }
Bool_t AddMotifType(AliMpMotifType *motifType, Bool_t warn=kTRUE)
TMap fMotifs
collection of motifs
#define AliWarning(message)
Definition: AliLog.h:541
A container to keep track of allocated motifs and motifTypes for slats (both St345 and trigger ones)...
TString GetID() const
Return the motif identifier.
Definition: AliMpVMotif.h:90
void Print(Option_t *opt="") const
AliMpVMotif * FindMotif(const TString &id) const
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
Abstract base class for a motif with its unique ID and the motif type.
Definition: AliMpVMotif.h:24
TString GetID() const
Return unique motif ID.
#define AliError(message)
Definition: AliLog.h:591
AliMpMotifType * FindMotifType(const TString &id) const
Bool_t AddMotif(AliMpVMotif *motif, Bool_t warn=kTRUE)
TMap fMotifTypes
collection of motifTypes
Class that defines the motif properties.