Skip to content

Commit

Permalink
Perform 'End of Run' behavior on all run transitions
Browse files Browse the repository at this point in the history
Perform the requested end of run behavior on NoRun => BeginRun
transitions (in addition to the EndRun => NoRun transitions we've been
performing it on).

This change is just the beginning and only works for the SNS live
listener.  Haven't looked at ISIS yet.  Also haven't updated the GUI,
yet.

Refs #7209
  • Loading branch information
rgmiller committed Apr 9, 2014
1 parent b0d8ba3 commit 476c32c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
Expand Up @@ -195,6 +195,11 @@ namespace Mantid
// Returns false if the packet should be processed, true if is should be ignored
bool ignorePacket( const ADARA::PacketHeader &hdr, const ADARA::RunStatus::Enum status = ADARA::RunStatus::NO_RUN);
void setRunDetails( const ADARA::RunStatusPkt& pkt );

// We have to defer calling setRunDetails() at the start of a run until the foreground thread has called
// extractData() and retrieved the last data from the previous state (which was probably NO_RUN).
// This holds a copy of the RunStatusPkt until we can call setRunDetails().
boost::shared_ptr<ADARA::RunStatusPkt> m_deferredRunDetailsPkt;
};

} // namespace LiveData
Expand Down
31 changes: 28 additions & 3 deletions Code/Mantid/Framework/LiveData/src/MonitorLiveData.cpp
Expand Up @@ -130,6 +130,7 @@ namespace LiveData

m_chunkNumber = 0;
int runNumber = 0;
int prevRunNumber = 0;

std::string AccumulationWorkspace = this->getPropertyValue("AccumulationWorkspace");
std::string OutputWorkspace = this->getPropertyValue("OutputWorkspace");
Expand Down Expand Up @@ -182,8 +183,17 @@ namespace LiveData
g_log.debug() << "Run number set to " << runNumber << std::endl;
}

// Did we just hit the end of a run?
if (listener->runStatus() == ILiveListener::EndRun)
// Did we just hit a run transition?
ILiveListener::RunStatus runStatus = listener->runStatus();
if (runStatus == ILiveListener::EndRun)
{
// Need to keep track of what the run number *was* so we
// can properly rename workspaces
prevRunNumber = runNumber;
}

if ( (runStatus == ILiveListener::BeginRun) ||
(runStatus == ILiveListener::EndRun) )
{
std::stringstream message;
message << "Run";
Expand All @@ -206,7 +216,22 @@ namespace LiveData
NextAccumulationMethod = "Replace";

// Now we clone the existing workspaces
std::string postFix = "_" + Strings::toString(runNumber);
std::string postFix;
if (runStatus == ILiveListener::EndRun)
{
postFix = "_" + Strings::toString(runNumber);
}
else
{
// indicate that this is data that arrived *after* the run ended
postFix = "_";
if (prevRunNumber != 0)
postFix += Strings::toString(prevRunNumber);

postFix += "_post";
}


doClone(OutputWorkspace, OutputWorkspace + postFix);
if (!AccumulationWorkspace.empty())
doClone(AccumulationWorkspace, AccumulationWorkspace + postFix);
Expand Down
38 changes: 27 additions & 11 deletions Code/Mantid/Framework/LiveData/src/SNSLiveEventDataListener.cpp
Expand Up @@ -607,9 +607,20 @@ namespace LiveData
}
else
{
setRunDetails(pkt);
// Save a copy of the packet so we can call setRunDetails() later (after
// extractData() has been called to fetch any data remaining from before
// this run start.
// Note: need to actually copy the contents (not just a pointer) because
// pkt will go away when this function returns. And since packets don't have
// default constructors, we can only keep a pointer as a member, and thus
// have to actually allocate our deferred packet with new.
// Fortunately, this doesn't happen to often, so performance isn't an issue.
m_deferredRunDetailsPkt = boost::shared_ptr<ADARA::RunStatusPkt>(new ADARA::RunStatusPkt(pkt));
}

// See detailed comments below for what this flag does
m_pauseNetRead = true;

}
else if (pkt.status() == ADARA::RunStatus::END_RUN)
{
Expand Down Expand Up @@ -1281,17 +1292,10 @@ namespace LiveData
// It's only appropriate to return EndRun once (ie: when we've just
// returned the last events from the run). After that, we need to
// change the status to NoRun.
// As far as I can tell, nobody ever checks for BeginRun, but I'm
// assuming the same logic applies....
if (m_status == BeginRun)
// The same logic applies to BeginRun and Running
if (m_status == BeginRun || m_status == EndRun)
{
m_status = Running;
}
else if (m_status == EndRun)
{
m_status = NoRun;

// If the run has ended, replace the old workspace with a new one
// At run transitions, replace the old workspace with a new one
// (This ensures that we're not using log data and/or geometry from
// a previous run that are no longer valid. SMS is guaranteed to
// send us new device descriptor packets at the start of every run.)
Expand All @@ -1300,6 +1304,18 @@ namespace LiveData
m_workspaceInitialized = false;
m_nameMap.clear();
initWorkspacePart1();

if (m_status == BeginRun)
{
// Set the run details using the packet we saved from the rxPacket() function
setRunDetails( *m_deferredRunDetailsPkt);
m_deferredRunDetailsPkt.reset(); // shared_ptr, so we don't use delete
m_status = Running;
}
else if (m_status == EndRun)
{
m_status = NoRun;
}
}

m_pauseNetRead = false; // make sure the network reads start back up
Expand Down

0 comments on commit 476c32c

Please sign in to comment.