]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON2DMap.cxx
Adding comments
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMap.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 // $Id$
17
18 #include "AliMUON2DMap.h"
19
20 #include "AliLog.h"
21 #include "AliMpExMap.h"
22
23 #include <cassert>
24
25 ClassImp(AliMUON2DMap)
26
27 //_____________________________________________________________________________
28 AliMUON2DMap::AliMUON2DMap() : AliMUONV2DStore(), fMap(new AliMpExMap(true))
29 {
30   //
31   // ctor.
32   //
33 }
34
35 //_____________________________________________________________________________
36 AliMUON2DMap::~AliMUON2DMap()
37 {
38   //
39   // dtor. we delete the map, which will delete the objects, as we're owner.
40   //
41   delete fMap;
42 }
43
44 //_____________________________________________________________________________
45 TObject* 
46 AliMUON2DMap::Get(Int_t i, Int_t j) const
47 {
48   //
49   // Return the value at position (i,j).
50   //
51   TObject* o = fMap->GetValue(i);
52   if ( o )
53   {
54     AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
55     if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
56     return m->GetValue(j);
57   }
58   return 0x0;
59 }
60
61 //_____________________________________________________________________________
62 void
63 AliMUON2DMap::Print(Option_t*) const
64 {
65   //
66   // Not implemented (yet?)
67   //
68 }
69
70 //_____________________________________________________________________________
71 Bool_t 
72 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
73 {
74   //
75   // Set the object at position (i,j).
76   // If replace==kTRUE, we don't care if there's an object there already,
77   // otherwise we might refuse to set if the (i,j) location is already
78   // filled (in which case we return kFALSE).
79   
80   TObject* o = fMap->GetValue(i);
81   if ( !o )
82   {
83     AliMpExMap* m = new AliMpExMap(true);
84     fMap->Add(i,m);
85     o = fMap->GetValue(i);
86     assert(m==o);
87   }
88   AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
89   if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
90   o = m->GetValue(j);
91   if ( !o || ( o && replace ) )
92   {
93     if ( IsOwner() ) 
94     {
95       delete o;
96     }
97     m->Add(j,object);
98   }
99   else if ( o && !replace )
100   {
101     AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));
102     return kFALSE;
103   }
104   return kTRUE;
105 }
106
107
108
109
110