52 lines
962 B
C++
52 lines
962 B
C++
//CaloGrid.hh
|
|
|
|
#include "CaloCell.hh"
|
|
|
|
#ifndef CALOGRID_HH
|
|
#define CALOGRID_HH
|
|
class CaloGrid
|
|
{
|
|
public:
|
|
CaloGrid( int nx, int ny ) {
|
|
init(nx, ny );
|
|
}
|
|
CaloGrid( const CaloGrid& other ) {
|
|
// Set everything using init to allocate memory
|
|
init(other.nx, other.ny ) ;
|
|
|
|
// Copy elements
|
|
// Because we make it a 1Dim array, we can simply run over all elements in one go
|
|
for (int i=0 ; i<nx*ny ; i++ ) {
|
|
cells[i] = other.cells[i] ;
|
|
}
|
|
}
|
|
~CaloGrid() {
|
|
delete[] cells;
|
|
}
|
|
|
|
CaloCell* cell(int x, int y);
|
|
const CaloCell* cell(int x, int y) const {
|
|
return const_cast<CaloCell*> (cell(x, y));
|
|
}
|
|
|
|
|
|
private:
|
|
int nx, ny ;
|
|
CaloCell* cells ;
|
|
|
|
void init( int in_nx, int in_ny ) {
|
|
nx = in_nx ;
|
|
ny = in_ny ;
|
|
|
|
// contigious cells
|
|
cells = new CaloCell[ nx*ny ];
|
|
|
|
// set Cell Ids
|
|
for ( int i = 0; i < nx ; i++ ) {
|
|
for ( int j = 0; j < ny ; j++ ) {
|
|
cells[i*ny +j].setId( i*ny+j );
|
|
}
|
|
}
|
|
}
|
|
} ;
|
|
#endif
|