[3feed3e] | 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 | """ |
---|
[c70eb7c] | 12 | import copy |
---|
| 13 | |
---|
[3feed3e] | 14 | |
---|
| 15 | class DataState(object): |
---|
| 16 | """ |
---|
| 17 | Store information about data |
---|
| 18 | """ |
---|
[a3c96f7a] | 19 | def __init__(self, data, theory_data=None, model=None, parent=None): |
---|
[3feed3e] | 20 | """ |
---|
| 21 | |
---|
| 22 | """ |
---|
[a3c96f7a] | 23 | self.model = model |
---|
| 24 | self.theory_data = theory_data |
---|
[3feed3e] | 25 | self.parent = parent |
---|
[584c4c4] | 26 | self.data = data |
---|
| 27 | self.name = "" |
---|
| 28 | self.path = None |
---|
[5c4b674] | 29 | self.theory_list = {} |
---|
[584c4c4] | 30 | self.message = "" |
---|
[c70eb7c] | 31 | self.id = None |
---|
| 32 | |
---|
| 33 | def __str__(self): |
---|
| 34 | _str = "" |
---|
| 35 | _str += "State with ID : %s \n" % str(self.id) |
---|
| 36 | if self.data is not None: |
---|
| 37 | _str += "Data name : %s \n" % str(self.data.name) |
---|
| 38 | _str += "Data ID : %s \n" % str(self.data.id) |
---|
| 39 | else: |
---|
[a3c96f7a] | 40 | _str += "Theory Data: %s \n" % str(self.theory_data) |
---|
| 41 | if self.theory_data is not None: |
---|
| 42 | _str += "Data name : %s \n" % str(self.theory_data.name) |
---|
| 43 | _str += "Theory Data ID : %s \n" % str(self.theory_data.id) |
---|
| 44 | else: |
---|
| 45 | _str += "Theory Data: %s \n" % str(self.theory_data) |
---|
[c70eb7c] | 46 | |
---|
[df22224] | 47 | _str += "Theories available: %s \n" % len(self.theory_list) |
---|
[c70eb7c] | 48 | if self.theory_list: |
---|
| 49 | for id, item in self.theory_list.iteritems(): |
---|
| 50 | theory_data, theory_state = item |
---|
| 51 | _str += "Theory name : %s \n" % str(theory_data.name) |
---|
| 52 | _str += "Theory ID : %s \n" % str(id) |
---|
[df22224] | 53 | _str += "Theory info: \n" |
---|
[c70eb7c] | 54 | _str += str(theory_data) |
---|
[5080cda] | 55 | |
---|
[c70eb7c] | 56 | return _str |
---|
| 57 | |
---|
| 58 | def clone(self): |
---|
| 59 | obj = DataState(copy.deepcopy(self.data)) |
---|
| 60 | obj.parent = self.parent |
---|
| 61 | obj.name = self.name |
---|
| 62 | obj.path = self.path |
---|
| 63 | obj.message = self.message |
---|
| 64 | obj.id = self.id |
---|
| 65 | for id, item in self.theory_list.iteritems(): |
---|
| 66 | theory_data, theory_state = item |
---|
| 67 | state = None |
---|
| 68 | if theory_state is not None: |
---|
| 69 | state = theory_state.clone() |
---|
| 70 | obj.theory_list[id] = [copy.deepcopy(theory_data), |
---|
| 71 | state] |
---|
| 72 | return obj |
---|
[3feed3e] | 73 | |
---|
| 74 | def set_name(self, name): |
---|
[584c4c4] | 75 | self.name = name |
---|
[c70eb7c] | 76 | |
---|
[3feed3e] | 77 | def get_name(self): |
---|
[584c4c4] | 78 | return self.name |
---|
[c70eb7c] | 79 | |
---|
[3feed3e] | 80 | def set_data(self, data): |
---|
[584c4c4] | 81 | self.data = data |
---|
[3feed3e] | 82 | |
---|
[a3c96f7a] | 83 | def set_theory_data(self, theory_data): |
---|
| 84 | """ |
---|
| 85 | """ |
---|
| 86 | self.theory_data = theory_data |
---|
| 87 | |
---|
| 88 | def get_theory_data(self): |
---|
| 89 | """ |
---|
| 90 | """ |
---|
| 91 | return self.theory_data |
---|
| 92 | |
---|
| 93 | def set_model(self, model): |
---|
| 94 | """ |
---|
| 95 | """ |
---|
| 96 | self.model = model |
---|
| 97 | |
---|
| 98 | def get_model(self): |
---|
| 99 | """ |
---|
| 100 | """ |
---|
| 101 | return self.model |
---|
| 102 | |
---|
[3feed3e] | 103 | def get_data(self): |
---|
[584c4c4] | 104 | return self.data |
---|
[3feed3e] | 105 | |
---|
| 106 | def set_path(self, path): |
---|
| 107 | """ |
---|
| 108 | Set the path of the loaded data |
---|
| 109 | """ |
---|
[584c4c4] | 110 | self.path = path |
---|
[3feed3e] | 111 | |
---|
| 112 | def get_path(self): |
---|
| 113 | """ |
---|
| 114 | return the path of the loaded data |
---|
| 115 | """ |
---|
[584c4c4] | 116 | return self.path |
---|
[3feed3e] | 117 | |
---|
[c70eb7c] | 118 | def set_theory(self, theory_data, theory_state=None): |
---|
[3feed3e] | 119 | """ |
---|
| 120 | """ |
---|
[c70eb7c] | 121 | self.theory_list[theory_data.id] = [theory_data, theory_state] |
---|
[df22224] | 122 | data, state = self.theory_list.values()[0] |
---|
[552b3d5] | 123 | |
---|
[3feed3e] | 124 | def get_theory(self): |
---|
[584c4c4] | 125 | return self.theory_list |
---|
[3feed3e] | 126 | |
---|
| 127 | def get_message(self): |
---|
| 128 | """ |
---|
| 129 | return message |
---|
| 130 | """ |
---|
[584c4c4] | 131 | return self.message |
---|
[3feed3e] | 132 | |
---|
| 133 | |
---|