Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions Framework/LiveData/inc/MantidLiveData/SNSLiveEventDataListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
namespace Mantid {
namespace LiveData {

/** An implementation of ILiveListener for use at SNS. Connects to the Stream
Management
Service and receives events from it.
/** An implementation of ILiveListener for use at SNS.
* Connects to the Stream Management Service and receives events from it.
*/
class SNSLiveEventDataListener : public API::LiveListener, public Poco::Runnable, public ADARA::Parser {
public:
Expand Down Expand Up @@ -53,18 +52,17 @@ class SNSLiveEventDataListener : public API::LiveListener, public Poco::Runnable
protected:
using ADARA::Parser::rxPacket;
// virtual bool rxPacket( const ADARA::Packet &pkt);
// virtual bool rxPacket( const ADARA::RawDataPkt &pkt);
bool rxPacket(const ADARA::AnnotationPkt &pkt) override;
bool rxPacket(const ADARA::BankedEventPkt &pkt) override;
bool rxPacket(const ADARA::BeamlineInfoPkt &pkt) override;
bool rxPacket(const ADARA::BeamMonitorPkt &pkt) override;
bool rxPacket(const ADARA::DeviceDescriptorPkt &pkt) override;
bool rxPacket(const ADARA::GeometryPkt &pkt) override;
bool rxPacket(const ADARA::BeamlineInfoPkt &pkt) override;
bool rxPacket(const ADARA::RunInfoPkt &pkt) override;
bool rxPacket(const ADARA::RunStatusPkt &pkt) override;
bool rxPacket(const ADARA::VariableU32Pkt &pkt) override;
bool rxPacket(const ADARA::VariableDoublePkt &pkt) override;
bool rxPacket(const ADARA::VariableStringPkt &pkt) override;
bool rxPacket(const ADARA::DeviceDescriptorPkt &pkt) override;
bool rxPacket(const ADARA::AnnotationPkt &pkt) override;
bool rxPacket(const ADARA::RunInfoPkt &pkt) override;

private:
// Workspace initialization needs to happen in 2 steps. Part 1 must happen
Expand Down Expand Up @@ -117,11 +115,11 @@ class SNSLiveEventDataListener : public API::LiveListener, public Poco::Runnable
detid2index_map m_indexMap; // maps pixel id's to workspace indexes
detid2index_map m_monitorIndexMap; // Same as above for the monitor workspace

// We need these 2 strings to initialize m_buffer
// We need these 2 strings to initialize m_eventBuffer
std::string m_instrumentName;
std::string m_instrumentXML;

// Names of log values that we need before we can initialize m_buffer.
// Names of log values that we need before we can initialize m_eventBuffer.
// We get the names by parsing m_instrumentXML;
std::vector<std::string> m_requiredLogs;

Expand All @@ -133,7 +131,7 @@ class SNSLiveEventDataListener : public API::LiveListener, public Poco::Runnable
bool m_isConnected{false};

Poco::Thread m_thread;
std::mutex m_mutex; // protects m_buffer & m_status
std::mutex m_mutex; // protects m_eventBuffer & m_status
bool m_pauseNetRead{false};
bool m_stopThread{false}; // background thread checks this periodically.
// If true, the thread exits
Expand Down Expand Up @@ -161,7 +159,7 @@ class SNSLiveEventDataListener : public API::LiveListener, public Poco::Runnable
// --- Data structures necessary for handling all the process variable info
// ---

// maps <device id, variable id> to variable name
// maps a pair<device id, variable id> to its Processing Variable's name
// (variable names are unique, so we don't need to worry about device names.)
using NameMapType = std::map<std::pair<unsigned int, unsigned int>, std::string>;
NameMapType m_nameMap;
Expand All @@ -176,12 +174,15 @@ class SNSLiveEventDataListener : public API::LiveListener, public Poco::Runnable
// need to parse whatever variable value packets we have in order to set the
// state of the system properly.

// Maps the device ID / variable ID pair to the actual packet. Using a map
// Maps the pair<device ID, variable ID> to the actual packet. Using a map
// means we will only keep one packet (the most recent one) for each variable
using VariableMapType = std::map<std::pair<unsigned int, unsigned int>, std::shared_ptr<ADARA::Packet>>;
VariableMapType m_variableMap;

// Process all the variable value packets stored in m_variableMap
/// Process all the variable value packets stored in m_variableMap and then clear this cache
///
/// The method is triggered through the packet processing chain:
/// - rxPacket() → ignorePacket() → replayVariableCache()
void replayVariableCache();

// ---------------------------------------------------------------------------
Expand Down
48 changes: 24 additions & 24 deletions Framework/LiveData/src/ADARA/ADARAParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void Parser::reset() {
m_len = 0;
m_oversize_len = 0;
m_restart_offset = 0;

m_oversize_offset = 0;
m_discarded_packets.clear();
}

Expand Down Expand Up @@ -314,38 +314,38 @@ bool Parser::rxOversizePkt(const PacketHeader *hdr, const uint8_t * /*unused*/,
return false; \
}

EXPAND_HANDLER(RawDataPkt)
EXPAND_HANDLER(MappedDataPkt)
EXPAND_HANDLER(RTDLPkt)
EXPAND_HANDLER(SourceListPkt)
EXPAND_HANDLER(AnnotationPkt)
EXPAND_HANDLER(BankedEventPkt)
EXPAND_HANDLER(BankedEventStatePkt)
EXPAND_HANDLER(BeamMonitorPkt)
EXPAND_HANDLER(PixelMappingPkt)
EXPAND_HANDLER(PixelMappingAltPkt)
EXPAND_HANDLER(RunStatusPkt)
EXPAND_HANDLER(RunInfoPkt)
EXPAND_HANDLER(TransCompletePkt)
EXPAND_HANDLER(ClientHelloPkt)
EXPAND_HANDLER(AnnotationPkt)
EXPAND_HANDLER(SyncPkt)
EXPAND_HANDLER(HeartbeatPkt)
EXPAND_HANDLER(GeometryPkt)
EXPAND_HANDLER(BeamlineInfoPkt)
EXPAND_HANDLER(BeamMonitorConfigPkt)
EXPAND_HANDLER(DetectorBankSetsPkt)
EXPAND_HANDLER(BeamMonitorPkt)
EXPAND_HANDLER(ClientHelloPkt)
EXPAND_HANDLER(DataDonePkt)
EXPAND_HANDLER(DetectorBankSetsPkt)
EXPAND_HANDLER(DeviceDescriptorPkt)
EXPAND_HANDLER(VariableU32Pkt)
EXPAND_HANDLER(VariableDoublePkt)
EXPAND_HANDLER(VariableStringPkt)
EXPAND_HANDLER(VariableU32ArrayPkt)
EXPAND_HANDLER(VariableDoubleArrayPkt)
EXPAND_HANDLER(MultVariableU32Pkt)
EXPAND_HANDLER(GeometryPkt)
EXPAND_HANDLER(HeartbeatPkt)
EXPAND_HANDLER(MappedDataPkt)
EXPAND_HANDLER(MultVariableDoublePkt)
EXPAND_HANDLER(MultVariableDoubleArrayPkt)
EXPAND_HANDLER(MultVariableStringPkt)
EXPAND_HANDLER(MultVariableU32ArrayPkt)
EXPAND_HANDLER(MultVariableDoubleArrayPkt)
EXPAND_HANDLER(MultVariableU32Pkt)
EXPAND_HANDLER(PixelMappingAltPkt)
EXPAND_HANDLER(PixelMappingPkt)
EXPAND_HANDLER(RawDataPkt)
EXPAND_HANDLER(RTDLPkt)
EXPAND_HANDLER(RunInfoPkt)
EXPAND_HANDLER(RunStatusPkt)
EXPAND_HANDLER(SourceListPkt)
EXPAND_HANDLER(SyncPkt)
EXPAND_HANDLER(TransCompletePkt)
EXPAND_HANDLER(VariableDoublePkt)
EXPAND_HANDLER(VariableDoubleArrayPkt)
EXPAND_HANDLER(VariableStringPkt)
EXPAND_HANDLER(VariableU32ArrayPkt)
EXPAND_HANDLER(VariableU32Pkt)

void Parser::getDiscardedPacketsLogString(std::string &log_info) {
log_info = "Discarded ADARA Packet/Counts: ";
Expand Down
36 changes: 14 additions & 22 deletions Framework/LiveData/src/SNSLiveEventDataListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,12 @@ bool SNSLiveEventDataListener::rxPacket(const ADARA::BankedEventPkt &pkt) {
/// Parse a beam monitor event packet

/** Overrides the default function defined in ADARA::Parser and processes data from ADARA::BeamMonitorPkt packets.
* Parsed events are counted and the counts are accumulated in the temporary workspace until the forground thread
* Parsed events are counted and the counts are accumulated in the temporary workspace until the foreground thread
* retrieves them.
*
* @see extractData()
* @param pkt The packet to be parsed
* @return Returns false if there were no problems. Returns true if there was an error and packet parsing should be
* interrupted
* @return false if no problems, true if error occurred and packet parsing should be interrupted
*/
bool SNSLiveEventDataListener::rxPacket(const ADARA::BeamMonitorPkt &pkt) {
// Check to see if we should process this packet (depending on what the user selected for start up options, the SMS
Expand Down Expand Up @@ -1517,20 +1516,16 @@ ILiveListener::RunStatus SNSLiveEventDataListener::runStatus() {
return rv;
}

// Called by the rxPacket() functions to determine if the packet should be
// processed
// (Depending on when it last indexed its data, SMS might send us packets that
// are
// older than we requested.)
// Returns false if the packet should be processed, true if is should be ignored
// Called by the rxPacket() functions to determine if the packet should be processed
// (Depending on when it last indexed its data, SNS might send us packets that are older than we requested)
// Returns false if the packet should be processed, true if it should be ignored
bool SNSLiveEventDataListener::ignorePacket(const ADARA::PacketHeader &hdr, const ADARA::RunStatus::Enum status) {
// Since we're filtering based on time (either the absolute timestamp or
// nothing
// before the start of the most recent run), once we've determined a given
// packet should be processed, we know all packets after that should also be
// processed. Thus, we can reduce most calls to this function to a simple
// boolean test...
if (!m_ignorePackets)
// Since we're filtering based on time (either the absolute timestamp or nothing
// before the start of the most recent run),
// once we've determined a given packet should be processed,
// we know all packets after that should also be processed.
// Thus, we can reduce most calls to this function to a simple boolean test
if (!m_ignorePackets) // don't ignore
return false;

// Are we looking for the start of the run?
Expand All @@ -1548,7 +1543,7 @@ bool SNSLiveEventDataListener::ignorePacket(const ADARA::PacketHeader &hdr, cons

// If we've just hit our start-up condition, then process
// all the variable value packets we've been hanging on to.
if (!m_ignorePackets) {
if (!m_ignorePackets) { // don't ignore
replayVariableCache();
}

Expand All @@ -1557,12 +1552,9 @@ bool SNSLiveEventDataListener::ignorePacket(const ADARA::PacketHeader &hdr, cons

// Process all the variable value packets stored in m_variableMap
void SNSLiveEventDataListener::replayVariableCache() {
auto it = m_variableMap.begin();
while (it != m_variableMap.end()) {
rxPacket(*(*it).second); // call rxPacket() on the stored packet
it++;
for (const auto &varPacketPair : m_variableMap) {
rxPacket(*varPacketPair.second); // call rxPacket() on the stored packet
}

m_variableMap.clear(); // empty the map to save a little ram
}

Expand Down
18 changes: 11 additions & 7 deletions Framework/PythonInterface/mantid/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def capture_logs(level=None) -> io.StringIO:
sys.stdout = backup["stdout"]


def log_to_python(level="debug"):
def log_to_python(level=None, pattern=None) -> None:
r"""
Modify Mantid's logger to forward messages to Python's logging framework instead
of outputting them itself. This allows users to configure the logger from Python
Expand All @@ -70,14 +70,18 @@ def log_to_python(level="debug"):

@param str level: Logging level for the *Mantid* logger. Should be set to a low value
to forward all potentially relevant messages to Python and let *Python's* logger
filter out undesired messages. Possible values: 'trace', 'debug' (default),
filter out undesired messages. Possible values: 'trace', 'debug',
'information', 'notice', 'warning', 'error', 'critical', 'fatal'.
@param str pattern: A logging pattern to format messages before forwarding them (example: %t)
See https://github.com/pocoproject/poco/wiki/Poco::Util::Application-Logging-Configuration#logging-format-placeholders
"""
config = ConfigService.Instance()
config["logging.loggers.root.level"] = level
config["logging.channels.consoleChannel.formatter"] = "f1"
# Output only the message text and let Python take care of formatting.
config["logging.formatters.f1.class"] = "PatternFormatter"
config["logging.formatters.f1.pattern"] = "%t"
if level is not None:
config["logging.loggers.root.level"] = level
if pattern is not None:
config["logging.channels.consoleChannel.formatter"] = "f1"
# Output only the message text and let Python take care of formatting.
config["logging.formatters.f1.class"] = "PatternFormatter"
config["logging.formatters.f1.pattern"] = pattern
# Important: Do this one last because it triggers re-init of logging system!
config["logging.channels.consoleChannel.class"] = "PythonLoggingChannel"

This file was deleted.