1 #ifndef ALIITSUSENSMAP_H
2 #define ALIITSUSENSMAP_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
6 //***********************************************************************
8 // It consist of a TClonesArray of objects
9 // and B-tree for fast sorted access
10 // This array can be accessed via 2 indexed
11 // it is used at digitization level by
12 // all the ITS subdetectors
14 // The items should be added to the map like this:
15 // map->RegisterItem( new(map->GetFree()) ItemConstructor(...) );
17 // ***********************************************************************
18 #include <TClonesArray.h>
20 #define _ROWWISE_SORT_
22 class AliITSUSensMap: public TObject
26 enum {kDisableBit=BIT(14)};
29 AliITSUSensMap(const char* className, UInt_t dimCol,UInt_t dimRow,UInt_t dimCycle=1);
30 virtual ~AliITSUSensMap();
31 AliITSUSensMap(const AliITSUSensMap &source);
32 AliITSUSensMap& operator=(const AliITSUSensMap &source);
33 void Clear(Option_t* option = "");
34 void DeleteItem(UInt_t col,UInt_t row, Int_t cycle);
35 void DeleteItem(TObject* obj);
37 void SetDimensions(UInt_t dimCol,UInt_t dimRow,UInt_t dimCycle=1);
38 void GetMaxIndex(UInt_t &col,UInt_t &row,UInt_t &cycle) const {col=fDimCol; row=fDimRow; cycle=fDimCycle;}
39 Int_t GetMaxIndex() const {return fDimCol*fDimRow*(fDimCycle*2+1);}
40 Int_t GetEntries() const {return fBTree->GetEntries();}
41 Int_t GetEntriesUnsorted() const {return fItems->GetEntriesFast();}
42 void GetMapIndex(UInt_t index,UInt_t &col,UInt_t &row,Int_t &cycle) const {return GetCell(index,fDimCol,fDimRow,fDimCycle,col,row,cycle);}
43 void GetCell(UInt_t index,UInt_t &col,UInt_t &row,Int_t &cycle) const {return GetCell(index,fDimCol,fDimRow,fDimCycle,col,row,cycle);}
44 TObject* GetItem(UInt_t col,UInt_t row,Int_t cycle) {SetUniqueID(GetIndex(col,row,cycle)); return fBTree->FindObject(this);}
45 TObject* GetItem(UInt_t index) {SetUniqueID(index); return fBTree->FindObject(this);}
46 TObject* GetItem(const TObject* obj) {return fBTree->FindObject(obj);}
47 TObject* At(Int_t i) const {return fBTree->At(i);} //!!! Access in sorted order !!!
48 TObject* AtUnsorted(Int_t i) const {return fItems->At(i);} //!!! Access in unsorted order !!!
49 TObject* RegisterItem(TObject* obj) {fBTree->Add(obj); return obj;}
50 TObject* GetFree() {return (*fItems)[fItems->GetEntriesFast()];}
52 UInt_t GetIndex(UInt_t col,UInt_t row,Int_t cycle=0) const;
54 TClonesArray* GetItems() const {return fItems;}
55 TBtree* GetItemsBTree() const {return fBTree;}
57 Bool_t IsSortable() const {return kTRUE;}
58 Bool_t IsEqual(const TObject* obj) const {return GetUniqueID()==obj->GetUniqueID();}
59 Int_t Compare(const TObject* obj) const {return (GetUniqueID()<obj->GetUniqueID()) ? -1 : ((GetUniqueID()>obj->GetUniqueID()) ? 1 : 0 );}
61 static Bool_t IsDisabled(TObject* obj) {return obj ? obj->TestBit(kDisableBit) : kFALSE;}
62 static void Disable(TObject* obj) {if (obj) obj->SetBit(kDisableBit);}
63 static void Enable(TObject* obj) {if (obj) obj->ResetBit(kDisableBit);}
64 static void GetCell(UInt_t index,UInt_t dcol,UInt_t drow,UInt_t dcycle,UInt_t &col,UInt_t &row,Int_t &cycle);
68 UInt_t fDimCol; // 1st dimension of the matrix, col index may span from 0 to fDimCol
69 UInt_t fDimRow; // 2nd dimention of the matrix, row index may span from 0 to fDimRow
70 UInt_t fDimCycle; // readout cycle range, may span from -fDimCycle to fDimCycle
71 TClonesArray* fItems; // pListItems array
72 TBtree* fBTree; // tree for ordered access
74 ClassDef(AliITSUSensMap,1) // list of sensor signals (should be sortable objects)
77 //______________________________________________________________________
78 inline UInt_t AliITSUSensMap::GetIndex(UInt_t col,UInt_t row, Int_t cycle) const
80 // linearized ID of digit
81 UInt_t cyclePos = cycle+fDimCycle; // cycle may span from -fDimCycle to fDimCycle
83 return fDimCol*(cyclePos*fDimRow+row)+col; // sorted in row, then in column
85 return fDimRow*(cyclePos*fDimCol+col)+row; // sorted in column, then in row
89 //______________________________________________________________________
90 inline void AliITSUSensMap::GetCell(UInt_t index,UInt_t dcol,UInt_t drow,UInt_t dcycle,UInt_t &col,UInt_t &row,Int_t &cycle)
92 // returns the i,j index numbers from the linearized index computed with GetIndex
93 UInt_t dcr = dcol*drow;
94 cycle = int(index/dcr) - dcycle;
97 col = index%dcol; // sorted in row, then in column
100 col = index/drow; // sorted in column, then in row