/** This method saves investigations to a table workspace * @param investigations :: a vector containing investigation data * @param outputws :: shared pointer to output workspace */ void CICatHelper::saveInvestigations( const std::vector<ns1__investigation *> &investigations, API::ITableWorkspace_sptr &outputws) { try { std::vector<ns1__investigation *>::const_iterator citr; for (citr = investigations.begin(); citr != investigations.end(); ++citr) { API::TableRow t = outputws->appendRow(); std::string id = std::to_string(*(*citr)->id); savetoTableWorkspace(&id, t); savetoTableWorkspace((*citr)->facility, t); savetoTableWorkspace((*citr)->title, t); savetoTableWorkspace((*citr)->instrument, t); savetoTableWorkspace((*citr)->invParamValue, t); std::string startDate = std::to_string(*(*citr)->invStartDate); savetoTableWorkspace(&startDate, t); std::string endDate = std::to_string(*(*citr)->invEndDate); savetoTableWorkspace(&endDate, t); std::string sessionID = m_session->getSessionId(); savetoTableWorkspace(&sessionID, t); } } catch (std::runtime_error &) { throw std::runtime_error( "Error when saving the ICat Search Results data to Workspace"); } }
void EnggDiffFittingModel::mergeTables( const API::ITableWorkspace_sptr tableToCopy, API::ITableWorkspace_sptr targetTable) const { for (size_t i = 0; i < tableToCopy->rowCount(); ++i) { API::TableRow rowToCopy = tableToCopy->getRow(i); API::TableRow newRow = targetTable->appendRow(); for (size_t j = 0; j < tableToCopy->columnCount(); ++j) { double valueToCopy; rowToCopy >> valueToCopy; newRow << valueToCopy; } } }
/** Read from the instrument file the dead wires and store the information in a TableWorkspace. If asked, the dead wires are removed from the data set. @param localWorkspace :: input raw data workspace, containing the information about the instrument @param outputws :: input dead wire liste workspace */ void PoldiRemoveDeadWires::runExcludWires3 ( DataObjects::Workspace2D_sptr &localWorkspace, API::ITableWorkspace_sptr &outputws ) { outputws->addColumn("int","DeadWires"); boost::shared_ptr<const Mantid::Geometry::IComponent> comp = localWorkspace->getInstrument()->getComponentByName("holder"); boost::shared_ptr<const Mantid::Geometry::ICompAssembly> bank = boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(comp); if (bank) { // Get a vector of children (recursively) std::vector<boost::shared_ptr<const Mantid::Geometry::IComponent> > children; bank->getChildren(children, true); std::vector<double> defaultDeadWires; int ewLine = 0; for (unsigned int it = 0; it < children.size(); ++it) { string wireName = children.at(it)->getName(); std::vector<boost::shared_ptr<const Mantid::Geometry::IComponent> > tyty = localWorkspace.get()->getInstrument().get()->getAllComponentsWithName(wireName); std::vector<double> tempWire = tyty[0]->getNumberParameter("excluded"); if(tempWire.size()>0) { int val = (int)tempWire[0]; g_log.debug() << "_poldi : dead wires :" << val << std::endl; defaultDeadWires.push_back(val); for(unsigned int j=0; j<m_channelsPerSpectrum; j++) { localWorkspace->maskBin(val-1,j,1); } ewLine++; TableRow t = outputws->appendRow(); t << val ; } } g_log.information() << "_poldi : dead wires set to 0 (nb:" << ewLine << ")" << std::endl; setProperty("nbExcludedWires",ewLine); } else { g_log.information() << "_poldi : no dead wire removed" << std::endl; } }
/** * Loops through the response vector and saves the datasets details to a table * workspace. * @param response :: A vector containing the results of the search query. * @param outputws :: Shared pointer to output workspace. */ void ICat4Catalog::saveDataSets(std::vector<xsd__anyType *> response, API::ITableWorkspace_sptr &outputws) { if (outputws->getColumnNames().empty()) { // Add rows headers to the output workspace. outputws->addColumn("long64", "ID"); outputws->addColumn("str", "Name"); outputws->addColumn("str", "Description"); outputws->addColumn("str", "Type"); outputws->addColumn("str", "Related investigation ID"); outputws->addColumn("size_t", "Number of datafiles"); } std::string emptyCell; for (auto &iter : response) { ns1__dataset *dataset = dynamic_cast<ns1__dataset *>(iter); if (dataset) { API::TableRow table = outputws->appendRow(); savetoTableWorkspace(dataset->id, table); savetoTableWorkspace(dataset->name, table); if (dataset->description) savetoTableWorkspace(dataset->description, table); else savetoTableWorkspace(&emptyCell, table); if (dataset->type) savetoTableWorkspace(dataset->type->name, table); else savetoTableWorkspace(&emptyCell, table); if (dataset->investigation) savetoTableWorkspace(dataset->investigation->name, table); else savetoTableWorkspace(&emptyCell, table); size_t datafileCount = dataset->datafiles.size(); savetoTableWorkspace(&datafileCount, table); } else { throw std::runtime_error("ICat4Catalog::saveDataSets expected a dataset. " "Please contact the Mantid development team."); } } }
/** This method loops through the response return_vector and saves the datasets details to a table workspace * @param response :: const reference to response object * @param outputws :: shred pointer to workspace * @returns shared pointer to table workspace which stores the data */ void CICatHelper::saveDataSets(const ns1__getInvestigationIncludesResponse& response,API::ITableWorkspace_sptr& outputws) { //create table workspace if (outputws->getColumnNames().empty()) { outputws->addColumn("str","Name");//File name outputws->addColumn("str","Status"); outputws->addColumn("str","Type"); outputws->addColumn("str","Description"); outputws->addColumn("long64","Sample Id"); } try { std::vector<ns1__dataset*> datasetVec; datasetVec.assign((response.return_)->datasetCollection.begin(),(response.return_)->datasetCollection.end()); std::vector<ns1__dataset*>::const_iterator dataset_citr; for(dataset_citr=datasetVec.begin();dataset_citr!=datasetVec.end();++dataset_citr) { API::TableRow t = outputws->appendRow(); // DataSet Name savetoTableWorkspace((*dataset_citr)->name,t); // DataSet Status savetoTableWorkspace((*dataset_citr)->datasetStatus,t); //DataSet Type savetoTableWorkspace((*dataset_citr)->datasetType,t); //DataSet Type savetoTableWorkspace((*dataset_citr)->description,t); //DataSet Type savetoTableWorkspace((*dataset_citr)->sampleId,t); } } catch(std::runtime_error& ) { throw; } //return outputws; }
/** * Saves result from "getDataFiles" to workspace. * @param response :: result response from the catalog. * @param outputws :: shared pointer to datasets */ void ICat4Catalog::saveDataFiles(std::vector<xsd__anyType *> response, API::ITableWorkspace_sptr &outputws) { if (outputws->getColumnNames().empty()) { // Add rows headers to the output workspace. outputws->addColumn("str", "Name"); outputws->addColumn("str", "Location"); outputws->addColumn("str", "Create Time"); outputws->addColumn("long64", "Id"); outputws->addColumn("long64", "File size(bytes)"); outputws->addColumn("str", "File size"); outputws->addColumn("str", "Description"); } std::vector<xsd__anyType *>::const_iterator iter; for (iter = response.begin(); iter != response.end(); ++iter) { ns1__datafile *datafile = dynamic_cast<ns1__datafile *>(*iter); if (datafile) { API::TableRow table = outputws->appendRow(); // Now add the relevant investigation data to the table. savetoTableWorkspace(datafile->name, table); savetoTableWorkspace(datafile->location, table); std::string createDate = formatDateTime(*datafile->createTime, "%Y-%m-%d %H:%M:%S"); savetoTableWorkspace(&createDate, table); savetoTableWorkspace(datafile->id, table); savetoTableWorkspace(datafile->fileSize, table); std::string fileSize = bytesToString(*datafile->fileSize); savetoTableWorkspace(&fileSize, table); if (datafile->description) savetoTableWorkspace(datafile->description, table); } else { throw std::runtime_error("ICat4Catalog::saveDataFiles expected a " "datafile. Please contact the Mantid " "development team."); } } }
/** Extracts detector asymmetries and phases from fitting results * and adds a new row to the results table with them * @param paramTab :: [input] Output parameter table resulting from the fit * @param resultsTab :: [input] Results table to update with a new row * @param spectrumNumber :: [input] Spectrum number */ void CalMuonDetectorPhases::extractDetectorInfo( const API::ITableWorkspace_sptr ¶mTab, const API::ITableWorkspace_sptr &resultsTab, const specnum_t spectrumNumber) { double asym = paramTab->Double(0, 1); double phase = paramTab->Double(2, 1); // If asym<0, take the absolute value and add \pi to phase // f(x) = A * sin( w * x + p) = -A * sin( w * x + p + PI) if (asym < 0) { asym = -asym; phase = phase + M_PI; } // Now convert phases to interval [0, 2PI) int factor = static_cast<int>(floor(phase / 2 / M_PI)); if (factor) { phase = phase - factor * 2 * M_PI; } // Copy parameters to new row in results table API::TableRow row = resultsTab->appendRow(); row << static_cast<int>(spectrumNumber) << asym << phase; }
/** Load PhaseTable file to a vector of HistData. * @param phaseTable :: [input] phase table containing detector info * @param deadTimeTable :: [output] phase table containing dead times */ void PhaseQuadMuon::loadPhaseTable(API::ITableWorkspace_sptr phaseTable, API::ITableWorkspace_sptr deadTimeTable) { if ( phaseTable->rowCount() ) { if ( phaseTable->columnCount()<4 ) { throw std::invalid_argument("PhaseQuad: PhaseTable must contain at least four columns"); } // Check number of histograms in inputWs match number of detectors in phase table if (m_nHist != static_cast<int>(phaseTable->rowCount())) { throw std::runtime_error("PhaseQuad: Number of histograms in phase table does not match number of spectra in workspace"); } for (size_t i=0; i<phaseTable->rowCount(); ++i) { API::TableRow phaseRow = phaseTable->getRow(i); // The first three columns go to m_histData HistData tempHist; tempHist.detOK = phaseRow.Bool(0); tempHist.alpha = phaseRow.Double(1); tempHist.phi = phaseRow.Double(2); m_histData.push_back(tempHist); // The last column goes to deadTimeTable API::TableRow deadRow = deadTimeTable->appendRow(); deadRow << static_cast<int>(i)+1 << phaseRow.Double(3); } } else { throw std::invalid_argument("PhaseQuad: PhaseTable is empty"); } }
/** Auto detecte the dead wires and store the information in the TableWorkspace. If asked, the dead wires are removed from the data set. @param localWorkspace :: input raw data workspace, containing the information about the instrument @param outputws :: input dead wire liste workspace */ void PoldiRemoveDeadWires::autoRemoveDeadWires ( DataObjects::Workspace2D_sptr &localWorkspace, API::ITableWorkspace_sptr &outputws ) { double autoDeadWiresThreshold = 0; autoDeadWiresThreshold = getProperty("BadWiresThreshold"); if(!autoDeadWiresThreshold) autoDeadWiresThreshold = m_defautDWThreshold; autoDeadWiresThreshold = 1.-autoDeadWiresThreshold; // double autoDeadWiresThreshold = 1-0.4; g_log.information() << "_poldi : auto removed wires : BadWiresThreshold:" << autoDeadWiresThreshold << std::endl; int count = 0; double minValue=INFINITY; unsigned int minPos = 0; bool checkContinue = true; std::vector<double> average(this->m_numberOfSpectra); double globalAverage = 0; //compute the average intensity per spectrum for(unsigned int i=0; i<this->m_numberOfSpectra; i++) { if(!localWorkspace.get()->hasMaskedBins(i)) { average.at(i) = 0; MantidVec& tempY = localWorkspace.get()->dataY(i); for(unsigned int j=0; j<this->m_channelsPerSpectrum; j++) { average.at(i) += tempY[j]; } average.at(i) /= static_cast<double>(this->m_channelsPerSpectrum); if(average[i]<minValue) { minValue = average[i]; minPos = i; } } } g_log.debug() << "_poldi : auto removed wires : average done" << std::endl; while(checkContinue) { checkContinue = false; minValue=INFINITY; minPos = 0; int n = 0; // find the minimum average position, the most probably wrong spectra for(unsigned int i=0; i<this->m_numberOfSpectra; i++) { if(!localWorkspace.get()->hasMaskedBins(i)) { globalAverage += average[i]; n++; if(average[i]<minValue) { minValue = average[i]; minPos = i; } } } globalAverage /=n; //applied the threshold to determine if a wires should be excluded //check if the wire is not already excluded if(!localWorkspace.get()->hasMaskedBins(minPos)) { if(average[minPos]<globalAverage*autoDeadWiresThreshold) { //mask the wires for(unsigned int j=0; j<this->m_channelsPerSpectrum; j++) { localWorkspace->maskBin(minPos,j,1); } count++; checkContinue = true; TableRow t = outputws->appendRow(); t << int(minPos) ; } } //applied the threshold to determine if a wires should be excluded //check if the wire is not already excluded if(!localWorkspace.get()->hasMaskedBins(minPos)) { //check the threshold on the left unsigned int left = minPos-1; //find the first used wires on the left while(localWorkspace.get()->hasMaskedBins(left) && left>0) { left--; } if(left>0 && average[minPos]<average[left]*autoDeadWiresThreshold) { //mask the wires for(unsigned int j=0; j<this->m_channelsPerSpectrum; j++) { localWorkspace->maskBin(minPos,j,1); } count++; checkContinue = true; TableRow t = outputws->appendRow(); t << int(minPos) ; } } if(!localWorkspace.get()->hasMaskedBins(minPos)) { //check the threshold on the right unsigned int right = minPos+1; //find the first used wires on the left while(localWorkspace.get()->hasMaskedBins(right) && right<this->m_numberOfSpectra) { right++; } if(right<m_numberOfSpectra-1 && average[minPos]<average[right]*autoDeadWiresThreshold) { //mask the wires for(unsigned int j=0; j<this->m_channelsPerSpectrum; j++) { localWorkspace->maskBin(minPos,j,1); } count++; checkContinue = true; TableRow t = outputws->appendRow(); t << int(minPos) ; } } } g_log.information() << "_poldi : auto removed wires (nb:" << count << ")" << std::endl; setProperty("nbAuteDeadWires",count); }
/** * This method loops through the response return_vector and saves the datafile * details to a table workspace * @param response :: const reference to response object * @param outputws :: shared pointer to table workspace which stores the data */ void CICatHelper::saveInvestigationIncludesResponse( const ns1__getInvestigationIncludesResponse &response, API::ITableWorkspace_sptr &outputws) { if (outputws->getColumnNames().empty()) { outputws->addColumn("str", "Name"); outputws->addColumn("str", "Location"); outputws->addColumn("str", "Create Time"); outputws->addColumn("long64", "Id"); outputws->addColumn("long64", "File size(bytes)"); outputws->addColumn("str", "File size"); outputws->addColumn("str", "Description"); } try { std::vector<ns1__dataset *> datasetVec; datasetVec.assign((response.return_)->datasetCollection.begin(), (response.return_)->datasetCollection.end()); if (datasetVec.empty()) { throw std::runtime_error("No data files exists in the ICAT database for " "the selected investigation"); } std::vector<ns1__dataset *>::const_iterator dataset_citr; for (dataset_citr = datasetVec.begin(); dataset_citr != datasetVec.end(); ++dataset_citr) { std::vector<ns1__datafile *> datafileVec; datafileVec.assign((*dataset_citr)->datafileCollection.begin(), (*dataset_citr)->datafileCollection.end()); if (datafileVec.empty()) { throw std::runtime_error("No data files exists in the ICAT database " "for the selected investigation "); } std::vector<ns1__datafile *>::const_iterator datafile_citr; for (datafile_citr = datafileVec.begin(); datafile_citr != datafileVec.end(); ++datafile_citr) { API::TableRow t = outputws->appendRow(); // File Name savetoTableWorkspace((*datafile_citr)->name, t); savetoTableWorkspace((*datafile_citr)->location, t); // File creation Time. std::string *creationtime = nullptr; if ((*datafile_citr)->datafileCreateTime != nullptr) { time_t crtime = *(*datafile_citr)->datafileCreateTime; char temp[25]; strftime(temp, 25, "%Y-%b-%d %H:%M:%S", localtime(&crtime)); std::string ftime(temp); creationtime = new std::string; creationtime->assign(ftime); } savetoTableWorkspace(creationtime, t); if (creationtime) delete creationtime; // savetoTableWorkspace((*datafile_citr)->id, t); LONG64 fileSize = boost::lexical_cast<LONG64>(*(*datafile_citr)->fileSize); savetoTableWorkspace(&fileSize, t); savetoTableWorkspace((*datafile_citr)->description, t); } } } catch (std::runtime_error &) { throw; } }
/** Load PhaseList file to a vector of HistData and a deadTimeTable. * @param filename :: [input] phase list .inf filename * @param deadTimeTable :: [output] table containing dead times */ void PhaseQuadMuon::loadPhaseList(const std::string& filename, API::ITableWorkspace_sptr deadTimeTable ) { std::ifstream input(filename.c_str(), std::ios_base::in); if (input.is_open()) { if ( input.eof() ) { throw Exception::FileError("PhaseQuad: File is empty.", filename); } else { std::string line; // Header of .INF file is as follows: // // Comment on the output file // Top row of numbers are: // #histos, typ. first good bin#, typ. bin# when pulse over, mean lag. // Tabulated numbers are, per histogram: // det ok, asymmetry, phase, lag, deadtime_c, deadtime_m. // std::getline( input, line ); // Skip first line in header std::getline( input, line ); // Skip second line std::getline( input, line ); // ... std::getline( input, line ); std::getline( input, line ); // Read first useful line int nHist; input >> nHist >> m_tValid >> m_tPulseOver >> m_meanLag; if (m_nHist!=nHist) { throw std::runtime_error("PhaseQuad: Number of histograms in phase list does not match number of spectra in workspace"); } // Read histogram data int cont=0; HistData tempData; double lag, dead, deadm; while( input >> tempData.detOK >> tempData.alpha >> tempData.phi >> lag >> dead >> deadm ) { m_histData.push_back (tempData); cont++; // Add dead time to deadTimeTable API::TableRow row = deadTimeTable->appendRow(); row << cont << dead; } if ( cont != m_nHist ) { if ( cont < m_nHist ) { throw Exception::FileError("PhaseQuad: Lines missing in phase list", filename); } else { throw Exception::FileError("PhaseQuad: Extra lines in phase list", filename); } } } } else { // Throw exception if file cannot be opened throw std::runtime_error("PhaseQuad: Unable to open PhaseList");
/** * Saves investigations to a table workspace. * @param response :: A vector containing the results of the search query. * @param outputws :: Shared pointer to output workspace. */ void ICat4Catalog::saveInvestigations(std::vector<xsd__anyType *> response, API::ITableWorkspace_sptr &outputws) { if (outputws->getColumnNames().empty()) { // Add rows headers to the output workspace. outputws->addColumn("long64", "DatabaseID"); outputws->addColumn("str", "InvestigationID"); outputws->addColumn("str", "Facility"); outputws->addColumn("str", "Title"); outputws->addColumn("str", "Instrument"); outputws->addColumn("str", "Run range"); outputws->addColumn("str", "Start date"); outputws->addColumn("str", "End date"); outputws->addColumn("str", "SessionID"); } // Add data to each row in the output workspace. std::vector<xsd__anyType *>::const_iterator iter; for (iter = response.begin(); iter != response.end(); ++iter) { // Cast from xsd__anyType to subclass (xsd__string). ns1__investigation *investigation = dynamic_cast<ns1__investigation *>(*iter); if (investigation) { API::TableRow table = outputws->appendRow(); // Used to insert an empty string into the cell if value does not exist. std::string emptyCell; // Now add the relevant investigation data to the table (They always // exist). savetoTableWorkspace(investigation->id, table); savetoTableWorkspace(investigation->name, table); savetoTableWorkspace(investigation->facility->name, table); savetoTableWorkspace(investigation->title, table); savetoTableWorkspace( investigation->investigationInstruments.at(0)->instrument->name, table); // Verify that the run parameters vector exist prior to doing anything. // Since some investigations may not have run parameters. if (!investigation->parameters.empty()) { savetoTableWorkspace(investigation->parameters[0]->stringValue, table); } else { savetoTableWorkspace(&emptyCell, table); } // Again, we need to check first if start and end date exist prior to // insertion. if (investigation->startDate) { std::string startDate = formatDateTime(*investigation->startDate, "%Y-%m-%d"); savetoTableWorkspace(&startDate, table); } else { savetoTableWorkspace(&emptyCell, table); } if (investigation->endDate) { std::string endDate = formatDateTime(*investigation->endDate, "%Y-%m-%d"); savetoTableWorkspace(&endDate, table); } else { savetoTableWorkspace(&emptyCell, table); } std::string sessionID = m_session->getSessionId(); savetoTableWorkspace(&sessionID, table); } else { throw std::runtime_error("ICat4Catalog::saveInvestigations expected an " "investigation. Please contact the Mantid " "development team."); } } }