Mantid
Loading...
Searching...
No Matches
LoadDNSEvent.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2022 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#include "BitStream.h"
10#include "MantidDataHandling/DllConfig.h"
14#include "MantidKernel/System.h"
15#include "MantidTypes/Core/DateAndTime.h"
16
17using namespace Mantid::Kernel;
18using namespace Mantid::API;
19
20namespace Mantid::DataHandling {
21
33class MANTID_DATAHANDLING_DLL LoadDNSEvent : public API::IFileLoader<Kernel::FileDescriptor> {
34public:
36 const std::string name() const override { return "LoadDNSEvent"; }
38 const std::string summary() const override {
39 return "Loads data from the DNS PSD detector to a Mantid EventWorkspace.";
40 }
41
42 // Algorithm's version for identification
43 int version() const override { return 1; }
44 const std::vector<std::string> seeAlso() const override { return {}; }
45 // Algorithm's category for identification
46 const std::string category() const override { return "DataHandling"; }
47 // Returns a confidence value that this algorithm can load a file
48 int confidence(Kernel::FileDescriptor &descriptor) const override;
49
50private:
51 // Initialise the properties
52 void init() override;
53 // Run the algorithm
54 void exec() override;
55
56 struct BufferHeader {
57 uint16_t bufferLength = 0;
58 uint16_t bufferVersion = 0;
59 uint16_t headerLength = 0;
60 uint16_t bufferNumber = 0;
61 uint16_t runId = 0;
62 uint8_t mcpdId = 0;
63 uint8_t deviceStatus = 0;
64 uint64_t timestamp = 0;
65 };
66
67public:
68 enum event_id_e { NEUTRON = 0, TRIGGER = 1 };
69
70 struct CompactEvent {
71 uint64_t timestamp = 0;
72 };
73
74private:
76 // Neutron Events for each pixel
77 std::vector<std::vector<CompactEvent>> neutronEvents;
78 std::vector<CompactEvent> triggerEvents;
79 };
80
81 struct TriggerEvent {
82 bool isChopperTrigger = false;
83 CompactEvent event = {};
84 };
85
86 struct NeutronEvent {
87 size_t wsIndex = 0;
88 CompactEvent event = {};
89 };
90
91 uint32_t m_chopperChannel = 2;
92 uint32_t m_detectorPixelCount = 0;
93
94 bool m_discardPreChopperEvents = true;
95 bool m_setBinBoundary = false;
96
97 void populate_EventWorkspace(Mantid::DataObjects::EventWorkspace_sptr &eventWS,
98 EventAccumulator &finalEventAccumulator);
99
100 EventAccumulator parse_File(FileByteStream &file, const std::string &fileName);
101 std::vector<uint8_t> parse_Header(FileByteStream &file);
102
103 std::vector<std::vector<uint8_t>> split_File(FileByteStream &file, const unsigned maxChunckCount);
104
105 void parse_BlockList(VectorByteStream &file, EventAccumulator &eventAccumulator);
106 void parse_Block(VectorByteStream &file, EventAccumulator &eventAccumulator);
107 void parse_BlockSeparator(VectorByteStream &file);
108 void parse_DataBuffer(VectorByteStream &file, EventAccumulator &eventAccumulator);
109 BufferHeader parse_DataBufferHeader(VectorByteStream &file);
110
111 inline void parse_andAddEvent(VectorByteStream &file, const BufferHeader &bufferHeader,
112 EventAccumulator &eventAccumulator);
113
114 void parse_EndSignature(FileByteStream &file);
115
116 TriggerEvent processTrigger(const uint64_t &data, const LoadDNSEvent::BufferHeader &bufferHeader);
117 NeutronEvent processNeutron(const uint64_t &data, const LoadDNSEvent::BufferHeader &bufferHeader);
118};
119
120} // namespace Mantid::DataHandling
Defines an interface to an algorithm that loads a file so that it can take part in the automatic sele...
Definition: IFileLoader.h:19
const std::string name() const override
function to return a name of the algorithm, must be overridden in all algorithms
Definition: LoadDNSEvent.h:36
const std::string summary() const override
Summary of algorithms purpose.
Definition: LoadDNSEvent.h:38
int version() const override
function to return a version of the algorithm, must be overridden in all algorithms
Definition: LoadDNSEvent.h:43
const std::string category() const override
function to return a category of the algorithm.
Definition: LoadDNSEvent.h:46
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
Definition: LoadDNSEvent.h:44
Defines a wrapper around an open file.
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::vector< std::vector< CompactEvent > > neutronEvents
Definition: LoadDNSEvent.h:77