Line data Source code
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 : // $Id$
17 : // $MpId: AliMpMotifMap.cxx,v 1.16 2006/05/24 13:58:41 ivana Exp $
18 : // Category: motif
19 :
20 : //-----------------------------------------------------------------------------
21 : // Class AliMpMotifMap
22 : // -------------------
23 : // Class describing the motif map container, where motifs are
24 : // mapped to their string IDs.
25 : // Included in AliRoot: 2003/05/02
26 : // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 : //-----------------------------------------------------------------------------
28 :
29 : #include "AliMpMotifMap.h"
30 :
31 : #include "AliCodeTimer.h"
32 : #include "AliMpExMapIterator.h"
33 : #include "AliMpVMotif.h"
34 : #include "AliMpMotif.h"
35 : #include "AliMpMotifSpecial.h"
36 : #include "AliMpMotifType.h"
37 : #include "AliMpMotifPosition.h"
38 : #include "AliMpEncodePair.h"
39 :
40 : #include "AliLog.h"
41 :
42 : #include <Riostream.h>
43 : #include <TArrayI.h>
44 :
45 : using std::cout;
46 : using std::endl;
47 : using std::setw;
48 : using std::ofstream;
49 : using std::ios;
50 : using std::ifstream;
51 : /// \cond CLASSIMP
52 18 : ClassImp(AliMpMotifMap)
53 : /// \endcond
54 :
55 : //_____________________________________________________________________________
56 : AliMpMotifMap::AliMpMotifMap()
57 12 : : TObject(),
58 12 : fMotifs(),
59 12 : fMotifTypes(),
60 12 : fMotifPositions(),
61 12 : fMotifPositions2()
62 60 : {
63 : /// Standard constructor
64 :
65 12 : fMotifPositions2.SetOwner(false);
66 24 : }
67 :
68 : //_____________________________________________________________________________
69 : AliMpMotifMap::AliMpMotifMap(TRootIOCtor* ioCtor)
70 0 : : TObject(),
71 0 : fMotifs(ioCtor),
72 0 : fMotifTypes(ioCtor),
73 0 : fMotifPositions(ioCtor),
74 0 : fMotifPositions2(ioCtor)
75 0 : {
76 : /// Root IO constructor
77 :
78 0 : fMotifPositions2.SetOwner(false);
79 0 : }
80 :
81 : //_____________________________________________________________________________
82 : AliMpMotifMap::~AliMpMotifMap()
83 48 : {
84 : /// Destructor
85 :
86 : // Delete all registered motifs, motif types, motif positions
87 24 : }
88 :
89 : //
90 : // private methods
91 : //
92 :
93 : //_____________________________________________________________________________
94 : void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
95 : {
96 : /// Print the motif.
97 :
98 0 : cout << motif->GetID().Data() << " "
99 0 : << motif->GetMotifType()->GetID() << " "
100 0 : << motif->DimensionX() << " "
101 0 : << motif->DimensionY();
102 0 : }
103 :
104 : //_____________________________________________________________________________
105 : void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
106 : {
107 : /// Print the motif type.
108 :
109 0 : cout << motifType->GetID().Data() << " "
110 0 : << motifType->GetNofPadsX() << " "
111 0 : << motifType->GetNofPadsY() << " ";
112 0 : }
113 :
114 : //_____________________________________________________________________________
115 : void AliMpMotifMap::PrintMotifPosition(
116 : const AliMpMotifPosition* motifPosition) const
117 : {
118 : /// Print the motif position.
119 :
120 0 : cout << " ID " << motifPosition->GetID() << " "
121 0 : << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
122 0 : << " Pos (X,Y) = (" << motifPosition->GetPositionX() << ","
123 0 : << motifPosition->GetPositionY() << ")";
124 0 : }
125 :
126 : //_____________________________________________________________________________
127 : void AliMpMotifMap::PrintMotifPosition2(
128 : const AliMpMotifPosition* motifPosition) const
129 : {
130 : /// Print the motif position.
131 :
132 0 : cout << setw(3) << motifPosition->GetLowLimitIx() << " "
133 0 : << setw(3) << motifPosition->GetLowLimitIy() << " "
134 0 : << setw(3) << motifPosition->GetHighLimitIx() << " "
135 0 : << setw(3) << motifPosition->GetHighLimitIy() << " "
136 0 : << motifPosition->GetID() << " ";
137 0 : }
138 :
139 : //_____________________________________________________________________________
140 : void AliMpMotifMap::PrintMotifs() const
141 : {
142 : /// Print all the motifs and their motif types
143 : /// for all motifs in the motifs map.
144 :
145 0 : if (fMotifs.GetSize()) {
146 0 : cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
147 : Int_t counter = 0;
148 0 : AliMpExMapIterator* it = fMotifs.CreateIterator();
149 0 : Int_t key;
150 : AliMpVMotif* motif;
151 :
152 0 : while ( ( motif = static_cast<AliMpVMotif*>(it->Next(key)) ) )
153 : {
154 0 : TString id = fMotifs.AliMpExMap::GetString(key);
155 0 : cout << "Map element "
156 0 : << setw(3) << counter++ << " "
157 0 : << id.Data() << " " ;
158 0 : PrintMotif(motif);
159 0 : cout << endl;
160 0 : }
161 0 : cout << endl;
162 0 : delete it;
163 0 : }
164 0 : }
165 :
166 : //_____________________________________________________________________________
167 : void AliMpMotifMap::PrintMotifTypes() const
168 : {
169 : /// Print all the the motifs types and their motif dimensions
170 : /// for all motif types in the motif types map.
171 :
172 0 : if (fMotifTypes.GetSize()) {
173 0 : cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
174 : Int_t counter = 0;
175 0 : AliMpExMapIterator* it = fMotifTypes.CreateIterator();
176 0 : Int_t key;
177 : AliMpMotifType* motifType;
178 :
179 0 : while ( ( motifType = static_cast<AliMpMotifType*>(it->Next(key)) ) )
180 : {
181 0 : TString id = AliMpExMap::GetString(key);
182 0 : cout << "Map element "
183 0 : << setw(3) << counter++ << " "
184 0 : << id.Data() << " " ;
185 0 : PrintMotifType(motifType);
186 0 : cout << endl;
187 0 : }
188 0 : cout << endl;
189 0 : delete it;
190 0 : }
191 0 : }
192 :
193 : //_____________________________________________________________________________
194 : void
195 : AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
196 : {
197 : /// Fill the given array with all motif positions IDs (electronic card numbers)
198 : /// defined in the map
199 :
200 600 : ecn.Set(fMotifPositions.GetSize());
201 300 : TIter next(fMotifPositions.CreateIterator());
202 : AliMpMotifPosition* motifPosition;
203 : Int_t i(0);
204 202050 : while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
205 : {
206 134100 : ecn[i] = motifPosition->GetID();
207 67050 : ++i;
208 : }
209 300 : }
210 :
211 : //_____________________________________________________________________________
212 : UInt_t AliMpMotifMap::GetNofMotifPositions() const
213 : {
214 : /// Return the number of all motif positions IDs (electronic card numbers)
215 :
216 57344 : return fMotifPositions.GetSize();
217 : }
218 :
219 : //_____________________________________________________________________________
220 : AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
221 : {
222 : /// Return the motif position which is in the map on the index-th position
223 :
224 28608 : AliCodeTimerAuto("",0);
225 :
226 28608 : if ( index >= GetNofMotifPositions() ) {
227 0 : AliErrorStream() << "Index " << index << " outside limits." << endl;
228 0 : return 0;
229 : }
230 :
231 28608 : TIter next(fMotifPositions.CreateIterator());
232 3197216 : while (index-- > 0) next();
233 28608 : return static_cast<AliMpMotifPosition*>(next());
234 28608 : }
235 :
236 : //_____________________________________________________________________________
237 : Int_t AliMpMotifMap::CalculateNofPads() const
238 : {
239 : /// Calculate total number of pads in the map
240 :
241 : Int_t nofPads = 0;
242 :
243 24 : TIter next(fMotifPositions.CreateIterator());
244 : AliMpMotifPosition* motifPosition;
245 8082 : while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
246 : {
247 2682 : nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
248 : }
249 :
250 : return nofPads;
251 12 : }
252 :
253 : //_____________________________________________________________________________
254 : void AliMpMotifMap::PrintMotifPositions() const
255 : {
256 : /// Print all motif positions.
257 :
258 0 : if (fMotifPositions.GetSize()) {
259 0 : cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
260 : Int_t counter = 0;
261 0 : TIter next(fMotifPositions.CreateIterator());
262 : AliMpMotifPosition* motifPosition;
263 :
264 0 : while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
265 : {
266 0 : cout << "Map element "
267 0 : << setw(3) << counter++ << " ";
268 0 : PrintMotifPosition(motifPosition);
269 0 : cout << endl;
270 : }
271 0 : cout << endl;
272 0 : }
273 0 : }
274 :
275 : //_____________________________________________________________________________
276 : void AliMpMotifMap::PrintMotifPositions2() const
277 : {
278 : /// Print all motif positions from the second map
279 : /// (by global indices)
280 :
281 0 : if (fMotifPositions2.GetSize())
282 : {
283 0 : cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
284 0 : TIter next(fMotifPositions2.CreateIterator());
285 : AliMpMotifPosition* motifPosition(0x0);
286 : Int_t counter = 0;
287 :
288 0 : while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
289 : {
290 0 : cout << "Map element " << setw(3) << counter++ << " ";
291 0 : PrintMotifPosition2(motifPosition);
292 0 : cout << endl;
293 : }
294 0 : cout << endl;
295 0 : }
296 0 : }
297 :
298 : //
299 : // public methods
300 : //
301 :
302 : //_____________________________________________________________________________
303 : Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
304 : {
305 : /// Add the specified motif
306 : /// if the motif with this ID is not yet present.
307 :
308 744 : AliMpVMotif* found = FindMotif(motif->GetID());
309 372 : if (found) {
310 0 : if (warn && found == motif)
311 0 : AliWarningStream() << "The motif is already in map." << endl;
312 :
313 0 : if (warn && found != motif) {
314 0 : AliWarningStream()
315 0 : << "Another motif with the same ID is already in map." << endl;
316 0 : }
317 0 : return false;
318 : }
319 :
320 744 : fMotifs.Add(motif->GetID(), motif);
321 :
322 372 : return true;
323 372 : }
324 :
325 : //_____________________________________________________________________________
326 : Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
327 : {
328 : /// Add the specified motif type
329 : /// if the motif with this ID is not yet present.
330 :
331 636 : AliMpMotifType* found = FindMotifType(motifType->GetID());
332 318 : if (found) {
333 0 : if (warn && found == motifType)
334 0 : AliWarningStream() << "The motif type is already in map." << endl;
335 :
336 0 : if (warn && found != motifType) {
337 0 : AliWarningStream()
338 0 : << "Another motif type with the same ID is already in map." << endl;
339 0 : }
340 0 : return false;
341 : }
342 :
343 636 : fMotifTypes.Add(motifType->GetID(), motifType);
344 :
345 318 : return true;
346 318 : }
347 :
348 : //_____________________________________________________________________________
349 : Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
350 : {
351 : /// Add the specified motif position
352 : /// if this position is not yet present.
353 :
354 2712 : AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
355 2712 : if (found) {
356 30 : if (warn && found == motifPosition) {
357 0 : AliWarningStream()
358 0 : << "ID: " << motifPosition->GetID()
359 0 : << " found: " << found
360 0 : << " new: " << motifPosition << endl
361 0 : << "This motif position is already in map." << endl;
362 0 : }
363 :
364 30 : if (warn && found != motifPosition) {
365 0 : AliWarningStream()
366 0 : << "ID: " << motifPosition->GetID()
367 0 : << " found: " << found
368 0 : << " new: " << motifPosition << endl
369 0 : << "Another motif position with the same ID is already in map."
370 0 : << endl;
371 0 : }
372 :
373 30 : return false;
374 : }
375 :
376 2682 : fMotifPositions.Add(motifPosition->GetID() << 16, motifPosition);
377 :
378 2682 : return true;
379 2712 : }
380 :
381 : //_____________________________________________________________________________
382 : void AliMpMotifMap::FillMotifPositionMap2()
383 : {
384 : /// Fill the second map (by global indices) of motif positions.
385 :
386 0 : if (fMotifPositions2.GetSize() > 0 ) {
387 0 : AliWarningStream() <<"Map has been already filled." << endl;
388 0 : return;
389 : }
390 :
391 0 : TIter next(fMotifPositions.CreateIterator());
392 : AliMpMotifPosition* motifPosition(0x0);
393 0 : while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
394 : {
395 0 : fMotifPositions2.Add(motifPosition->GetLowLimitIx(),
396 0 : motifPosition->GetLowLimitIy(),
397 0 : motifPosition);
398 : }
399 0 : }
400 :
401 : //_____________________________________________________________________________
402 : void AliMpMotifMap::Print(const char* opt) const
403 : {
404 : /// Print the motifs and motif types maps.
405 :
406 0 : TString sopt(opt);
407 :
408 0 : sopt.ToUpper();
409 :
410 0 : if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
411 0 : if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
412 0 : if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
413 0 : if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
414 0 : }
415 :
416 : //_____________________________________________________________________________
417 : void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
418 : {
419 : /// Print all motif positions and their global indices.
420 :
421 0 : ofstream out(fileName, ios::out);
422 :
423 0 : if (fMotifPositions.GetSize()) {
424 0 : TIter next(fMotifPositions.CreateIterator());
425 : AliMpMotifPosition* motifPosition;
426 0 : while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
427 : {
428 0 : out << setw(5) << motifPosition->GetID() << " "
429 0 : << setw(3) << motifPosition->GetLowLimitIx() << " "
430 0 : << setw(3) << motifPosition->GetLowLimitIy()
431 0 : << endl;
432 : }
433 0 : out << endl;
434 0 : }
435 0 : }
436 :
437 : //_____________________________________________________________________________
438 : void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
439 : {
440 : /// Update the motif positions global indices from the file.
441 :
442 0 : ifstream in(fileName, ios::in);
443 :
444 0 : Int_t motifPositionId, offx, offy;
445 :
446 0 : do {
447 0 : in >> motifPositionId >> offx >> offy;
448 :
449 0 : if (in.eof()) {
450 0 : FillMotifPositionMap2();
451 0 : return;
452 : }
453 :
454 0 : AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
455 :
456 0 : if (motifPosition) {
457 0 : AliDebugStream(1)
458 0 : << "Processing "
459 0 : << motifPosition->GetID() << " " << offx << " " << offy << endl;
460 :
461 0 : motifPosition->SetLowIndicesLimit(offx, offy);
462 :
463 : Int_t offx2
464 0 : = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
465 :
466 : Int_t offy2
467 0 : = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
468 :
469 0 : motifPosition->SetHighIndicesLimit(offx2, offy2);
470 0 : }
471 : else {
472 0 : AliWarningStream()
473 0 : << "Motif position " << motifPositionId << " not found" << endl;
474 : }
475 0 : }
476 0 : while (!in.eof());
477 0 : }
478 :
479 :
480 : //_____________________________________________________________________________
481 : AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
482 : {
483 : /// Find the motif with the specified ID.
484 :
485 : //AliCodeTimerAuto("",0);
486 :
487 5826 : return (AliMpVMotif*)fMotifs.GetValue(motifID);
488 : }
489 :
490 : //_____________________________________________________________________________
491 : AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
492 : const TString& motifTypeID,
493 : Double_t padDimensionX,
494 : Double_t padDimensionY ) const
495 : {
496 : /// Find the motif with the specified ID and returns it
497 : /// only if its motif type and motif dimensions agree
498 : /// with the given motifTypeID and motifDimensions.
499 : /// Disagreement causes fatal error.
500 :
501 : //AliCodeTimerAuto("",0);
502 :
503 744 : AliMpVMotif* motif = FindMotif(motifID);
504 :
505 1116 : if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
506 0 : AliFatal("Motif has been already defined with a different type.");
507 0 : return 0;
508 : }
509 :
510 : // check pad dimension in case of a normal motif
511 372 : if ( motif &&
512 0 : dynamic_cast<AliMpMotif*>(motif) &&
513 0 : ( motif->GetPadDimensionX(0) != padDimensionX ||
514 0 : motif->GetPadDimensionY(0) != padDimensionY ) ) {
515 :
516 0 : AliFatal("Motif type has been already defined with different dimensions.");
517 0 : return 0;
518 :
519 : }
520 :
521 : // check case of a special motif
522 744 : if ( motif &&
523 744 : ( padDimensionX == 0. && padDimensionY == 0.) &&
524 0 : ! dynamic_cast<AliMpMotifSpecial*>(motif) ) {
525 :
526 0 : AliFatal("Motif type has been already defined with different dimensions.");
527 0 : return 0;
528 :
529 : }
530 :
531 372 : return motif;
532 372 : }
533 :
534 : //_____________________________________________________________________________
535 : AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
536 : {
537 : /// Find the motif type with the specified motif type ID.
538 :
539 : //AliCodeTimerAuto("",0);
540 :
541 1380 : return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
542 : }
543 :
544 : //_____________________________________________________________________________
545 : AliMpMotifPosition*
546 : AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
547 : {
548 : /// Find the motif position with the specified motif position ID.
549 :
550 : //AliCodeTimerAuto("",0);
551 :
552 767330 : return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID << 16);
553 : }
|