void EstimatePDDetectorResolution::retrieveInstrumentParameters() { #if 0 // Call SolidAngle to get solid angles for all detectors Algorithm_sptr calsolidangle = createChildAlgorithm("SolidAngle", -1, -1, true); calsolidangle->initialize(); calsolidangle->setProperty("InputWorkspace", m_inputWS); calsolidangle->execute(); if (!calsolidangle->isExecuted()) throw runtime_error("Unable to run solid angle. "); m_solidangleWS = calsolidangle->getProperty("OutputWorkspace"); if (!m_solidangleWS) throw runtime_error("Unable to get solid angle workspace from SolidAngle(). "); size_t numspec = m_solidangleWS->getNumberHistograms(); for (size_t i = 0; i < numspec; ++i) g_log.debug() << "[DB]: " << m_solidangleWS->readY(i)[0] << "\n"; #endif // Calculate centre neutron velocity Property* cwlproperty = m_inputWS->run().getProperty("LambdaRequest"); if (!cwlproperty) throw runtime_error("Unable to locate property LambdaRequest as central wavelength. "); TimeSeriesProperty<double>* cwltimeseries = dynamic_cast<TimeSeriesProperty<double>* >(cwlproperty); if (!cwltimeseries) throw runtime_error("LambdaReqeust is not a TimeSeriesProperty in double. "); if (cwltimeseries->size() != 1) throw runtime_error("LambdaRequest should contain 1 and only 1 entry. "); double centrewavelength = cwltimeseries->nthValue(0); string unit = cwltimeseries->units(); if (unit.compare("Angstrom") == 0) centrewavelength *= 1.0E-10; else throw runtime_error("Unit is not recognized"); m_centreVelocity = PhysicalConstants::h/PhysicalConstants::NeutronMass/centrewavelength; g_log.notice() << "Centre wavelength = " << centrewavelength << ", Centre neutron velocity = " << m_centreVelocity << "\n"; // Calcualte L1 sample to source Instrument_const_sptr instrument = m_inputWS->getInstrument(); V3D samplepos = instrument->getSample()->getPos(); V3D sourcepos = instrument->getSource()->getPos(); m_L1 = samplepos.distance(sourcepos); g_log.notice() << "L1 = " << m_L1 << "\n"; return; }
/** Execute the algorithm. */ void LoadLiveData::exec() { // The full, post-processed output workspace m_outputWS = this->getProperty("OutputWorkspace"); // Validate inputs if (this->hasPostProcessing()) { if (this->getPropertyValue("AccumulationWorkspace").empty()) throw std::invalid_argument("Must specify the AccumulationWorkspace " "parameter if using PostProcessing."); // The accumulated but not post-processed output workspace m_accumWS = this->getProperty("AccumulationWorkspace"); } else { // No post-processing, so the accumulation and output are the same m_accumWS = m_outputWS; } // Get or create the live listener ILiveListener_sptr listener = this->getLiveListener(); // Do we need to reset the data? bool dataReset = listener->dataReset(); // The listener returns a MatrixWorkspace containing the chunk of live data. Workspace_sptr chunkWS; bool dataNotYetGiven = true; while (dataNotYetGiven) { try { chunkWS = listener->extractData(); dataNotYetGiven = false; } catch (Exception::NotYet &ex) { g_log.warning() << "The " << listener->name() << " is not ready to return data: " << ex.what() << "\n"; g_log.warning() << "Trying again in 10 seconds - cancel the algorithm to stop.\n"; const int tenSeconds = 40; for (int i = 0; i < tenSeconds; ++i) { Poco::Thread::sleep(10000 / tenSeconds); // 250 ms this->interruption_point(); } } } // TODO: Have the ILiveListener tell me exactly the time stamp DateAndTime lastTimeStamp = DateAndTime::getCurrentTime(); this->setPropertyValue("LastTimeStamp", lastTimeStamp.toISO8601String()); // Now we process the chunk Workspace_sptr processed = this->processChunk(chunkWS); bool PreserveEvents = this->getProperty("PreserveEvents"); EventWorkspace_sptr processedEvent = boost::dynamic_pointer_cast<EventWorkspace>(processed); if (!PreserveEvents && processedEvent) { // Convert the monitor workspace, if there is one and it's necessary MatrixWorkspace_sptr monitorWS = processedEvent->monitorWorkspace(); auto monitorEventWS = boost::dynamic_pointer_cast<EventWorkspace>(monitorWS); if (monitorEventWS) { auto monAlg = this->createChildAlgorithm("ConvertToMatrixWorkspace"); monAlg->setProperty("InputWorkspace", monitorEventWS); monAlg->executeAsChildAlg(); if (!monAlg->isExecuted()) g_log.error( "Failed to convert monitors from events to histogram form."); monitorWS = monAlg->getProperty("OutputWorkspace"); } // Now do the main workspace Algorithm_sptr alg = this->createChildAlgorithm("ConvertToMatrixWorkspace"); alg->setProperty("InputWorkspace", processedEvent); std::string outputName = "__anonymous_livedata_convert_" + this->getPropertyValue("OutputWorkspace"); alg->setPropertyValue("OutputWorkspace", outputName); alg->execute(); if (!alg->isExecuted()) throw std::runtime_error("Error when calling ConvertToMatrixWorkspace " "(since PreserveEvents=False). See log."); // Replace the "processed" workspace with the converted one. MatrixWorkspace_sptr temp = alg->getProperty("OutputWorkspace"); if (monitorWS) temp->setMonitorWorkspace(monitorWS); // Set back the monitor workspace processed = temp; } // How do we accumulate the data? std::string accum = this->getPropertyValue("AccumulationMethod"); // If the AccumulationWorkspace does not exist, we always replace the // AccumulationWorkspace. // Also, if the listener said we are resetting the data, then we clear out the // old. if (!m_accumWS || dataReset) accum = "Replace"; g_log.notice() << "Performing the " << accum << " operation.\n"; // Perform the accumulation and set the AccumulationWorkspace workspace if (accum == "Replace") this->replaceChunk(processed); else if (accum == "Append") this->appendChunk(processed); else // Default to Add. this->addChunk(processed); // At this point, m_accumWS is set. if (this->hasPostProcessing()) { // ----------- Run post-processing ------------- this->runPostProcessing(); // Set both output workspaces this->setProperty("AccumulationWorkspace", m_accumWS); this->setProperty("OutputWorkspace", m_outputWS); doSortEvents(m_outputWS); } else { // ----------- No post-processing ------------- m_outputWS = m_accumWS; // We DO NOT set AccumulationWorkspace. this->setProperty("OutputWorkspace", m_outputWS); } // Output group requires some additional handling WorkspaceGroup_sptr out_gws = boost::dynamic_pointer_cast<WorkspaceGroup>(m_outputWS); if (out_gws) { size_t n = static_cast<size_t>(out_gws->getNumberOfEntries()); for (size_t i = 0; i < n; ++i) { auto ws = out_gws->getItem(i); std::string itemName = ws->name(); std::string wsName = getPropertyValue("OutputWorkspace") + "_" + std::to_string(i + 1); if (wsName != itemName) { if (AnalysisDataService::Instance().doesExist(itemName)) { // replace the temporary name with the proper one AnalysisDataService::Instance().rename(itemName, wsName); } } else { // touch the workspace in the ADS to issue a notification to update the // GUI AnalysisDataService::Instance().addOrReplace(itemName, ws); } } } }