diff --git a/Code/Mantid/API/inc/MantidAPI/Algorithm.h b/Code/Mantid/API/inc/MantidAPI/Algorithm.h index 5a9652ddfca775c8652dac1ee9682f10fcfb2394..8c159d20598f8126ac6df9ce465da915e5ea0d43 100644 --- a/Code/Mantid/API/inc/MantidAPI/Algorithm.h +++ b/Code/Mantid/API/inc/MantidAPI/Algorithm.h @@ -122,9 +122,10 @@ public: class ProgressNotification: public AlgorithmNotification { public: - ProgressNotification(Algorithm* alg, double p):AlgorithmNotification(alg),progress(p){}///< Constructor + ProgressNotification(Algorithm* alg, double p,const std::string& msg):AlgorithmNotification(alg),progress(p),message(msg){}///< Constructor virtual std::string name() const{return "ProgressNotification";}///< class name double progress;///< Current progress. Value must be between 0 and 1. + std::string message;///< Message sent with notification }; /// ErrorNotification is sent when an exception is caught during execution of the algorithm. @@ -220,7 +221,7 @@ protected: using Kernel::PropertyManager::declareProperty; /// Sends ProgressNotification. p must be between 0 (just started) and 1 (finished) - void progress(double p); + void progress(double p, const std::string& msg = ""); /// Interrupts algorithm execution if Algorithm::cancel() has been called. /// Does nothing otherwise. void interruption_point(); diff --git a/Code/Mantid/API/src/Algorithm.cpp b/Code/Mantid/API/src/Algorithm.cpp index 11283880aab544ee7aefecf4603b7b5784b44fe0..1b6f55c06519676945c2ae3bb8586ea1123dcd61 100644 --- a/Code/Mantid/API/src/Algorithm.cpp +++ b/Code/Mantid/API/src/Algorithm.cpp @@ -302,9 +302,9 @@ void Algorithm::setExecuted(bool state) m_isExecuted = state; } -void Algorithm::progress(double p) +void Algorithm::progress(double p, const std::string& msg ) { - notificationCenter.postNotification(new ProgressNotification(this,p)); + notificationCenter.postNotification(new ProgressNotification(this,p,msg)); } void Algorithm::interruption_point() diff --git a/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadRaw2.h b/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadRaw2.h index 082e23c9332626f9402bd12df28a929569ef71c1..710e22f0979fcda203ff0a910f395759fe9f7c57 100644 --- a/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadRaw2.h +++ b/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadRaw2.h @@ -106,6 +106,8 @@ namespace Mantid int m_spec_min; /// The value of the spectrum_max property int m_spec_max; + /// Allowed values for the cache property + std::vector<std::string> m_cache_options; ///static reference to the logger class static Kernel::Logger& g_log; diff --git a/Code/Mantid/DataHandling/inc/MantidDataHandling/ManagedRawFileWorkspace2D.h b/Code/Mantid/DataHandling/inc/MantidDataHandling/ManagedRawFileWorkspace2D.h index 6677aa04bb7540a7ad26267295fbfcc60a2b052f..d91294a320bfa0e623dc75d0cf2c90d9539c956f 100644 --- a/Code/Mantid/DataHandling/inc/MantidDataHandling/ManagedRawFileWorkspace2D.h +++ b/Code/Mantid/DataHandling/inc/MantidDataHandling/ManagedRawFileWorkspace2D.h @@ -65,7 +65,7 @@ public: virtual ~ManagedRawFileWorkspace2D(); /// Sets the RAW file for this workspace. - void setRawFile(const std::string& fileName); + void setRawFile(const std::string& fileName,int opt=0); protected: /// Reads in a data block. @@ -78,6 +78,10 @@ private: /// Private copy assignment operator. NO ASSIGNMENT ALLOWED ManagedRawFileWorkspace2D& operator=(const ManagedRawFileWorkspace2D&); + bool needCache(int opt); + void openTempFile(); + void removeTempFile()const; + ISISRAW2 *isisRaw; std::string m_filenameRaw;//< RAW file name. FILE* m_fileRaw; //< RAW file pointer. @@ -89,6 +93,8 @@ private: The block's index = startIndex / m_vectorsPerBlock. */ std::vector<bool> m_changedBlock; + static int g_uniqueID; + std::string m_tempfile; int m_numberOfTimeChannels; //< The number of time channels (i.e. bins) from the RAW file int m_numberOfBinBoundaries; //< The number of time bin boundaries == m_numberOfTimeChannels + 1 diff --git a/Code/Mantid/DataHandling/src/LoadRaw2.cpp b/Code/Mantid/DataHandling/src/LoadRaw2.cpp index 8188a1c1ce7b0020104ba16e85343c8d7feacc28..2435d5276958b2e0e80d260a5947967eb03c9283 100644 --- a/Code/Mantid/DataHandling/src/LoadRaw2.cpp +++ b/Code/Mantid/DataHandling/src/LoadRaw2.cpp @@ -56,6 +56,11 @@ namespace Mantid declareProperty("spectrum_max",0, mustBePositive->clone()); declareProperty(new ArrayProperty<int>("spectrum_list")); + m_cache_options.push_back("If slow"); + m_cache_options.push_back("Always"); + m_cache_options.push_back("Never"); + declareProperty("Cache","If slow",new ListValidator(m_cache_options)); + } /** Executes the algorithm. Reading in the file and creating and populating @@ -92,7 +97,10 @@ namespace Mantid { ManagedRawFileWorkspace2D *localWorkspace_ptr = new ManagedRawFileWorkspace2D; DataObjects::Workspace2D_sptr localWorkspace( dynamic_cast<DataObjects::Workspace2D*>(localWorkspace_ptr) ); - localWorkspace_ptr->setRawFile(m_filename); + const std::string cache_option = getPropertyValue("Cache"); + int option = find(m_cache_options.begin(),m_cache_options.end(),cache_option) - m_cache_options.begin(); + progress(0.,"Reading raw file..."); + localWorkspace_ptr->setRawFile(m_filename,option); runLoadInstrument(localWorkspace ); runLoadMappingTable(localWorkspace ); runLoadLog(localWorkspace ); diff --git a/Code/Mantid/DataHandling/src/ManagedRawFileWorkspace2D.cpp b/Code/Mantid/DataHandling/src/ManagedRawFileWorkspace2D.cpp index a0dd1be26a2542d938da625246abe83a44f67ffb..3a60418e3bb5c3a4bcd531d0b70d0e174d2d2951 100644 --- a/Code/Mantid/DataHandling/src/ManagedRawFileWorkspace2D.cpp +++ b/Code/Mantid/DataHandling/src/ManagedRawFileWorkspace2D.cpp @@ -7,8 +7,11 @@ #include "MantidAPI/WorkspaceProperty.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidKernel/UnitFactory.h" +#include "MantidKernel/ConfigService.h" #include "LoadRaw/isisraw2.h" +#include <boost/timer.hpp> +#include <boost/filesystem.hpp> //DECLARE_WORKSPACE(ManagedRawFileWorkspace2D) @@ -20,6 +23,9 @@ namespace Mantid // Get a reference to the logger Kernel::Logger& ManagedRawFileWorkspace2D::g_log = Kernel::Logger::get("ManagedRawFileWorkspace2D"); + // Initialise the instance count + int ManagedRawFileWorkspace2D::g_uniqueID = 1; + /// Constructor ManagedRawFileWorkspace2D::ManagedRawFileWorkspace2D(): isisRaw(new ISISRAW2),m_fileRaw(NULL),m_readIndex(0) @@ -31,21 +37,30 @@ namespace Mantid { delete isisRaw; if (m_fileRaw) fclose(m_fileRaw); + removeTempFile(); } /** Sets the RAW file for this workspace. \param fileName The path to the RAW file. + \param opt Caching option. 0 - cache on local drive if raw file is very slow to read. + 1 - cache anyway, 2 - never cache. */ - void ManagedRawFileWorkspace2D::setRawFile(const std::string& fileName) + void ManagedRawFileWorkspace2D::setRawFile(const std::string& fileName,int opt) { m_filenameRaw = fileName; - FILE *fileRaw = fopen(m_filenameRaw.c_str(),"rb"); - if (fileRaw == NULL) + m_fileRaw = fopen(m_filenameRaw.c_str(),"rb"); + if (m_fileRaw == NULL) { g_log.error("Unable to open file " + m_filenameRaw); throw Kernel::Exception::FileError("Unable to open File:" , m_filenameRaw); } - isisRaw->ioRAW(fileRaw, true); + + if ( needCache(opt) ) + { + openTempFile(); + } + + isisRaw->ioRAW(m_fileRaw, true); m_numberOfBinBoundaries = isisRaw->t_ntc1 + 1; m_numberOfPeriods = isisRaw->t_nper; @@ -57,10 +72,9 @@ namespace Mantid float* timeChannels = new float[m_numberOfBinBoundaries]; isisRaw->getTimeChannels(timeChannels, m_numberOfBinBoundaries); isisRaw->skipData(0); - fgetpos(fileRaw, &m_data_pos); //< Save the data start position. + fgetpos(m_fileRaw, &m_data_pos); //< Save the data start position. m_timeChannels.reset(new std::vector<double>(timeChannels, timeChannels + m_numberOfBinBoundaries)); - m_fileRaw = fileRaw; getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("TOF"); } @@ -107,6 +121,8 @@ namespace Mantid } if (fseek(m_fileRaw,-nwords,SEEK_CUR) != 0) { + fclose(m_fileRaw); + removeTempFile(); g_log.error("Error reading RAW file."); throw std::runtime_error("ManagedRawFileWorkspace2D: Error reading RAW file."); } @@ -131,7 +147,67 @@ namespace Mantid ManagedWorkspace2D::writeDataBlock(toWrite); int blockIndex = toWrite->minIndex() / m_vectorsPerBlock; m_changedBlock[blockIndex] = toWrite->hasChanges(); - //std::cerr<<"Writing! "<<toWrite->minIndex()<<' '<<toWrite->hasChanges()<<'\n'; + } + + /** + Decides if the raw file must be copied to a cache file on the local drive to improve reading time. + */ + bool ManagedRawFileWorkspace2D::needCache(int opt) + { + if (opt == 1) return true; + if (opt == 2) return false; + + FILE * ff = fopen(m_filenameRaw.c_str(),"rb"); + if (ff) + { + size_t n = 100000; + char *buf = new char[n]; + boost::timer tim; + size_t i = fread(buf,sizeof(char),n,ff); + double elapsed = tim.elapsed(); + fclose(ff); + delete[] buf; + if (i > 0) + { + return elapsed > 0.01; + } + } + return false; + } + + void ManagedRawFileWorkspace2D::openTempFile() + { + // Look for the (optional) path from the configuration file + std::string path = Kernel::ConfigService::Instance().getString("ManagedWorkspace.FilePath"); + if ( !path.empty() ) + { + if ( ( *(path.rbegin()) != '/' ) && ( *(path.rbegin()) != '\\' ) ) + { + path.push_back('/'); + } + } + + boost::filesystem::path source(m_filenameRaw); + std::stringstream filename; + filename << "WS2D_" <<boost::filesystem::basename(source)<<'_'<< ManagedRawFileWorkspace2D::g_uniqueID<<".raw"; + // Increment the instance count + ++ManagedRawFileWorkspace2D::g_uniqueID; + m_tempfile = path + filename.str(); + boost::filesystem::path dest(m_tempfile); + boost::filesystem::copy_file(source,dest); + + FILE *fileRaw = fopen(m_tempfile.c_str(),"rb"); + if (fileRaw) + { + fclose(m_fileRaw); + m_fileRaw = fileRaw; + } + + } + + void ManagedRawFileWorkspace2D::removeTempFile()const + { + if (!m_tempfile.empty()) remove(m_tempfile.c_str()); } } // namespace DataHandling diff --git a/Code/Mantid/DataObjects/inc/MantidDataObjects/TableColumn.h b/Code/Mantid/DataObjects/inc/MantidDataObjects/TableColumn.h index 750d5e7d6e86e5077c6df392a67cfc0ae668dcbe..2c9175057847e20ea7ef65f914de3a0a5242b455 100644 --- a/Code/Mantid/DataObjects/inc/MantidDataObjects/TableColumn.h +++ b/Code/Mantid/DataObjects/inc/MantidDataObjects/TableColumn.h @@ -28,8 +28,19 @@ class TableVector; /** \class TableColumn - + Class TableColumn implements abstract class Column for any copyable data type. + A TableColumn is created using TableWorkspace::createColumn(type,name). + type is the simbolic name of the data type which must be first declared with + DECLARE_TABLECOLUMN macro. Predeclared types are: + "int" for int + "float" for float + "double" for double + "bool" for Boolean + "str" for std::string + "V3D" for Mantid::Geometry::V3D + + Boolean is used instead of bool because of bool's non-standard treatmemt in std::vector. \author Roman Tolchenov \date 31/10/2008 @@ -66,8 +77,11 @@ public: int size()const{return int(m_data.size());} /// Reference to the data. std::vector<Type>& data(){return m_data;} + /// Type id of the data in the column const std::type_info& get_type_info()const{return typeid(Type);} + /// Type id of the pointer to data in the column const std::type_info& get_pointer_type_info()const{return typeid(Type*);} + /// Output to an ostream. void print(std::ostream& s, int index)const{s << m_data[index];} protected: /// Resize. @@ -80,15 +94,18 @@ protected: else m_data.push_back(Type()); } - /// Removes an item. + /// Removes an item at index. void remove(int index){m_data.erase(m_data.begin()+index);} + /// Returns a pointer to the data element. void* void_pointer(int index){return &m_data[index];} private: + /// Column data std::vector<Type> m_data; friend class TableWorkspace; }; - +/// Shared pointer to a column with aoutomatic type cast and data type check. +/// Can be created with TableWorkspace::getColumn(...) template< class T> class TableColumn_ptr: public boost::shared_ptr<TableColumn<T> > { @@ -105,6 +122,10 @@ public: } }; +/* + As TableColumn stores its data in a std::vector bool type cannot be used + in the same way as the other types. Class Boolean is used instead. +*/ struct Boolean { Boolean():value(false){} @@ -113,11 +134,33 @@ struct Boolean bool value; }; +/// Special case of bool +template<> +class TableColumn_ptr<bool>: public TableColumn_ptr<Boolean> +{ +public: + TableColumn_ptr(boost::shared_ptr<Column> c):TableColumn_ptr<Boolean>(c) + { + if (this->get() == NULL) + { + Kernel::Logger& log = Kernel::Logger::get("TableWorkspace"); + std::string str = "Data type of column "+c->name()+" does not match "+typeid(Boolean).name(); + log.error(str); + throw std::runtime_error(str); + } + } +}; + DLLExport std::ostream& operator<<(std::ostream& s,const Boolean& b); } // namespace DataObjects } // Namespace Mantid +/* + Macro to declare a type to be used with TableColumn. + DataType is the actual C++ type. TypeName is a symbolic name, used in TableWorkspace::createColumn(...) + TypeName can contain only letters, numbers and _s. +*/ #define DECLARE_TABLECOLUMN(DataType,TypeName) \ namespace{ \ Mantid::Kernel::RegistrationHelper register_column_##TypeName( \ diff --git a/Code/Mantid/DataObjects/inc/MantidDataObjects/TablePointerColumn.h b/Code/Mantid/DataObjects/inc/MantidDataObjects/TablePointerColumn.h index 87a0ab0c7d7e656cea11f0cc8a240c3ec3b1d3fe..005691cf42e1056b521606c0d51cdac3aa617a6a 100644 --- a/Code/Mantid/DataObjects/inc/MantidDataObjects/TablePointerColumn.h +++ b/Code/Mantid/DataObjects/inc/MantidDataObjects/TablePointerColumn.h @@ -26,7 +26,9 @@ namespace DataObjects /** \class TablePointerColumn - + Class TablePointerColumn is an implementation of Column for non-copyable types. + Types must be declared with DECLARE_TABLEPOINTERCOLUMN before they can be used + with TablePointerColumn. \author Roman Tolchenov diff --git a/Code/qtiplot/qtiplot/src/Mantid/AlgMonitor.cpp b/Code/qtiplot/qtiplot/src/Mantid/AlgMonitor.cpp index 354044c5ec4e28511f73351242822e7f841fa5b3..2576144036e1d10e62054d1bc411547bc2c358df 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/AlgMonitor.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/AlgMonitor.cpp @@ -85,7 +85,7 @@ void AlgorithmMonitor::handleAlgorithmFinishedNotification(const Poco::AutoPtr<A void AlgorithmMonitor::handleAlgorithmProgressNotification(const Poco::AutoPtr<Algorithm::ProgressNotification>& pNf) { - if (m_monitorDlg) emit needUpdateProgress(pNf->algorithm(),int(pNf->progress*100)); + if (m_monitorDlg) emit needUpdateProgress(pNf->algorithm(),int(pNf->progress*100),QString::fromStdString(pNf->message)); } void AlgorithmMonitor::handleAlgorithmErrorNotification(const Poco::AutoPtr<Algorithm::ErrorNotification>& pNf) @@ -114,7 +114,7 @@ MonitorDlg::MonitorDlg(QWidget *parent,AlgorithmMonitor *algMonitor):QDialog(par m_tree = 0; update(0); connect(algMonitor,SIGNAL(countChanged(int)),this,SLOT(update(int))); - connect(algMonitor,SIGNAL(needUpdateProgress(const Algorithm*,int)),SLOT(updateProgress(const Algorithm*,int))); + connect(algMonitor,SIGNAL(needUpdateProgress(const Algorithm*,int, const QString&)),SLOT(updateProgress(const Algorithm*,int, const QString&))); QHBoxLayout *buttonLayout = new QHBoxLayout; QPushButton *closeButton = new QPushButton("Close"); @@ -178,7 +178,7 @@ void MonitorDlg::update(int n) m_algMonitor->unlock(); } -void MonitorDlg::updateProgress(const Algorithm* alg,int p) +void MonitorDlg::updateProgress(const Algorithm* alg,int p, const QString& msg) { int i = m_algorithms.indexOf(alg); if (i >= 0) diff --git a/Code/qtiplot/qtiplot/src/Mantid/AlgMonitor.h b/Code/qtiplot/qtiplot/src/Mantid/AlgMonitor.h index 924f9ed3d8bba9372da07a2580f3a3c1a26a21d5..8d14cefabecda617cf450ec5a25fd2b50ed3c465 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/AlgMonitor.h +++ b/Code/qtiplot/qtiplot/src/Mantid/AlgMonitor.h @@ -41,7 +41,7 @@ public: Algorithm_sptr getShared(const Algorithm *alg); signals: void countChanged(int); - void needUpdateProgress(const Algorithm* alg,int p); + void needUpdateProgress(const Algorithm* alg,int p, const QString& msg); protected: /// Algorithm notifiv=cation handlers @@ -80,7 +80,7 @@ public: ~MonitorDlg(); public slots: void update(int n); - void updateProgress(const Algorithm* alg,int p); + void updateProgress(const Algorithm* alg,int p, const QString& msg); private: QVector<const Algorithm*> m_algorithms; AlgorithmMonitor *m_algMonitor; diff --git a/Code/qtiplot/qtiplot/src/Mantid/LoadRawDlg.cpp b/Code/qtiplot/qtiplot/src/Mantid/LoadRawDlg.cpp index 786ff737f777ecab76783bb72967d6bbe0327664..f899a928e2025dd4ee291fb397023c003cd7cef5 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/LoadRawDlg.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/LoadRawDlg.cpp @@ -72,6 +72,33 @@ loadRawDlg::loadRawDlg(QWidget *parent) : QDialog(parent), fileName(""), workspa paramsLayout->addWidget(maxSpLabel,1,0); paramsLayout->addWidget(maxSpLineEdit,1,1); + QLabel *listSpLabel = new QLabel("Spectrum list"); + listSpLineEdit = new QLineEdit; + propValue = InputHistory::Instance().algorithmProperty("LoadRaw","spectrum_list"); + if (!propValue.isEmpty()) + { + listSpLineEdit->setText(propValue); + } + paramsLayout->addWidget(listSpLabel,2,0); + paramsLayout->addWidget(listSpLineEdit,2,1); + + QLabel *cacheLabel = new QLabel("Cache on local drive"); + cacheCBox = new QComboBox; + cacheCBox->insertItem(0,"Never"); + cacheCBox->insertItem(0,"Always"); + cacheCBox->insertItem(0,"If slow"); + cacheCBox->setCurrentIndex(0); + propValue = InputHistory::Instance().algorithmProperty("LoadRaw","Cache"); + if (!propValue.isEmpty()) + { + int i = cacheCBox->findText(propValue); + if (i >= 0) + cacheCBox->setCurrentIndex(i); + } + paramsLayout->addWidget(cacheLabel,3,0); + paramsLayout->addWidget(cacheCBox,3,1); + + mainLayout = new QVBoxLayout; mainLayout->addLayout(topRowLayout); mainLayout->addLayout(middleRowLayout); @@ -114,6 +141,8 @@ void loadRawDlg::loadClicked() workspaceName = lineName->text(); spectrum_min = minSpLineEdit->text(); spectrum_max = maxSpLineEdit->text(); + spectrum_list = listSpLineEdit->text(); + cache_option = cacheCBox->currentText(); close(); } } diff --git a/Code/qtiplot/qtiplot/src/Mantid/LoadRawDlg.h b/Code/qtiplot/qtiplot/src/Mantid/LoadRawDlg.h index eaa431ca232f2516bd46083e52b5df0799c8e74f..ccc2c6bc41f75fd26b58913cf9a1cb06a67f2612 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/LoadRawDlg.h +++ b/Code/qtiplot/qtiplot/src/Mantid/LoadRawDlg.h @@ -9,6 +9,7 @@ class QLineEdit; class QPushButton; class QString; class QVBoxLayout; +class QComboBox; class loadRawDlg : public QDialog { @@ -22,6 +23,8 @@ public: const QString& getWorkspaceName() { return workspaceName; } const QString& getSpectrumMin() { return spectrum_min; } const QString& getSpectrumMax() { return spectrum_max; } + const QString& getSpectrumList() { return spectrum_list; } + const QString& getCacheOption() { return cache_option; } protected: @@ -34,6 +37,8 @@ private: QString workspaceName; QString spectrum_min; QString spectrum_max; + QString spectrum_list; + QString cache_option; QVBoxLayout *mainLayout; @@ -44,6 +49,8 @@ private: QLineEdit *lineName; QLineEdit *minSpLineEdit; QLineEdit *maxSpLineEdit; + QLineEdit *listSpLineEdit; + QComboBox *cacheCBox; QPushButton *browseButton; QPushButton *loadButton; diff --git a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp index 5ce1a3f86140c7911014784b05b8a0a94701a9b1..81f1aee930487f304216aa6a0e2b49632505af75 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp @@ -80,7 +80,7 @@ m_deleteObserver(*this,&MantidUI::handleDeleteWorkspace) connect(this,SIGNAL(needsUpdating()),this,SLOT(update())); connect(this,SIGNAL(needToCloseProgressDialog()),this,SLOT(closeProgressDialog())); - connect(this,SIGNAL(needToUpdateProgressDialog(int)),this,SLOT(updateProgressDialog(int))); + connect(this,SIGNAL(needToUpdateProgressDialog(int,const QString&)),this,SLOT(updateProgressDialog(int,const QString&))); connect(this,SIGNAL(needToCreateLoadDAEMantidMatrix(const Mantid::API::Algorithm*)),this,SLOT(createLoadDAEMantidMatrix(const Mantid::API::Algorithm*))); connect(this,SIGNAL(needToShowCritical(const QString&)),this,SLOT(showCritical(const QString&))); @@ -159,7 +159,8 @@ IAlgorithm* MantidUI::CreateAlgorithm(const QString& algName) return alg; } -void MantidUI::LoadIsisRawFile(const QString& fileName,const QString& workspaceName,const QString& spectrum_min,const QString& spectrum_max) +void MantidUI::LoadIsisRawFile(const QString& fileName,const QString& workspaceName,const QString& spectrum_min,const QString& spectrum_max + ,const QString& spectrum_list,const QString& cache) { //Check workspace does not exist if (AnalysisDataService::Instance().doesExist(workspaceName.toStdString())) @@ -177,6 +178,10 @@ void MantidUI::LoadIsisRawFile(const QString& fileName,const QString& workspaceN alg->setPropertyValue("spectrum_min", spectrum_min.toStdString()); alg->setPropertyValue("spectrum_max", spectrum_max.toStdString()); } + if ( !spectrum_list.isEmpty() ) + alg->setPropertyValue("spectrum_list", spectrum_list.toStdString()); + if ( !cache.isEmpty() ) + alg->setPropertyValue("Cache", cache.toStdString()); executeAlgorithmAsync(alg); } @@ -194,7 +199,9 @@ void MantidUI::loadWorkspace() LoadIsisRawFile(dlg->getFilename(), dlg->getWorkspaceName(), dlg->getSpectrumMin(), - dlg->getSpectrumMax()); + dlg->getSpectrumMax(), + dlg->getSpectrumList(), + dlg->getCacheOption()); } } @@ -812,9 +819,9 @@ void MantidUI::tst(MdiSubWindow* w) cerr<<"OK closed\n"; } -void MantidUI::updateProgressDialog(int ip) +void MantidUI::updateProgressDialog(int ip,const QString& msg) { - if (m_progressDialog) m_progressDialog->setValue( ip ); + if (m_progressDialog) m_progressDialog->setValue( ip , msg ); } void MantidUI::closeProgressDialog() @@ -829,7 +836,7 @@ void MantidUI::closeProgressDialog() void MantidUI::handleAlgorithmFinishedNotification(const Poco::AutoPtr<Mantid::API::Algorithm::FinishedNotification>& pNf) { if (pNf->algorithm() == m_algAsync) m_algAsync = 0; - emit needToUpdateProgressDialog(100); + emit needToUpdateProgressDialog(100,"Algorithm finished."); emit needToCloseProgressDialog(); emit needsUpdating(); } @@ -880,7 +887,9 @@ void MantidUI::createLoadDAEMantidMatrix(const Mantid::API::Algorithm* alg) void MantidUI::handleAlgorithmProgressNotification(const Poco::AutoPtr<Mantid::API::Algorithm::ProgressNotification>& pNf) { if (m_algAsync == pNf->algorithm()) - emit needToUpdateProgressDialog( int(pNf->progress*100) ); + { + emit needToUpdateProgressDialog( int(pNf->progress*100) ,QString::fromStdString(pNf->message)); + } } void MantidUI::showCritical(const QString& text) @@ -1120,26 +1129,31 @@ Table* MantidUI::createTableFromSelectedRows(const QString& wsName, Mantid::API: bool isHistogram = workspace->isHistogramData(); if (isHistogram && !forPlotting) numRows++; +// Table* t = new Table(appWindow()->scriptEnv, numRows, c*index.size() + 1, "", appWindow(), 0); Table* t = new Table(appWindow()->scriptEnv, numRows, c*(i1 - i0 + 1) + 1, "", appWindow(), 0); appWindow()->initTable(t, appWindow()->generateUniqueName(wsName+"-")); int kY,kErr; +// for(int i=0;i<=index.size();i++) for(int i=i0;i<=i1;i++) { - const std::vector<double>& dataX = workspace->readX(i); + const std::vector<double>& dataX = workspace->readX(i);//index(i) const std::vector<double>& dataY = workspace->readY(i); const std::vector<double>& dataE = workspace->readE(i); +// kY = c*i+1; kY = c*(i-i0)+1; - t->setColName(kY,"Y"+QString::number(i)); + t->setColName(kY,"Y"+QString::number(i));//index(i) if (errs) { +// kErr = 2*i + 2; kErr = 2*(i - i0) + 2; t->setColPlotDesignation(kErr,Table::yErr); - t->setColName(kErr,"E"+QString::number(i)); + t->setColName(kErr,"E"+QString::number(i));//index(i) } for(int j=0;j<numRows;j++) { +// if (i == 0) if (i == i0) { // in histograms the point is to be drawn in the centre of the bin. @@ -1153,6 +1167,7 @@ Table* MantidUI::createTableFromSelectedRows(const QString& wsName, Mantid::API: if (isHistogram && !forPlotting) { int iRow = numRows - 1; +// if (i == 0) t->setCell(iRow,0,dataX[iRow]); if (i == i0) t->setCell(iRow,0,dataX[iRow]); t->setCell(iRow,kY,0); if (errs) t->setCell(iRow,kErr,0); diff --git a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.h b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.h index 9c31691dba70fb1aad87459936a93a18f13f8e24..efc21728b89bc1c18968d245ed61422e2968d63a 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.h +++ b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.h @@ -46,7 +46,8 @@ public: QStringList getWorkspaceNames(); // Returns a list of registered algorithms QStringList getAlgorithmNames(); - void LoadIsisRawFile(const QString& fileName, const QString& workspaceName,const QString& spectrum_min,const QString& spectrum_max); + void LoadIsisRawFile(const QString& fileName, const QString& workspaceName,const QString& spectrum_min,const QString& spectrum_max + ,const QString& spectrum_list,const QString& cache); Mantid::API::IAlgorithm* CreateAlgorithm(const QString& algName); // Gets a pointer to workspace workspaceName Mantid::API::Workspace_sptr getWorkspace(const QString& workspaceName); @@ -101,7 +102,7 @@ signals: void needsUpdating(); void needToCloseProgressDialog(); - void needToUpdateProgressDialog(int ip); + void needToUpdateProgressDialog(int ip,const QString& msg); void needToCreateLoadDAEMantidMatrix(const Mantid::API::Algorithm*); void needToShowCritical(const QString&); @@ -128,7 +129,7 @@ public slots: void copyDetectorsToTable(); void copyValues(); void closeProgressDialog(); - void updateProgressDialog(int ip); + void updateProgressDialog(int ip,const QString& msg); void cancelAsyncAlgorithm(); void backgroundAsyncAlgorithm(); void createLoadDAEMantidMatrix(const Mantid::API::Algorithm*); diff --git a/Code/qtiplot/qtiplot/src/Mantid/ProgressDlg.cpp b/Code/qtiplot/qtiplot/src/Mantid/ProgressDlg.cpp index 5bf7861f3971e7af3d7d052f85a31c107b55c32b..08e2a752152f21024d6b6e52d1e3a161d68eff83 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/ProgressDlg.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/ProgressDlg.cpp @@ -7,8 +7,10 @@ ProgressDlg::ProgressDlg(QWidget *parent):QDialog(parent) QVBoxLayout *topLayout = new QVBoxLayout; QLabel *label = new QLabel("Algorithm progress"); m_progressBar = new QProgressBar; + m_message = new QLabel(""); topLayout->addWidget(label); topLayout->addWidget(m_progressBar); + topLayout->addWidget(m_message); QPushButton *backgroundButton = new QPushButton("Run in background"); QPushButton *cancelButton = new QPushButton("Cancel algorithm"); @@ -37,7 +39,8 @@ void ProgressDlg::backgroundClicked() emit toBackground(); } -void ProgressDlg::setValue(int p) +void ProgressDlg::setValue(int p,const QString& msg) { m_progressBar->setValue(p); + m_message->setText(msg); } diff --git a/Code/qtiplot/qtiplot/src/Mantid/ProgressDlg.h b/Code/qtiplot/qtiplot/src/Mantid/ProgressDlg.h index da99c54cca543b5c07c10ec5e074a12c2c821a7e..6cedce86eda3c8ddc501450bb404d1a4b695b3cd 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/ProgressDlg.h +++ b/Code/qtiplot/qtiplot/src/Mantid/ProgressDlg.h @@ -5,6 +5,7 @@ #include <QDialog> class QProgressBar; +class QLabel; class ProgressDlg : public QDialog { @@ -13,7 +14,7 @@ class ProgressDlg : public QDialog public: ProgressDlg(QWidget *parent = 0); //~ProgressDlg(); - void setValue(int p); + void setValue(int p,const QString& msg); private slots: void cancelClicked(); @@ -24,6 +25,7 @@ signals: void toBackground(); private: QProgressBar *m_progressBar; + QLabel *m_message; }; #endif /* PROGRESSDLG_H */