Ticket #1295 (closed: fixed)

Opened 10 years ago

Last modified 5 years ago

Mantid terminates using LoadNexus and then deleting some of the periods

Reported by: Steve Williams Owned by: Roman Tolchenov
Priority: critical Milestone: Iteration 23
Component: Keywords:
Cc: Blocked By:
Blocking: Tester:

Description

The following script is from the SANS scripts and deals with loading a multi-period Nexus file and deleting all but 1 period. It crashes Mantidplot on _my_ computer when logging to file is set to warning, logging to information seems to slow things down enough to stop the conflict. It doesn't crash when run from the command prompt. Problem around add and remove from workspace group signals to Mantidplot's workspace list?

def _leaveSinglePeriod(groupW, period):
    oldName = groupW.getName()+'_'+str(period)
    #move this workspace out of the group (this doesn't delete it)
    groupW.remove(oldName)

    newName = groupW.getName()+'p'+str(period)
    
    #remove the rest of the group
    mtd.deleteWorkspace(groupW.getName())
    return newName

def _loadRawData(filename, wsName, ext, spec_min = None, spec_max = None, period = -1):
    alg = LoadNexus(filename + '.' + ext, wsName,SpectrumMin=spec_min,SpectrumMax=spec_max)

    pWorksp = mtd[wsName]

    if pWorksp.isGroup() :
        #get the number of periods in a group using the fact that each period has a different name
        nNames = len(pWorksp.getNames())
        numPeriods = nNames - 1
    else :
        #if the work space isn't a group there is only one period
        numPeriods = 1
        
    #period greater than one means we must be looking at a workspace group
    if period > 1 :
        if not pWorksp.isGroup() : raise Exception('_loadRawData: A period number can only be specified for a group and workspace '+ pWorksp.getName() + ' is not a group')
        wsName = _leaveSinglePeriod(pWorksp, period)
	pWorksp = mtd[wsName]
    else :
        #if it is a group but they hadn't specified the period it means load the first spectrum
        if pWorksp.isGroup() :
            wsName = _leaveSinglePeriod(pWorksp, 1)
            pWorksp = mtd[wsName]
    
    # Return the filepath actually used to load the data
    fullpath = alg.getPropertyValue("Filename")
    return [ os.path.dirname(fullpath), wsName, numPeriods]

def _assignHelper(run_string, period = -1):
    wkspname =  '5508_sans_nxs'

    filename = os.path.join(DATA_PATH,'SANS2D00005508')
    
    [filepath, wkspname, nPeriods] = _loadRawData(filename, wkspname, 'nxs', None, None, period)
            
    return True, filepath, nPeriods

DATA_PATH = '//isis/inst$/cycle_10_1/NDXSANS2D/'
print _assignHelper('5508.nxs', 11)

Change History

comment:1 Changed 10 years ago by Steve Williams

This Python causes the same crashes on my machine

alg = LoadNexus("//isis/inst$/NDXSANS2D/Instrument/data/cycle_10_1/SANS2D00005508.nxs, '5508_sans_nxs')
worksp = alg.getPropertyValue("OutputWorkspace")
mtd[worksp].remove('5508_sans_nxs_11')
mtd.deleteWorkspace(worksp)

The following C++ is equivalent but runs OK in main(). Moving the code into Mantidplot should cause the same crash.

#include <iostream>
#include <iomanip>
#include "Benchmark.h"
#include "UserAlgorithmTest.h"
#include "MantidAPI/FrameworkManager.h" 
#include "MantidDataObjects/Workspace2D.h" 
#include "MantidAPI/WorkspaceGroup.h"

#include <boost/timer.hpp>

using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
using namespace Mantid::DataObjects;

int main()
{

  FrameworkManagerImpl& fm = FrameworkManager::Instance();

  IAlgorithm* alg = fm.createAlgorithm("LoadNexus");
  alg->setPropertyValue("Filename", "//isis/inst$/NDXSANS2D/Instrument/data/cycle_10_1/SANS2D00005508.nxs");
  alg->setPropertyValue("OutputWorkspace", "5508_sans_nxs");    
  alg->execute();
  
  Workspace* ws = fm.getWorkspace("5508_sans_nxs");
  WorkspaceGroup* group = dynamic_cast<WorkspaceGroup*>(ws);
  if ( ! group )
  {
    std::cout << "no cast";
    return 1;
  }
  group->remove("5508_sans_nxs_11");
  FrameworkManager::Instance().deleteWorkspace("5508_sans_nxs");

  std::cout << "done ---------";

  fm.clear();
  exit(0);

}

comment:2 Changed 10 years ago by Steve Williams

The problem caused by the Analysis Data service sends a QT signal to the Mantidplot GUI but doesn't wait for the SLOT function to complete before changing the contents of the Analysis Data service again.

comment:3 Changed 10 years ago by Nick Draper

  • Status changed from new to closed
  • Resolution set to fixed

comment:4 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 2142

Note: See TracTickets for help on using tickets.