本文整理汇总了C++中nexus::File::getSlab方法的典型用法代码示例。如果您正苦于以下问题:C++ File::getSlab方法的具体用法?C++ File::getSlab怎么用?C++ File::getSlab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nexus::File
的用法示例。
在下文中一共展示了File::getSlab方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadTof
/** Open and load the times-of-flight data
*/
void LoadBankFromDiskTask::loadTof(::NeXus::File &file) {
// Allocate the array
auto temp = new float[m_loadSize[0]];
delete[] m_event_time_of_flight;
m_event_time_of_flight = temp;
// Get the list of event_time_of_flight's
if (!m_oldNexusFileNames)
file.openData("event_time_offset");
else
file.openData("event_time_of_flight");
// Check that the required space is there in the file.
::NeXus::Info tof_info = file.getInfo();
int64_t tof_dim0 = recalculateDataSize(tof_info.dims[0]);
if (tof_dim0 < m_loadSize[0] + m_loadStart[0]) {
m_loader.alg->getLogger().warning()
<< "Entry " << entry_name << "'s event_time_offset field is too small "
"to load the desired data.\n";
m_loadError = true;
}
// Check that the type is what it is supposed to be
if (tof_info.type == ::NeXus::FLOAT32)
file.getSlab(m_event_time_of_flight, m_loadStart, m_loadSize);
else {
m_loader.alg->getLogger().warning()
<< "Entry " << entry_name
<< "'s event_time_offset field is not FLOAT32! It will be skipped.\n";
m_loadError = true;
}
if (!m_loadError) {
std::string units;
file.getAttr("units", units);
if (units != "microsecond") {
m_loader.alg->getLogger().warning()
<< "Entry " << entry_name << "'s event_time_offset field's units are "
"not microsecond. It will be skipped.\n";
m_loadError = true;
}
file.closeData();
} // no error
}
示例2: catch
/** Load weight of weigthed events if they exist
* @param file An NeXus::File object opened at the correct group
* @returns A new array containing the weights or a nullptr if the weights
* are not present
*/
std::unique_ptr<float[]>
LoadBankFromDiskTask::loadEventWeights(::NeXus::File &file) {
try {
// First, get info about the event_weight field in this bank
file.openData("event_weight");
} catch (::NeXus::Exception &) {
// Field not found error is most likely.
m_have_weight = false;
return std::unique_ptr<float[]>();
}
// OK, we've got them
m_have_weight = true;
// Allocate the array
auto event_weight = Mantid::Kernel::make_unique<float[]>(m_loadSize[0]);
::NeXus::Info weight_info = file.getInfo();
int64_t weight_dim0 = recalculateDataSize(weight_info.dims[0]);
if (weight_dim0 < m_loadSize[0] + m_loadStart[0]) {
m_loader.alg->getLogger().warning()
<< "Entry " << entry_name
<< "'s event_weight field is too small to load the desired data.\n";
m_loadError = true;
}
// Check that the type is what it is supposed to be
if (weight_info.type == ::NeXus::FLOAT32)
file.getSlab(event_weight.get(), m_loadStart, m_loadSize);
else {
m_loader.alg->getLogger().warning()
<< "Entry " << entry_name
<< "'s event_weight field is not FLOAT32! It will be skipped.\n";
m_loadError = true;
}
if (!m_loadError) {
file.closeData();
}
return event_weight;
}
示例3: recalculateDataSize
/** Load the event_id field, which has been opened
* @param file An NeXus::File object opened at the correct group
* @returns A new array containing the event Ids for this bank
*/
std::unique_ptr<uint32_t[]>
LoadBankFromDiskTask::loadEventId(::NeXus::File &file) {
// This is the data size
::NeXus::Info id_info = file.getInfo();
int64_t dim0 = recalculateDataSize(id_info.dims[0]);
// Now we allocate the required arrays
auto event_id = Mantid::Kernel::make_unique<uint32_t[]>(m_loadSize[0]);
// Check that the required space is there in the file.
if (dim0 < m_loadSize[0] + m_loadStart[0]) {
m_loader.alg->getLogger().warning()
<< "Entry " << entry_name << "'s event_id field is too small (" << dim0
<< ") to load the desired data size (" << m_loadSize[0] + m_loadStart[0]
<< ").\n";
m_loadError = true;
}
if (m_loader.alg->getCancel())
m_loadError = true; // To allow cancelling the algorithm
if (!m_loadError) {
// Must be uint32
if (id_info.type == ::NeXus::UINT32)
file.getSlab(event_id.get(), m_loadStart, m_loadSize);
else {
m_loader.alg->getLogger().warning()
<< "Entry " << entry_name
<< "'s event_id field is not UINT32! It will be skipped.\n";
m_loadError = true;
}
file.closeData();
// determine the range of pixel ids
for (int64_t i = 0; i < m_loadSize[0]; ++i) {
const auto id = event_id[i];
if (id < m_min_id)
m_min_id = id;
if (id > m_max_id)
m_max_id = id;
}
if (m_min_id > static_cast<uint32_t>(m_loader.eventid_max)) {
// All the detector IDs in the bank are higher than the highest 'known'
// (from the IDF)
// ID. Setting this will abort the loading of the bank.
m_loadError = true;
}
// fixup the minimum pixel id in the case that it's lower than the lowest
// 'known' id. We test this by checking that when we add the offset we
// would not get a negative index into the vector. Note that m_min_id is
// a uint so we have to be cautious about adding it to an int which may be
// negative.
if (static_cast<int32_t>(m_min_id) + m_loader.pixelID_to_wi_offset < 0) {
m_min_id = static_cast<uint32_t>(abs(m_loader.pixelID_to_wi_offset));
}
// fixup the maximum pixel id in the case that it's higher than the
// highest 'known' id
if (m_max_id > static_cast<uint32_t>(m_loader.eventid_max))
m_max_id = static_cast<uint32_t>(m_loader.eventid_max);
}
return event_id;
}
示例4: progInitial
//.........这里部分代码省略.........
}
if (!isAnyNeutrons && nNeutrons > 0)
isAnyNeutrons = true;
std::vector<int64_t> start(2);
std::vector<int64_t> step(2);
// read the event data in blocks. 1 million event is 1000000*6*8 doubles
// about 50Mb
int64_t nNeutronsInBlock = 1000000;
int64_t nOfFullBlocks = nNeutrons / nNeutronsInBlock;
int64_t nRemainingNeutrons = nNeutrons - nOfFullBlocks * nNeutronsInBlock;
// sum over number of blocks + 1 to cover the remainder
for (int64_t iBlock = 0; iBlock < nOfFullBlocks + 1; iBlock++) {
if (iBlock == nOfFullBlocks) {
// read remaining neutrons
start[0] = nOfFullBlocks * nNeutronsInBlock;
start[1] = 0;
step[0] = nRemainingNeutrons;
step[1] = numberOfDataColumn;
} else {
// read neutrons in a full block
start[0] = iBlock * nNeutronsInBlock;
start[1] = 0;
step[0] = nNeutronsInBlock;
step[1] = numberOfDataColumn;
}
const int64_t nNeutronsForthisBlock =
step[0]; // number of neutrons read for this block
data.resize(nNeutronsForthisBlock * numberOfDataColumn);
// Check that the type is what it is supposed to be
if (id_info.type == ::NeXus::FLOAT64) {
nxFile.getSlab(&data[0], start, step);
} else {
g_log.warning()
<< "Entry event field is not FLOAT64! It will be skipped.\n";
continue;
}
// populate workspace with McStas events
const detid2index_map detIDtoWSindex_map =
allEventWS[0].first->getDetectorIDToWorkspaceIndexMap(true);
progEntries.report("read event data into workspace");
for (int64_t in = 0; in < nNeutronsForthisBlock; in++) {
const int detectorID =
static_cast<int>(data[4 + numberOfDataColumn * in]);
const double detector_time = data[5 + numberOfDataColumn * in] *
1.0e6; // convert to microseconds
if (in == 0 && iBlock == 0) {
shortestTOF = detector_time;
longestTOF = detector_time;
} else {
if (detector_time < shortestTOF)
shortestTOF = detector_time;
if (detector_time > longestTOF)
longestTOF = detector_time;
}
const size_t workspaceIndex =
detIDtoWSindex_map.find(detectorID)->second;
int64_t pulse_time = 0;
auto weightedEvent = WeightedEvent();
if (errorBarsSetTo1) {
示例5: readEventData
//.........这里部分代码省略.........
}
if (isAnyNeutrons == false && nNeutrons > 0)
isAnyNeutrons = true;
std::vector<int64_t> start(2);
std::vector<int64_t> step(2);
// read the event data in blocks. 1 million event is 1000000*6*8 doubles
// about 50Mb
int64_t nNeutronsInBlock = 1000000;
int64_t nOfFullBlocks = nNeutrons / nNeutronsInBlock;
int64_t nRemainingNeutrons = nNeutrons - nOfFullBlocks * nNeutronsInBlock;
// sum over number of blocks + 1 to cover the remainder
for (int64_t iBlock = 0; iBlock < nOfFullBlocks + 1; iBlock++) {
if (iBlock == nOfFullBlocks) {
// read remaining neutrons
start[0] = nOfFullBlocks * nNeutronsInBlock;
start[1] = 0;
step[0] = nRemainingNeutrons;
step[1] = numberOfDataColumn;
} else {
// read neutrons in a full block
start[0] = iBlock * nNeutronsInBlock;
start[1] = 0;
step[0] = nNeutronsInBlock;
step[1] = numberOfDataColumn;
}
const int64_t nNeutronsForthisBlock =
step[0]; // number of neutrons read for this block
data.resize(nNeutronsForthisBlock * numberOfDataColumn);
// Check that the type is what it is supposed to be
if (id_info.type == ::NeXus::FLOAT64) {
nxFile.getSlab(&data[0], start, step);
} else {
g_log.warning()
<< "Entry event field is not FLOAT64! It will be skipped.\n";
continue;
}
// populate workspace with McStas events
const detid2index_map detIDtoWSindex_map =
eventWS->getDetectorIDToWorkspaceIndexMap(true);
progEntries.report("read event data into workspace");
for (int64_t in = 0; in < nNeutronsForthisBlock; in++) {
const int detectorID =
static_cast<int>(data[4 + numberOfDataColumn * in]);
const double detector_time = data[5 + numberOfDataColumn * in] *
1.0e6; // convert to microseconds
if (in == 0 && iBlock == 0) {
shortestTOF = detector_time;
longestTOF = detector_time;
} else {
if (detector_time < shortestTOF)
shortestTOF = detector_time;
if (detector_time > longestTOF)
longestTOF = detector_time;
}
const size_t workspaceIndex =
detIDtoWSindex_map.find(detectorID)->second;
int64_t pulse_time = 0;
// eventWS->getEventList(workspaceIndex) +=
// TofEvent(detector_time,pulse_time);