本文整理汇总了C++中DateAndTime::totalNanoseconds方法的典型用法代码示例。如果您正苦于以下问题:C++ DateAndTime::totalNanoseconds方法的具体用法?C++ DateAndTime::totalNanoseconds怎么用?C++ DateAndTime::totalNanoseconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateAndTime
的用法示例。
在下文中一共展示了DateAndTime::totalNanoseconds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveTimeVector
void saveTimeVector(::NeXus::File * file, TimeSeriesProperty<NumT> * prop)
{
std::vector<DateAndTime> times = prop->timesAsVector();
DateAndTime start = times[0];
std::vector<double> timeSec(times.size());
for (size_t i=0; i<times.size(); i++)
timeSec[i] = double(times[i].totalNanoseconds() - start.totalNanoseconds()) * 1e-9;
file->writeData("time", timeSec);
file->openData("time");
file->putAttr("start", start.toISO8601String() );
file->closeData();
}
示例2: exec
/**
* Execute the algorithm.
*/
void RebinByTimeBase::exec() {
using Mantid::DataObjects::EventWorkspace;
IEventWorkspace_sptr inWS = getProperty("InputWorkspace");
if (!boost::dynamic_pointer_cast<EventWorkspace>(inWS)) {
const std::string algName = this->name();
throw std::invalid_argument(
algName + " Algorithm requires an EventWorkspace as an input.");
}
MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
// retrieve the properties
const std::vector<double> inParams = getProperty("Params");
std::vector<double> rebinningParams;
// workspace independent determination of length
const int histnumber = static_cast<int>(inWS->getNumberHistograms());
const uint64_t nanoSecondsInASecond = static_cast<uint64_t>(1e9);
const DateAndTime runStartTime = inWS->run().startTime();
// The validator only passes parameters with size 1, or 3xn.
double tStep = 0;
if (inParams.size() >= 3) {
// Use the start of the run to offset the times provided by the user. pulse
// time of the events are absolute.
const DateAndTime startTime = runStartTime + inParams[0];
const DateAndTime endTime = runStartTime + inParams[2];
// Rebinning params in nanoseconds.
rebinningParams.push_back(
static_cast<double>(startTime.totalNanoseconds()));
tStep = inParams[1] * nanoSecondsInASecond;
rebinningParams.push_back(tStep);
rebinningParams.push_back(static_cast<double>(endTime.totalNanoseconds()));
} else if (inParams.size() == 1) {
const uint64_t xmin = getMinX(inWS);
const uint64_t xmax = getMaxX(inWS);
rebinningParams.push_back(static_cast<double>(xmin));
tStep = inParams[0] * nanoSecondsInASecond;
rebinningParams.push_back(tStep);
rebinningParams.push_back(static_cast<double>(xmax));
}
// Validate the timestep.
if (tStep <= 0) {
throw std::invalid_argument(
"Cannot have a timestep less than or equal to zero.");
}
// Initialize progress reporting.
Progress prog(this, 0.0, 1.0, histnumber);
MantidVecPtr XValues_new;
// create new X axis, with absolute times in seconds.
const int ntcnew = VectorHelper::createAxisFromRebinParams(
rebinningParams, XValues_new.access());
ConvertToRelativeTime transformToRelativeT(runStartTime);
// Transform the output into relative times in seconds.
MantidVec OutXValues_scaled(XValues_new->size());
std::transform(XValues_new->begin(), XValues_new->end(),
OutXValues_scaled.begin(), transformToRelativeT);
outputWS = WorkspaceFactory::Instance().create("Workspace2D", histnumber,
ntcnew, ntcnew - 1);
WorkspaceFactory::Instance().initializeFromParent(inWS, outputWS, true);
// Copy all the axes
for (int i = 1; i < inWS->axes(); i++) {
outputWS->replaceAxis(i, inWS->getAxis(i)->clone(outputWS.get()));
outputWS->getAxis(i)->unit() = inWS->getAxis(i)->unit();
}
// X-unit is relative time since the start of the run.
outputWS->getAxis(0)->unit() = boost::make_shared<Units::Time>();
// Copy the units over too.
for (int i = 1; i < outputWS->axes(); ++i) {
outputWS->getAxis(i)->unit() = inWS->getAxis(i)->unit();
}
outputWS->setYUnit(inWS->YUnit());
outputWS->setYUnitLabel(inWS->YUnitLabel());
// Assign it to the output workspace property
setProperty("OutputWorkspace", outputWS);
// Go through all the histograms and set the data
doHistogramming(inWS, outputWS, XValues_new, OutXValues_scaled, prog);
}
示例3: ConvertToRelativeTime
explicit ConvertToRelativeTime(const DateAndTime &offSet)
: m_offSet(static_cast<double>(offSet.totalNanoseconds()) * 1e-9) {}