From 371e3c78bf043d77eb032e8f64743d37bce07878 Mon Sep 17 00:00:00 2001 From: Alex Buts <alex.buts@stfc.ac.uk> Date: Tue, 18 Jan 2011 18:21:20 +0000 Subject: [PATCH] refs #1637 pixels locations moved into MDDataPoints --- .../MDAlgorithms/test/CPRebinKeepPixTest.h | 4 ++-- .../inc/MDDataObjects/MD_FileHoraceReader.h | 2 ++ .../inc/MDDataObjects/MD_File_hdfMatlab.h | 7 ++++++- .../MDDataObjects/src/MDDataPoints.cpp | 14 ++++++++++---- .../Framework/MDDataObjects/src/MDImage.cpp | 5 ----- .../MDDataObjects/src/MD_FileHoraceReader.cpp | 18 ++++++++++++------ .../MDDataObjects/src/MD_File_hdfMatlab.cpp | 12 +++++++++--- .../MDDataObjects/src/MD_File_hdfMatlab4D.cpp | 4 ++-- .../MDDataObjects/test/HoraceReaderTest.h | 5 ++--- .../Framework/MDDataObjects/test/MDImageTest.h | 8 ++++---- .../MDDataObjects/test/MDWorkspaceTest.h | 8 ++++---- 11 files changed, 53 insertions(+), 34 deletions(-) diff --git a/Code/Mantid/Framework/MDAlgorithms/test/CPRebinKeepPixTest.h b/Code/Mantid/Framework/MDAlgorithms/test/CPRebinKeepPixTest.h index 0fb3d9fc4ed..1a0277b4ac9 100644 --- a/Code/Mantid/Framework/MDAlgorithms/test/CPRebinKeepPixTest.h +++ b/Code/Mantid/Framework/MDAlgorithms/test/CPRebinKeepPixTest.h @@ -46,8 +46,8 @@ MDWorkspace_sptr load_fake_workspace(std::string &wsName){ IMD_FileFormat *pf = inputWS->get_pFileReader(); pf->read_MDImg_data(*inputWS->get_spMDImage()); - //TODO: should be moved into datapoints; - inputWS->get_spMDImage()->identify_SP_points_locations(); + + inputWS->get_spMDDPoints()->init_pix_locations(); return inputWS; diff --git a/Code/Mantid/Framework/MDDataObjects/inc/MDDataObjects/MD_FileHoraceReader.h b/Code/Mantid/Framework/MDDataObjects/inc/MDDataObjects/MD_FileHoraceReader.h index 75dadcbf35d..75cbec66e6c 100644 --- a/Code/Mantid/Framework/MDDataObjects/inc/MDDataObjects/MD_FileHoraceReader.h +++ b/Code/Mantid/Framework/MDDataObjects/inc/MDDataObjects/MD_FileHoraceReader.h @@ -127,6 +127,8 @@ private: void compact_hor_data(char *buffer,size_t &buf_size); // the size of data block for Horace reader; static const unsigned int hbs=9*4; + // the array specifying the locations of MD points wrt MD cells; + std::vector<uint64_t> hor_points_locations; // Function performing work previously in GOTO statement. void inline validateFileStreamHolder(std::ifstream& fileStreamHolder); diff --git a/Code/Mantid/Framework/MDDataObjects/inc/MDDataObjects/MD_File_hdfMatlab.h b/Code/Mantid/Framework/MDDataObjects/inc/MDDataObjects/MD_File_hdfMatlab.h index 2346cf7462b..399bde6e09d 100644 --- a/Code/Mantid/Framework/MDDataObjects/inc/MDDataObjects/MD_File_hdfMatlab.h +++ b/Code/Mantid/Framework/MDDataObjects/inc/MDDataObjects/MD_File_hdfMatlab.h @@ -134,7 +134,12 @@ protected: // function checks if pixel dataset is opened and if not opens it. true if it was already opened, false if did nothing bool check_or_open_pix_dataset(void); - + // the array specifying the locations of MD points wrt MD cells; + std::vector<uint64_t> mp_points_locations; +private: + + + }; // function used to understand Horace written Matlab dataset. diff --git a/Code/Mantid/Framework/MDDataObjects/src/MDDataPoints.cpp b/Code/Mantid/Framework/MDDataObjects/src/MDDataPoints.cpp index 54c35806b57..e95db38850a 100644 --- a/Code/Mantid/Framework/MDDataObjects/src/MDDataPoints.cpp +++ b/Code/Mantid/Framework/MDDataObjects/src/MDDataPoints.cpp @@ -20,7 +20,7 @@ void MDDataPoints::init_pix_locations() { // and calculate cells location for pixels; - const MD_image_point const* pData = this->spMDImage->get_const_pData(); + MD_image_point const * const pData = this->spMDImage->get_const_pData(); size_t nCells = this->spMDImage->getDataSize(); if(this->pix_location.size()!=nCells){ this->pix_location.resize(nCells); @@ -80,7 +80,11 @@ MDDataPoints::initialize(boost::shared_ptr<const MDImage> spImage,boost::shared_ } } //this->alloc_pix_array(); - this->n_data_points = this->spFileReader->getNPix(); + this->n_data_points = this->spFileReader->getNPix(); + + unsigned int nDims= this->spMDImage->getGeometry()->getNumDims(); + this->box_min.assign(nDims,FLT_MAX); + this->box_max.assign(nDims,-FLT_MAX); } // boost::shared_ptr<IMD_FileFormat> @@ -91,6 +95,10 @@ MDDataPoints::initialize(boost::shared_ptr<const MDImage> pImageData) } this->n_data_points =0; //this->alloc_pix_array(); + unsigned int nDims= this->spMDImage->getGeometry()->getNumDims(); + + this->box_min.assign(nDims,FLT_MAX); + this->box_max.assign(nDims,-FLT_MAX); return this->spFileReader; } @@ -127,8 +135,6 @@ MDDataPoints::alloc_pix_array(size_t buf_size) } unsigned int nDims = this->spMDImage->getGeometry()->getNumDims(); - this->box_min.assign(nDims,FLT_MAX); - this->box_max.assign(nDims,-FLT_MAX); // identify maximal number of pixels, possible to fit into buffer for current architecture; size_t nMemPix(0); diff --git a/Code/Mantid/Framework/MDDataObjects/src/MDImage.cpp b/Code/Mantid/Framework/MDDataObjects/src/MDImage.cpp index b2d19732730..7edfa8bc678 100644 --- a/Code/Mantid/Framework/MDDataObjects/src/MDImage.cpp +++ b/Code/Mantid/Framework/MDDataObjects/src/MDImage.cpp @@ -278,11 +278,6 @@ MDImage::~MDImage() this->clear_class(); } // -void -MDImage::identify_SP_points_locations() -{ - -} //*************************************************************************************** void diff --git a/Code/Mantid/Framework/MDDataObjects/src/MD_FileHoraceReader.cpp b/Code/Mantid/Framework/MDDataObjects/src/MD_FileHoraceReader.cpp index 715ac54cd56..e2f16acfd64 100644 --- a/Code/Mantid/Framework/MDDataObjects/src/MD_FileHoraceReader.cpp +++ b/Code/Mantid/Framework/MDDataObjects/src/MD_FileHoraceReader.cpp @@ -243,16 +243,22 @@ MD_FileHoraceReader::read_MDImg_data(MDImage & mdd) this->fileStreamHolder.seekg(this->positions.s_start,std::ios::beg); this->fileStreamHolder.read(&buff[0],nCells*8); + for(i=0;i<nCells;i++){ pImg_data[i].s = (double)*((float32*)(&buff[i*4])); pImg_data[i].err = (double)*((float32*)(&buff[(i+nCells)*4])); + } // read npixels this->fileStreamHolder.seekg(this->positions.n_cell_pix_start,std::ios::beg); this->fileStreamHolder.read(&buff[0],buff.size()); - for(i=0;i<nCells;i++){ - pImg_data[i].npix = (size_t)*((uint64_t*)(&buff[i*8])); + hor_points_locations.resize(nCells); + pImg_data[0].npix = (size_t)*((uint64_t*)(&buff[0*8])); + hor_points_locations[0] = 0; + for(i=1;i<nCells;i++){ + pImg_data[i].npix = (size_t)*((uint64_t*)(&buff[i*8])); + hor_points_locations[i] = hor_points_locations[i-1]+pImg_data[i-1].npix; } @@ -327,15 +333,15 @@ MD_FileHoraceReader::read_pix_subset(const MDImage &dnd,const std::vector<size_t while(true){ cell_index = selected_cells[ic]; - pixels_start = this->positions.pix_start+hbs*pImgData[cell_index].chunk_location; + pixels_start = this->positions.pix_start+hbs*hor_points_locations[cell_index]; // optimisaion possible when cells are adjacent block_size = hbs*pImgData[cell_index].npix; // if the next cell follows the current on HDD, we should read them together aggregating adjacent cells; - size_t next_block = pImgData[cell_index].chunk_location+pImgData[cell_index].npix; + uint64_t next_block = hor_points_locations[cell_index]+pImgData[cell_index].npix; size_t next_index = selected_cells[ic_next]; - while(pImgData[next_index].chunk_location==next_block){ + while(hor_points_locations[next_index]==next_block){ // block size grows and all other is auxiliary block_size += hbs*pImgData[next_index].npix; ic = ic_next; @@ -343,7 +349,7 @@ MD_FileHoraceReader::read_pix_subset(const MDImage &dnd,const std::vector<size_t if(ic_next > iCellRead)break; cell_index = selected_cells[ic]; - next_block = pImgData[cell_index].chunk_location+pImgData[cell_index].npix; + next_block = hor_points_locations[cell_index]+pImgData[cell_index].npix; next_index = selected_cells[ic_next]; } diff --git a/Code/Mantid/Framework/MDDataObjects/src/MD_File_hdfMatlab.cpp b/Code/Mantid/Framework/MDDataObjects/src/MD_File_hdfMatlab.cpp index ed821b601b9..14092c5d7ba 100644 --- a/Code/Mantid/Framework/MDDataObjects/src/MD_File_hdfMatlab.cpp +++ b/Code/Mantid/Framework/MDDataObjects/src/MD_File_hdfMatlab.cpp @@ -266,10 +266,16 @@ MD_File_hdfMatlab::read_MDImg_data(MDImage & dnd) } MD_image_point *pData = pMD_struct->data; // transform the data into the format specified -for(unsigned long i=0;i<pMD_struct->data_size;i++){ +mp_points_locations.resize(pMD_struct->data_size); +pData[0].s =buf[0]; +pData[0].err =buf[1]; +pData[0].npix=(size_t)buf[2]; +mp_points_locations[0] = 0; +for(unsigned long i=1;i<pMD_struct->data_size;i++){ pData[i].s =buf[i*3+0]; pData[i].err =buf[i*3+1]; pData[i].npix=(size_t)buf[i*3+2]; + mp_points_locations[i]=mp_points_locations[i-1]+pData[i-1].npix; } delete [] buf; H5Tclose(memtype); @@ -521,10 +527,10 @@ MD_File_hdfMatlab::read_pix_subset(const MDImage &DND,const std::vector<size_t> cells_preselection_buf.resize(max_npix_selected); size_t ic(0); uint64_t max_npix_indataset = this->getNPix(); - size_t pixel_num,block_location; + uint64_t pixel_num,block_location; for(i=starting_cell;i<=n_selected_cells;i++){ npix_tt =pData[selected_cells[i]].npix; - block_location =pData[selected_cells[i]].chunk_location; + block_location =mp_points_locations[selected_cells[i]]; for(j=0;j<npix_tt;j++){ pixel_num=block_location+j; // this to go around the bug in hdf dataset creation. diff --git a/Code/Mantid/Framework/MDDataObjects/src/MD_File_hdfMatlab4D.cpp b/Code/Mantid/Framework/MDDataObjects/src/MD_File_hdfMatlab4D.cpp index b4f7563b6d0..d0cb4692eb6 100644 --- a/Code/Mantid/Framework/MDDataObjects/src/MD_File_hdfMatlab4D.cpp +++ b/Code/Mantid/Framework/MDDataObjects/src/MD_File_hdfMatlab4D.cpp @@ -231,10 +231,10 @@ MD_File_hdfMatlab4D::read_pix_subset(const MDImage &SQW,const std::vector<size_t cells_preselection_buf.resize(max_npix_selected); size_t ic(0); hsize_t max_npix_indataset = this->getNPix(); - size_t pixel_num,block_location; + uint64_t pixel_num,block_location; for(i=starting_cell;i<=n_selected_cells;i++){ npix_tt =pData[selected_cells[i]].npix; - block_location =pData[selected_cells[i]].chunk_location; + block_location =mp_points_locations[selected_cells[i]]; for(j=0;j<npix_tt;j++){ pixel_num=block_location+j; // this to go around the bug in hdf dataset creation. diff --git a/Code/Mantid/Framework/MDDataObjects/test/HoraceReaderTest.h b/Code/Mantid/Framework/MDDataObjects/test/HoraceReaderTest.h index 9a4261924da..70279009a27 100644 --- a/Code/Mantid/Framework/MDDataObjects/test/HoraceReaderTest.h +++ b/Code/Mantid/Framework/MDDataObjects/test/HoraceReaderTest.h @@ -108,9 +108,8 @@ public: TSM_ASSERT_THROWS_NOTHING("MD image reader should not normaly throw", this->pReader->read_MDImg_data(*pImg)); - // temporary here and should move to constructor for MDDataPoints; - pImg->identify_SP_points_locations(); - // check what has been read; + + // check what has been read; } void testReadAllPixels(){ MDPointDescription defaultDescr; diff --git a/Code/Mantid/Framework/MDDataObjects/test/MDImageTest.h b/Code/Mantid/Framework/MDDataObjects/test/MDImageTest.h index c8a41e9f369..f1d4be5a450 100644 --- a/Code/Mantid/Framework/MDDataObjects/test/MDImageTest.h +++ b/Code/Mantid/Framework/MDDataObjects/test/MDImageTest.h @@ -59,10 +59,10 @@ private: static std::auto_ptr<MDGeometry> getMDGeometry() { std::set<MDBasisDimension> basisDimensions; - basisDimensions.insert(MDBasisDimension("q1", true, 1)); - basisDimensions.insert(MDBasisDimension("q2", true, 2)); - basisDimensions.insert(MDBasisDimension("q3", true, 3)); - basisDimensions.insert(MDBasisDimension("u1", false, 5)); + basisDimensions.insert(MDBasisDimension("q1", true, 0)); + basisDimensions.insert(MDBasisDimension("q2", true, 1)); + basisDimensions.insert(MDBasisDimension("q3", true, 2)); + basisDimensions.insert(MDBasisDimension("u1", false, 3)); UnitCell cell; return std::auto_ptr<MDGeometry>(new MDGeometry(MDGeometryBasis(basisDimensions, cell))); diff --git a/Code/Mantid/Framework/MDDataObjects/test/MDWorkspaceTest.h b/Code/Mantid/Framework/MDDataObjects/test/MDWorkspaceTest.h index fb26ad2ed5d..e7336e6f01c 100644 --- a/Code/Mantid/Framework/MDDataObjects/test/MDWorkspaceTest.h +++ b/Code/Mantid/Framework/MDDataObjects/test/MDWorkspaceTest.h @@ -48,10 +48,10 @@ private: { using namespace Mantid::Geometry; std::set<MDBasisDimension> basisDimensions; - basisDimensions.insert(MDBasisDimension("q1", true, 1)); - basisDimensions.insert(MDBasisDimension("q2", true, 2)); - basisDimensions.insert(MDBasisDimension("q3", true, 3)); - basisDimensions.insert(MDBasisDimension("u1", false, 4)); + basisDimensions.insert(MDBasisDimension("q1", true, 0)); + basisDimensions.insert(MDBasisDimension("q2", true, 1)); + basisDimensions.insert(MDBasisDimension("q3", true, 2)); + basisDimensions.insert(MDBasisDimension("u1", false, 3)); UnitCell cell; return new MDGeometry(MDGeometryBasis(basisDimensions, cell)); -- GitLab