1 | ################################################################################ |
---|
2 | #This software was developed by the University of Tennessee as part of the |
---|
3 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
4 | #project funded by the US National Science Foundation. |
---|
5 | # |
---|
6 | #See the license text in license.txt |
---|
7 | # |
---|
8 | #copyright 2010, University of Tennessee |
---|
9 | ################################################################################ |
---|
10 | """ |
---|
11 | """ |
---|
12 | import copy |
---|
13 | |
---|
14 | |
---|
15 | class DataState(object): |
---|
16 | """ |
---|
17 | Store information about data |
---|
18 | """ |
---|
19 | def __init__(self, data, parent=None): |
---|
20 | """ |
---|
21 | |
---|
22 | """ |
---|
23 | self.parent = parent |
---|
24 | self.data = data |
---|
25 | self.name = "" |
---|
26 | self.path = None |
---|
27 | self.theory_list = {} |
---|
28 | self.message = "" |
---|
29 | self.id = None |
---|
30 | |
---|
31 | def __str__(self): |
---|
32 | _str = "" |
---|
33 | _str += "State with ID : %s \n" % str(self.id) |
---|
34 | if self.data is not None: |
---|
35 | _str += "Data name : %s \n" % str(self.data.name) |
---|
36 | _str += "Data ID : %s \n" % str(self.data.id) |
---|
37 | else: |
---|
38 | _str += "Data: %s \n" % str(self.data) |
---|
39 | |
---|
40 | if self.theory_list: |
---|
41 | _str += "Theories available: \n" |
---|
42 | for id, item in self.theory_list.iteritems(): |
---|
43 | theory_data, theory_state = item |
---|
44 | _str += "Theory name : %s \n" % str(theory_data.name) |
---|
45 | _str += "Theory ID : %s \n" % str(id) |
---|
46 | else: |
---|
47 | for key , value in self.theory_list.iteritems(): |
---|
48 | theory_data, theory_state = value |
---|
49 | _str += "Theory with ID : %s \n" % str(key) |
---|
50 | _str += str(theory_data) |
---|
51 | _str += str(theory_state) |
---|
52 | return _str |
---|
53 | |
---|
54 | def clone(self): |
---|
55 | obj = DataState(copy.deepcopy(self.data)) |
---|
56 | obj.parent = self.parent |
---|
57 | obj.name = self.name |
---|
58 | obj.path = self.path |
---|
59 | obj.message = self.message |
---|
60 | obj.id = self.id |
---|
61 | for id, item in self.theory_list.iteritems(): |
---|
62 | theory_data, theory_state = item |
---|
63 | state = None |
---|
64 | if theory_state is not None: |
---|
65 | state = theory_state.clone() |
---|
66 | obj.theory_list[id] = [copy.deepcopy(theory_data), |
---|
67 | state] |
---|
68 | return obj |
---|
69 | |
---|
70 | def set_name(self, name): |
---|
71 | self.name = name |
---|
72 | |
---|
73 | def get_name(self): |
---|
74 | return self.name |
---|
75 | |
---|
76 | def set_data(self, data): |
---|
77 | self.data = data |
---|
78 | |
---|
79 | def get_data(self): |
---|
80 | return self.data |
---|
81 | |
---|
82 | def set_path(self, path): |
---|
83 | """ |
---|
84 | Set the path of the loaded data |
---|
85 | """ |
---|
86 | self.path = path |
---|
87 | |
---|
88 | def get_path(self): |
---|
89 | """ |
---|
90 | return the path of the loaded data |
---|
91 | """ |
---|
92 | return self.path |
---|
93 | |
---|
94 | def set_theory(self, theory_data, theory_state=None): |
---|
95 | """ |
---|
96 | """ |
---|
97 | self.theory_list[theory_data.id] = [theory_data, theory_state] |
---|
98 | |
---|
99 | def get_theory(self): |
---|
100 | return self.theory_list |
---|
101 | |
---|
102 | def get_message(self): |
---|
103 | """ |
---|
104 | return message |
---|
105 | """ |
---|
106 | return self.message |
---|
107 | |
---|
108 | |
---|