diff --git a/Code/Mantid/Framework/UserAlgorithms/ModifyData.cpp b/Code/Mantid/Framework/UserAlgorithms/ModifyData.cpp index ae9ba1baf078..67e9b5f54edd 100644 --- a/Code/Mantid/Framework/UserAlgorithms/ModifyData.cpp +++ b/Code/Mantid/Framework/UserAlgorithms/ModifyData.cpp @@ -37,8 +37,8 @@ void ModifyData::init() */ void ModifyData::exec() { - // g_log is a reference to the logger. It is used to print out information, - // warning, and error messages + // g_log is a reference to the logger. It is used to print out information, + // warning, and error messages g_log.information() << "Running algorithm " << name() << " version " << version() << std::endl; // Get the input workspace @@ -47,61 +47,30 @@ void ModifyData::exec() // make output Workspace the same type and size as the input one MatrixWorkspace_sptr outputW = WorkspaceFactory::Instance().create(inputW); - bool useVectors = getProperty("UseVectors"); - - if ( useVectors ) + g_log.information() << "Option 1. Original values:" << std::endl; + // Get the count of histograms in the input workspace + size_t histogramCount = inputW->getNumberHistograms(); + // Loop over spectra + for (size_t i = 0; i < histogramCount; ++i) { - g_log.information() << "Option 1. Original values:" << std::endl; - // Get the count of histograms in the input workspace - size_t histogramCount = inputW->getNumberHistograms(); - // Loop over spectra - for (size_t i = 0; i < histogramCount; ++i) - { - // Retrieve the data into a vector - const MantidVec& XValues = inputW->readX(i); - const MantidVec& YValues = inputW->readY(i); - const MantidVec& EValues = inputW->readE(i); - MantidVec& newX = outputW->dataX(i); - MantidVec& newY = outputW->dataY(i); - MantidVec& newE = outputW->dataE(i); - - // Iterate over i-th spectrum and modify the data - for(size_t j=0; jblocksize(); j++) - { - g_log.information() << "Spectrum " << i << " Point " << j << " values: " - << XValues[j] << ' ' << YValues[j] << ' ' << EValues[j] << std::endl; - newX[j] = XValues[j] + static_cast(i + j); - newY[j] = YValues[j]*(2. + 0.1*static_cast(j)); - newE[j] = EValues[j]+0.1; - } - } + // Retrieve the data into a vector + MantidVec& newX = outputW->dataX(i); + MantidVec& newY = outputW->dataY(i); + MantidVec& newE = outputW->dataE(i); + const MantidVec& XValues = inputW->readX(i); + const MantidVec& YValues = inputW->readY(i); + const MantidVec& EValues = inputW->readE(i); + + // Iterate over i-th spectrum and modify the data + for(size_t j=0; jblocksize(); j++) + { + g_log.information() << "Spectrum " << i << " Point " << j << " values: " + << XValues[j] << ' ' << YValues[j] << ' ' << EValues[j] << std::endl; + newX[j] = XValues[j] + static_cast(i + j); + newY[j] = YValues[j]*(2. + 0.1*static_cast(j)); + newE[j] = EValues[j]+0.1; + } } - else - { - g_log.information() << "Option 2. Original values:" << std::endl; - // Iterate over the workspace and modify the data - int count = 0; - MatrixWorkspace::iterator ti_out(*outputW); - for(MatrixWorkspace::const_iterator ti(*inputW); ti != ti.end(); ++ti,++ti_out) - { - // get the spectrum number - size_t i = count / inputW->blocksize(); - // get the point number - size_t j = count % inputW->blocksize(); - // Get the reference to a data point - LocatedDataRef tr = *ti; - LocatedDataRef tr_out = *ti_out; - g_log.information() << "Spectrum " << i << " Point " << j << " values: " - << tr.X() << ' ' << tr.Y() << ' ' << tr.E() << std::endl; - tr_out.X() = tr.X() + count; - tr_out.Y() = tr.Y()*2; - tr_out.E() = tr.E()+0.1; - - count++; - } - - } - // Assign it to the output workspace property setProperty("OutputWorkspace",outputW); @@ -112,14 +81,20 @@ void ModifyData::exec() // Check the new workspace g_log.information() << "New values:" << std::endl; int count = 0; - for(MatrixWorkspace::const_iterator ti(*newW); ti != ti.end(); ++ti) + for(size_t i = 0; i < histogramCount; ++i) { + const MantidVec& XValues = outputW->readX(i); + const MantidVec& YValues = outputW->readY(i); + const MantidVec& EValues = outputW->readE(i); + + for(size_t j = 0; j < outputW->blocksize(); ++j) + { // Get the reference to a data point - LocatedDataRef tr = *ti; g_log.information() << "Point number " << count++ << " values: " - << tr.X() << ' ' << tr.Y() << ' ' << tr.E() << std::endl; + << XValues[j] << ' ' << YValues[j] << ' ' << EValues[j] << std::endl; + } } - + } } diff --git a/Code/Mantid/Framework/UserAlgorithms/WorkspaceAlgorithm.cpp b/Code/Mantid/Framework/UserAlgorithms/WorkspaceAlgorithm.cpp index 69deb90c3724..578e0933be9c 100644 --- a/Code/Mantid/Framework/UserAlgorithms/WorkspaceAlgorithm.cpp +++ b/Code/Mantid/Framework/UserAlgorithms/WorkspaceAlgorithm.cpp @@ -31,9 +31,9 @@ void WorkspaceAlgorithm::init() */ void WorkspaceAlgorithm::exec() { - // g_log is a reference to the logger. It is used to print out information, - // warning, and error messages - g_log.information() << "Running algorithm " << name() << " version " << version() << std::endl; + // g_log is a reference to the logger. It is used to print out information, + // warning, and error messages + g_log.information() << "Running algorithm " << name() << " version " << version() << std::endl; // Get the input workspace MatrixWorkspace_const_sptr workspace = getProperty("Workspace"); @@ -42,26 +42,19 @@ void WorkspaceAlgorithm::exec() g_log.information() << "Number of items = " << workspace->size() << std::endl; int count = 0; - // Iterate over the workspace - for(MatrixWorkspace::const_iterator ti(*workspace); ti != ti.end(); ++ti) + size_t histogramCount = workspace->getNumberHistograms(); + for(size_t i = 0; i < histogramCount; ++i) { - // Get the reference to a data point - LocatedDataRef tr = *ti; - g_log.information() << "Point number " << count++ << " values: " - << tr.X() << ' ' << tr.Y() << ' ' << tr.E() << std::endl; - } + const MantidVec& XValues = workspace->readX(i); + const MantidVec& YValues = workspace->readY(i); + const MantidVec& EValues = workspace->readE(i); - count = 0; - int loopCount = 2; - // Do several loops - for(MatrixWorkspace::const_iterator ti(*workspace,loopCount,LoopOrientation::Horizontal); ti != ti.end(); ++ti) - { - // Get the reference to a data point - LocatedDataRef tr = *ti; + for(size_t j = 0; j < workspace->blocksize(); ++j) + { g_log.information() << "Point number " << count++ << " values: " - << tr.X() << ' ' << tr.Y() << ' ' << tr.E() << std::endl; + << XValues[j] << ' ' << YValues[j] << ' ' << EValues[j] << std::endl; + } } - } }