diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadLog.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadLog.h index dfa4df5cb69231548b61210b613911ea35659fe8..dca2cb8690976694194e62c5d60ed64ac1b15383 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadLog.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadLog.h @@ -110,7 +110,7 @@ namespace Mantid /// Check if first 19 characters of a string is data-time string according to yyyy-mm-ddThh:mm:ss bool isDateTimeString(const std::string& str) const; /// Checks if a log file name was provided (e.g. through setPropertyValue). If not it creates one based on provided path. - std::string createLogFileName(std::string fileName); + std::string extractLogName(std::string fileName); /// Return the name of the three column log file for associated with the specified file. Empty string if one doesn't exist std::string getThreeColumnName() const; /// Check for SNS-style text file diff --git a/Code/Mantid/Framework/DataHandling/src/LoadLog.cpp b/Code/Mantid/Framework/DataHandling/src/LoadLog.cpp index fcd9ef75a8ffacfee1c41ac4ae8749039ad9f5ee..e8cad2bef3af4dd5a7d06880d68bd31b12d1f7ff 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadLog.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadLog.cpp @@ -111,100 +111,17 @@ void LoadLog::init() } -/** Check if the file is SNS text; load it if it is, return false otherwise. - * - * @return true if the file was a SNS style; false otherwise. - */ -bool LoadLog::LoadSNSText() -{ - - // Get the SNS-specific parameter - std::vector<std::string> names = getProperty("Names"); - std::vector<std::string> units = getProperty("Units"); - - // Get the input workspace and retrieve run from workspace. - // the log file(s) will be loaded into the run object of the workspace - const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace"); - - // open log file - std::ifstream inLogFile(m_filename.c_str()); - - // Get the first line - std::string aLine; - if (!Mantid::Kernel::extractToEOL(inLogFile,aLine)) - return false; - - std::vector<double> cols; - bool ret = SNSTextFormatColumns(aLine, cols); - // Any error? - if (!ret || cols.size() < 2) - return false; - - size_t numCols = static_cast<size_t>(cols.size()-1); - if (names.size() != numCols) - throw std::invalid_argument("The Names parameter should have one fewer entry as the number of columns in a SNS-style text log file."); - if ((!units.empty()) && (units.size() != numCols)) - throw std::invalid_argument("The Units parameter should have either 0 entries or one fewer entry as the number of columns in a SNS-style text log file."); - - // Ok, create all the logs - std::vector<TimeSeriesProperty<double>*> props; - for(size_t i=0; i < numCols; i++) - { - TimeSeriesProperty<double>* p = new TimeSeriesProperty<double>(names[i]); - if (units.size() == numCols) - p->setUnits(units[i]); - props.push_back(p); - } - // Go back to start - inLogFile.seekg(0); - while(Mantid::Kernel::extractToEOL(inLogFile,aLine)) - { - if (aLine.size() == 0) - break; - - if (SNSTextFormatColumns(aLine, cols)) - { - if (cols.size() == numCols+1) - { - DateAndTime time(cols[0], 0.0); - for(size_t i=0; i<numCols; i++) - props[i]->addValue(time, cols[i+1]); - } - else - throw std::runtime_error("Inconsistent number of columns while reading SNS-style text file."); - } - else - throw std::runtime_error("Error while reading columns in SNS-style text file."); - } - // Now add all the full logs to the workspace - for(size_t i=0; i < numCols; i++) - { - std::string name = props[i]->name(); - if (localWorkspace->mutableRun().hasProperty(name)) - { - localWorkspace->mutableRun().removeLogData(name); - g_log.information() << "Log data named " << name << " already existed and was overwritten.\n"; - } - localWorkspace->mutableRun().addLogData(props[i]); - } - - return true; -} - - - -/** Executes the algorithm. Reading in ISIS log file(s) - * - * @throw Mantid::Kernel::Exception::FileError Thrown if file is not recognised to be a raw datafile or log file - * @throw std::runtime_error Thrown with Workspace problems +/** + * Executes the algorithm. Reading in ISIS log file(s) + * @throw Mantid::Kernel::Exception::FileError Thrown if file is not recognised to be a raw datafile or log file + * @throw std::runtime_error Thrown with Workspace problems */ void LoadLog::exec() { // Retrieve the filename from the properties and perform some initial checks on the filename m_filename = getPropertyValue("Filename"); - std::string logFileName = getPropertyValue("Names"); - // File property checks whether the given path exists, just check that is actually a file + // File property checks whether the given path exists, just check that is actually a file Poco::File l_path( m_filename ); if ( l_path.isDirectory() ) { @@ -213,7 +130,7 @@ void LoadLog::exec() } // Get the input workspace and retrieve run from workspace. - // the log file(s) will be loaded into the run object of the workspace + // the log file(s) will be loaded into the run object of the workspace const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace"); if ( isAscii(m_filename) ) @@ -226,11 +143,11 @@ void LoadLog::exec() } //.if a .log file exists in the raw file directory - // (This is a search, so perhaps move to LoadRawHelper?) std::string threecolumnLogfile = getThreeColumnName(); if ( !threecolumnLogfile.empty() ) { createthreecolumnFileLogProperty( threecolumnLogfile,localWorkspace->mutableRun() ); + return; } std::ifstream inLogFile(m_filename.c_str()); @@ -240,6 +157,9 @@ void LoadLog::exec() g_log.warning("Unable to open file " + m_filename); } + // Now working with two column log files (ISIS) + std::string logFileName = getProperty("Names"); + // figure out if second column is a number or a string std::string aLine; if( Mantid::Kernel::extractToEOL(inLogFile,aLine) ) @@ -267,12 +187,7 @@ void LoadLog::exec() try { - std::cout << "FILENAME: " << m_filename << std::endl; - std::cout << "LOGNAME: " << logFileName << std::endl; - std::cout << "LN FROM FUNCTION: " << (createLogFileName(logFileName)) << std::endl; - std::cout << std::endl; - - Property* log = LogParser::createLogProperty(m_filename,stringToLower(createLogFileName(logFileName))); + Property* log = LogParser::createLogProperty(m_filename,stringToLower(extractLogName(logFileName))); if (log) { localWorkspace->mutableRun().addLogData(log); @@ -288,24 +203,108 @@ void LoadLog::exec() return; } - -std::string LoadLog::createLogFileName(std::string fileName) +/** + * Check if log file property name has been set. If it has, then return it. + * Otherwise we return the workspace name and log file name (e.g. HRP37129_ICPevent). + * @param logName :: The name of the log file. + * @return The name of the log file. + */ +std::string LoadLog::extractLogName(std::string logName) { - if(fileName.empty()) + if(!logName.empty()) { - std::string path = Poco::Path(Poco::Path(m_filename).getFileName()).getBaseName(); - return (path.substr(path.find_first_of('_') + 1)); -// return (path); + return (logName); } else { - return (fileName); + return (Poco::Path(Poco::Path(m_filename).getFileName()).getBaseName()); + } +} + +/** + * Check if the file is SNS text; load it if it is, return false otherwise. + * @return true if the file was a SNS style; false otherwise. + */ +bool LoadLog::LoadSNSText() +{ + + // Get the SNS-specific parameter + std::vector<std::string> names = getProperty("Names"); + std::vector<std::string> units = getProperty("Units"); + + // Get the input workspace and retrieve run from workspace. + // the log file(s) will be loaded into the run object of the workspace + const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace"); + + // open log file + std::ifstream inLogFile(m_filename.c_str()); + + // Get the first line + std::string aLine; + if (!Mantid::Kernel::extractToEOL(inLogFile,aLine)) + return false; + + std::vector<double> cols; + bool ret = SNSTextFormatColumns(aLine, cols); + // Any error? + if (!ret || cols.size() < 2) + return false; + + size_t numCols = static_cast<size_t>(cols.size()-1); + if (names.size() != numCols) + throw std::invalid_argument("The Names parameter should have one fewer entry as the number of columns in a SNS-style text log file."); + if ((!units.empty()) && (units.size() != numCols)) + throw std::invalid_argument("The Units parameter should have either 0 entries or one fewer entry as the number of columns in a SNS-style text log file."); + + // Ok, create all the logs + std::vector<TimeSeriesProperty<double>*> props; + for(size_t i=0; i < numCols; i++) + { + TimeSeriesProperty<double>* p = new TimeSeriesProperty<double>(names[i]); + if (units.size() == numCols) + p->setUnits(units[i]); + props.push_back(p); } + // Go back to start + inLogFile.seekg(0); + while(Mantid::Kernel::extractToEOL(inLogFile,aLine)) + { + if (aLine.size() == 0) + break; + + if (SNSTextFormatColumns(aLine, cols)) + { + if (cols.size() == numCols+1) + { + DateAndTime time(cols[0], 0.0); + for(size_t i=0; i<numCols; i++) + props[i]->addValue(time, cols[i+1]); + } + else + throw std::runtime_error("Inconsistent number of columns while reading SNS-style text file."); + } + else + throw std::runtime_error("Error while reading columns in SNS-style text file."); + } + // Now add all the full logs to the workspace + for(size_t i=0; i < numCols; i++) + { + std::string name = props[i]->name(); + if (localWorkspace->mutableRun().hasProperty(name)) + { + localWorkspace->mutableRun().removeLogData(name); + g_log.information() << "Log data named " << name << " already existed and was overwritten.\n"; + } + localWorkspace->mutableRun().addLogData(props[i]); + } + + return true; } -/** Return the name of the three column log file if we have one. +/** + * Return the name of the three column log file if we have one. * @returns A string containing the full log file path to a three column log file if one exists. An empty string otherwise. -*/ + */ std::string LoadLog::getThreeColumnName() const { std::string rawID; @@ -370,7 +369,8 @@ std::string LoadLog::getThreeColumnName() const else return ""; } -/** This method reads the.log file and creates timeseries property and sets that to the run object +/** + * This method reads the.log file and creates timeseries property and sets that to the run object * @param logfile :: three column log(.log) file name. * @param run :: The run information object * @returns list of logfiles which exists as blockname in the .log file @@ -493,7 +493,8 @@ std::set<std::string> LoadLog::createthreecolumnFileLogProperty(const std::strin } -/** this method looks for file with second column(block column) name exists in the raw file directory +/** + * This method looks for file with second column(block column) name exists in the raw file directory * @param fileName :: -name of the file * @return True if the file exists */ @@ -503,10 +504,11 @@ bool LoadLog::blockcolumnFileExists(const std::string& fileName) else return false; } -/** Takes as input a string and try to determine what type it is. - * @param s :: The input string - * @param s :: string to be classified - * @return A enum kind which tells what type the string is +/** + * Takes as input a string and try to determine what type it is. + * @param s :: The input string + * @param s :: string to be classified + * @return A enum kind which tells what type the string is */ LoadLog::kind LoadLog::classify(const std::string& s) const { @@ -530,7 +532,8 @@ LoadLog::kind LoadLog::classify(const std::string& s) const } } -/** change each element of the string to lower case +/** + * Change each element of the string to lower case * @param strToConvert :: The input string * @returns The string but with all characters in lower case */ @@ -540,7 +543,8 @@ std::string LoadLog::stringToLower(std::string strToConvert) return strToConvert; } -/** Checks whether filename is a simple text file +/** + * Checks whether filename is a simple text file * @param filename :: The filename to inspect * @returns true if the filename has the .txt extension */ @@ -567,7 +571,8 @@ bool LoadLog::isAscii(const std::string& filename) return true; } -/** check if first 19 characters of a string is date-time string according to yyyy-mm-ddThh:mm:ss +/** + * Check if first 19 characters of a string is date-time string according to yyyy-mm-ddThh:mm:ss * @param str :: The string to test * @returns true if the strings format matched the expected date format */ @@ -577,8 +582,8 @@ bool LoadLog::isDateTimeString(const std::string& str) const } -/** Read a line of a SNS-style text file. - * +/** + * Read a line of a SNS-style text file. * @param str :: The string to test * @param out :: a vector that will be filled with the double values. * @return false if the format is NOT SNS style or a conversion failed. diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index 5ef126034957e2894f9ab8ea6df784b5b53c8802..4eed5248a7d0e0c0d5729e2e90c3009fa3af1c25 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -665,24 +665,18 @@ namespace Mantid } progress(m_prog, "Reading log files..."); - IAlgorithm_sptr loadLog = createChildAlgorithm("LoadLog"); //Iterate over the set, and load each log file into the localWorkspace. - std::set<std::string>::const_iterator location; - for (location = logFiles.begin(); location != logFiles.end(); ++location) + std::set<std::string>::const_iterator logFileName; + for (logFileName = logFiles.begin(); logFileName != logFiles.end(); ++logFileName) { - std::cout << "Location: " << *location << std::endl; // Pass through the same input filename - loadLog->setPropertyValue("Filename", *location); + loadLog->setPropertyValue("Filename", *logFileName); // Set the workspace property to be the same one filled above loadLog->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); - - // Find the name of the file - std::string logName = extractLogName(*location); - // Pass the name of the log file explicitly to LoadLog. -// loadLog->setPropertyValue("Names", extractLogName(*location)); + loadLog->setPropertyValue("Names", extractLogName(*logFileName)); // Enable progress reporting by Child Algorithm - if progress range has duration if ( progStart < progEnd ) @@ -707,7 +701,6 @@ namespace Mantid g_log.error("Unable to successfully run LoadLog Child Algorithm"); } } - // Make log creator object and add the run status log if we have the appropriate ICP log m_logCreator.reset(new ISISRunLogs(localWorkspace->run(), m_numberOfPeriods)); m_logCreator->addStatusLog(localWorkspace->mutableRun()); @@ -720,9 +713,8 @@ namespace Mantid */ std::string LoadRawHelper::extractLogName(std::string path) { - std::string loc(path); - size_t pos = loc.find('_'); - std::string logName = loc.substr(pos + 1); + size_t pos = path.find('_'); + std::string logName = path.substr(pos + 1); logName.erase(logName.find_last_of('.')); return (logName); }