forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CheckForSampleLogs.py
61 lines (50 loc) · 2.02 KB
/
CheckForSampleLogs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
#pylint: disable=invalid-name, no-init
from mantid.api import PythonAlgorithm, AlgorithmFactory, WorkspaceProperty
from mantid.kernel import Direction, logger
class CheckForSampleLogs(PythonAlgorithm):
""" Check if certain sample logs exists on a workspace
"""
def category(self):
""" Return category
"""
return "Utility\\Workspaces"
def seeAlso(self):
return [ "CompareSampleLogs","CopyLogs" ]
def name(self):
""" Return name
"""
return "CheckForSampleLogs"
def summary(self):
return "Check if the workspace has some given sample logs"
def PyInit(self):
""" Declare properties
"""
self.declareProperty(WorkspaceProperty("Workspace", "",Direction.Input), "The workspace to check.")
self.declareProperty("LogNames","","Names of the logs to look for")
self.declareProperty("Result","A string that will be empty if all the logs are found, "
"otherwise will contain an error message",Direction.Output)
return
def PyExec(self):
""" Main execution body
"""
#get parameters
w = self.getProperty("Workspace").value
logNames = self.getProperty("LogNames").value
resultString=''
#check for parameters and build the result string
for value in logNames.split(','):
value=value.strip()
if len(value)>0:
if not w.run().hasProperty(value):
resultString+='Property '+value+' not found\n'
#return the result
logger.notice(resultString)
self.setProperty("Result",resultString)
return
AlgorithmFactory.subscribe(CheckForSampleLogs)