X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=HLT%2FBASE%2FAliHLTIndexGrid.h;h=0fdda2067249c66d4e19a33b5f37d3a0ae62c6de;hb=91bf4f1de17e253a52c6b560e1ccc6a9e3a3569c;hp=ee0dd1d1c2c4e2ff42e095865db4ec9780b2ee5f;hpb=a7a49f77979492ee4077c303614f319022dc4fa2;p=u%2Fmrichter%2FAliRoot.git diff --git a/HLT/BASE/AliHLTIndexGrid.h b/HLT/BASE/AliHLTIndexGrid.h index ee0dd1d1c2c..0fdda206724 100644 --- a/HLT/BASE/AliHLTIndexGrid.h +++ b/HLT/BASE/AliHLTIndexGrid.h @@ -14,9 +14,10 @@ #include "AliHLTDataTypes.h" #include -#include #include #include +#include +#include template class AliHLTIndexGrid { @@ -84,26 +85,42 @@ class AliHLTIndexGrid { if (z<0) return 0; return (int)(z/fStepZ); } + int Index(int xindex, int yindex, int zindex) { + return xindex*fDimY*fDimZ + yindex*fDimZ + zindex; + } T GetLowerBoundX(int cell) const { - if (fDimX==0 || fDimY==0 ||fDimZ==0) return 0.; + if (fDimX==0 || fDimY==0 ||fDimZ==0) return (T)0; int index=cell/(fDimY*fDimZ); return index*fStepX; } + T GetCenterX(int cell) const { + if (fDimX==0 || fDimY==0 ||fDimZ==0) return (T)0; + return GetLowerBoundX(cell)+fStepX/2; + } T GetLowerBoundY(int cell) const { - if (fDimX==0 || fDimY==0 ||fDimZ==0) return 0.; + if (fDimX==0 || fDimY==0 ||fDimZ==0) return (T)0; int index=cell%(fDimY*fDimZ); index/=fDimZ; return index*fStepY; } + T GetCenterY(int cell) const { + if (fDimX==0 || fDimY==0 ||fDimZ==0) return (T)0; + return GetLowerBoundY(cell)+fStepY/2; + } T GetLowerBoundZ(int cell) const { - if (fDimX==0 || fDimY==0 ||fDimZ==0) return 0.; + if (fDimX==0 || fDimY==0 ||fDimZ==0) return (T)0; int index=cell%(fDimY*fDimZ); index%=fDimZ; return index*fStepZ; } + T GetCenterZ(int cell) const { + if (fDimX==0 || fDimY==0 ||fDimZ==0) return (T)0; + return GetLowerBoundZ(cell)+fStepZ/2; + } int GetCellIndex(T x, T y, T z) const { return GetXIndex(x)*fDimY*fDimZ + (y<0?0:GetYIndex(y))*fDimZ + (z<0?0:GetZIndex(z)); } - int GetNumberOfSpacePoints(int index, int endIndex) const { + int GetNumberOfSpacePoints(int index=0, int endIndex=-1) const { if (!fCells) return 0; + if (endIndex<0) endIndex=fCellDimension; int count=0; for (int cell=index; cell0) count+=fCells[cell].fCount; return count; @@ -144,34 +161,34 @@ class AliHLTIndexGrid { void Print(const char* /*option*/="") { // print info bool bPrintEmpty=false; - std::stringstream str; - str << "AliHLTIndexGrid: " << (fCells?fCellDimension:0) << " cells" << endl; - str << " x: " << fDimX << " [0," << fMaxX << "]" << endl; - str << " y: " << fDimY << " [0," << fMaxY << "]" << endl; - str << " z: " << fDimZ << " [0," << fMaxZ << "]" << endl; - str << " " << GetNumberOfSpacePoints(0, fCellDimension) << " point(s)" << endl; + ios::fmtflags coutflags=cout.flags(); // backup cout status flags + cout << "AliHLTIndexGrid: " << (fCells?fCellDimension:0) << " cells" << endl; + cout << " x: " << fDimX << " [0," << fMaxX << "]" << endl; + cout << " y: " << fDimY << " [0," << fMaxY << "]" << endl; + cout << " z: " << fDimZ << " [0," << fMaxZ << "]" << endl; + cout << " " << GetNumberOfSpacePoints(0, fCellDimension) << " point(s)" << endl; if (fCells) { for (int i=0; i0) { - str << " "; + cout << " "; for (iterator id=begin(GetLowerBoundX(i), GetLowerBoundY(i), GetLowerBoundZ(i)); id!=end(); id++) { - str << " 0x" << hex << setw(8) << setfill('0') << id.Data(); + cout << " 0x" << hex << setw(8) << setfill('0') << id.Data(); } - str << dec << endl; + cout << endl; } } } - cout << str; + cout.flags(coutflags); // restore the original flags } @@ -184,7 +201,7 @@ class AliHLTIndexGrid { iterator(const iterator& i) : fData(i.fData) {} iterator& operator=(const iterator& i) - { fData=i.fData; return *this;} + { if (this!=&i) {fData=i.fData;} return *this;} ~iterator() {fData=NULL;} bool operator==(const iterator& i) const {return (fData!=NULL) && (fData==i.fData);} @@ -201,6 +218,8 @@ class AliHLTIndexGrid { const ValueType& Data() const {return *fData;} ValueType& Data() {return *fData;} + ValueType operator*() {return *fData;} + protected: private: ValueType* fData; //! data @@ -227,19 +246,25 @@ class AliHLTIndexGrid { if (cell<0 || !fCells || cell>=fCellDimension) return fIterator; // get the index of the cell startIndex=fCells[cell].fStartIndex; - if (startIndex<0 || !fData || startIndex>=fDataDimension) return fIterator; + if (!fData || startIndex>=fDataDimension) return fIterator; // get the range end position int endCell=cell+1; if (x<0) endCell=fCellDimension; - else if (y<0) endCell=GetCellIndex(x+fStepX, -1., -1.); // all entries for fixed x - else if (z<0) endCell=GetCellIndex(x, y+fStepY, -1.); // all entries for fixed x and y + else if (y<0) endCell=GetCellIndex(x+fStepX, (T)-1, (T)-1); // all entries for fixed x + else if (z<0) endCell=GetCellIndex(x, y+fStepY, (T)-1); // all entries for fixed x and y if (endCell<=cell) { // cell index returned is never outside the array // so this is a special case where we get to the bounds of the array endCell=fCellDimension; } + // find the first cell with content in the range + for (; startIndex<0 && cell