9
9
#include " MantidAPI/Axis.h"
10
10
#include " MantidAPI/FileProperty.h"
11
11
#include " MantidAPI/MatrixWorkspace.h"
12
+ #include " MantidAPI/Run.h"
13
+ #include " MantidAPI/Sample.h"
12
14
#include " MantidDataHandling/LoadEventNexus.h"
13
15
#include " MantidDataObjects/EventList.h"
14
16
#include " MantidDataObjects/MaskWorkspace.h"
18
20
#include " MantidGeometry/Instrument/DetectorInfo.h"
19
21
#include " MantidKernel/ArrayLengthValidator.h"
20
22
#include " MantidKernel/ArrayProperty.h"
23
+ #include " MantidKernel/TimeSeriesProperty.h"
21
24
#include " MantidKernel/Timer.h"
22
25
#include " MantidKernel/VectorHelper.h"
23
26
#include " MantidNexus/H5Util.h"
@@ -38,6 +41,7 @@ using Mantid::DataObjects::Workspace2D;
38
41
using Mantid::Kernel::ArrayLengthValidator;
39
42
using Mantid::Kernel::ArrayProperty;
40
43
using Mantid::Kernel::Direction;
44
+ using Mantid::Kernel::TimeSeriesProperty;
41
45
42
46
namespace { // anonymous namespace
43
47
namespace PropertyNames {
@@ -103,30 +107,15 @@ class NexusLoader {
103
107
const std::pair<uint64_t , uint64_t > &eventRange) {
104
108
// g_log.information(NxsFieldNames::TIME_OF_FLIGHT);
105
109
auto tof_SDS = event_group.openDataSet (NxsFieldNames::TIME_OF_FLIGHT);
106
- // TODO probably should resize data array
107
- /*
108
- // This is the data size
109
- ::NeXus::Info id_info = m_h5file.getInfo();
110
- const auto dim0 = static_cast<size_t>(LoadBankFromDiskTask::recalculateDataSize(id_info.dims[0]));
111
- */
112
110
111
+ // H5Util resizes the vector
113
112
if (m_is_time_filtered) {
114
- throw std::runtime_error (" filtering not implemented" );
115
- // TODO sort this out H5Util doesn't have slab read yet
116
- /*
117
- // These are the arguments to getSlab()
118
- std::vector<int64_t> loadStart(1, eventRange.first);
119
- int64_t slabsize = (eventRange.second == std::numeric_limits<size_t>::max())
120
- ? dim0 - eventRange.first
121
- : eventRange.second - eventRange.first;
122
- std::vector<int64_t> loadSize(1, slabsize);
123
-
124
- data->resize(loadSize[0]);
125
- Mantid::NeXus::NeXusIOHelper::readNexusSlab<float, Mantid::NeXus::NeXusIOHelper::PreventNarrowing>(
126
- *data, m_h5file, NxsFieldNames::TIME_OF_FLIGHT, loadStart, loadSize);
127
- */
113
+ const size_t offset = eventRange.first ;
114
+ const size_t slabsize = (eventRange.second == std::numeric_limits<size_t >::max ())
115
+ ? std::numeric_limits<size_t >::max ()
116
+ : eventRange.second - eventRange.first ;
117
+ NeXus::H5Util::readArray1DCoerce (tof_SDS, *data, slabsize, offset);
128
118
} else {
129
- // TODO probably should resize data array
130
119
NeXus::H5Util::readArray1DCoerce (tof_SDS, *data);
131
120
}
132
121
@@ -143,30 +132,15 @@ class NexusLoader {
143
132
const std::pair<uint64_t , uint64_t > &eventRange) {
144
133
// g_log.information(NxsFieldNames::DETID);
145
134
auto detID_SDS = event_group.openDataSet (NxsFieldNames::DETID);
146
- // TODO probably should resize data array
147
- /*
148
- // This is the data size
149
- ::NeXus::Info id_info = m_h5file.getInfo();
150
- const auto dim0 = static_cast<size_t>(LoadBankFromDiskTask::recalculateDataSize(id_info.dims[0]));
151
- */
152
135
136
+ // H5Util resizes the vector
153
137
if (m_is_time_filtered) {
154
- throw std::runtime_error (" filtering not implemented" );
155
- // TODO sort this out H5Util doesn't have slab read yet
156
- /*
157
- // These are the arguments to getSlab()
158
- std::vector<int64_t> loadStart(1, eventRange.first);
159
- int64_t slabsize = (eventRange.second == std::numeric_limits<size_t>::max())
160
- ? dim0 - eventRange.first
161
- : eventRange.second - eventRange.first;
162
- std::vector<int64_t> loadSize(1, slabsize);
163
-
164
- data->resize(loadSize[0]);
165
- Mantid::NeXus::NeXusIOHelper::readNexusSlab<uint32_t, Mantid::NeXus::NeXusIOHelper::PreventNarrowing>(
166
- *data, m_h5file, NxsFieldNames::DETID, loadStart, loadSize);
167
- */
138
+ const size_t offset = eventRange.first ;
139
+ const size_t slabsize = (eventRange.second == std::numeric_limits<size_t >::max ())
140
+ ? std::numeric_limits<size_t >::max ()
141
+ : eventRange.second - eventRange.first ;
142
+ NeXus::H5Util::readArray1DCoerce (detID_SDS, *data, slabsize, offset);
168
143
} else {
169
- // TODO probably should resize data array
170
144
NeXus::H5Util::readArray1DCoerce (detID_SDS, *data);
171
145
}
172
146
}
@@ -452,7 +426,6 @@ void AlignAndFocusPowderSlim::exec() {
452
426
453
427
// Load the instrument
454
428
// prog->doReport("Loading instrument"); TODO add progress bar stuff
455
- // LoadEventNexus::loadInstrument<MatrixWorkspace_sptr>(filename, wksp, "entry", this, &descriptor);
456
429
LoadEventNexus::loadInstrument<MatrixWorkspace_sptr>(filename, wksp, ENTRY_TOP_LEVEL, this , &descriptor);
457
430
458
431
const std::string cal_filename = getPropertyValue (PropertyNames::CAL_FILE);
@@ -463,25 +436,12 @@ void AlignAndFocusPowderSlim::exec() {
463
436
}
464
437
465
438
/*
466
- // load run metadata
467
- // prog->doReport("Loading metadata"); TODO add progress bar stuff
468
- try {
469
- LoadEventNexus::loadEntryMetadata(filename, WS, "entry", descriptor);
470
- } catch (std::exception &e) {
471
- g_log.warning() << "Error while loading meta data: " << e.what() << '\n';
472
- }
473
-
474
439
// create IndexInfo
475
440
// prog->doReport("Creating IndexInfo"); TODO add progress bar stuff
476
441
const std::vector<int32_t> range;
477
442
LoadEventNexusIndexSetup indexSetup(WS, EMPTY_INT(), EMPTY_INT(), range);
478
443
auto indexInfo = indexSetup.makeIndexInfo();
479
444
const size_t numHist = indexInfo.size();
480
-
481
- // make output workspace with correct number of histograms
482
- MatrixWorkspace_sptr outWS = WorkspaceFactory::Instance().create(WS, numHist, 2, 1);
483
- // set spectrum index information
484
- outWS->setIndexInfo(indexInfo);
485
445
*/
486
446
487
447
// load the events
@@ -561,63 +521,24 @@ void AlignAndFocusPowderSlim::exec() {
561
521
m_calibration, m_masked, binWidth, linearBins);
562
522
constexpr size_t GRAINSIZE_BANK{2 };
563
523
tbb::parallel_for (tbb::blocked_range<size_t >(0 , bankEntryNames.size (), GRAINSIZE_BANK), task);
524
+ }
564
525
565
- /*
566
- NexusLoader loader(h5file, is_time_filtered, pulse_start_index, pulse_stop_index);
567
-
568
- size_t specnum = 0;
569
- for (const std::string &entry_name : bankEntryNames) {
570
- std::cout << "ENTRY: " << entry_name << std::endl;
571
- const auto startTimeBank = std::chrono::high_resolution_clock::now();
572
-
573
- // TODO should re-use vectors to save malloc/free calls
574
- std::unique_ptr<std::vector<uint32_t>> event_detid = std::make_unique<std::vector<uint32_t>>();
575
- std::unique_ptr<std::vector<float>> event_time_of_flight = std::make_unique<std::vector<float>>();
576
- // TODO std::unique_ptr<std::vector<float>> event_weight; some other time
577
- g_log.information() << "Loading bank " << entry_name << '\n';
578
- h5file.openGroup(entry_name, "NXevent_data");
579
-
580
- // get filtering range
581
- const auto eventRange = loader.getEventIndexRange(h5file);
582
-
583
- loader.loadTOF(event_time_of_flight, eventRange);
584
- loader.loadDetid(event_detid, eventRange);
585
-
586
- if (event_time_of_flight->empty() || event_detid->empty()) {
587
- g_log.warning() << "No data for bank " << entry_name << '\n';
588
- h5file.closeGroup();
589
- continue;
590
- }
591
-
592
- const auto startTimeSetup = std::chrono::high_resolution_clock::now();
593
- const auto [minval, maxval] = parallel_minmax(event_detid.get());
594
- BankCalibration calibration(static_cast<detid_t>(minval), static_cast<detid_t>(maxval), m_calibration);
595
-
596
- auto &spectrum = wksp->getSpectrum(specnum);
597
- Histogrammer histogrammer(&spectrum.readX(), binWidth, linearBins);
598
- const auto numEvent = event_time_of_flight->size();
599
- // std::atomic allows for multi-threaded accumulation and who cares about floats when you are just
600
- // counting things
601
- std::vector<std::atomic_uint32_t> y_temp(spectrum.dataY().size());
602
- addTimer("setup" + entry_name, startTimeSetup, std::chrono::high_resolution_clock::now());
603
-
604
- const auto startTimeProcess = std::chrono::high_resolution_clock::now();
605
- constexpr size_t GRAINSIZE_EVENT{2000};
606
- ProcessEventsTask task(&histogrammer, event_detid.get(), event_time_of_flight.get(), &calibration, &y_temp,
607
- &m_masked);
608
- tbb::parallel_for(tbb::blocked_range<size_t>(0, numEvent, GRAINSIZE_EVENT), task);
609
- auto &y_values = spectrum.dataY();
610
- std::copy(y_temp.cbegin(), y_temp.cend(), y_values.begin());
611
- addTimer("proc" + entry_name, startTimeProcess, std::chrono::high_resolution_clock::now());
612
- addTimer(entry_name, startTimeBank, std::chrono::high_resolution_clock::now());
526
+ // close the file so child algorithms can do their thing
527
+ h5file.close ();
613
528
614
- h5file.closeGroup();
615
- specnum++;
616
- }
617
- */
529
+ // load run metadata
530
+ // prog->doReport("Loading metadata"); TODO add progress bar stuff
531
+ try {
532
+ LoadEventNexus::loadEntryMetadata (filename, wksp, ENTRY_TOP_LEVEL, descriptor);
533
+ } catch (std::exception &e) {
534
+ g_log.warning () << " Error while loading meta data: " << e.what () << ' \n ' ;
618
535
}
619
536
620
- // TODO load logs
537
+ // load logs
538
+ auto periodLog = std::make_unique<const TimeSeriesProperty<int >>(" period_log" ); // not used
539
+ int nPeriods{1 };
540
+ LoadEventNexus::runLoadNexusLogs<MatrixWorkspace_sptr>(filename, wksp, *this , false , nPeriods, periodLog);
541
+
621
542
wksp->setYUnit (" Counts" );
622
543
wksp->getAxis (0 )->setUnit (" DSpacing" );
623
544
setProperty (PropertyNames::OUTPUT_WKSP, std::move (wksp));
0 commit comments