/** * Load the instrument * @param instrName :: Instrument name */ void ISISLiveEventDataListener::loadInstrument(const std::string &instrName) { // try to load the instrument. if it doesn't load give a warning and carry on if (instrName.empty()) { g_log.warning() << "Unable to read instrument name from DAE." << std::endl; return; } const char *warningMessage = "Failed to load instrument "; try { g_log.notice() << "Loading instrument " << instrName << " ... " << std::endl; API::Algorithm_sptr alg = API::AlgorithmFactory::Instance().create("LoadInstrument", -1); alg->initialize(); alg->setPropertyValue("InstrumentName", instrName); alg->setProperty("Workspace", m_eventBuffer[0]); alg->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false)); alg->setChild(true); alg->execute(); // check if the instrument was loaded if (!alg->isExecuted()) { g_log.warning() << warningMessage << instrName << std::endl; } g_log.notice() << "Instrument loaded." << std::endl; } catch (std::exception &e) { g_log.warning() << warningMessage << instrName << std::endl; g_log.warning() << e.what() << instrName << std::endl; } }
/** Rebin output workspace */ void CountEventsInPulses::rebin(DataObjects::EventWorkspace_sptr outputWS) { const double xmin = outputWS->getTofMin(); const double xmax = outputWS->getTofMax(); if (xmax <= xmin) { std::stringstream ss; ss << "Tof_max " << xmax << " is less than Tof_min " << xmin; throw std::runtime_error(ss.str()); } std::stringstream ss; ss << xmin << ", " << mPulseLength << ", " << xmax; std::string binparam = ss.str(); g_log.debug() << "Binning parameter = " << binparam << std::endl; API::Algorithm_sptr rebin = this->createChildAlgorithm("Rebin", 0.8, 0.9, true); rebin->initialize(); rebin->setProperty("InputWorkspace", outputWS); rebin->setProperty("OutputWorkspace", outputWS); rebin->setProperty("Params", binparam); rebin->setProperty("PreserveEvents", true); bool success = rebin->execute(); if (!success) { g_log.warning() << "Rebin output event workspace failed! " << std::endl; } return; }
/** Compress event */ DataObjects::EventWorkspace_sptr CountEventsInPulses::compressEvents(DataObjects::EventWorkspace_sptr inputws, double tolerance) { API::Algorithm_sptr alg = this->createChildAlgorithm("CompressEvents", 0.9, 1.0, true); alg->initialize(); alg->setProperty("InputWorkspace", inputws); alg->setProperty("OutputWorkspace", "TempWS"); alg->setProperty("Tolerance", tolerance); bool successful = alg->execute(); DataObjects::EventWorkspace_sptr outputws; if (!successful) { // Failed outputws = inputws; g_log.warning() << "CompressEvents() Failed!" << std::endl; } else { // Successful outputws = alg->getProperty("OutputWorkspace"); if (!outputws) { g_log.error() << "CompressEvents failed as the output is not a MatrixWorkspace. " << std::endl; throw std::runtime_error( "SumSpectra failed as the output is not a MatrixWorkspace."); } /* API::MatrixWorkspace_sptr testws = alg->getProperty("OutputWorkspace"); if (!testws) { g_log.error() << "CompressEvents failed as the output is not a MatrixWorkspace. " << std::endl; throw std::runtime_error("SumSpectra failed as the output is not a MatrixWorkspace."); } else { outputws = boost::dynamic_pointer_cast<DataObjects::EventWorkspace>(testws); } */ } return outputws; }
/** Executes the algorithm */ void FilterByTime2::exec() { DataObjects::EventWorkspace_const_sptr inWS = this->getProperty("InputWorkspace"); if (!inWS) { g_log.error() << "Input is not EventWorkspace" << std::endl; throw std::invalid_argument("Input is not EventWorksapce"); } else { g_log.debug() << "DB5244 InputWorkspace Name = " << inWS->getName() << std::endl; } double starttime = this->getProperty("StartTime"); double stoptime = this->getProperty("StopTime"); std::string absstarttime = this->getProperty("AbsoluteStartTime"); std::string absstoptime = this->getProperty("AbsoluteStopTime"); std::string start, stop; if ((absstarttime != "") && (absstoptime != "") && (starttime <= 0.0) && (stoptime <= 0.0)) { // Use the absolute string start = absstarttime; stop = absstoptime; } else if ((absstarttime != "" || absstoptime != "") && (starttime > 0.0 || stoptime > 0.0)) { throw std::invalid_argument( "It is not allowed to provide both absolute time and relative time."); } else { // Use second std::stringstream ss; ss << starttime; start = ss.str(); std::stringstream ss2; ss2 << stoptime; stop = ss2.str(); } // 1. Generate Filters g_log.debug() << "\nDB441: About to generate Filter. StartTime = " << starttime << " StopTime = " << stoptime << std::endl; API::Algorithm_sptr genfilter = createChildAlgorithm("GenerateEventsFilter", 0.0, 20.0, true, 1); genfilter->initialize(); genfilter->setPropertyValue("InputWorkspace", inWS->getName()); genfilter->setPropertyValue("OutputWorkspace", "FilterWS"); genfilter->setProperty("StartTime", start); genfilter->setProperty("StopTime", stop); genfilter->setProperty("UnitOfTime", "Seconds"); genfilter->setProperty("FastLog", false); bool sucgen = genfilter->execute(); if (!sucgen) { g_log.error() << "Unable to generate event filters" << std::endl; throw std::runtime_error("Unable to generate event filters"); } else { g_log.debug() << "Filters are generated. " << std::endl; } API::Workspace_sptr filterWS = genfilter->getProperty("OutputWorkspace"); if (!filterWS) { g_log.error() << "Unable to retrieve generated SplittersWorkspace object " "from AnalysisDataService." << std::endl; throw std::runtime_error("Unable to retrieve Splittersworkspace. "); } // 2. Filter events g_log.debug() << "\nAbout to filter events. " << "\n"; API::Algorithm_sptr filter = createChildAlgorithm("FilterEvents", 20.0, 100.0, true, 1); filter->initialize(); filter->setPropertyValue("InputWorkspace", inWS->getName()); filter->setPropertyValue("OutputWorkspaceBaseName", "ResultWS"); filter->setProperty("SplitterWorkspace", filterWS); filter->setProperty("FilterByPulseTime", true); bool sucfilt = filter->execute(); if (!sucfilt) { g_log.error() << "Unable to filter events" << std::endl; throw std::runtime_error("Unable to filter events"); } else { g_log.debug() << "Filter events is successful. " << std::endl; } DataObjects::EventWorkspace_sptr optws = filter->getProperty("OutputWorkspace_0"); this->setProperty("OutputWorkspace", optws); }