本文整理汇总了C++中nexus::File::readData方法的典型用法代码示例。如果您正苦于以下问题:C++ File::readData方法的具体用法?C++ File::readData怎么用?C++ File::readData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nexus::File
的用法示例。
在下文中一共展示了File::readData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: progInitial
/**
* Read Event Data
* @param eventEntries map of the file entries that have events
* @param nxFile Reads data from inside first top entry
* @return Names of workspaces to include in the output group
*/
std::vector<std::string> LoadMcStas::readEventData(
const std::map<std::string, std::string> &eventEntries,
::NeXus::File &nxFile) {
// vector to store output workspaces
std::vector<std::string> scatteringWSNames;
std::string filename = getPropertyValue("Filename");
auto entries = nxFile.getEntries();
const bool errorBarsSetTo1 = getProperty("ErrorBarsSetTo1");
// will assume that each top level entry contain one mcstas
// generated IDF and any event data entries within this top level
// entry are data collected for that instrument
// This code for loading the instrument is for now adjusted code from
// ExperimentalInfo.
// Close data folder and go back to top level. Then read and close the
// Instrument folder.
nxFile.closeGroup();
Geometry::Instrument_sptr instrument;
// Initialize progress reporting
int reports = 2;
const double progressFractionInitial = 0.1;
Progress progInitial(this, 0.0, progressFractionInitial, reports);
std::string instrumentXML;
progInitial.report("Loading instrument");
try {
nxFile.openGroup("instrument", "NXinstrument");
nxFile.openGroup("instrument_xml", "NXnote");
nxFile.readData("data", instrumentXML);
nxFile.closeGroup();
nxFile.closeGroup();
} catch (...) {
g_log.warning()
<< "\nCould not find the instrument description in the Nexus file:"
<< filename << " Ignore eventdata from the Nexus file\n";
return scatteringWSNames;
;
}
try {
std::string instrumentName = "McStas";
Geometry::InstrumentDefinitionParser parser(filename, instrumentName,
instrumentXML);
std::string instrumentNameMangled = parser.getMangledName();
// Check whether the instrument is already in the InstrumentDataService
if (InstrumentDataService::Instance().doesExist(instrumentNameMangled)) {
// If it does, just use the one from the one stored there
instrument =
InstrumentDataService::Instance().retrieve(instrumentNameMangled);
} else {
// Really create the instrument
instrument = parser.parseXML(nullptr);
// Add to data service for later retrieval
InstrumentDataService::Instance().add(instrumentNameMangled, instrument);
}
} catch (Exception::InstrumentDefinitionError &e) {
g_log.warning()
<< "When trying to read the instrument description in the Nexus file: "
<< filename << " the following error is reported: " << e.what()
<< " Ignore eventdata from the Nexus file\n";
return scatteringWSNames;
;
} catch (...) {
g_log.warning()
<< "Could not parse instrument description in the Nexus file: "
<< filename << " Ignore eventdata from the Nexus file\n";
return scatteringWSNames;
;
}
// Finished reading Instrument. Then open new data folder again
nxFile.openGroup("data", "NXdetector");
// create and prepare an event workspace ready to receive the mcstas events
progInitial.report("Set up EventWorkspace");
EventWorkspace_sptr eventWS(new EventWorkspace());
// initialize, where create up front number of eventlists = number of
// detectors
eventWS->initialize(instrument->getNumberDetectors(), 1, 1);
// Set the units
eventWS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
eventWS->setYUnit("Counts");
// set the instrument
eventWS->setInstrument(instrument);
// assign detector ID to eventlists
std::vector<detid_t> detIDs = instrument->getDetectorIDs();
for (size_t i = 0; i < instrument->getNumberDetectors(); i++) {
//.........这里部分代码省略.........
示例2: readMuonLogData
bool MuonNexusReader::readMuonLogData(NeXus::File &handle) {
const string NAME("name");
const string VALUES("values");
const string TIME("time");
// read name of Log data
string dataName;
handle.readData(NAME, dataName);
// read data values
try {
handle.openData(VALUES);
} catch (NeXus::Exception &) {
g_log.warning() << "No " << VALUES << " set in " << handle.getPath()
<< "\n";
return false;
}
std::vector<float> values;
std::vector<std::string> stringValues;
bool isNumeric(false);
NeXus::Info info = handle.getInfo();
if (info.type == NX_FLOAT32 && info.dims.size() == 1) {
isNumeric = true;
boost::scoped_array<float> dataVals(new float[info.dims[0]]);
handle.getData(dataVals.get());
values.assign(dataVals.get(), dataVals.get() + info.dims[0]);
stringValues.resize(info.dims[0]); // Leave empty
} else if (info.type == NX_CHAR && info.dims.size() == 2) {
boost::scoped_array<char> dataVals(
new char[info.dims[0] * info.dims[1] + 1]);
handle.getData(dataVals.get());
dataVals[info.dims[0] * info.dims[1]] = 0;
for (int i = 0; i < info.dims[0]; ++i) {
std::string str(&dataVals[i * info.dims[1]],
&dataVals[(i + 1) * info.dims[1]]);
stringValues.push_back(str);
}
values.resize(info.dims[0]); // Leave empty
} else {
// Leave both empty
values.resize(info.dims[0]);
stringValues.resize(info.dims[0]);
}
handle.closeData();
// read time values
try {
handle.openData(TIME);
} catch (NeXus::Exception &) {
g_log.warning() << "No " << TIME << " set in " << handle.getPath() << "\n";
return false;
}
info = handle.getInfo();
boost::scoped_array<float> timeVals(new float[info.dims[0]]);
if (info.type == NX_FLOAT32 && info.dims.size() == 1) {
handle.getData(timeVals.get());
} else {
throw std::runtime_error(
"Error in MuonNexusReader: expected float array for log times");
}
handle.closeData();
// Add loaded values to vectors
logNames.push_back(dataName);
std::vector<float> tmp(timeVals.get(), timeVals.get() + info.dims[0]);
logTimes.push_back(tmp);
logType.push_back(isNumeric);
logValues.push_back(values);
logStringValues.push_back(stringValues);
return true;
}
示例3: readEventData
/**
* Return the confidence with with this algorithm can load the file
* @param eventEntries map of the file entries that have events
* @param outputGroup pointer to the workspace group
* @param nxFile Reads data from inside first first top entry
*/
void LoadMcStas::readEventData(
const std::map<std::string, std::string> &eventEntries,
WorkspaceGroup_sptr &outputGroup, ::NeXus::File &nxFile) {
std::string filename = getPropertyValue("Filename");
auto entries = nxFile.getEntries();
// will assume that each top level entry contain one mcstas
// generated IDF and any event data entries within this top level
// entry are data collected for that instrument
// This code for loading the instrument is for now adjusted code from
// ExperimentalInfo.
// Close data folder and go back to top level. Then read and close the
// Instrument folder.
nxFile.closeGroup();
Geometry::Instrument_sptr instrument;
// Initialize progress reporting
int reports = 2;
const double progressFractionInitial = 0.1;
Progress progInitial(this, 0.0, progressFractionInitial, reports);
try {
nxFile.openGroup("instrument", "NXinstrument");
std::string instrumentXML;
nxFile.openGroup("instrument_xml", "NXnote");
nxFile.readData("data", instrumentXML);
nxFile.closeGroup();
nxFile.closeGroup();
progInitial.report("Loading instrument");
Geometry::InstrumentDefinitionParser parser;
std::string instrumentName = "McStas";
parser.initialize(filename, instrumentName, instrumentXML);
std::string instrumentNameMangled = parser.getMangledName();
// Check whether the instrument is already in the InstrumentDataService
if (InstrumentDataService::Instance().doesExist(instrumentNameMangled)) {
// If it does, just use the one from the one stored there
instrument =
InstrumentDataService::Instance().retrieve(instrumentNameMangled);
} else {
// Really create the instrument
instrument = parser.parseXML(NULL);
// Add to data service for later retrieval
InstrumentDataService::Instance().add(instrumentNameMangled, instrument);
}
} catch (...) {
// Loader should not stop if there is no IDF.xml
g_log.warning()
<< "\nCould not find the instrument description in the Nexus file:"
<< filename << " Ignore evntdata from data file" << std::endl;
return;
}
// Finished reading Instrument. Then open new data folder again
nxFile.openGroup("data", "NXdetector");
// create and prepare an event workspace ready to receive the mcstas events
progInitial.report("Set up EventWorkspace");
EventWorkspace_sptr eventWS(new EventWorkspace());
// initialize, where create up front number of eventlists = number of
// detectors
eventWS->initialize(instrument->getNumberDetectors(), 1, 1);
// Set the units
eventWS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
eventWS->setYUnit("Counts");
// set the instrument
eventWS->setInstrument(instrument);
// assign detector ID to eventlists
std::vector<detid_t> detIDs = instrument->getDetectorIDs();
for (size_t i = 0; i < instrument->getNumberDetectors(); i++) {
eventWS->getEventList(i).addDetectorID(detIDs[i]);
// spectrum number are treated as equal to detector IDs for McStas data
eventWS->getEventList(i).setSpectrumNo(detIDs[i]);
}
// the one is here for the moment for backward compatibility
eventWS->rebuildSpectraMapping(true);
bool isAnyNeutrons = false;
// to store shortest and longest recorded TOF
double shortestTOF(0.0);
double longestTOF(0.0);
const size_t numEventEntries = eventEntries.size();
Progress progEntries(this, progressFractionInitial, 1.0, numEventEntries * 2);
for (auto eit = eventEntries.begin(); eit != eventEntries.end(); ++eit) {
std::string dataName = eit->first;
std::string dataType = eit->second;
// open second level entry
//.........这里部分代码省略.........