1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUON2DMap.h"
21 #include "AliMUONVDataIterator.h"
22 #include "AliMUON2DMapIterator.h"
23 #include "AliMpExMap.h"
24 #include "AliMpIntPair.h"
25 #include "AliMpManuList.h"
26 #include "AliMpDEManager.h"
27 #include "AliMUONConstants.h"
30 /// \class AliMUON2DMap
31 /// \brief Basic implementation of AliMUONV2DStore container using
32 /// AliMpExMap internally.
33 /// What we store is a "double" map : an AliMpExMap of AliMpExMaps
35 /// \author Laurent Aphecetche
38 ClassImp(AliMUON2DMap)
41 //_____________________________________________________________________________
42 AliMUON2DMap::AliMUON2DMap(Bool_t optimizeForDEManu)
44 fMap(new AliMpExMap(true)),
45 fOptimizeForDEManu(optimizeForDEManu)
47 /// Default constructor.
48 if ( fOptimizeForDEManu )
51 for ( Int_t i = 0; i < AliMUONConstants::NTrackingCh(); ++i )
53 nDEs += AliMpDEManager::GetNofDEInChamber(i);
59 //_____________________________________________________________________________
60 AliMUON2DMap::AliMUON2DMap(const AliMUON2DMap& other)
63 fOptimizeForDEManu(kFALSE)
70 //_____________________________________________________________________________
72 AliMUON2DMap::operator=(const AliMUON2DMap& other)
74 /// Assignment operator
80 //_____________________________________________________________________________
81 AliMUON2DMap::~AliMUON2DMap()
84 /// We delete the map, which will delete the objects, as we're owner.
89 //_____________________________________________________________________________
91 AliMUON2DMap::CloneEmpty() const
93 /// Create a void copy of *this.
94 return new AliMUON2DMap(fOptimizeForDEManu);
97 //_____________________________________________________________________________
99 AliMUON2DMap::CopyTo(AliMUON2DMap& dest) const
101 /// Copy this into dest.
104 dest.fMap = new AliMpExMap(*fMap);
105 dest.fOptimizeForDEManu = fOptimizeForDEManu;
108 //_____________________________________________________________________________
110 AliMUON2DMap::Get(Int_t i, Int_t j) const
112 /// Return the value at position (i,j).
114 TObject* o = fMap->GetValue(i);
117 AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
118 if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
119 return m->GetValue(j);
124 //_____________________________________________________________________________
125 AliMUONVDataIterator*
126 AliMUON2DMap::Iterator() const
128 // Create and return an iterator on this map
129 // Returned iterator must be deleted by user.
132 return new AliMUON2DMapIterator(*fMap);
137 //_____________________________________________________________________________
139 AliMUON2DMap::Generate(const TObject& object)
141 /// Build a complete (i.e. all detElemId,manuId couple will be there) store
142 /// but with identical values, given by object
143 /// The returned store will be obviously optimized for DEManu.
145 AliMUONV2DStore* store = new AliMUON2DMap(true);
147 TList* list = AliMpManuList::ManuList();
153 while ( ( pair = static_cast<AliMpIntPair*>(next()) ) )
155 Int_t detElemId = pair->GetFirst();
156 Int_t manuId = pair->GetSecond();
157 store->Set(detElemId,manuId,object.Clone(),kFALSE);
165 //_____________________________________________________________________________
167 AliMUON2DMap::Set(Int_t i, Int_t j, TObject* object, Bool_t replace)
169 /// Set the object at position (i,j).
170 /// If replace==kTRUE, we don't care if there's an object there already,
171 /// otherwise we might refuse to set if the (i,j) location is already
172 /// filled (in which case we return kFALSE).
174 TObject* o = fMap->GetValue(i);
177 AliMpExMap* m = new AliMpExMap(true);
178 if ( fOptimizeForDEManu )
180 Int_t n(AliMpManuList::NumberOfManus(i));
183 AliError(Form("This does not look right : i = %d is supposed to "
184 "be a DetElemId with n = %d manus!",i,n));
192 o = fMap->GetValue(i);
194 AliMpExMap* m = dynamic_cast<AliMpExMap*>(o);
195 if (!m) AliFatal(Form("fMap[%d] not of the expected type",i));
197 if ( !o || ( o && replace ) )
205 else if ( o && !replace )
207 AliError(Form("Object %p is already there for (i,j)=(%d,%d)",o,i,j));