]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifMap.cxx
Improved warning messages in AddMotifPosition();
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifMap.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: motif
3//
4// Class AliMpMotifMap
5// -------------------
6// Class describing the motif map container, where motifs are
7// mapped to their string IDs.
8//
9// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
10
11#include <Riostream.h>
7a854749 12#include <TVector2.h>
5f91c9e8 13
14#include "AliMpMotifMap.h"
15#include "AliMpVMotif.h"
16#include "AliMpMotif.h"
17#include "AliMpMotifSpecial.h"
18#include "AliMpMotifType.h"
19#include "AliMpMotifPosition.h"
20
21ClassImp(AliMpMotifMap)
22
23//_____________________________________________________________________________
24AliMpMotifMap::AliMpMotifMap()
25 : TObject()
26{
27//
28}
29
30//_____________________________________________________________________________
31AliMpMotifMap::~AliMpMotifMap() {
32//
33
34 // Delete all registered motifs, motif types, motif positions
35
36 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
37 delete im->second;
38 }
39
40 for (MotifTypeMapIterator it=fMotifTypes.begin();
41 it != fMotifTypes.end(); it++) {
42 delete it->second;
43 }
44
45 for (MotifPositionMapIterator ip=fMotifPositions.begin();
46 ip != fMotifPositions.end(); ip++) {
47 delete ip->second;
48 }
49}
50
51//
52// private methods
53//
54
55//_____________________________________________________________________________
56void AliMpMotifMap::PrintMotifs() const
57{
58// Prints all the motifs and their motif types
59// for all motifs in the motifs map.
60// ---
61
62 if (fMotifs.size()) {
63 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
64 Int_t counter = 0;
65 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
66 const TString& id = (*i).first;
67 AliMpVMotif* motif = (*i).second;
68 cout << "Map element "
69 << setw(3) << counter++ << " "
70 << id.Data() << " "
71 << motif->GetID().Data() << " "
72 << motif->GetMotifType()->GetID() << " "
73 << motif->Dimensions().X() << " "
74 << motif->Dimensions().Y()
75 << endl;
76 }
77 cout << endl;
78 }
79}
80
81//_____________________________________________________________________________
82void AliMpMotifMap::PrintMotifTypes() const
83{
84// Prints all the the motifs types and their motif dimensions
85// for all motif types in the motif types map.
86// ---
87
88 if (fMotifTypes.size()) {
89 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
90 Int_t counter = 0;
91 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
92 const TString& id = (*i).first;
93 AliMpMotifType* motifType = (*i).second;
94 cout << "Map element "
95 << setw(3) << counter++ << " "
96 << id.Data() << " "
97 << motifType->GetID().Data() << " "
98 << motifType->GetNofPadsX() << " "
99 << motifType->GetNofPadsY() << " "
100 << endl;
101 }
102 cout << endl;
103 }
104}
105
106//_____________________________________________________________________________
107void AliMpMotifMap::PrintMotifPositions() const
108{
109// Prints all the the motifs positions.
110// ---
111
112 if (fMotifPositions.size()) {
113 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
114 Int_t counter = 0;
115 for (MotifPositionMapIterator i=fMotifPositions.begin();
116 i != fMotifPositions.end(); i++) {
117
118 AliMpMotifPosition* motifPosition = (*i).second;
119 cout << "Map element "
120 << setw(3) << counter++ << " "
121 << motifPosition->GetID() << " "
122 << motifPosition->GetMotif()->GetID() << " "
123 << motifPosition->Position().X() << " "
124 << motifPosition->Position().Y() << " "
125 << endl;
126 }
127 cout << endl;
128 }
129}
130
131//_____________________________________________________________________________
132void AliMpMotifMap::PrintMotifPositions2() const
133{
134// Prints all the the motifs positions from the second map
135// (by global indices)
136// ---
137
138 if (fMotifPositions2.size()) {
139 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
140 Int_t counter = 0;
141 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
142 i != fMotifPositions2.end(); i++) {
143
144 AliMpMotifPosition* motifPosition = (*i).second;
145 cout << "Map element "
146 << setw(3) << counter++ << " "
147 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
148 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
149 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
150 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
151 << motifPosition->GetID() << " "
152 << endl;
153 }
154 cout << endl;
155 }
156}
157
158//
159// public methods
160//
161
162//_____________________________________________________________________________
163Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
164{
165// Adds the specified motif
166// if the motif with this ID is not yet present.
167// ---
168
169 AliMpVMotif* found = FindMotif(motif->GetID());
170 if (found) {
171 if (warn && found == motif)
172 Warning("AddMotif", "The motif is already in map.");
173 if (warn && found != motif)
174 Warning("AddMotif", "Another motif with the same ID is already in map.");
175 return false;
176 }
177
178 fMotifs[motif->GetID()] = motif;
179 return true;
180}
181
182//_____________________________________________________________________________
183Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
184{
185// Adds the specified motif type
186// if the motif with this ID is not yet present.
187// ---
188
189 AliMpMotifType* found = FindMotifType(motifType->GetID());
190 if (found) {
191 if (warn && found == motifType)
192 Warning("AddMotifType", "The motif type is already in map.");
193 if (warn && found != motifType)
194 Warning("AddMotifType",
195 "Another motif type with the same ID is already in map.");
196 return false;
197 }
198
199 fMotifTypes[motifType->GetID()] = motifType;
200 return true;
201}
202
203//_____________________________________________________________________________
204Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
205{
206// Adds the specified motif position
207// if this position is not yet present.
208// ---
209
210 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
7a854749 211 if (found) {
212 if (warn && found == motifPosition) {
213 cerr << "ID: " << motifPosition->GetID()
214 << " found: " << found
215 << " new: " << motifPosition << endl;
5f91c9e8 216 Warning("AddMotifPosition", "This motif position is already in map.");
7a854749 217 }
218 if (warn && found != motifPosition) {
219 cerr << "ID: " << motifPosition->GetID()
220 << " found: " << found
221 << " new: " << motifPosition << endl;
5f91c9e8 222 Warning("AddMotifposition",
7a854749 223 "Another motif position with the same ID is already in map.");
224 }
5f91c9e8 225 return false;
226 }
227
228 fMotifPositions[motifPosition->GetID()] = motifPosition;
229 return true;
230}
231
232//_____________________________________________________________________________
233void AliMpMotifMap::FillMotifPositionMap2()
234{
235// Fills the second map (by global indices) of motif positions.
236// ---
237
238 if (fMotifPositions2.size() > 0 ) {
239 Warning("FillMotifPositionMap2", "Map has been already filled.");
240 return;
241 }
242
243 for (MotifPositionMapIterator ip=fMotifPositions.begin();
244 ip != fMotifPositions.end(); ip++) {
245
246 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
247 }
248
249}
250
251//_____________________________________________________________________________
7a854749 252void AliMpMotifMap::Print(const char* /*option*/) const
5f91c9e8 253{
254// Prints the motifs and motif types maps.
255// ---
256
257 PrintMotifs();
258 PrintMotifTypes();
259 PrintMotifPositions();
260 PrintMotifPositions2();
261}
262
263//_____________________________________________________________________________
264void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
265{
266// Prints all the motifs positions and their global indices.
267// ---
268
269 ofstream out(fileName, ios::out);
270
271 if (fMotifPositions.size()) {
272 for (MotifPositionMapIterator i=fMotifPositions.begin();
273 i != fMotifPositions.end(); i++) {
274
275 AliMpMotifPosition* motifPosition = (*i).second;
276 out << setw(5) << motifPosition->GetID() << " "
277 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
278 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
279 << endl;
280 }
281 out << endl;
282 }
283}
284
285//_____________________________________________________________________________
286void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
287{
288// Updates the motifs positions global indices
289// from the file.
290// ---
291
292 ifstream in(fileName, ios::in);
293
294 Int_t motifPositionId, offx, offy;
295
296 do {
297 in >> motifPositionId >> offx >> offy;
298
299 if (in.eof()) {
300 FillMotifPositionMap2();
301 return;
302 }
303
304 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
305
306 if (motifPosition) {
307 cout << "Processing "
308 << motifPosition->GetID() << " " << offx << " " << offy << endl;
309
310 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
311
312 Int_t offx2
313 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
314
315 Int_t offy2
316 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
317
318 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
319 }
320 else {
321 cerr <<"Motif position " << motifPositionId << endl;
322 Warning("UpdateGlobalIndices", "Motif position not found !!!");
323 }
324 }
325 while (!in.eof());
326}
327
328
329//_____________________________________________________________________________
330AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
331{
332// Finds the motif with the specified ID.
333// ---
334
335 MotifMapIterator i = fMotifs.find(motifID);
336
337 if (i != fMotifs.end())
338 return (*i).second;
339 else
340 return 0;
341}
342
343//_____________________________________________________________________________
344AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
7a854749 345 const TString& motifTypeID,
346 const TVector2& padDimensions ) const
5f91c9e8 347{
348// Finds the motif with the specified ID and returns it
349// only if its motif type and motif dimensions agree
350// with the given motifTypeID and motifDimensions.
351// Disagreement causes fatal error.
352// ---
353
354 AliMpVMotif* motif = FindMotif(motifID);
355
356 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
357 Fatal("FindMotif",
358 "Motif has been already defined with a different type.");
359 return 0;
360 }
361
362 // check pad dimension in case of a normal motif
363 if (motif &&
364 dynamic_cast<AliMpMotif*>(motif) &&
365 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
366 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
367
368 Fatal("FindMotifType",
369 "Motif type has been already defined with different dimensions.");
370 return 0;
371
372 }
373
374 // check case of a special motif
375 if (motif &&
376 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
377 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
378
379 Fatal("FindMotifType",
380 "Motif type has been already defined with different dimensions.");
381 return 0;
382
383 }
384
385 return motif;
386}
387
388//_____________________________________________________________________________
389AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
390{
391// Finds the motif type with the specified motif type ID.
392// ---
393
394 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
395
396 if (i != fMotifTypes.end())
397 return (*i).second;
398 else
399 return 0;
400}
401
402//_____________________________________________________________________________
7a854749 403AliMpMotifPosition*
404AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
5f91c9e8 405{
406// Finds the motif position with the specified motif position ID.
407// ---
408
409 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
410
411 if (i != fMotifPositions.end())
412 return (*i).second;
413 else
414 return 0;
415}
416
417//_____________________________________________________________________________
7a854749 418AliMpMotifPosition*
419AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
5f91c9e8 420{
421// Finds the last motif position which has the global indices (low limit)
422// less then the indices specified.
423// ---
424
425 MotifPositionMap2Iterator found
426 = fMotifPositions2.lower_bound(indices);
427
428 if (found == fMotifPositions2.end()) found--;
429
430 MotifPositionMap2Iterator i=found;
431 do {
432 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
433 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
434
435 if ( indices.GetFirst() >= low.GetFirst() &&
436 indices.GetSecond() >= low.GetSecond() &&
437 indices.GetFirst() <= up.GetFirst() &&
438 indices.GetSecond() <= up.GetSecond())
439
440 return (*i).second;
441 }
442 while ( i-- != fMotifPositions2.begin());
443
444 return 0;
445}