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 | _str += "Theories available: %s \n" % len(self.theory_list) |
---|
41 | if self.theory_list: |
---|
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 | _str += "Theory info: \n" |
---|
47 | _str += str(theory_data) |
---|
48 | #_str += "Theory info: \n" |
---|
49 | #_str += str(theory_state) |
---|
50 | return _str |
---|
51 | |
---|
52 | def clone(self): |
---|
53 | obj = DataState(copy.deepcopy(self.data)) |
---|
54 | obj.parent = self.parent |
---|
55 | obj.name = self.name |
---|
56 | obj.path = self.path |
---|
57 | obj.message = self.message |
---|
58 | obj.id = self.id |
---|
59 | for id, item in self.theory_list.iteritems(): |
---|
60 | theory_data, theory_state = item |
---|
61 | state = None |
---|
62 | if theory_state is not None: |
---|
63 | state = theory_state.clone() |
---|
64 | obj.theory_list[id] = [copy.deepcopy(theory_data), |
---|
65 | state] |
---|
66 | return obj |
---|
67 | |
---|
68 | def set_name(self, name): |
---|
69 | self.name = name |
---|
70 | |
---|
71 | def get_name(self): |
---|
72 | return self.name |
---|
73 | |
---|
74 | def set_data(self, data): |
---|
75 | self.data = data |
---|
76 | |
---|
77 | def get_data(self): |
---|
78 | return self.data |
---|
79 | |
---|
80 | def set_path(self, path): |
---|
81 | """ |
---|
82 | Set the path of the loaded data |
---|
83 | """ |
---|
84 | self.path = path |
---|
85 | |
---|
86 | def get_path(self): |
---|
87 | """ |
---|
88 | return the path of the loaded data |
---|
89 | """ |
---|
90 | return self.path |
---|
91 | |
---|
92 | def set_theory(self, theory_data, theory_state=None): |
---|
93 | """ |
---|
94 | """ |
---|
95 | self.theory_list[theory_data.id] = [theory_data, theory_state] |
---|
96 | data, state = self.theory_list.values()[0] |
---|
97 | |
---|
98 | def get_theory(self): |
---|
99 | return self.theory_list |
---|
100 | |
---|
101 | def get_message(self): |
---|
102 | """ |
---|
103 | return message |
---|
104 | """ |
---|
105 | return self.message |
---|
106 | |
---|
107 | |
---|