/** Checks whether the two input workspaces have the same bin masking. * Prints a warning if not. * @param w1 :: The first (sample) input workspace * @param w2 :: The second (vanadium) input workspace * @param index :: The workspace index to check */ void PointByPointVCorrection::check_masks( const API::MatrixWorkspace_const_sptr &w1, const API::MatrixWorkspace_const_sptr &w2, const int &index) const { static bool warned = false; if (!warned) { const bool w1masked = w1->hasMaskedBins(index); const bool w2masked = w2->hasMaskedBins(index); if ((w1masked && w2masked && (w1->maskedBins(index) != w2->maskedBins(index))) || (w1masked && !w2masked) || (!w1masked && w2masked)) { g_log.warning("The input workspaces do not have matching bin masking"); warned = true; } } }
/** * Write bin masking information * @param ws :: The workspace * @return true for OK, false for error */ bool NexusFileIO::writeNexusBinMasking(API::MatrixWorkspace_const_sptr ws) const { std::vector< int > spectra; std::vector< std::size_t > bins; std::vector< double > weights; int spectra_count = 0; int offset = 0; for(std::size_t i=0;i<ws->getNumberHistograms(); ++i) { if (ws->hasMaskedBins(i)) { const API::MatrixWorkspace::MaskList& mList = ws->maskedBins(i); spectra.push_back(spectra_count); spectra.push_back(offset); API::MatrixWorkspace::MaskList::const_iterator it = mList.begin(); for(;it != mList.end(); ++it) { bins.push_back(it->first); weights.push_back(it->second); } ++spectra_count; offset += static_cast<int>(mList.size()); } } if (spectra_count == 0) return false; NXstatus status; // save spectra offsets as a 2d array of ints int dimensions[2]; dimensions[0]=spectra_count; dimensions[1]=2; status=NXmakedata(fileID, "masked_spectra", NX_INT32, 2, dimensions); if(status==NX_ERROR) return false; NXopendata(fileID, "masked_spectra"); const std::string description = "spectra index,offset in masked_bins and mask_weights"; NXputattr(fileID, "description", reinterpret_cast<void*>(const_cast<char*>(description.c_str())), static_cast<int>(description.size()+1), NX_CHAR); NXputdata(fileID, (void*)&spectra[0]); NXclosedata(fileID); // save masked bin indices dimensions[0]=static_cast<int>(bins.size()); status=NXmakedata(fileID, "masked_bins", NX_INT32, 1, dimensions); if(status==NX_ERROR) return false; NXopendata(fileID, "masked_bins"); NXputdata(fileID, (void*)&bins[0]); NXclosedata(fileID); // save masked bin weights dimensions[0]=static_cast<int>(bins.size()); status=NXmakedata(fileID, "mask_weights", NX_FLOAT64, 1, dimensions); if(status==NX_ERROR) return false; NXopendata(fileID, "mask_weights"); NXputdata(fileID, (void*)&weights[0]); NXclosedata(fileID); return true; }