66from typing import Any , Callable , Dict , List , Optional , Set , Tuple
77
88import numpy as np
9+ from mantid .api import FileLoaderRegistry
910from mantid .dataobjects import MaskWorkspace
1011from pydantic import validate_call
1112
@@ -282,11 +283,7 @@ def _createDiffCalTableFilepath(
282283
283284 @validate_call
284285 def _lookupNormalizationWorkspaceFilename (
285- self ,
286- normcalRunNumber : str ,
287- useLiteMode : bool ,
288- version : Optional [int ],
289- state : str ,
286+ self , normcalRunNumber : str , useLiteMode : bool , version : Optional [int ], state : str
290287 ) -> str :
291288 # NOTE: The normCal Record currently does NOT store workspace type -> workspace name mappings.
292289 # It is just a list of workspace names. So we need to infer.
@@ -852,7 +849,14 @@ def _fetchNeutronDataSingleUse(self, item: GroceryListItem, missingDataHandler:
852849 self .getCloneOfWorkspace (rawWorkspaceName , workspaceName )
853850 elif bool (filePath ) and filePath .exists () and item .liveDataArgs is None :
854851 workspaceName = self ._createNeutronWorkspaceName (runNumber , useLiteMode )
855- data = self .grocer .executeRecipe (str (filePath ), workspaceName , loader )
852+ loaderArgs = "{}"
853+ if not bool (loader ) and Config ["nexus.dataFormat.event" ]:
854+ # If the loader hasn't been specified, check if this is original input data in event format.
855+ # In this case, specifying only a single bin allows a much faster load.
856+ loader = FileLoaderRegistry .Instance ().chooseLoader (str (filePath )).name ()
857+ if loader == "LoadEventNexus" :
858+ loaderArgs = '{"NumberOfBins": 1}'
859+ data = self .grocer .executeRecipe (str (filePath ), workspaceName , loader , loaderArgs = loaderArgs )
856860 else :
857861 data = missingDataHandler ()
858862 workspaceName = data ["workspace" ]
@@ -1242,11 +1246,12 @@ def fetchNormalizationWorkspace(self, item: GroceryListItem) -> Dict[str, Any]:
12421246 :rtype: Dict[str, Any]
12431247 """
12441248
1245- runNumber , useLiteMode , version , state , hidden = (
1249+ runNumber , useLiteMode , version , state , loader , hidden = (
12461250 item .runNumber ,
12471251 item .useLiteMode ,
12481252 item .normCalVersion ,
12491253 item .state ,
1254+ item .loader ,
12501255 item .hidden ,
12511256 )
12521257 normcalRunNumber = self ._lookupNormcalRunNumber (runNumber , useLiteMode , version , state )
@@ -1262,14 +1267,14 @@ def fetchNormalizationWorkspace(self, item: GroceryListItem) -> Dict[str, Any]:
12621267 self ._clearNormalizationCache ()
12631268
12641269 # then load the new one
1265- filename = self ._lookupNormalizationWorkspaceFilename (normcalRunNumber , useLiteMode , version , state )
1270+ filePath = self ._lookupNormalizationWorkspaceFilename (normcalRunNumber , useLiteMode , version , state )
1271+
1272+ # Unfortunately, `LoadNexusProcessed` does not support the `NumberOfBins=1` optimization for loading
1273+ # event data. As a work-around: event-format normalization data will be saved with only one bin
1274+ # to speed up reload. (See also: "nexus.dataFormat.event" flag in "application.yml".)
12661275
12671276 # Note: 'LoadNexusProcessed' neither requires nor makes use of an instrument donor.
1268- data = self .grocer .executeRecipe (
1269- filename = filename ,
1270- workspace = workspaceName ,
1271- loader = "LoadNexusProcessed" ,
1272- )
1277+ data = self .grocer .executeRecipe (filename = filePath , workspace = workspaceName , loader = loader )
12731278 self ._processNeutronDataCopy (item , workspaceName )
12741279 self .normalizationCache .add (workspaceName )
12751280 return data
@@ -1620,7 +1625,7 @@ def getResidentWorkspaces(self, excludeCache: bool):
16201625 return list (workspaces )
16211626
16221627 def _filterEvents (self , runNumber , workspaceName ):
1623- # NOTE: We always want to generate the instruemnt state, to get the latest SNAPInstPRm parameters.
1628+ # NOTE: We always want to generate the instrument state, to get the latest SNAPInstPRm parameters.
16241629 instrumentState = self .dataService .generateInstrumentState (runNumber )
16251630
16261631 self .mantidSnapper .CropWorkspace (
0 commit comments