36 std::string grpName(
"Specify the Instrument");
40 "Optional: An input workspace with the instrument we want to use.");
43 "Optional: Name of the instrument to base the "
44 "GroupingWorkspace on which to base the "
45 "GroupingWorkspace.");
48 "Optional: Path to the instrument definition file on "
49 "which to base the GroupingWorkspace.");
51 alg->setPropertyGroup(
"InputWorkspace", grpName);
52 alg->setPropertyGroup(
"InstrumentName", grpName);
53 alg->setPropertyGroup(
"InstrumentFilename", grpName);
62 if (!InstrumentName.empty())
65 std::string InstrumentFilename = alg->
getPropertyValue(
"InstrumentFilename");
66 return !InstrumentFilename.empty();
76 std::string InstrumentFilename = alg->
getPropertyValue(
"InstrumentFilename");
82 if (!InstrumentName.empty())
84 if (!InstrumentFilename.empty())
88 throw std::invalid_argument(
"You must specify exactly ONE way to get an "
89 "instrument (workspace, instrument name, or "
90 "IDF file). You specified more than one.");
92 throw std::invalid_argument(
"You must specify exactly ONE way to get an "
93 "instrument (workspace, instrument name, or "
94 "IDF file). You specified none.");
99 inst = inWS->getInstrument();
104 childAlg->setPropertyValue(
"Filename", InstrumentFilename);
105 childAlg->setPropertyValue(
"InstrumentName", InstrumentName);
107 childAlg->executeAsChildAlg();
108 inst = tempWS->getInstrument();
121 "Path to the old-style .cal grouping/calibration file (multi-column "
122 "ASCII). You must also specify the instrument.");
125 "Set to true to create a GroupingWorkspace with called "
126 "WorkspaceName_group.");
129 "Set to true to create a OffsetsWorkspace with called "
130 "WorkspaceName_offsets.");
133 "Set to true to create a MaskWorkspace with called WorkspaceName_mask.");
136 "The base of the output workspace names. Names will have '_group', "
137 "'_cal', '_offsets', '_mask' appended to them.");
146 bool MakeGroupingWorkspace =
getProperty(
"MakeGroupingWorkspace");
147 bool MakeOffsetsWorkspace =
getProperty(
"MakeOffsetsWorkspace");
148 bool MakeMaskWorkspace =
getProperty(
"MakeMaskWorkspace");
150 if (WorkspaceName.empty())
151 throw std::invalid_argument(
"Must specify WorkspaceName.");
160 std::string title = Poco::Path(CalFilename).getFileName();
163 if (MakeGroupingWorkspace) {
165 groupWS->setTitle(title);
168 "Set the the output GroupingWorkspace, if any.");
169 groupWS->mutableRun().addProperty(
"Filename", CalFilename);
173 if (MakeOffsetsWorkspace) {
175 offsetsWS->setTitle(title);
178 "Set the the output OffsetsWorkspace, if any.");
179 offsetsWS->mutableRun().addProperty(
"Filename", CalFilename);
183 if (MakeMaskWorkspace) {
185 maskWS->setTitle(title);
188 "Set the the output MaskWorkspace, if any.");
189 maskWS->mutableRun().addProperty(
"Filename", CalFilename);
195 if (MakeOffsetsWorkspace) {
197 alg->setProperty(
"OffsetsWorkspace", offsetsWS);
198 alg->executeAsChildAlg();
200 calWS->setTitle(title);
203 "Set the output Diffraction Calibration workspace, if any.");
221 auto doGroup = bool(groupWS);
222 auto doOffsets = bool(offsetsWS);
223 auto doMask = bool(maskWS);
225 bool hasUnmasked(
false);
226 bool hasGrouped(
false);
228 if (!doOffsets && !doGroup && !doMask)
229 throw std::invalid_argument(
"You must give at least one of the grouping, "
230 "offsets or masking workspaces.");
232 std::ifstream grFile(calFileName.c_str());
234 throw std::runtime_error(
"Unable to open calibration file " + calFileName);
237 size_t numErrors = 0;
241 detID_to_wi = maskWS->getDetectorIDToWorkspaceIndexMap();
246 int n, udet, select, group;
247 double n_d, udet_d, offset, select_d, group_d;
251 maskSpectrumInfo = &maskWS->mutableSpectrumInfo();
253 while (getline(grFile, str)) {
254 if (str.empty() || str[0] ==
'#')
256 std::istringstream istr(str);
259 istr >> n_d >> udet_d >> offset >> select_d >> group_d;
260 n =
static_cast<int>(n_d);
261 udet =
static_cast<int>(udet_d);
262 select =
static_cast<int>(select_d);
263 group =
static_cast<int>(group_d);
268 std::stringstream msg;
269 msg <<
"Encountered offset = " << offset <<
" at index " <<
n <<
" for udet = " << udet
270 <<
". Offsets must be greater than -1.";
271 throw std::runtime_error(msg.str());
275 offsetsWS->setValue(udet, offset);
276 }
catch (std::invalid_argument &) {
278 if (!
idIsMonitor(offsetsWS->getInstrument(), udet))
285 groupWS->setValue(udet,
double(group));
286 if ((!hasGrouped) && (group > 0))
288 }
catch (std::invalid_argument &) {
296 detid2index_map::const_iterator it = detID_to_wi.find(udet);
297 if (it != detID_to_wi.end()) {
298 size_t wi = it->second;
302 maskWS->getSpectrum(wi).clearData();
303 maskSpectrumInfo->setMasked(wi,
true);
304 maskWS->mutableY(wi)[0] = 1.0;
307 maskWS->mutableY(wi)[0] = 0.0;
322 Logger(
"LoadCalFile").
warning() << numErrors <<
" errors (invalid Detector ID's) found when reading .cal file '"
323 << calFileName <<
"'.\n";
324 if (doGroup && (!hasGrouped))
325 Logger(
"LoadCalFile").
warning() <<
"'" << calFileName <<
"' has no spectra grouped\n";
326 if (doMask && (!hasUnmasked))
327 Logger(
"LoadCalFile").
warning() <<
"'" << calFileName <<
"' masks all spectra\n";
338 auto monitorList = inst->getMonitors();
339 auto it = std::find(monitorList.begin(), monitorList.end(), detID);
340 return (it != monitorList.end());
343Parallel::ExecutionMode
349 static_cast<void>(storageModes);
350 return Parallel::ExecutionMode::Identical;
#define DECLARE_ALGORITHM(classname)
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
@ Load
allowed here which will be passed to the algorithm
API::SpectrumInfo is an intermediate step towards a SpectrumInfo that is part of Instrument-2....
A property class for workspaces.
Algorithm to load a 5-column ascii .cal file into up to 3 workspaces: a GroupingWorkspace,...
Parallel::ExecutionMode getParallelExecutionMode(const std::map< std::string, Parallel::StorageMode > &storageModes) const override
Get correct execution mode based on input storage modes for an MPI run.
static bool idIsMonitor(const Mantid::Geometry::Instrument_const_sptr &inst, int detID)
Checks if a detector ID is for a monitor on a given instrument.
void exec() override
Run the algorithm.
static bool instrumentIsSpecified(API::Algorithm *alg)
static void getInstrument3WaysInit(Mantid::API::Algorithm *alg)
For use by getInstrument3Ways, initializes the properties.
void init() override
Initialise the properties.
static Geometry::Instrument_const_sptr getInstrument3Ways(API::Algorithm *alg)
Get a pointer to an instrument in one of 3 ways: InputWorkspace, InstrumentName, InstrumentFilename.
static void readCalFile(const std::string &calFileName, const Mantid::DataObjects::GroupingWorkspace_sptr &groupWS, const Mantid::DataObjects::OffsetsWorkspace_sptr &offsetsWS, const Mantid::DataObjects::MaskWorkspace_sptr &maskWS)
Reads the calibration file.
A GroupingWorkspace is a subclass of Workspace2D where each spectrum has a single number entry,...
An OffsetsWorkspace is a specialized Workspace2D where the Y value at each pixel is the offset to be ...
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
The Logger class is in charge of the publishing messages from the framework through various channels.
void warning(const std::string &msg)
Logs at warning level.
OptionalBool : Tri-state bool.
The concrete, templated class for properties.
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< GroupingWorkspace > GroupingWorkspace_sptr
shared pointer to the GroupingWorkspace class
std::shared_ptr< MaskWorkspace > MaskWorkspace_sptr
shared pointer to the MaskWorkspace class
std::shared_ptr< OffsetsWorkspace > OffsetsWorkspace_sptr
shared pointer to the OffsetsWorkspace class
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
@ Input
An input workspace.
@ Output
An output workspace.