]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUSensMap.cxx
Coverity fixes
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUSensMap.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 /* $Id: AliITSUSensMap.cxx 39464 2010-03-09 14:59:19Z masera $ */
16
17 //***********************************************************************
18 //
19 // It consist of a TClonesArray of 
20 // AliITSUSensMapItem objects
21 // This array can be accessed via 2 indexed
22 // it is used at digitization level by 
23 // all the 3 ITS subdetectors
24 //
25 //
26 // The items should be added to the map like this:
27 // map->RegisterItem( new(map->GetFree()) ItemConstructor(...) );
28 //
29 // The items must be sortable with the same sorting algorithm like 
30 // for AliITSUSensMap::IsSortable,IsEqual,Compare
31 //
32 // ***********************************************************************
33
34 #include "AliITSUSensMap.h"
35 #include "AliLog.h"
36 //______________________________________________________________________
37
38 ClassImp(AliITSUSensMap)
39 //______________________________________________________________________
40 AliITSUSensMap::AliITSUSensMap() 
41 :  fDim0(0)
42   ,fDim1(0)
43   ,fItems(0)
44   ,fBTree(0)
45 {
46   // Default constructor
47 }
48
49 //______________________________________________________________________
50 AliITSUSensMap::AliITSUSensMap(const char* className, UInt_t dim0,UInt_t dim1)
51   :fDim0(dim0)
52   ,fDim1(dim1)
53   ,fItems(new TClonesArray(className,100))
54   ,fBTree(new TBtree())
55 {
56   // Standard constructor
57 }
58
59 //______________________________________________________________________
60 AliITSUSensMap::~AliITSUSensMap() 
61 {
62   // Default destructor
63   delete fItems;
64   delete fBTree;
65 }
66
67
68 //______________________________________________________________________
69 AliITSUSensMap::AliITSUSensMap(const AliITSUSensMap &source)
70   :TObject(source)
71   ,fDim0(source.fDim0)
72   ,fDim1(source.fDim1)
73   ,fItems( source.fItems ? new TClonesArray(*source.fItems) : 0)
74   ,fBTree( 0 )
75 {
76   if (source.fBTree) {
77     fBTree = new TBtree();
78     if (fItems) {
79       for (int i=fItems->GetEntriesFast();i--;) {
80         TObject* obj = fItems->At(i);
81         if (obj && ! IsDisabled(obj)) continue;
82         RegisterItem(obj);
83       }
84     }
85   }
86 }
87
88 //______________________________________________________________________
89 AliITSUSensMap& AliITSUSensMap::operator=(const AliITSUSensMap &source)
90 {
91   // = operator
92   if (this!=&source) {
93     this->~AliITSUSensMap();
94     new(this) AliITSUSensMap(source);
95   }
96   return *this;
97 }
98
99 //______________________________________________________________________
100 void AliITSUSensMap::Clear(Option_t*) 
101 {
102   // clean everything
103   if (fItems) fItems->Clear();
104   if (fBTree) fBTree->Clear();
105 }
106
107 //______________________________________________________________________
108 void AliITSUSensMap::DeleteItem(UInt_t i,UInt_t j)
109 {
110   // Delete a particular AliITSUSensMapItems.
111   SetUniqueID( GetIndex(i,j) );
112   TObject* fnd = fBTree->FindObject(this);
113   if (!fnd) return;
114   Disable(fnd);
115   fBTree->Remove(fnd);
116 }
117
118 //______________________________________________________________________
119 void AliITSUSensMap::DeleteItem(TObject* obj)
120 {
121   // Delete a particular AliITSUSensMapItems.
122   TObject* fnd = fBTree->FindObject(obj);
123   if (!fnd) return;
124   Disable(fnd);
125   fBTree->Remove(fnd);
126 }
127
128 //______________________________________________________________________
129 void AliITSUSensMap::GetCell(UInt_t index,UInt_t &i,UInt_t &j) const 
130 {
131   // returns the i,j index numbers from the linearized index computed
132   // with GetIndex
133   if(index>=fDim0*fDim1){
134     Warning("GetCell","Index out of range 0<=index=%d<%d",index,fDim0*fDim1);
135     i=-1;j=-1;
136     return;
137   } // end if
138 #ifdef _ROWWISE_SORT_
139   i = index%fDim0;   // sorted in row, then in column
140   j = index/fDim0;
141 #else
142   i = index/fDim1;   // sorted in column, then in row
143   j = index%fDim1;
144 #endif  
145   //
146   return;
147 }