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