/** * * @param filename filename A full path to the input RAW file */ void LoadDetectorInfo::loadFromIsisNXS(const std::string &filename) { ::NeXus::File nxsFile(filename, NXACC_READ); // will throw if file can't be opened // two types of file: // - new type entry per detector // - old libisis with single pressure, thickness entry for whole file // hold data read from file DetectorInfo detInfo; std::map<std::string, std::string> entries; nxsFile.getEntries(entries); if (entries.find("full_reference_detector") != entries.end()) { nxsFile.openGroup("full_reference_detector", "NXIXTdetector"); readLibisisNxs(nxsFile, detInfo); nxsFile.closeGroup(); } else if (entries.find("detectors.dat") != entries.end()) { nxsFile.openGroup("detectors.dat", "NXEntry"); readNXSDotDat(nxsFile, detInfo); nxsFile.closeGroup(); } else { throw std::invalid_argument("Unknown NeXus file type"); } nxsFile.close(); // Start loop over detectors auto &pmap = m_workspace->instrumentParameters(); auto &wsDetInfo = m_workspace->mutableDetectorInfo(); int numDets = static_cast<int>(detInfo.ids.size()); for (int i = 0; i < numDets; ++i) { detid_t detID = detInfo.ids[i]; int code = detInfo.codes[i]; try { size_t index = wsDetInfo.indexOf(detID); if (wsDetInfo.isMonitor(index) || code == 1) continue; // Positions double l2 = detInfo.l2[i]; double theta = detInfo.theta[i]; double phi = detInfo.phi[i]; // Parameters double delta = detInfo.delays[i]; // offset value is be subtracted so store negative delta *= -1.0; // pressure, wall thickness double pressure = detInfo.pressures[i]; double thickness = detInfo.thicknesses[i]; updateParameterMap(wsDetInfo, index, pmap, l2, theta, phi, delta, pressure, thickness); } catch (std::out_of_range &) { continue; } } }
/** * @param filename A full path to the input RAW file */ void LoadDetectorInfo::loadFromRAW(const std::string &filename) { ISISRAW2 iraw; if (iraw.readFromFile(filename.c_str(), false) != 0) { throw Exception::FileError("Unable to access raw file:", filename); } const int numDets = iraw.i_det; const int numUserTables = iraw.i_use; int pressureTabNum(0), thicknessTabNum(0); if (numUserTables == 10) { pressureTabNum = 7; thicknessTabNum = 8; } else if (numUserTables == 14) { pressureTabNum = 11; thicknessTabNum = 12; } else { throw std::invalid_argument( "RAW file contains unexpected number of user tables=" + std::to_string(numUserTables) + ". Expected 10 or 14."); } // Is ut01 (=phi) present? Sometimes an array is present but has wrong values // e.g.all 1.0 or all 2.0 bool phiPresent = (iraw.ut[0] != 1.0 && iraw.ut[0] != 2.0); // Start loop over detectors auto &pmap = m_workspace->instrumentParameters(); auto &wsDetInfo = m_workspace->mutableDetectorInfo(); for (int i = 0; i < numDets; ++i) { detid_t detID = static_cast<detid_t>(iraw.udet[i]); int code = iraw.code[i]; try { size_t index = wsDetInfo.indexOf(detID); if (wsDetInfo.isMonitor(index) || code == 1) continue; // Positions float l2 = iraw.len2[i]; float theta = iraw.tthe[i]; float phi = (phiPresent ? iraw.ut[i] : 0.0f); // Parameters float delta = iraw.delt[i]; // offset value is be subtracted so store negative delta *= -1.0f; // pressure, wall thickness float pressure = iraw.ut[i + pressureTabNum * numDets]; float thickness = iraw.ut[i + thicknessTabNum * numDets]; updateParameterMap(wsDetInfo, index, pmap, l2, theta, phi, delta, pressure, thickness); } catch (std::out_of_range &) { continue; } } }
/** * Full format is defined in doc text * @param filename A full path to the input DAT file */ void LoadDetectorInfo::loadFromDAT(const std::string & filename) { std::ifstream datFile(filename.c_str()); if(!datFile) { throw Exception::FileError("Unable to access dat file", filename); } std::string line; // skip 3 lines of header info for(int i = 0; i < 3; ++i) getline(datFile, line); // start loop over file auto & pmap = m_workspace->instrumentParameters(); while(getline(datFile, line)) { if(line.empty() || line[0] == '#') continue; std::istringstream is(line); detid_t detID(0); int code(0); float droppedFloat(0.0f); float delta(0.0f), l2(0.0f), theta(0.0f), phi(0.0f); is >> detID >> delta >> l2 >> code >> theta >> phi; // offset value is be subtracted so store negative delta *= -1.0f; IDetector_const_sptr det; try { det = m_baseInstrument->getDetector(detID); } catch(Exception::NotFoundError&) { continue; } if(det->isMonitor() || code == 1) continue; // drop 10 float columns for(int i = 0; i < 10; ++i) is >> droppedFloat; // pressure, wall thickness float pressure(0.0), thickness(0.0); is >> pressure >> thickness; updateParameterMap(pmap, det, l2, theta, phi, delta, pressure, thickness); } }