diff --git a/Framework/DataHandling/src/LoadANSTOHelper.cpp b/Framework/DataHandling/src/LoadANSTOHelper.cpp index 5cae0af5a124b94a446c34a9b90f697166c99a62..0e0d4cd38312c1f87890e8ba6147472319c7c583 100644 --- a/Framework/DataHandling/src/LoadANSTOHelper.cpp +++ b/Framework/DataHandling/src/LoadANSTOHelper.cpp @@ -17,12 +17,17 @@ namespace ANSTO { // ProgressTracker ProgressTracker::ProgressTracker(API::Progress &progBar, const char *msg, int64_t target, size_t count) - : m_msg(msg), m_count(count), m_step(target / count), m_next(m_step), - m_progBar(progBar) { + : m_msg(msg), + m_count(count), + m_step(target / count), + m_next(m_step), + m_progBar(progBar) { m_progBar.doReport(m_msg); } -ProgressTracker::~ProgressTracker() { complete(); } +ProgressTracker::~ProgressTracker() { + complete(); +} void ProgressTracker::update(int64_t position) { while (m_next <= position) { m_progBar.report(m_msg); @@ -50,17 +55,23 @@ void ProgressTracker::complete() { } // EventProcessor -EventProcessor::EventProcessor(const std::vector<bool> &roi, - const size_t stride, const double period, - const double phase, const double tofMinBoundary, +EventProcessor::EventProcessor(const std::vector<bool> &roi, const size_t stride, + const double period, const double phase, + const double tofMinBoundary, const double tofMaxBoundary, const double timeMinBoundary, const double timeMaxBoundary) - : m_roi(roi), m_stride(stride), m_frames(0), m_period(period), - m_phase(phase), m_tofMinBoundary(tofMinBoundary), - m_tofMaxBoundary(tofMaxBoundary), m_timeMinBoundary(timeMinBoundary), - m_timeMaxBoundary(timeMaxBoundary) {} -void EventProcessor::newFrame() { m_frames++; } + : m_roi(roi), m_stride(stride), + m_frames(0), + m_period(period), m_phase(phase), + m_tofMinBoundary(tofMinBoundary), + m_tofMaxBoundary(tofMaxBoundary), + m_timeMinBoundary(timeMinBoundary), + m_timeMaxBoundary(timeMaxBoundary) { +} +void EventProcessor::newFrame() { + m_frames++; +} void EventProcessor::addEvent(size_t x, size_t y, double tof) { // tof correction if (m_period > 0.0) { @@ -75,7 +86,7 @@ void EventProcessor::addEvent(size_t x, size_t y, double tof) { // frame boundary double frameTime = (m_frames * m_period) * 1e-6; // in seconds - if ((frameTime <= m_timeMinBoundary) || (frameTime > m_timeMaxBoundary)) + if ((frameTime < m_timeMinBoundary) || (frameTime > m_timeMaxBoundary)) return; // ToF boundary @@ -97,16 +108,17 @@ void EventProcessor::addEvent(size_t x, size_t y, double tof) { // EventCounter EventCounter::EventCounter(const std::vector<bool> &roi, const size_t stride, const double period, const double phase, - const double tofMinBoundary, - const double tofMaxBoundary, - const double timeMinBoundary, - const double timeMaxBoundary, + const double tofMinBoundary, const double tofMaxBoundary, + const double timeMinBoundary, const double timeMaxBoundary, std::vector<size_t> &eventCounts) - : EventProcessor(roi, stride, period, phase, tofMinBoundary, tofMaxBoundary, - timeMinBoundary, timeMaxBoundary), - m_eventCounts(eventCounts), m_tofMin(std::numeric_limits<double>::max()), - m_tofMax(std::numeric_limits<double>::min()) {} -size_t EventCounter::numFrames() const { return m_frames; } + : EventProcessor(roi, stride, period, phase, tofMinBoundary, tofMaxBoundary, timeMinBoundary, timeMaxBoundary), + m_eventCounts(eventCounts), + m_tofMin(std::numeric_limits<double>::max()), + m_tofMax(std::numeric_limits<double>::min()) { +} +size_t EventCounter::numFrames() const { + return m_frames; +} double EventCounter::tofMin() const { return m_tofMin <= m_tofMax ? m_tofMin : 0.0; } @@ -125,14 +137,12 @@ void EventCounter::addEventImpl(size_t id, double tof) { // EventAssigner EventAssigner::EventAssigner(const std::vector<bool> &roi, const size_t stride, const double period, const double phase, - const double tofMinBoundary, - const double tofMaxBoundary, - const double timeMinBoundary, - const double timeMaxBoundary, + const double tofMinBoundary, const double tofMaxBoundary, + const double timeMinBoundary, const double timeMaxBoundary, std::vector<EventVector_pt> &eventVectors) - : EventProcessor(roi, stride, period, phase, tofMinBoundary, tofMaxBoundary, - timeMinBoundary, timeMaxBoundary), - m_eventVectors(eventVectors) {} + : EventProcessor(roi, stride, period, phase, tofMinBoundary, tofMaxBoundary, timeMinBoundary, timeMaxBoundary), + m_eventVectors(eventVectors) { +} void EventAssigner::addEventImpl(size_t id, double tof) { m_eventVectors[id]->push_back(tof); } @@ -143,8 +153,12 @@ FastReadOnlyFile::FastReadOnlyFile(const char *filename) { m_handle = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); } -FastReadOnlyFile::~FastReadOnlyFile() { close(); } -void *FastReadOnlyFile::handle() const { return m_handle; } +FastReadOnlyFile::~FastReadOnlyFile() { + close(); +} +void *FastReadOnlyFile::handle() const { + return m_handle; +} void FastReadOnlyFile::close() { CloseHandle(m_handle); m_handle = NULL; @@ -162,8 +176,12 @@ bool FastReadOnlyFile::seek(int64_t offset, int whence, int64_t *newPosition) { FastReadOnlyFile::FastReadOnlyFile(const char *filename) { m_handle = fopen(filename, "rb"); } -FastReadOnlyFile::~FastReadOnlyFile() { close(); } -void *FastReadOnlyFile::handle() const { return m_handle; } +FastReadOnlyFile::~FastReadOnlyFile() { + close(); +} +void *FastReadOnlyFile::handle() const { + return m_handle; +} void FastReadOnlyFile::close() { fclose(m_handle); m_handle = NULL; @@ -179,16 +197,17 @@ bool FastReadOnlyFile::seek(int64_t offset, int whence, int64_t *newPosition) { #endif namespace Tar { - + void EntryHeader::writeChecksum() { memset(Checksum, ' ', sizeof(Checksum)); size_t value = std::accumulate( - (const char *)this, (const char *)this + sizeof(EntryHeader), (size_t)0); - + (const char*)this, + (const char*)this + sizeof(EntryHeader), + (size_t)0); + std::ostringstream buffer; - buffer << std::oct << std::setfill('0') << std::setw(sizeof(Checksum) - 1) - << value; + buffer << std::oct << std::setfill('0') << std::setw(sizeof(Checksum) - 1) << value; std::string string = buffer.str(); std::copy(string.cbegin(), string.cend(), Checksum); @@ -197,8 +216,7 @@ void EntryHeader::writeChecksum() { void EntryHeader::writeFileSize(int64_t value) { std::ostringstream buffer; - buffer << std::oct << std::setfill('0') << std::setw(sizeof(FileSize) - 1) - << value; + buffer << std::oct << std::setfill('0') << std::setw(sizeof(FileSize) - 1) << value; std::string string = buffer.str(); std::copy(string.cbegin(), string.cend(), FileSize); @@ -217,8 +235,8 @@ int64_t EntryHeader::readFileSize() { // construction File::File(const std::string &path) - : m_good(true), m_file(path.c_str()), m_selected(static_cast<size_t>(-1)), - m_position(0), m_size(0), m_bufferPosition(0), m_bufferAvailable(0) { + : m_good(true), m_file(path.c_str()), m_selected(static_cast<size_t>(-1)), m_position(0), + m_size(0), m_bufferPosition(0), m_bufferAvailable(0) { m_good = m_file.handle() != NULL; while (m_good) { @@ -263,13 +281,21 @@ void File::close() { } // properties -bool File::good() const { return m_good; } -const std::vector<std::string> &File::files() const { return m_fileNames; } +bool File::good() const { + return m_good; +} +const std::vector<std::string> &File::files() const { + return m_fileNames; +} const std::string &File::selected_name() const { return m_fileNames[m_selected]; } -int64_t File::selected_position() const { return m_position; } -int64_t File::selected_size() const { return m_size; } +int64_t File::selected_position() const { + return m_position; +} +int64_t File::selected_size() const { + return m_size; +} // methods bool File::select(const char *file) { @@ -382,11 +408,11 @@ int File::read_byte() { m_position++; return m_buffer[m_bufferPosition++]; } -bool File::append(const std::string &path, const std::string &name, - const void *buffer, size_t size) { - std::unique_ptr<FILE, decltype(&fclose)> handle(fopen(path.c_str(), "rb+"), - fclose); - +bool File::append(const std::string &path, const std::string &name, const void *buffer, size_t size) { + std::unique_ptr<FILE, decltype(&fclose)> handle( + fopen(path.c_str(), "rb+"), + fclose); + bool good = handle != NULL; int64_t lastHeaderPosition = 0; int64_t targetPosition = -1; @@ -396,7 +422,7 @@ bool File::append(const std::string &path, const std::string &name, int64_t position; lastHeaderPosition = static_cast<int64_t>(ftell(handle.get())); - + good &= 1 == fread(&header, sizeof(EntryHeader), 1, handle.get()); good &= 0 == fseek(handle.get(), 512 - sizeof(EntryHeader), SEEK_CUR); good &= 0 <= (position = static_cast<int64_t>(ftell(handle.get()))); @@ -407,12 +433,11 @@ bool File::append(const std::string &path, const std::string &name, std::string fileName(header.FileName); if (fileName.length() == 0) break; - + if (fileName.compare(name) == 0) targetPosition = lastHeaderPosition; else if (targetPosition != -1) - throw std::exception( - "format exception"); // it has to be the last file in the archive + throw std::exception("format exception"); // it has to be the last file in the archive FileInfo fileInfo; fileInfo.Offset = position; @@ -422,8 +447,7 @@ bool File::append(const std::string &path, const std::string &name, if (offset != 0) offset = 512 - offset; - good &= 0 == fseek(handle.get(), static_cast<long>(fileInfo.Size + offset), - SEEK_CUR); + good &= 0 == fseek(handle.get(), static_cast<long>(fileInfo.Size + offset), SEEK_CUR); } if (!good) @@ -431,7 +455,7 @@ bool File::append(const std::string &path, const std::string &name, if (targetPosition == -1) targetPosition = lastHeaderPosition; - + // empty buffer char padding[512]; memset(padding, 0, 512); @@ -444,7 +468,7 @@ bool File::append(const std::string &path, const std::string &name, memset(header.OwnerUserID, '0', sizeof(header.OwnerUserID) - 1); memset(header.OwnerGroupID, '0', sizeof(header.OwnerGroupID) - 1); memset(header.LastModification, '0', sizeof(header.LastModification) - 1); - + header.TypeFlag = TarTypeFlag_NormalFile; header.writeFileSize(size); header.writeChecksum(); @@ -456,7 +480,7 @@ bool File::append(const std::string &path, const std::string &name, // write content good &= 1 == fwrite(buffer, size, 1, handle.get()); - + // write padding size_t offset = static_cast<size_t>(size % 512); if (offset != 0) { diff --git a/Framework/DataHandling/src/LoadBBY.cpp b/Framework/DataHandling/src/LoadBBY.cpp index 8ffce50352c3f2cc46856d1c666d1ba25145ff71..4a98f7ed3b473d0a49c0b0c9d9297b620193d59f 100644 --- a/Framework/DataHandling/src/LoadBBY.cpp +++ b/Framework/DataHandling/src/LoadBBY.cpp @@ -27,21 +27,20 @@ static const size_t HISTO_BINS_Y = 256; // 100 = 40 + 20 + 40 static const size_t Progress_LoadBinFile = 48; static const size_t Progress_ReserveMemory = 4; -static const size_t Progress_Total = - 2 * Progress_LoadBinFile + Progress_ReserveMemory; +static const size_t Progress_Total = 2 * Progress_LoadBinFile + Progress_ReserveMemory; -static char const *const FilenameStr = "Filename"; -static char const *const MaskStr = "Mask"; +static char const* const FilenameStr = "Filename"; +static char const* const MaskStr = "Mask"; -static char const *const PeriodMasterStr = "PeriodMaster"; -static char const *const PeriodSlaveStr = "PeriodSlave"; -static char const *const PhaseSlaveStr = "PhaseSlave"; +static char const* const PeriodMasterStr = "PeriodMaster"; +static char const* const PeriodSlaveStr = "PeriodSlave"; +static char const* const PhaseSlaveStr = "PhaseSlave"; -static char const *const FilterByTofMinStr = "FilterByTofMin"; -static char const *const FilterByTofMaxStr = "FilterByTofMax"; +static char const* const FilterByTofMinStr = "FilterByTofMin"; +static char const* const FilterByTofMaxStr = "FilterByTofMax"; -static char const *const FilterByTimeStartStr = "FilterByTimeStart"; -static char const *const FilterByTimeStopStr = "FilterByTimeStop"; +static char const* const FilterByTimeStartStr = "FilterByTimeStart"; +static char const* const FilterByTimeStopStr = "FilterByTimeStop"; using ANSTO::EventVector_pt; @@ -51,8 +50,7 @@ void AddSinglePointTimeSeriesProperty(API::LogManager &logManager, const std::string &name, const TYPE value) { // create time series property and add single value - Kernel::TimeSeriesProperty<TYPE> *p = - new Kernel::TimeSeriesProperty<TYPE>(name); + Kernel::TimeSeriesProperty<TYPE> *p = new Kernel::TimeSeriesProperty<TYPE>(name); p->addValue(time, value); // add to log manager @@ -138,22 +136,24 @@ void LoadBBY::init() { // OutputWorkspace declareProperty(new API::WorkspaceProperty<API::IEventWorkspace>( "OutputWorkspace", "", Kernel::Direction::Output)); - + // FilterByTofMin - declareProperty(new Kernel::PropertyWithValue<double>( - FilterByTofMinStr, 0, Kernel::Direction::Input), - "Optional: To exclude events that do not fall within a range " - "of times-of-flight. " - "This is the minimum accepted value in microseconds. Keep " - "blank to load all events."); + declareProperty( + new Kernel::PropertyWithValue<double>(FilterByTofMinStr, 0, + Kernel::Direction::Input), + "Optional: To exclude events that do not fall within a range " + "of times-of-flight. " + "This is the minimum accepted value in microseconds. Keep " + "blank to load all events."); // FilterByTofMax - declareProperty(new Kernel::PropertyWithValue<double>( - FilterByTofMaxStr, EMPTY_DBL(), Kernel::Direction::Input), - "Optional: To exclude events that do not fall within a range " - "of times-of-flight. " - "This is the maximum accepted value in microseconds. Keep " - "blank to load all events."); + declareProperty( + new Kernel::PropertyWithValue<double>(FilterByTofMaxStr, EMPTY_DBL(), + Kernel::Direction::Input), + "Optional: To exclude events that do not fall within a range " + "of times-of-flight. " + "This is the maximum accepted value in microseconds. Keep " + "blank to load all events."); // FilterByTimeStart declareProperty( @@ -171,13 +171,13 @@ void LoadBBY::init() { // period and phase declareProperty(new Kernel::PropertyWithValue<double>( - PeriodMasterStr, EMPTY_DBL(), Kernel::Direction::Input), + PeriodMasterStr, EMPTY_DBL(), Kernel::Direction::Input), "Optional"); declareProperty(new Kernel::PropertyWithValue<double>( - PeriodSlaveStr, EMPTY_DBL(), Kernel::Direction::Input), + PeriodSlaveStr, EMPTY_DBL(), Kernel::Direction::Input), "Optional"); declareProperty(new Kernel::PropertyWithValue<double>( - PhaseSlaveStr, EMPTY_DBL(), Kernel::Direction::Input), + PhaseSlaveStr, EMPTY_DBL(), Kernel::Direction::Input), "Optional"); std::string grpOptional = "Filters"; @@ -204,20 +204,21 @@ void LoadBBY::exec() { std::string filename = getPropertyValue(FilenameStr); ANSTO::Tar::File tarFile(filename); if (!tarFile.good()) - throw std::invalid_argument("invalid BBY file"); + throw std::invalid_argument("invalid BBY file"); // region of intreset std::vector<bool> roi = createRoiVector(getPropertyValue(MaskStr)); - + double tofMinBoundary = getProperty(FilterByTofMinStr); double tofMaxBoundary = getProperty(FilterByTofMaxStr); - + double timeMinBoundary = getProperty(FilterByTimeStartStr); double timeMaxBoundary = getProperty(FilterByTimeStopStr); - + + if (isEmpty(tofMaxBoundary)) + tofMaxBoundary = std::numeric_limits<double>::infinity(); if (isEmpty(timeMaxBoundary)) - timeMaxBoundary = - std::numeric_limits<decltype(timeMaxBoundary)>::infinity(); + timeMaxBoundary = std::numeric_limits<double>::infinity(); API::Progress prog(this, 0.0, 1.0, Progress_Total); prog.doReport("creating instrument"); @@ -252,57 +253,61 @@ void LoadBBY::exec() { // create instrument InstrumentInfo instrumentInfo; - - // Geometry::Instrument_sptr instrument = - createInstrument(tarFile, /* ref */ instrumentInfo); - // eventWS->setInstrument(instrument); + + //Geometry::Instrument_sptr instrument = + createInstrument(tarFile, /* ref */ instrumentInfo); + //eventWS->setInstrument(instrument); // load events size_t numberHistograms = eventWS->getNumberHistograms(); std::vector<EventVector_pt> eventVectors(numberHistograms, NULL); std::vector<size_t> eventCounts(numberHistograms, 0); - + // phase correction - Kernel::Property *periodMasterProperty = - getPointerToProperty(PeriodMasterStr); - Kernel::Property *periodSlaveProperty = getPointerToProperty(PeriodSlaveStr); - Kernel::Property *phaseSlaveProperty = getPointerToProperty(PhaseSlaveStr); - + Kernel::Property* periodMasterProperty = getPointerToProperty(PeriodMasterStr); + Kernel::Property* periodSlaveProperty = getPointerToProperty(PeriodSlaveStr); + Kernel::Property* phaseSlaveProperty = getPointerToProperty(PhaseSlaveStr); + double periodMaster; double periodSlave; double phaseSlave; - if (periodMasterProperty->isDefault() || periodSlaveProperty->isDefault() || + if (periodMasterProperty->isDefault() || + periodSlaveProperty->isDefault() || phaseSlaveProperty->isDefault()) { - + if (!periodMasterProperty->isDefault() || - !periodSlaveProperty->isDefault() || !phaseSlaveProperty->isDefault()) { - throw std::invalid_argument("Please specify PeriodMaster, PeriodSlave " - "and PhaseSlave or none of them."); + !periodSlaveProperty->isDefault() || + !phaseSlaveProperty->isDefault()) { + throw std::invalid_argument("Please specify PeriodMaster, PeriodSlave and PhaseSlave or none of them."); } - + // if values have not been specified in loader then use values from hdf file periodMaster = instrumentInfo.period_master; periodSlave = instrumentInfo.period_slave; phaseSlave = instrumentInfo.phase_slave; - } else { + } + else { periodMaster = getProperty(PeriodMasterStr); periodSlave = getProperty(PeriodSlaveStr); phaseSlave = getProperty(PhaseSlaveStr); if ((periodMaster < 0.0) || (periodSlave < 0.0)) - throw std::invalid_argument( - "Please specify a positive value for PeriodMaster and PeriodSlave."); + throw std::invalid_argument("Please specify a positive value for PeriodMaster and PeriodSlave."); } - + double period = periodSlave; - double shift = -1.0 / 6.0 * periodMaster - periodSlave * phaseSlave / 360.0; + double shift = -1.0/6.0*periodMaster - periodSlave * phaseSlave / 360.0; // count total events per pixel to reserve necessary memory - ANSTO::EventCounter eventCounter( - roi, HISTO_BINS_Y, period, shift, tofMinBoundary, tofMaxBoundary, - timeMinBoundary, timeMaxBoundary, eventCounts); + ANSTO::EventCounter eventCounter(roi, HISTO_BINS_Y, + period, shift, + tofMinBoundary, + tofMaxBoundary, + timeMinBoundary, + timeMaxBoundary, + eventCounts); loadEvents(prog, "loading neutron counts", tarFile, eventCounter); @@ -313,7 +318,8 @@ void LoadBBY::exec() { for (size_t i = 0; i != numberHistograms; ++i) { DataObjects::EventList &eventList = eventWS->getEventList(i); - eventList.setSortOrder(DataObjects::PULSETIME_SORT); + eventList.setSortOrder( + DataObjects::PULSETIME_SORT); eventList.reserve(eventCounts[i]); eventList.setDetectorID(static_cast<detid_t>(i)); @@ -324,19 +330,21 @@ void LoadBBY::exec() { progTracker.update(i); } progTracker.complete(); - - ANSTO::EventAssigner eventAssigner( - roi, HISTO_BINS_Y, period, shift, tofMinBoundary, tofMaxBoundary, - timeMinBoundary, timeMaxBoundary, eventVectors); + + ANSTO::EventAssigner eventAssigner(roi, HISTO_BINS_Y, + period, shift, + tofMinBoundary, + tofMaxBoundary, + timeMinBoundary, + timeMaxBoundary, + eventVectors); loadEvents(prog, "loading neutron events", tarFile, eventAssigner); Kernel::cow_ptr<MantidVec> axis; MantidVec &xRef = axis.access(); xRef.resize(2, 0.0); - xRef[0] = std::max( - 0.0, - floor(eventCounter.tofMin())); // just to make sure the bins hold it all + xRef[0] = std::max(0.0, floor(eventCounter.tofMin())); // just to make sure the bins hold it all xRef[1] = eventCounter.tofMax() + 1; eventWS->setAllX(axis); @@ -360,26 +368,21 @@ void LoadBBY::exec() { maskingAlg->setProperty("WorkspaceIndexList", maskIndexList); maskingAlg->executeAsChildAlg(); } - + // set log values API::LogManager &logManager = eventWS->mutableRun(); - + logManager.addProperty("filename", filename); logManager.addProperty("att_pos", static_cast<int>(instrumentInfo.att_pos)); - logManager.addProperty("frame_count", - static_cast<int>(eventCounter.numFrames())); + logManager.addProperty("frame_count", static_cast<int>(eventCounter.numFrames())); logManager.addProperty("period", period); - - // currently beam monitor counts are not available, instead number of frames - // times period is used - logManager.addProperty( - "bm_counts", eventCounter.numFrames() * period / - 1.0e6); // static_cast<double>(instrumentInfo.bm_counts) - + + // currently beam monitor counts are not available, instead number of frames times period is used + logManager.addProperty("bm_counts", eventCounter.numFrames() * period / 1.0e6); // static_cast<double>(instrumentInfo.bm_counts) + // currently - Kernel::time_duration duration = boost::posix_time::microseconds( - static_cast<boost::int64_t>(eventCounter.numFrames() * period)); - + Kernel::time_duration duration = boost::posix_time::microseconds(static_cast<boost::int64_t>(eventCounter.numFrames() * period)); + Kernel::DateAndTime start_time("2000-01-01T00:00:00"); Kernel::DateAndTime end_time(start_time + duration); @@ -387,33 +390,20 @@ void LoadBBY::exec() { logManager.addProperty("end_time", end_time.toISO8601String()); std::string time_str = start_time.toISO8601String(); - AddSinglePointTimeSeriesProperty(logManager, time_str, "L1_chopper_value", - instrumentInfo.L1_chopper_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_det_value", - instrumentInfo.L2_det_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainl_value", - instrumentInfo.L2_curtainl_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainr_value", - instrumentInfo.L2_curtainr_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainu_value", - instrumentInfo.L2_curtainu_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtaind_value", - instrumentInfo.L2_curtaind_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "D_det_value", - instrumentInfo.D_det_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainl_value", - instrumentInfo.D_curtainl_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainr_value", - instrumentInfo.D_curtainr_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainu_value", - instrumentInfo.D_curtainu_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtaind_value", - instrumentInfo.D_curtaind_value); - AddSinglePointTimeSeriesProperty(logManager, time_str, "curtain_rotation", - 10.0); - - API::IAlgorithm_sptr loadInstrumentAlg = - createChildAlgorithm("LoadInstrument"); + AddSinglePointTimeSeriesProperty(logManager, time_str, "L1_chopper_value", instrumentInfo.L1_chopper_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_det_value", instrumentInfo.L2_det_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainl_value", instrumentInfo.L2_curtainl_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainr_value", instrumentInfo.L2_curtainr_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainu_value", instrumentInfo.L2_curtainu_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtaind_value", instrumentInfo.L2_curtaind_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "D_det_value", instrumentInfo.D_det_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainl_value", instrumentInfo.D_curtainl_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainr_value", instrumentInfo.D_curtainr_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainu_value", instrumentInfo.D_curtainu_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtaind_value", instrumentInfo.D_curtaind_value); + AddSinglePointTimeSeriesProperty(logManager, time_str, "curtain_rotation", 10.0); + + API::IAlgorithm_sptr loadInstrumentAlg = createChildAlgorithm("LoadInstrument"); loadInstrumentAlg->setProperty("Workspace", eventWS); loadInstrumentAlg->setPropertyValue("InstrumentName", "BILBY"); loadInstrumentAlg->executeAsChildAlg(); @@ -430,8 +420,8 @@ std::vector<bool> LoadBBY::createRoiVector(const std::string &maskfile) { std::ifstream input(maskfile.c_str()); if (!input.good()) - throw std::invalid_argument("invalid mask file"); - + throw std::invalid_argument("invalid mask file"); + std::string line; while (std::getline(input, line)) { auto i0 = line.find("<detids>"); @@ -473,9 +463,8 @@ std::vector<bool> LoadBBY::createRoiVector(const std::string &maskfile) { } // instrument creation -Geometry::Instrument_sptr -LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, - InstrumentInfo &instrumentInfo) { +Geometry::Instrument_sptr LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, + InstrumentInfo& instrumentInfo) { const double toMeters = 1.0 / 1000; @@ -529,13 +518,12 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, float tmp_float; int32_t tmp_int32 = 0; - + if (loadNXDataSet(entry, "monitor/bm1_counts", tmp_int32)) instrumentInfo.bm_counts = tmp_int32; if (loadNXDataSet(entry, "instrument/att_pos", tmp_float)) - instrumentInfo.att_pos = - static_cast<int32_t>(tmp_float + 0.5f); // [1.0, 2.0, ..., 5.0] - + instrumentInfo.att_pos = static_cast<int32_t>(tmp_float + 0.5f); // [1.0, 2.0, ..., 5.0] + if (loadNXDataSet(entry, "instrument/master_chopper_freq", tmp_float)) instrumentInfo.period_master = 1.0 / tmp_float * 1.0e6; if (loadNXDataSet(entry, "instrument/t0_chopper_freq", tmp_float)) @@ -546,8 +534,7 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, if (loadNXDataSet(entry, "instrument/L2_det", tmp_float)) instrumentInfo.L2_det_value = tmp_float * toMeters; if (loadNXDataSet(entry, "instrument/Ltof_det", tmp_float)) - instrumentInfo.L1_chopper_value = - tmp_float * toMeters - instrumentInfo.L2_det_value; + instrumentInfo.L1_chopper_value = tmp_float * toMeters - instrumentInfo.L2_det_value; // if (loadNXDataSet(entry, "instrument/L1", tmp_float)) // instrumentInfo.L1_source_value = tmp_float * toMeters; @@ -583,45 +570,36 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, if (logContent.size() > 0) { auto data = std::istringstream(logContent); - Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> conf( - new Poco::Util::PropertyFileConfiguration(data)); - + Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> conf(new Poco::Util::PropertyFileConfiguration(data)); + if (conf->hasProperty("bm1_counts")) instrumentInfo.bm_counts = conf->getInt("bm1_counts"); if (conf->hasProperty("att_pos")) - instrumentInfo.att_pos = - static_cast<int32_t>(conf->getDouble("att_pos") + 0.5f); - + instrumentInfo.att_pos = static_cast<int32_t>(conf->getDouble("att_pos") + 0.5f); + if (conf->hasProperty("master_chopper_freq")) - instrumentInfo.period_master = - 1.0 / conf->getDouble("master_chopper_freq") * 1.0e6; + instrumentInfo.period_master = 1.0 / conf->getDouble("master_chopper_freq") * 1.0e6; if (conf->hasProperty("t0_chopper_freq")) - instrumentInfo.period_slave = - 1.0 / conf->getDouble("t0_chopper_freq") * 1.0e6; + instrumentInfo.period_slave = 1.0 / conf->getDouble("t0_chopper_freq") * 1.0e6; if (conf->hasProperty("t0_chopper_phase")) instrumentInfo.phase_slave = conf->getDouble("t0_chopper_phase"); - + if (conf->hasProperty("L2_det")) instrumentInfo.L2_det_value = conf->getDouble("L2_det") * toMeters; if (conf->hasProperty("Ltof_det")) - instrumentInfo.L1_chopper_value = - conf->getDouble("Ltof_det") * toMeters - instrumentInfo.L2_det_value; - // if (conf->hasProperty("L1")) + instrumentInfo.L1_chopper_value = conf->getDouble("Ltof_det") * toMeters - instrumentInfo.L2_det_value; + //if (conf->hasProperty("L1")) // instrumentInfo.L1_source_value = conf->getDouble("L1") * toMeters; - + if (conf->hasProperty("L2_curtainl")) - instrumentInfo.L2_curtainl_value = - conf->getDouble("L2_curtainl") * toMeters; + instrumentInfo.L2_curtainl_value = conf->getDouble("L2_curtainl") * toMeters; if (conf->hasProperty("L2_curtainr")) - instrumentInfo.L2_curtainr_value = - conf->getDouble("L2_curtainr") * toMeters; + instrumentInfo.L2_curtainr_value = conf->getDouble("L2_curtainr") * toMeters; if (conf->hasProperty("L2_curtainu")) - instrumentInfo.L2_curtainu_value = - conf->getDouble("L2_curtainu") * toMeters; + instrumentInfo.L2_curtainu_value = conf->getDouble("L2_curtainu") * toMeters; if (conf->hasProperty("L2_curtaind")) - instrumentInfo.L2_curtaind_value = - conf->getDouble("L2_curtaind") * toMeters; - + instrumentInfo.L2_curtaind_value = conf->getDouble("L2_curtaind") * toMeters; + if (conf->hasProperty("curtainl")) instrumentInfo.D_curtainl_value = conf->getDouble("curtainl") * toMeters; if (conf->hasProperty("curtainr")) @@ -636,19 +614,16 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, /* // instrument - Geometry::Instrument_sptr instrument = - boost::make_shared<Geometry::Instrument>("BILBY"); + Geometry::Instrument_sptr instrument = boost::make_shared<Geometry::Instrument>("BILBY"); instrument->setDefaultViewAxis("Z-"); // source - Geometry::ObjComponent *source = new Geometry::ObjComponent("Source", - instrument.get()); + Geometry::ObjComponent *source = new Geometry::ObjComponent("Source", instrument.get()); instrument->add(source); instrument->markAsSource(source); - + // sample - Geometry::ObjComponent *samplePos = new Geometry::ObjComponent("Sample", - instrument.get()); + Geometry::ObjComponent *samplePos = new Geometry::ObjComponent("Sample", instrument.get()); instrument->add(samplePos); instrument->markAsSamplePos(samplePos); @@ -661,14 +636,14 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, double height = 640.0 / 1000; // meters double angle = 10.0; // degree - // raw data format + // raw data format size_t xPixelCount = HISTO_BINS_X / 6; size_t yPixelCount = HISTO_BINS_Y; - + // we assumed that individual pixels have the same size and shape of a cuboid: double pixel_width = width / static_cast<double>(xPixelCount); double pixel_height = height / static_cast<double>(yPixelCount); - + // final number of pixels size_t pixelCount = xPixelCount * yPixelCount; @@ -685,14 +660,10 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, // shapes in Mantid. std::string detXML = "<cuboid id=\"pixel\">" - "<left-front-bottom-point x=\"+"+pixel_width_str+"\" - y=\"-"+pixel_height_str+"\" z=\"0\" />" - "<left-front-top-point x=\"+"+pixel_width_str+"\" - y=\"-"+pixel_height_str+"\" z=\""+pixel_depth_str+"\" />" - "<left-back-bottom-point x=\"-"+pixel_width_str+"\" - y=\"-"+pixel_height_str+"\" z=\"0\" />" - "<right-front-bottom-point x=\"+"+pixel_width_str+"\" - y=\"+"+pixel_height_str+"\" z=\"0\" />" + "<left-front-bottom-point x=\"+"+pixel_width_str+"\" y=\"-"+pixel_height_str+"\" z=\"0\" />" + "<left-front-top-point x=\"+"+pixel_width_str+"\" y=\"-"+pixel_height_str+"\" z=\""+pixel_depth_str+"\" />" + "<left-back-bottom-point x=\"-"+pixel_width_str+"\" y=\"-"+pixel_height_str+"\" z=\"0\" />" + "<right-front-bottom-point x=\"+"+pixel_width_str+"\" y=\"+"+pixel_height_str+"\" z=\"0\" />" "</cuboid>"; // Create a shape object which will be shared by all pixels. @@ -706,42 +677,36 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, // curtain l factory.createAndAssign(0 * pixelCount, - Kernel::V3D(+instrumentInfo.D_curtainl_value, 0, - instrumentInfo.L2_curtainl_value), + Kernel::V3D(+instrumentInfo.D_curtainl_value, 0, instrumentInfo.L2_curtainl_value), Kernel::Quat(0, Kernel::V3D(0, 0, 1)) * Kernel::Quat(angle, Kernel::V3D(0, 1, 0))); // curtain r factory.createAndAssign(1 * pixelCount, - Kernel::V3D(-instrumentInfo.D_curtainr_value, 0, - instrumentInfo.L2_curtainr_value), + Kernel::V3D(-instrumentInfo.D_curtainr_value, 0, instrumentInfo.L2_curtainr_value), Kernel::Quat(180, Kernel::V3D(0, 0, 1)) * Kernel::Quat(angle, Kernel::V3D(0, 1, 0))); // curtain u factory.createAndAssign(2 * pixelCount, - Kernel::V3D(0, +instrumentInfo.D_curtainu_value, - instrumentInfo.L2_curtainu_value), + Kernel::V3D(0, +instrumentInfo.D_curtainu_value, instrumentInfo.L2_curtainu_value), Kernel::Quat(90, Kernel::V3D(0, 0, 1)) * Kernel::Quat(angle, Kernel::V3D(0, 1, 0))); // curtain d factory.createAndAssign(3 * pixelCount, - Kernel::V3D(0, -instrumentInfo.D_curtaind_value, - instrumentInfo.L2_curtaind_value), + Kernel::V3D(0, -instrumentInfo.D_curtaind_value, instrumentInfo.L2_curtaind_value), Kernel::Quat(-90, Kernel::V3D(0, 0, 1)) * Kernel::Quat(angle, Kernel::V3D(0, 1, 0))); // back 1 (left) factory.createAndAssign(4 * pixelCount, - Kernel::V3D(+instrumentInfo.D_det_value, 0, - instrumentInfo.L2_det_value), + Kernel::V3D(+instrumentInfo.D_det_value, 0, instrumentInfo.L2_det_value), Kernel::Quat(0, Kernel::V3D(0, 0, 1))); // back 2 (right) factory.createAndAssign(5 * pixelCount, - Kernel::V3D(-instrumentInfo.D_det_value, 0, - instrumentInfo.L2_det_value), + Kernel::V3D(-instrumentInfo.D_det_value, 0, instrumentInfo.L2_det_value), Kernel::Quat(180, Kernel::V3D(0, 0, 1))); return instrument; @@ -750,7 +715,8 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, // load nx dataset template <class T> -bool LoadBBY::loadNXDataSet(NeXus::NXEntry &entry, const std::string &path, +bool LoadBBY::loadNXDataSet(NeXus::NXEntry &entry, + const std::string &path, T &value) { try { NeXus::NXDataSetTyped<T> dataSet = entry.openNXDataSet<T>(path); @@ -758,7 +724,8 @@ bool LoadBBY::loadNXDataSet(NeXus::NXEntry &entry, const std::string &path, value = *dataSet(); return true; - } catch (std::runtime_error &) { + } + catch (std::runtime_error&) { return false; } } @@ -766,8 +733,7 @@ bool LoadBBY::loadNXDataSet(NeXus::NXEntry &entry, const std::string &path, // read counts/events from binary file template <class EventProcessor> void LoadBBY::loadEvents(API::Progress &prog, const char *progMsg, - ANSTO::Tar::File &tarFile, - EventProcessor &eventProcessor) { + ANSTO::Tar::File &tarFile, EventProcessor &eventProcessor) { prog.doReport(progMsg); // select bin file @@ -857,12 +823,13 @@ void LoadBBY::loadEvents(API::Progress &prog, const char *progMsg, // DetectorBankFactory BbyDetectorBankFactory::BbyDetectorBankFactory( - Geometry::Instrument_sptr instrument, Geometry::Object_sptr pixelShape, - size_t xPixelCount, size_t yPixelCount, double pixelWidth, - double pixelHeight, const Kernel::V3D ¢er) - : m_instrument(instrument), m_pixelShape(pixelShape), - m_xPixelCount(xPixelCount), m_yPixelCount(yPixelCount), - m_pixelWidth(pixelWidth), m_pixelHeight(pixelHeight), m_center(center) {} + Geometry::Instrument_sptr instrument, Geometry::Object_sptr pixelShape, + size_t xPixelCount, size_t yPixelCount, double pixelWidth, + double pixelHeight, const Kernel::V3D ¢er) + : m_instrument(instrument), m_pixelShape(pixelShape), + m_xPixelCount(xPixelCount), m_yPixelCount(yPixelCount), + m_pixelWidth(pixelWidth), m_pixelHeight(pixelHeight), m_center(center) { +} void BbyDetectorBankFactory::createAndAssign(size_t startIndex, const Kernel::V3D &pos, const Kernel::Quat &rot) const {