/** * Load an ISIS log file into the local workspace. * @param logFileStream :: The stream of the log file (data). * @param logFileName :: The name of the log file to load. * @param run :: The run information object */ void LoadLog::loadTwoColumnLogFile(std::ifstream& logFileStream, std::string logFileName, API::Run& run) { if (!logFileStream) { throw std::invalid_argument("Unable to open file " + m_filename); } // figure out if second column is a number or a string std::string aLine; if( Mantid::Kernel::Strings::extractToEOL(logFileStream,aLine) ) { if ( !isDateTimeString(aLine) ) { throw std::invalid_argument("File" + m_filename + " is not a standard ISIS log file. Expected to be a two column file."); } std::string DateAndTime; std::stringstream ins(aLine); ins >> DateAndTime; // read in what follows the date-time string in the log file and figure out what type it is std::string whatType; ins >> whatType; kind l_kind = classify(whatType); if (LoadLog::string != l_kind && LoadLog::number != l_kind) { throw std::invalid_argument("ISIS log file contains unrecognised second column entries: " + m_filename); } try { Property* log = LogParser::createLogProperty(m_filename,stringToLower(logFileName)); if (log) { run.addLogData(log); } } catch(std::exception&) { } } }
/** * reads the .log stream and creates timeseries property and sets that to the run object * @param logFileStream :: The stream of the log file (data). * @param logFileName :: The name of the log file to load. * @param run :: The run information object */ void LoadLog::loadThreeColumnLogFile(std::ifstream& logFileStream, std::string logFileName, API::Run& run) { std::string str; std::string propname; Mantid::Kernel::TimeSeriesProperty<double>* logd = 0; Mantid::Kernel::TimeSeriesProperty<std::string>* logs = 0; std::map<std::string,Kernel::TimeSeriesProperty<double>*> dMap; std::map<std::string,Kernel::TimeSeriesProperty<std::string>*> sMap; typedef std::pair<std::string,Kernel::TimeSeriesProperty<double>* > dpair; typedef std::pair<std::string,Kernel::TimeSeriesProperty<std::string>* > spair; kind l_kind(LoadLog::empty); bool isNumeric(false); if (!logFileStream) { throw std::invalid_argument("Unable to open file " + m_filename); } while(Mantid::Kernel::Strings::extractToEOL(logFileStream,str)) { if ( !isDateTimeString(str) ) { throw std::invalid_argument("File" + logFileName + " is not a standard ISIS log file. Expected to be a file starting with DateTime String format."); } if (!Kernel::TimeSeriesProperty<double>::isTimeString(str) || (str[0]=='#')) { //if the line doesn't start with a time read the next line continue; } std::stringstream line(str); std::string timecolumn; line >> timecolumn; std::string blockcolumn; line >> blockcolumn; l_kind = classify(blockcolumn); if ( LoadLog::string != l_kind ) { throw std::invalid_argument("ISIS log file contains unrecognised second column entries:" + logFileName); } std::string valuecolumn; line >> valuecolumn; l_kind = classify(valuecolumn); if ( LoadLog::string != l_kind && LoadLog::number != l_kind) { continue; //no value defined, just skip this entry } // column two in .log file is called block column propname = stringToLower(blockcolumn); //check if the data is numeric std::istringstream istr(valuecolumn); double dvalue; istr >> dvalue; isNumeric = !istr.fail(); if (isNumeric) { std::map<std::string,Kernel::TimeSeriesProperty<double>*>::iterator ditr = dMap.find(propname); if(ditr != dMap.end()) { Kernel::TimeSeriesProperty<double>* prop = ditr->second; if (prop) prop->addValue(timecolumn,dvalue); } else { logd = new Kernel::TimeSeriesProperty<double>(propname); logd->addValue(timecolumn,dvalue); dMap.insert(dpair(propname,logd)); } } else { std::map<std::string,Kernel::TimeSeriesProperty<std::string>*>::iterator sitr = sMap.find(propname); if(sitr != sMap.end()) { Kernel::TimeSeriesProperty<std::string>* prop = sitr->second; if (prop) prop->addValue(timecolumn,valuecolumn); } else { logs = new Kernel::TimeSeriesProperty<std::string>(propname); logs->addValue(timecolumn,valuecolumn); sMap.insert(spair(propname,logs)); } } } try { std::map<std::string,Kernel::TimeSeriesProperty<double>*>::const_iterator itr = dMap.begin(); for(;itr != dMap.end(); ++itr) { run.addLogData(itr->second); } std::map<std::string,Kernel::TimeSeriesProperty<std::string>*>::const_iterator sitr = sMap.begin(); for(;sitr!=sMap.end();++sitr) { run.addLogData(sitr->second); } } catch(std::invalid_argument &e) { g_log.warning() << e.what(); } catch(Exception::ExistsError&e) { g_log.warning() << e.what(); } }