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