@@ -0,0 +1,68 | |||||
|
1 | ''' | |||
|
2 | Created on Jul 9, 2014 | |||
|
3 | ||||
|
4 | @author: roj-idl71 | |||
|
5 | ''' | |||
|
6 | import os | |||
|
7 | import datetime | |||
|
8 | import numpy | |||
|
9 | ||||
|
10 | from figure import Figure | |||
|
11 | ||||
|
12 | class Plotter(Figure): | |||
|
13 | ||||
|
14 | isConfig = None | |||
|
15 | name = None | |||
|
16 | plotterQueue = None | |||
|
17 | ||||
|
18 | def __init__(self, plotter_name, plotter_queue=None): | |||
|
19 | ||||
|
20 | self.isConfig = False | |||
|
21 | self.name = plotter_name | |||
|
22 | self.plotterQueue = plotter_queue | |||
|
23 | ||||
|
24 | def getSubplots(self): | |||
|
25 | ||||
|
26 | nrow = self.nplots | |||
|
27 | ncol = 1 | |||
|
28 | return nrow, ncol | |||
|
29 | ||||
|
30 | def setup(self, **kwargs): | |||
|
31 | ||||
|
32 | # self.nplots = nplots | |||
|
33 | # | |||
|
34 | # self.createFigure(id=id, | |||
|
35 | # wintitle=wintitle, | |||
|
36 | # show=show) | |||
|
37 | # | |||
|
38 | # nrow,ncol = self.getSubplots() | |||
|
39 | # colspan = 3 | |||
|
40 | # rowspan = 1 | |||
|
41 | # | |||
|
42 | # for i in range(nplots): | |||
|
43 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |||
|
44 | ||||
|
45 | ||||
|
46 | ||||
|
47 | print "Initializing ..." | |||
|
48 | ||||
|
49 | ||||
|
50 | def run(self, dataOut, **kwargs): | |||
|
51 | ||||
|
52 | """ | |||
|
53 | ||||
|
54 | Input: | |||
|
55 | dataOut : | |||
|
56 | id : | |||
|
57 | wintitle : | |||
|
58 | channelList : | |||
|
59 | show : | |||
|
60 | """ | |||
|
61 | ||||
|
62 | if not self.isConfig: | |||
|
63 | self.setup(**kwargs) | |||
|
64 | self.isConfig=True | |||
|
65 | ||||
|
66 | print "Putting data on %s queue:" %self.name | |||
|
67 | print kwargs | |||
|
68 |
@@ -1,7 +1,7 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
__version__ = "2.1.4. |
|
7 | __version__ = "2.1.4.2" No newline at end of file |
@@ -1,1234 +1,1252 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on September , 2012 |
|
2 | Created on September , 2012 | |
3 | @author: |
|
3 | @author: | |
4 | ''' |
|
4 | ''' | |
5 |
|
5 | |||
6 | import sys |
|
6 | import sys | |
7 | import ast |
|
7 | import ast | |
8 | import datetime |
|
8 | import datetime | |
9 | import traceback |
|
9 | import traceback | |
10 | import schainpy |
|
10 | import schainpy | |
11 | import schainpy.admin |
|
11 | import schainpy.admin | |
12 |
|
12 | |||
13 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
13 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring | |
14 | from xml.dom import minidom |
|
14 | from xml.dom import minidom | |
15 |
|
15 | |||
16 | from schainpy.model import * |
|
16 | from schainpy.model import * | |
17 | from time import sleep |
|
17 | from time import sleep | |
18 |
|
18 | |||
19 | def prettify(elem): |
|
19 | def prettify(elem): | |
20 | """Return a pretty-printed XML string for the Element. |
|
20 | """Return a pretty-printed XML string for the Element. | |
21 | """ |
|
21 | """ | |
22 | rough_string = tostring(elem, 'utf-8') |
|
22 | rough_string = tostring(elem, 'utf-8') | |
23 | reparsed = minidom.parseString(rough_string) |
|
23 | reparsed = minidom.parseString(rough_string) | |
24 | return reparsed.toprettyxml(indent=" ") |
|
24 | return reparsed.toprettyxml(indent=" ") | |
25 |
|
25 | |||
26 | class ParameterConf(): |
|
26 | class ParameterConf(): | |
27 |
|
27 | |||
28 | id = None |
|
28 | id = None | |
29 | name = None |
|
29 | name = None | |
30 | value = None |
|
30 | value = None | |
31 | format = None |
|
31 | format = None | |
32 |
|
32 | |||
33 | __formated_value = None |
|
33 | __formated_value = None | |
34 |
|
34 | |||
35 | ELEMENTNAME = 'Parameter' |
|
35 | ELEMENTNAME = 'Parameter' | |
36 |
|
36 | |||
37 | def __init__(self): |
|
37 | def __init__(self): | |
38 |
|
38 | |||
39 | self.format = 'str' |
|
39 | self.format = 'str' | |
40 |
|
40 | |||
41 | def getElementName(self): |
|
41 | def getElementName(self): | |
42 |
|
42 | |||
43 | return self.ELEMENTNAME |
|
43 | return self.ELEMENTNAME | |
44 |
|
44 | |||
45 | def getValue(self): |
|
45 | def getValue(self): | |
46 |
|
46 | |||
47 | value = self.value |
|
47 | value = self.value | |
48 | format = self.format |
|
48 | format = self.format | |
49 |
|
49 | |||
50 | if self.__formated_value != None: |
|
50 | if self.__formated_value != None: | |
51 |
|
51 | |||
52 | return self.__formated_value |
|
52 | return self.__formated_value | |
53 |
|
53 | |||
54 | if format == 'str': |
|
54 | if format == 'str': | |
55 | self.__formated_value = str(value) |
|
55 | self.__formated_value = str(value) | |
56 | return self.__formated_value |
|
56 | return self.__formated_value | |
57 |
|
57 | |||
58 | if value == '': |
|
58 | if value == '': | |
59 | raise ValueError, "%s: This parameter value is empty" %self.name |
|
59 | raise ValueError, "%s: This parameter value is empty" %self.name | |
60 |
|
60 | |||
61 | if format == 'list': |
|
61 | if format == 'list': | |
62 | strList = value.split(',') |
|
62 | strList = value.split(',') | |
63 |
|
63 | |||
64 | self.__formated_value = strList |
|
64 | self.__formated_value = strList | |
65 |
|
65 | |||
66 | return self.__formated_value |
|
66 | return self.__formated_value | |
67 |
|
67 | |||
68 | if format == 'intlist': |
|
68 | if format == 'intlist': | |
69 | """ |
|
69 | """ | |
70 | Example: |
|
70 | Example: | |
71 | value = (0,1,2) |
|
71 | value = (0,1,2) | |
72 | """ |
|
72 | """ | |
73 | value = value.replace('(', '') |
|
73 | value = value.replace('(', '') | |
74 | value = value.replace(')', '') |
|
74 | value = value.replace(')', '') | |
75 |
|
75 | |||
76 | value = value.replace('[', '') |
|
76 | value = value.replace('[', '') | |
77 | value = value.replace(']', '') |
|
77 | value = value.replace(']', '') | |
78 |
|
78 | |||
79 | strList = value.split(',') |
|
79 | strList = value.split(',') | |
80 | intList = [int(float(x)) for x in strList] |
|
80 | intList = [int(float(x)) for x in strList] | |
81 |
|
81 | |||
82 | self.__formated_value = intList |
|
82 | self.__formated_value = intList | |
83 |
|
83 | |||
84 | return self.__formated_value |
|
84 | return self.__formated_value | |
85 |
|
85 | |||
86 | if format == 'floatlist': |
|
86 | if format == 'floatlist': | |
87 | """ |
|
87 | """ | |
88 | Example: |
|
88 | Example: | |
89 | value = (0.5, 1.4, 2.7) |
|
89 | value = (0.5, 1.4, 2.7) | |
90 | """ |
|
90 | """ | |
91 |
|
91 | |||
92 | value = value.replace('(', '') |
|
92 | value = value.replace('(', '') | |
93 | value = value.replace(')', '') |
|
93 | value = value.replace(')', '') | |
94 |
|
94 | |||
95 | value = value.replace('[', '') |
|
95 | value = value.replace('[', '') | |
96 | value = value.replace(']', '') |
|
96 | value = value.replace(']', '') | |
97 |
|
97 | |||
98 | strList = value.split(',') |
|
98 | strList = value.split(',') | |
99 | floatList = [float(x) for x in strList] |
|
99 | floatList = [float(x) for x in strList] | |
100 |
|
100 | |||
101 | self.__formated_value = floatList |
|
101 | self.__formated_value = floatList | |
102 |
|
102 | |||
103 | return self.__formated_value |
|
103 | return self.__formated_value | |
104 |
|
104 | |||
105 | if format == 'date': |
|
105 | if format == 'date': | |
106 | strList = value.split('/') |
|
106 | strList = value.split('/') | |
107 | intList = [int(x) for x in strList] |
|
107 | intList = [int(x) for x in strList] | |
108 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
108 | date = datetime.date(intList[0], intList[1], intList[2]) | |
109 |
|
109 | |||
110 | self.__formated_value = date |
|
110 | self.__formated_value = date | |
111 |
|
111 | |||
112 | return self.__formated_value |
|
112 | return self.__formated_value | |
113 |
|
113 | |||
114 | if format == 'time': |
|
114 | if format == 'time': | |
115 | strList = value.split(':') |
|
115 | strList = value.split(':') | |
116 | intList = [int(x) for x in strList] |
|
116 | intList = [int(x) for x in strList] | |
117 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
117 | time = datetime.time(intList[0], intList[1], intList[2]) | |
118 |
|
118 | |||
119 | self.__formated_value = time |
|
119 | self.__formated_value = time | |
120 |
|
120 | |||
121 | return self.__formated_value |
|
121 | return self.__formated_value | |
122 |
|
122 | |||
123 | if format == 'pairslist': |
|
123 | if format == 'pairslist': | |
124 | """ |
|
124 | """ | |
125 | Example: |
|
125 | Example: | |
126 | value = (0,1),(1,2) |
|
126 | value = (0,1),(1,2) | |
127 | """ |
|
127 | """ | |
128 |
|
128 | |||
129 | value = value.replace('(', '') |
|
129 | value = value.replace('(', '') | |
130 | value = value.replace(')', '') |
|
130 | value = value.replace(')', '') | |
131 |
|
131 | |||
132 | value = value.replace('[', '') |
|
132 | value = value.replace('[', '') | |
133 | value = value.replace(']', '') |
|
133 | value = value.replace(']', '') | |
134 |
|
134 | |||
135 | strList = value.split(',') |
|
135 | strList = value.split(',') | |
136 | intList = [int(item) for item in strList] |
|
136 | intList = [int(item) for item in strList] | |
137 | pairList = [] |
|
137 | pairList = [] | |
138 | for i in range(len(intList)/2): |
|
138 | for i in range(len(intList)/2): | |
139 | pairList.append((intList[i*2], intList[i*2 + 1])) |
|
139 | pairList.append((intList[i*2], intList[i*2 + 1])) | |
140 |
|
140 | |||
141 | self.__formated_value = pairList |
|
141 | self.__formated_value = pairList | |
142 |
|
142 | |||
143 | return self.__formated_value |
|
143 | return self.__formated_value | |
144 |
|
144 | |||
145 | if format == 'multilist': |
|
145 | if format == 'multilist': | |
146 | """ |
|
146 | """ | |
147 | Example: |
|
147 | Example: | |
148 | value = (0,1,2),(3,4,5) |
|
148 | value = (0,1,2),(3,4,5) | |
149 | """ |
|
149 | """ | |
150 | multiList = ast.literal_eval(value) |
|
150 | multiList = ast.literal_eval(value) | |
151 |
|
151 | |||
152 | if type(multiList[0]) == int: |
|
152 | if type(multiList[0]) == int: | |
153 | multiList = ast.literal_eval("(" + value + ")") |
|
153 | multiList = ast.literal_eval("(" + value + ")") | |
154 |
|
154 | |||
155 | self.__formated_value = multiList |
|
155 | self.__formated_value = multiList | |
156 |
|
156 | |||
157 | return self.__formated_value |
|
157 | return self.__formated_value | |
158 |
|
158 | |||
159 | if format == 'bool': |
|
159 | if format == 'bool': | |
160 | value = int(value) |
|
160 | value = int(value) | |
161 |
|
161 | |||
162 | if format == 'int': |
|
162 | if format == 'int': | |
163 | value = float(value) |
|
163 | value = float(value) | |
164 |
|
164 | |||
165 | format_func = eval(format) |
|
165 | format_func = eval(format) | |
166 |
|
166 | |||
167 | self.__formated_value = format_func(value) |
|
167 | self.__formated_value = format_func(value) | |
168 |
|
168 | |||
169 | return self.__formated_value |
|
169 | return self.__formated_value | |
170 |
|
170 | |||
171 | def updateId(self, new_id): |
|
171 | def updateId(self, new_id): | |
172 |
|
172 | |||
173 | self.id = str(new_id) |
|
173 | self.id = str(new_id) | |
174 |
|
174 | |||
175 | def setup(self, id, name, value, format='str'): |
|
175 | def setup(self, id, name, value, format='str'): | |
176 |
|
176 | |||
177 | self.id = str(id) |
|
177 | self.id = str(id) | |
178 | self.name = name |
|
178 | self.name = name | |
179 | self.value = str(value) |
|
179 | self.value = str(value) | |
180 | self.format = str.lower(format) |
|
180 | self.format = str.lower(format) | |
181 |
|
181 | |||
182 | try: |
|
182 | try: | |
183 | self.getValue() |
|
183 | self.getValue() | |
184 | except: |
|
184 | except: | |
185 | return 0 |
|
185 | return 0 | |
186 |
|
186 | |||
187 | return 1 |
|
187 | return 1 | |
188 |
|
188 | |||
189 | def update(self, name, value, format='str'): |
|
189 | def update(self, name, value, format='str'): | |
190 |
|
190 | |||
191 | self.name = name |
|
191 | self.name = name | |
192 | self.value = str(value) |
|
192 | self.value = str(value) | |
193 | self.format = format |
|
193 | self.format = format | |
194 |
|
194 | |||
195 | def makeXml(self, opElement): |
|
195 | def makeXml(self, opElement): | |
196 |
|
196 | |||
197 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
197 | parmElement = SubElement(opElement, self.ELEMENTNAME) | |
198 | parmElement.set('id', str(self.id)) |
|
198 | parmElement.set('id', str(self.id)) | |
199 | parmElement.set('name', self.name) |
|
199 | parmElement.set('name', self.name) | |
200 | parmElement.set('value', self.value) |
|
200 | parmElement.set('value', self.value) | |
201 | parmElement.set('format', self.format) |
|
201 | parmElement.set('format', self.format) | |
202 |
|
202 | |||
203 | def readXml(self, parmElement): |
|
203 | def readXml(self, parmElement): | |
204 |
|
204 | |||
205 | self.id = parmElement.get('id') |
|
205 | self.id = parmElement.get('id') | |
206 | self.name = parmElement.get('name') |
|
206 | self.name = parmElement.get('name') | |
207 | self.value = parmElement.get('value') |
|
207 | self.value = parmElement.get('value') | |
208 | self.format = str.lower(parmElement.get('format')) |
|
208 | self.format = str.lower(parmElement.get('format')) | |
209 |
|
209 | |||
210 | #Compatible with old signal chain version |
|
210 | #Compatible with old signal chain version | |
211 | if self.format == 'int' and self.name == 'idfigure': |
|
211 | if self.format == 'int' and self.name == 'idfigure': | |
212 | self.name = 'id' |
|
212 | self.name = 'id' | |
213 |
|
213 | |||
214 | def printattr(self): |
|
214 | def printattr(self): | |
215 |
|
215 | |||
216 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
216 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) | |
217 |
|
217 | |||
218 | class OperationConf(): |
|
218 | class OperationConf(): | |
219 |
|
219 | |||
220 | id = None |
|
220 | id = None | |
221 | name = None |
|
221 | name = None | |
222 | priority = None |
|
222 | priority = None | |
223 | type = None |
|
223 | type = None | |
224 |
|
224 | |||
225 | parmConfObjList = [] |
|
225 | parmConfObjList = [] | |
226 |
|
226 | |||
227 | ELEMENTNAME = 'Operation' |
|
227 | ELEMENTNAME = 'Operation' | |
228 |
|
228 | |||
229 | def __init__(self): |
|
229 | def __init__(self): | |
230 |
|
230 | |||
231 | self.id = '0' |
|
231 | self.id = '0' | |
232 | self.name = None |
|
232 | self.name = None | |
233 | self.priority = None |
|
233 | self.priority = None | |
234 | self.type = 'self' |
|
234 | self.type = 'self' | |
235 |
|
235 | |||
236 |
|
236 | |||
237 | def __getNewId(self): |
|
237 | def __getNewId(self): | |
238 |
|
238 | |||
239 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
239 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
240 |
|
240 | |||
241 | def updateId(self, new_id): |
|
241 | def updateId(self, new_id): | |
242 |
|
242 | |||
243 | self.id = str(new_id) |
|
243 | self.id = str(new_id) | |
244 |
|
244 | |||
245 | n = 1 |
|
245 | n = 1 | |
246 | for parmObj in self.parmConfObjList: |
|
246 | for parmObj in self.parmConfObjList: | |
247 |
|
247 | |||
248 | idParm = str(int(new_id)*10 + n) |
|
248 | idParm = str(int(new_id)*10 + n) | |
249 | parmObj.updateId(idParm) |
|
249 | parmObj.updateId(idParm) | |
250 |
|
250 | |||
251 | n += 1 |
|
251 | n += 1 | |
252 |
|
252 | |||
253 | def getElementName(self): |
|
253 | def getElementName(self): | |
254 |
|
254 | |||
255 | return self.ELEMENTNAME |
|
255 | return self.ELEMENTNAME | |
256 |
|
256 | |||
257 | def getParameterObjList(self): |
|
257 | def getParameterObjList(self): | |
258 |
|
258 | |||
259 | return self.parmConfObjList |
|
259 | return self.parmConfObjList | |
260 |
|
260 | |||
261 | def getParameterObj(self, parameterName): |
|
261 | def getParameterObj(self, parameterName): | |
262 |
|
262 | |||
263 | for parmConfObj in self.parmConfObjList: |
|
263 | for parmConfObj in self.parmConfObjList: | |
264 |
|
264 | |||
265 | if parmConfObj.name != parameterName: |
|
265 | if parmConfObj.name != parameterName: | |
266 | continue |
|
266 | continue | |
267 |
|
267 | |||
268 | return parmConfObj |
|
268 | return parmConfObj | |
269 |
|
269 | |||
270 | return None |
|
270 | return None | |
271 |
|
271 | |||
272 | def getParameterObjfromValue(self, parameterValue): |
|
272 | def getParameterObjfromValue(self, parameterValue): | |
273 |
|
273 | |||
274 | for parmConfObj in self.parmConfObjList: |
|
274 | for parmConfObj in self.parmConfObjList: | |
275 |
|
275 | |||
276 | if parmConfObj.getValue() != parameterValue: |
|
276 | if parmConfObj.getValue() != parameterValue: | |
277 | continue |
|
277 | continue | |
278 |
|
278 | |||
279 | return parmConfObj.getValue() |
|
279 | return parmConfObj.getValue() | |
280 |
|
280 | |||
281 | return None |
|
281 | return None | |
282 |
|
282 | |||
283 | def getParameterValue(self, parameterName): |
|
283 | def getParameterValue(self, parameterName): | |
284 |
|
284 | |||
285 | parameterObj = self.getParameterObj(parameterName) |
|
285 | parameterObj = self.getParameterObj(parameterName) | |
286 |
|
286 | |||
287 | # if not parameterObj: |
|
287 | # if not parameterObj: | |
288 | # return None |
|
288 | # return None | |
289 |
|
289 | |||
290 | value = parameterObj.getValue() |
|
290 | value = parameterObj.getValue() | |
291 |
|
291 | |||
292 | return value |
|
292 | return value | |
293 |
|
293 | |||
294 | def setup(self, id, name, priority, type): |
|
294 | def setup(self, id, name, priority, type): | |
295 |
|
295 | |||
296 | self.id = str(id) |
|
296 | self.id = str(id) | |
297 | self.name = name |
|
297 | self.name = name | |
298 | self.type = type |
|
298 | self.type = type | |
299 | self.priority = priority |
|
299 | self.priority = priority | |
300 |
|
300 | |||
301 | self.parmConfObjList = [] |
|
301 | self.parmConfObjList = [] | |
302 |
|
302 | |||
303 | def removeParameters(self): |
|
303 | def removeParameters(self): | |
304 |
|
304 | |||
305 | for obj in self.parmConfObjList: |
|
305 | for obj in self.parmConfObjList: | |
306 | del obj |
|
306 | del obj | |
307 |
|
307 | |||
308 | self.parmConfObjList = [] |
|
308 | self.parmConfObjList = [] | |
309 |
|
309 | |||
310 | def addParameter(self, name, value, format='str'): |
|
310 | def addParameter(self, name, value, format='str'): | |
311 |
|
311 | |||
312 | id = self.__getNewId() |
|
312 | id = self.__getNewId() | |
313 |
|
313 | |||
314 | parmConfObj = ParameterConf() |
|
314 | parmConfObj = ParameterConf() | |
315 | if not parmConfObj.setup(id, name, value, format): |
|
315 | if not parmConfObj.setup(id, name, value, format): | |
316 | return None |
|
316 | return None | |
317 |
|
317 | |||
318 | self.parmConfObjList.append(parmConfObj) |
|
318 | self.parmConfObjList.append(parmConfObj) | |
319 |
|
319 | |||
320 | return parmConfObj |
|
320 | return parmConfObj | |
321 |
|
321 | |||
322 | def changeParameter(self, name, value, format='str'): |
|
322 | def changeParameter(self, name, value, format='str'): | |
323 |
|
323 | |||
324 | parmConfObj = self.getParameterObj(name) |
|
324 | parmConfObj = self.getParameterObj(name) | |
325 | parmConfObj.update(name, value, format) |
|
325 | parmConfObj.update(name, value, format) | |
326 |
|
326 | |||
327 | return parmConfObj |
|
327 | return parmConfObj | |
328 |
|
328 | |||
329 | def makeXml(self, procUnitElement): |
|
329 | def makeXml(self, procUnitElement): | |
330 |
|
330 | |||
331 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
331 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) | |
332 | opElement.set('id', str(self.id)) |
|
332 | opElement.set('id', str(self.id)) | |
333 | opElement.set('name', self.name) |
|
333 | opElement.set('name', self.name) | |
334 | opElement.set('type', self.type) |
|
334 | opElement.set('type', self.type) | |
335 | opElement.set('priority', str(self.priority)) |
|
335 | opElement.set('priority', str(self.priority)) | |
336 |
|
336 | |||
337 | for parmConfObj in self.parmConfObjList: |
|
337 | for parmConfObj in self.parmConfObjList: | |
338 | parmConfObj.makeXml(opElement) |
|
338 | parmConfObj.makeXml(opElement) | |
339 |
|
339 | |||
340 | def readXml(self, opElement): |
|
340 | def readXml(self, opElement): | |
341 |
|
341 | |||
342 | self.id = opElement.get('id') |
|
342 | self.id = opElement.get('id') | |
343 | self.name = opElement.get('name') |
|
343 | self.name = opElement.get('name') | |
344 | self.type = opElement.get('type') |
|
344 | self.type = opElement.get('type') | |
345 | self.priority = opElement.get('priority') |
|
345 | self.priority = opElement.get('priority') | |
346 |
|
346 | |||
347 | #Compatible with old signal chain version |
|
347 | #Compatible with old signal chain version | |
348 | #Use of 'run' method instead 'init' |
|
348 | #Use of 'run' method instead 'init' | |
349 | if self.type == 'self' and self.name == 'init': |
|
349 | if self.type == 'self' and self.name == 'init': | |
350 | self.name = 'run' |
|
350 | self.name = 'run' | |
351 |
|
351 | |||
352 | self.parmConfObjList = [] |
|
352 | self.parmConfObjList = [] | |
353 |
|
353 | |||
354 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
354 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) | |
355 |
|
355 | |||
356 | for parmElement in parmElementList: |
|
356 | for parmElement in parmElementList: | |
357 | parmConfObj = ParameterConf() |
|
357 | parmConfObj = ParameterConf() | |
358 | parmConfObj.readXml(parmElement) |
|
358 | parmConfObj.readXml(parmElement) | |
359 |
|
359 | |||
360 | #Compatible with old signal chain version |
|
360 | #Compatible with old signal chain version | |
361 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER |
|
361 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
362 | if self.type != 'self' and self.name == 'Plot': |
|
362 | if self.type != 'self' and self.name == 'Plot': | |
363 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
363 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': | |
364 | self.name = parmConfObj.value |
|
364 | self.name = parmConfObj.value | |
365 | continue |
|
365 | continue | |
366 |
|
366 | |||
367 | self.parmConfObjList.append(parmConfObj) |
|
367 | self.parmConfObjList.append(parmConfObj) | |
368 |
|
368 | |||
369 | def printattr(self): |
|
369 | def printattr(self): | |
370 |
|
370 | |||
371 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
371 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, | |
372 | self.id, |
|
372 | self.id, | |
373 | self.name, |
|
373 | self.name, | |
374 | self.type, |
|
374 | self.type, | |
375 | self.priority) |
|
375 | self.priority) | |
376 |
|
376 | |||
377 | for parmConfObj in self.parmConfObjList: |
|
377 | for parmConfObj in self.parmConfObjList: | |
378 | parmConfObj.printattr() |
|
378 | parmConfObj.printattr() | |
379 |
|
379 | |||
380 | def createObject(self): |
|
380 | def createObject(self, plotter_queue=None): | |
381 |
|
381 | |||
382 | if self.type == 'self': |
|
382 | if self.type == 'self': | |
383 | raise ValueError, "This operation type cannot be created" |
|
383 | raise ValueError, "This operation type cannot be created" | |
384 |
|
384 | |||
|
385 | if self.type == 'plotter': | |||
|
386 | #Plotter(plotter_name) | |||
|
387 | opObj = Plotter(self.name, plotter_queue) | |||
|
388 | ||||
385 | if self.type == 'external' or self.type == 'other': |
|
389 | if self.type == 'external' or self.type == 'other': | |
386 | className = eval(self.name) |
|
390 | className = eval(self.name) | |
387 | opObj = className() |
|
391 | opObj = className() | |
388 |
|
392 | |||
389 | return opObj |
|
393 | return opObj | |
390 |
|
394 | |||
391 | class ProcUnitConf(): |
|
395 | class ProcUnitConf(): | |
392 |
|
396 | |||
393 | id = None |
|
397 | id = None | |
394 | name = None |
|
398 | name = None | |
395 | datatype = None |
|
399 | datatype = None | |
396 | inputId = None |
|
400 | inputId = None | |
397 | parentId = None |
|
401 | parentId = None | |
398 |
|
402 | |||
399 | opConfObjList = [] |
|
403 | opConfObjList = [] | |
400 |
|
404 | |||
401 | procUnitObj = None |
|
405 | procUnitObj = None | |
402 | opObjList = [] |
|
406 | opObjList = [] | |
403 |
|
407 | |||
404 | ELEMENTNAME = 'ProcUnit' |
|
408 | ELEMENTNAME = 'ProcUnit' | |
405 |
|
409 | |||
406 | def __init__(self): |
|
410 | def __init__(self): | |
407 |
|
411 | |||
408 | self.id = None |
|
412 | self.id = None | |
409 | self.datatype = None |
|
413 | self.datatype = None | |
410 | self.name = None |
|
414 | self.name = None | |
411 | self.inputId = None |
|
415 | self.inputId = None | |
412 |
|
416 | |||
413 | self.opConfObjList = [] |
|
417 | self.opConfObjList = [] | |
414 |
|
418 | |||
415 | self.procUnitObj = None |
|
419 | self.procUnitObj = None | |
416 | self.opObjDict = {} |
|
420 | self.opObjDict = {} | |
417 |
|
421 | |||
418 | def __getPriority(self): |
|
422 | def __getPriority(self): | |
419 |
|
423 | |||
420 | return len(self.opConfObjList)+1 |
|
424 | return len(self.opConfObjList)+1 | |
421 |
|
425 | |||
422 | def __getNewId(self): |
|
426 | def __getNewId(self): | |
423 |
|
427 | |||
424 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
428 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
425 |
|
429 | |||
426 | def getElementName(self): |
|
430 | def getElementName(self): | |
427 |
|
431 | |||
428 | return self.ELEMENTNAME |
|
432 | return self.ELEMENTNAME | |
429 |
|
433 | |||
430 | def getId(self): |
|
434 | def getId(self): | |
431 |
|
435 | |||
432 | return self.id |
|
436 | return self.id | |
433 |
|
437 | |||
434 | def updateId(self, new_id, parentId=parentId): |
|
438 | def updateId(self, new_id, parentId=parentId): | |
435 |
|
439 | |||
436 |
|
440 | |||
437 | new_id = int(parentId)*10 + (int(self.id) % 10) |
|
441 | new_id = int(parentId)*10 + (int(self.id) % 10) | |
438 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) |
|
442 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) | |
439 |
|
443 | |||
440 | #If this proc unit has not inputs |
|
444 | #If this proc unit has not inputs | |
441 | if self.inputId == '0': |
|
445 | if self.inputId == '0': | |
442 | new_inputId = 0 |
|
446 | new_inputId = 0 | |
443 |
|
447 | |||
444 | n = 1 |
|
448 | n = 1 | |
445 | for opConfObj in self.opConfObjList: |
|
449 | for opConfObj in self.opConfObjList: | |
446 |
|
450 | |||
447 | idOp = str(int(new_id)*10 + n) |
|
451 | idOp = str(int(new_id)*10 + n) | |
448 | opConfObj.updateId(idOp) |
|
452 | opConfObj.updateId(idOp) | |
449 |
|
453 | |||
450 | n += 1 |
|
454 | n += 1 | |
451 |
|
455 | |||
452 | self.parentId = str(parentId) |
|
456 | self.parentId = str(parentId) | |
453 | self.id = str(new_id) |
|
457 | self.id = str(new_id) | |
454 | self.inputId = str(new_inputId) |
|
458 | self.inputId = str(new_inputId) | |
455 |
|
459 | |||
456 |
|
460 | |||
457 | def getInputId(self): |
|
461 | def getInputId(self): | |
458 |
|
462 | |||
459 | return self.inputId |
|
463 | return self.inputId | |
460 |
|
464 | |||
461 | def getOperationObjList(self): |
|
465 | def getOperationObjList(self): | |
462 |
|
466 | |||
463 | return self.opConfObjList |
|
467 | return self.opConfObjList | |
464 |
|
468 | |||
465 | def getOperationObj(self, name=None): |
|
469 | def getOperationObj(self, name=None): | |
466 |
|
470 | |||
467 | for opConfObj in self.opConfObjList: |
|
471 | for opConfObj in self.opConfObjList: | |
468 |
|
472 | |||
469 | if opConfObj.name != name: |
|
473 | if opConfObj.name != name: | |
470 | continue |
|
474 | continue | |
471 |
|
475 | |||
472 | return opConfObj |
|
476 | return opConfObj | |
473 |
|
477 | |||
474 | return None |
|
478 | return None | |
475 |
|
479 | |||
476 | def getOpObjfromParamValue(self, value=None): |
|
480 | def getOpObjfromParamValue(self, value=None): | |
477 |
|
481 | |||
478 | for opConfObj in self.opConfObjList: |
|
482 | for opConfObj in self.opConfObjList: | |
479 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
483 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: | |
480 | continue |
|
484 | continue | |
481 | return opConfObj |
|
485 | return opConfObj | |
482 | return None |
|
486 | return None | |
483 |
|
487 | |||
484 | def getProcUnitObj(self): |
|
488 | def getProcUnitObj(self): | |
485 |
|
489 | |||
486 | return self.procUnitObj |
|
490 | return self.procUnitObj | |
487 |
|
491 | |||
488 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
492 | def setup(self, id, name, datatype, inputId, parentId=None): | |
489 |
|
493 | |||
490 | #Compatible with old signal chain version |
|
494 | #Compatible with old signal chain version | |
491 | if datatype==None and name==None: |
|
495 | if datatype==None and name==None: | |
492 | raise ValueError, "datatype or name should be defined" |
|
496 | raise ValueError, "datatype or name should be defined" | |
493 |
|
497 | |||
494 | if name==None: |
|
498 | if name==None: | |
495 | if 'Proc' in datatype: |
|
499 | if 'Proc' in datatype: | |
496 | name = datatype |
|
500 | name = datatype | |
497 | else: |
|
501 | else: | |
498 | name = '%sProc' %(datatype) |
|
502 | name = '%sProc' %(datatype) | |
499 |
|
503 | |||
500 | if datatype==None: |
|
504 | if datatype==None: | |
501 | datatype = name.replace('Proc','') |
|
505 | datatype = name.replace('Proc','') | |
502 |
|
506 | |||
503 | self.id = str(id) |
|
507 | self.id = str(id) | |
504 | self.name = name |
|
508 | self.name = name | |
505 | self.datatype = datatype |
|
509 | self.datatype = datatype | |
506 | self.inputId = inputId |
|
510 | self.inputId = inputId | |
507 | self.parentId = parentId |
|
511 | self.parentId = parentId | |
508 |
|
512 | |||
509 | self.opConfObjList = [] |
|
513 | self.opConfObjList = [] | |
510 |
|
514 | |||
511 | self.addOperation(name='run', optype='self') |
|
515 | self.addOperation(name='run', optype='self') | |
512 |
|
516 | |||
513 | def removeOperations(self): |
|
517 | def removeOperations(self): | |
514 |
|
518 | |||
515 | for obj in self.opConfObjList: |
|
519 | for obj in self.opConfObjList: | |
516 | del obj |
|
520 | del obj | |
517 |
|
521 | |||
518 | self.opConfObjList = [] |
|
522 | self.opConfObjList = [] | |
519 | self.addOperation(name='run') |
|
523 | self.addOperation(name='run') | |
520 |
|
524 | |||
521 | def addParameter(self, **kwargs): |
|
525 | def addParameter(self, **kwargs): | |
522 | ''' |
|
526 | ''' | |
523 | Add parameters to "run" operation |
|
527 | Add parameters to "run" operation | |
524 | ''' |
|
528 | ''' | |
525 | opObj = self.opConfObjList[0] |
|
529 | opObj = self.opConfObjList[0] | |
526 |
|
530 | |||
527 | opObj.addParameter(**kwargs) |
|
531 | opObj.addParameter(**kwargs) | |
528 |
|
532 | |||
529 | return opObj |
|
533 | return opObj | |
530 |
|
534 | |||
531 | def addOperation(self, name, optype='self'): |
|
535 | def addOperation(self, name, optype='self'): | |
532 |
|
536 | |||
533 | id = self.__getNewId() |
|
537 | id = self.__getNewId() | |
534 | priority = self.__getPriority() |
|
538 | priority = self.__getPriority() | |
535 |
|
539 | |||
536 | opConfObj = OperationConf() |
|
540 | opConfObj = OperationConf() | |
537 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
541 | opConfObj.setup(id, name=name, priority=priority, type=optype) | |
538 |
|
542 | |||
539 | self.opConfObjList.append(opConfObj) |
|
543 | self.opConfObjList.append(opConfObj) | |
540 |
|
544 | |||
541 | return opConfObj |
|
545 | return opConfObj | |
542 |
|
546 | |||
543 | def makeXml(self, projectElement): |
|
547 | def makeXml(self, projectElement): | |
544 |
|
548 | |||
545 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
549 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
546 | procUnitElement.set('id', str(self.id)) |
|
550 | procUnitElement.set('id', str(self.id)) | |
547 | procUnitElement.set('name', self.name) |
|
551 | procUnitElement.set('name', self.name) | |
548 | procUnitElement.set('datatype', self.datatype) |
|
552 | procUnitElement.set('datatype', self.datatype) | |
549 | procUnitElement.set('inputId', str(self.inputId)) |
|
553 | procUnitElement.set('inputId', str(self.inputId)) | |
550 |
|
554 | |||
551 | for opConfObj in self.opConfObjList: |
|
555 | for opConfObj in self.opConfObjList: | |
552 | opConfObj.makeXml(procUnitElement) |
|
556 | opConfObj.makeXml(procUnitElement) | |
553 |
|
557 | |||
554 | def readXml(self, upElement): |
|
558 | def readXml(self, upElement): | |
555 |
|
559 | |||
556 | self.id = upElement.get('id') |
|
560 | self.id = upElement.get('id') | |
557 | self.name = upElement.get('name') |
|
561 | self.name = upElement.get('name') | |
558 | self.datatype = upElement.get('datatype') |
|
562 | self.datatype = upElement.get('datatype') | |
559 | self.inputId = upElement.get('inputId') |
|
563 | self.inputId = upElement.get('inputId') | |
560 |
|
564 | |||
561 | if self.ELEMENTNAME == "ReadUnit": |
|
565 | if self.ELEMENTNAME == "ReadUnit": | |
562 | self.datatype = self.datatype.replace("Reader", "") |
|
566 | self.datatype = self.datatype.replace("Reader", "") | |
563 |
|
567 | |||
564 | if self.ELEMENTNAME == "ProcUnit": |
|
568 | if self.ELEMENTNAME == "ProcUnit": | |
565 | self.datatype = self.datatype.replace("Proc", "") |
|
569 | self.datatype = self.datatype.replace("Proc", "") | |
566 |
|
570 | |||
567 | if self.inputId == 'None': |
|
571 | if self.inputId == 'None': | |
568 | self.inputId = '0' |
|
572 | self.inputId = '0' | |
569 |
|
573 | |||
570 | self.opConfObjList = [] |
|
574 | self.opConfObjList = [] | |
571 |
|
575 | |||
572 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
576 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
573 |
|
577 | |||
574 | for opElement in opElementList: |
|
578 | for opElement in opElementList: | |
575 | opConfObj = OperationConf() |
|
579 | opConfObj = OperationConf() | |
576 | opConfObj.readXml(opElement) |
|
580 | opConfObj.readXml(opElement) | |
577 | self.opConfObjList.append(opConfObj) |
|
581 | self.opConfObjList.append(opConfObj) | |
578 |
|
582 | |||
579 | def printattr(self): |
|
583 | def printattr(self): | |
580 |
|
584 | |||
581 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
585 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, | |
582 | self.id, |
|
586 | self.id, | |
583 | self.name, |
|
587 | self.name, | |
584 | self.datatype, |
|
588 | self.datatype, | |
585 | self.inputId) |
|
589 | self.inputId) | |
586 |
|
590 | |||
587 | for opConfObj in self.opConfObjList: |
|
591 | for opConfObj in self.opConfObjList: | |
588 | opConfObj.printattr() |
|
592 | opConfObj.printattr() | |
589 |
|
593 | |||
590 | def createObjects(self): |
|
594 | def createObjects(self, plotter_queue=None): | |
591 |
|
595 | |||
592 | className = eval(self.name) |
|
596 | className = eval(self.name) | |
593 | procUnitObj = className() |
|
597 | procUnitObj = className() | |
594 |
|
598 | |||
595 | for opConfObj in self.opConfObjList: |
|
599 | for opConfObj in self.opConfObjList: | |
596 |
|
600 | |||
597 | if opConfObj.type == 'self': |
|
601 | if opConfObj.type == 'self': | |
598 | continue |
|
602 | continue | |
599 |
|
603 | |||
600 | opObj = opConfObj.createObject() |
|
604 | opObj = opConfObj.createObject(plotter_queue) | |
601 |
|
605 | |||
602 | self.opObjDict[opConfObj.id] = opObj |
|
606 | self.opObjDict[opConfObj.id] = opObj | |
603 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
607 | procUnitObj.addOperation(opObj, opConfObj.id) | |
604 |
|
608 | |||
605 | self.procUnitObj = procUnitObj |
|
609 | self.procUnitObj = procUnitObj | |
606 |
|
610 | |||
607 | return procUnitObj |
|
611 | return procUnitObj | |
608 |
|
612 | |||
609 | def run(self): |
|
613 | def run(self): | |
610 |
|
614 | |||
611 | is_ok = False |
|
615 | is_ok = False | |
612 |
|
616 | |||
613 | for opConfObj in self.opConfObjList: |
|
617 | for opConfObj in self.opConfObjList: | |
614 |
|
618 | |||
615 | kwargs = {} |
|
619 | kwargs = {} | |
616 | for parmConfObj in opConfObj.getParameterObjList(): |
|
620 | for parmConfObj in opConfObj.getParameterObjList(): | |
617 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': |
|
621 | if opConfObj.name == 'run' and parmConfObj.name == 'datatype': | |
618 | continue |
|
622 | continue | |
619 |
|
623 | |||
620 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
624 | kwargs[parmConfObj.name] = parmConfObj.getValue() | |
621 |
|
625 | |||
622 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
626 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) | |
623 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
627 | sts = self.procUnitObj.call(opType = opConfObj.type, | |
624 | opName = opConfObj.name, |
|
628 | opName = opConfObj.name, | |
625 | opId = opConfObj.id, |
|
629 | opId = opConfObj.id, | |
626 | **kwargs) |
|
630 | **kwargs) | |
627 | is_ok = is_ok or sts |
|
631 | is_ok = is_ok or sts | |
628 |
|
632 | |||
629 | return is_ok |
|
633 | return is_ok | |
630 |
|
634 | |||
631 | def close(self): |
|
635 | def close(self): | |
632 |
|
636 | |||
633 | for opConfObj in self.opConfObjList: |
|
637 | for opConfObj in self.opConfObjList: | |
634 | if opConfObj.type == 'self': |
|
638 | if opConfObj.type == 'self': | |
635 | continue |
|
639 | continue | |
636 |
|
640 | |||
637 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
641 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) | |
638 | opObj.close() |
|
642 | opObj.close() | |
639 |
|
643 | |||
640 | self.procUnitObj.close() |
|
644 | self.procUnitObj.close() | |
641 |
|
645 | |||
642 | return |
|
646 | return | |
643 |
|
647 | |||
644 | class ReadUnitConf(ProcUnitConf): |
|
648 | class ReadUnitConf(ProcUnitConf): | |
645 |
|
649 | |||
646 | path = None |
|
650 | path = None | |
647 | startDate = None |
|
651 | startDate = None | |
648 | endDate = None |
|
652 | endDate = None | |
649 | startTime = None |
|
653 | startTime = None | |
650 | endTime = None |
|
654 | endTime = None | |
651 |
|
655 | |||
652 | ELEMENTNAME = 'ReadUnit' |
|
656 | ELEMENTNAME = 'ReadUnit' | |
653 |
|
657 | |||
654 | def __init__(self): |
|
658 | def __init__(self): | |
655 |
|
659 | |||
656 | self.id = None |
|
660 | self.id = None | |
657 | self.datatype = None |
|
661 | self.datatype = None | |
658 | self.name = None |
|
662 | self.name = None | |
659 | self.inputId = None |
|
663 | self.inputId = None | |
660 |
|
664 | |||
661 | self.parentId = None |
|
665 | self.parentId = None | |
662 |
|
666 | |||
663 | self.opConfObjList = [] |
|
667 | self.opConfObjList = [] | |
664 | self.opObjList = [] |
|
668 | self.opObjList = [] | |
665 |
|
669 | |||
666 | def getElementName(self): |
|
670 | def getElementName(self): | |
667 |
|
671 | |||
668 | return self.ELEMENTNAME |
|
672 | return self.ELEMENTNAME | |
669 |
|
673 | |||
670 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): |
|
674 | def setup(self, id, name, datatype, path, startDate="", endDate="", startTime="", endTime="", parentId=None, **kwargs): | |
671 |
|
675 | |||
672 | #Compatible with old signal chain version |
|
676 | #Compatible with old signal chain version | |
673 | if datatype==None and name==None: |
|
677 | if datatype==None and name==None: | |
674 | raise ValueError, "datatype or name should be defined" |
|
678 | raise ValueError, "datatype or name should be defined" | |
675 |
|
679 | |||
676 | if name==None: |
|
680 | if name==None: | |
677 | if 'Reader' in datatype: |
|
681 | if 'Reader' in datatype: | |
678 | name = datatype |
|
682 | name = datatype | |
679 | else: |
|
683 | else: | |
680 | name = '%sReader' %(datatype) |
|
684 | name = '%sReader' %(datatype) | |
681 |
|
685 | |||
682 | if datatype==None: |
|
686 | if datatype==None: | |
683 | datatype = name.replace('Reader','') |
|
687 | datatype = name.replace('Reader','') | |
684 |
|
688 | |||
685 | self.id = id |
|
689 | self.id = id | |
686 | self.name = name |
|
690 | self.name = name | |
687 | self.datatype = datatype |
|
691 | self.datatype = datatype | |
688 |
|
692 | |||
689 | self.path = os.path.abspath(path) |
|
693 | self.path = os.path.abspath(path) | |
690 | self.startDate = startDate |
|
694 | self.startDate = startDate | |
691 | self.endDate = endDate |
|
695 | self.endDate = endDate | |
692 | self.startTime = startTime |
|
696 | self.startTime = startTime | |
693 | self.endTime = endTime |
|
697 | self.endTime = endTime | |
694 |
|
698 | |||
695 | self.inputId = '0' |
|
699 | self.inputId = '0' | |
696 | self.parentId = parentId |
|
700 | self.parentId = parentId | |
697 |
|
701 | |||
698 | self.addRunOperation(**kwargs) |
|
702 | self.addRunOperation(**kwargs) | |
699 |
|
703 | |||
700 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): |
|
704 | def update(self, datatype, path, startDate, endDate, startTime, endTime, parentId=None, name=None, **kwargs): | |
701 |
|
705 | |||
702 | #Compatible with old signal chain version |
|
706 | #Compatible with old signal chain version | |
703 | if datatype==None and name==None: |
|
707 | if datatype==None and name==None: | |
704 | raise ValueError, "datatype or name should be defined" |
|
708 | raise ValueError, "datatype or name should be defined" | |
705 |
|
709 | |||
706 | if name==None: |
|
710 | if name==None: | |
707 | if 'Reader' in datatype: |
|
711 | if 'Reader' in datatype: | |
708 | name = datatype |
|
712 | name = datatype | |
709 | else: |
|
713 | else: | |
710 | name = '%sReader' %(datatype) |
|
714 | name = '%sReader' %(datatype) | |
711 |
|
715 | |||
712 | if datatype==None: |
|
716 | if datatype==None: | |
713 | datatype = name.replace('Reader','') |
|
717 | datatype = name.replace('Reader','') | |
714 |
|
718 | |||
715 | self.datatype = datatype |
|
719 | self.datatype = datatype | |
716 | self.name = name |
|
720 | self.name = name | |
717 | self.path = path |
|
721 | self.path = path | |
718 | self.startDate = startDate |
|
722 | self.startDate = startDate | |
719 | self.endDate = endDate |
|
723 | self.endDate = endDate | |
720 | self.startTime = startTime |
|
724 | self.startTime = startTime | |
721 | self.endTime = endTime |
|
725 | self.endTime = endTime | |
722 |
|
726 | |||
723 | self.inputId = '0' |
|
727 | self.inputId = '0' | |
724 | self.parentId = parentId |
|
728 | self.parentId = parentId | |
725 |
|
729 | |||
726 | self.updateRunOperation(**kwargs) |
|
730 | self.updateRunOperation(**kwargs) | |
727 |
|
731 | |||
728 | def removeOperations(self): |
|
732 | def removeOperations(self): | |
729 |
|
733 | |||
730 | for obj in self.opConfObjList: |
|
734 | for obj in self.opConfObjList: | |
731 | del obj |
|
735 | del obj | |
732 |
|
736 | |||
733 | self.opConfObjList = [] |
|
737 | self.opConfObjList = [] | |
734 |
|
738 | |||
735 | def addRunOperation(self, **kwargs): |
|
739 | def addRunOperation(self, **kwargs): | |
736 |
|
740 | |||
737 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
741 | opObj = self.addOperation(name = 'run', optype = 'self') | |
738 |
|
742 | |||
739 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
743 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
740 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
744 | opObj.addParameter(name='path' , value=self.path, format='str') | |
741 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
745 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
742 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
746 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
743 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
747 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
744 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
748 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
745 |
|
749 | |||
746 | for key, value in kwargs.items(): |
|
750 | for key, value in kwargs.items(): | |
747 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
751 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
748 |
|
752 | |||
749 | return opObj |
|
753 | return opObj | |
750 |
|
754 | |||
751 | def updateRunOperation(self, **kwargs): |
|
755 | def updateRunOperation(self, **kwargs): | |
752 |
|
756 | |||
753 | opObj = self.getOperationObj(name = 'run') |
|
757 | opObj = self.getOperationObj(name = 'run') | |
754 | opObj.removeParameters() |
|
758 | opObj.removeParameters() | |
755 |
|
759 | |||
756 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') |
|
760 | opObj.addParameter(name='datatype' , value=self.datatype, format='str') | |
757 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
761 | opObj.addParameter(name='path' , value=self.path, format='str') | |
758 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
762 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') | |
759 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
763 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') | |
760 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
764 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') | |
761 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
765 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') | |
762 |
|
766 | |||
763 | for key, value in kwargs.items(): |
|
767 | for key, value in kwargs.items(): | |
764 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
768 | opObj.addParameter(name=key, value=value, format=type(value).__name__) | |
765 |
|
769 | |||
766 | return opObj |
|
770 | return opObj | |
767 |
|
771 | |||
768 | # def makeXml(self, projectElement): |
|
772 | # def makeXml(self, projectElement): | |
769 | # |
|
773 | # | |
770 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
774 | # procUnitElement = SubElement(projectElement, self.ELEMENTNAME) | |
771 | # procUnitElement.set('id', str(self.id)) |
|
775 | # procUnitElement.set('id', str(self.id)) | |
772 | # procUnitElement.set('name', self.name) |
|
776 | # procUnitElement.set('name', self.name) | |
773 | # procUnitElement.set('datatype', self.datatype) |
|
777 | # procUnitElement.set('datatype', self.datatype) | |
774 | # procUnitElement.set('inputId', str(self.inputId)) |
|
778 | # procUnitElement.set('inputId', str(self.inputId)) | |
775 | # |
|
779 | # | |
776 | # for opConfObj in self.opConfObjList: |
|
780 | # for opConfObj in self.opConfObjList: | |
777 | # opConfObj.makeXml(procUnitElement) |
|
781 | # opConfObj.makeXml(procUnitElement) | |
778 |
|
782 | |||
779 | def readXml(self, upElement): |
|
783 | def readXml(self, upElement): | |
780 |
|
784 | |||
781 | self.id = upElement.get('id') |
|
785 | self.id = upElement.get('id') | |
782 | self.name = upElement.get('name') |
|
786 | self.name = upElement.get('name') | |
783 | self.datatype = upElement.get('datatype') |
|
787 | self.datatype = upElement.get('datatype') | |
784 | self.inputId = upElement.get('inputId') |
|
788 | self.inputId = upElement.get('inputId') | |
785 |
|
789 | |||
786 | if self.ELEMENTNAME == "ReadUnit": |
|
790 | if self.ELEMENTNAME == "ReadUnit": | |
787 | self.datatype = self.datatype.replace("Reader", "") |
|
791 | self.datatype = self.datatype.replace("Reader", "") | |
788 |
|
792 | |||
789 | if self.inputId == 'None': |
|
793 | if self.inputId == 'None': | |
790 | self.inputId = '0' |
|
794 | self.inputId = '0' | |
791 |
|
795 | |||
792 | self.opConfObjList = [] |
|
796 | self.opConfObjList = [] | |
793 |
|
797 | |||
794 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
798 | opElementList = upElement.getiterator(OperationConf().getElementName()) | |
795 |
|
799 | |||
796 | for opElement in opElementList: |
|
800 | for opElement in opElementList: | |
797 | opConfObj = OperationConf() |
|
801 | opConfObj = OperationConf() | |
798 | opConfObj.readXml(opElement) |
|
802 | opConfObj.readXml(opElement) | |
799 | self.opConfObjList.append(opConfObj) |
|
803 | self.opConfObjList.append(opConfObj) | |
800 |
|
804 | |||
801 | if opConfObj.name == 'run': |
|
805 | if opConfObj.name == 'run': | |
802 | self.path = opConfObj.getParameterValue('path') |
|
806 | self.path = opConfObj.getParameterValue('path') | |
803 | self.startDate = opConfObj.getParameterValue('startDate') |
|
807 | self.startDate = opConfObj.getParameterValue('startDate') | |
804 | self.endDate = opConfObj.getParameterValue('endDate') |
|
808 | self.endDate = opConfObj.getParameterValue('endDate') | |
805 | self.startTime = opConfObj.getParameterValue('startTime') |
|
809 | self.startTime = opConfObj.getParameterValue('startTime') | |
806 | self.endTime = opConfObj.getParameterValue('endTime') |
|
810 | self.endTime = opConfObj.getParameterValue('endTime') | |
807 |
|
811 | |||
808 | class Project(): |
|
812 | class Project(): | |
809 |
|
813 | |||
810 | id = None |
|
814 | id = None | |
811 | name = None |
|
815 | name = None | |
812 | description = None |
|
816 | description = None | |
813 | filename = None |
|
817 | filename = None | |
814 |
|
818 | |||
815 | procUnitConfObjDict = None |
|
819 | procUnitConfObjDict = None | |
816 |
|
820 | |||
817 | ELEMENTNAME = 'Project' |
|
821 | ELEMENTNAME = 'Project' | |
818 |
|
822 | |||
819 | def __init__(self): |
|
823 | __plotterQueue = None | |
|
824 | ||||
|
825 | def __init__(self, filename="./schain.xml", plotter_queue=None): | |||
820 |
|
826 | |||
821 | self.id = None |
|
827 | self.id = None | |
822 | self.name = None |
|
828 | self.name = None | |
823 | self.description = None |
|
829 | self.description = None | |
824 |
|
830 | |||
|
831 | self.filename = filename | |||
|
832 | self.__plotterQueue = plotter_queue | |||
|
833 | ||||
825 | self.procUnitConfObjDict = {} |
|
834 | self.procUnitConfObjDict = {} | |
826 |
|
835 | |||
827 | def __getNewId(self): |
|
836 | def __getNewId(self): | |
828 |
|
837 | |||
829 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
838 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 | |
830 |
|
839 | |||
831 | return str(id) |
|
840 | return str(id) | |
832 |
|
841 | |||
833 | def getElementName(self): |
|
842 | def getElementName(self): | |
834 |
|
843 | |||
835 | return self.ELEMENTNAME |
|
844 | return self.ELEMENTNAME | |
836 |
|
845 | |||
837 | def getId(self): |
|
846 | def getId(self): | |
838 |
|
847 | |||
839 | return self.id |
|
848 | return self.id | |
840 |
|
849 | |||
841 | def updateId(self, new_id): |
|
850 | def updateId(self, new_id): | |
842 |
|
851 | |||
843 | self.id = str(new_id) |
|
852 | self.id = str(new_id) | |
844 |
|
853 | |||
845 | keyList = self.procUnitConfObjDict.keys() |
|
854 | keyList = self.procUnitConfObjDict.keys() | |
846 | keyList.sort() |
|
855 | keyList.sort() | |
847 |
|
856 | |||
848 | n = 1 |
|
857 | n = 1 | |
849 | newProcUnitConfObjDict = {} |
|
858 | newProcUnitConfObjDict = {} | |
850 |
|
859 | |||
851 | for procKey in keyList: |
|
860 | for procKey in keyList: | |
852 |
|
861 | |||
853 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
862 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
854 | idProcUnit = str(int(self.id)*10 + n) |
|
863 | idProcUnit = str(int(self.id)*10 + n) | |
855 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) |
|
864 | procUnitConfObj.updateId(idProcUnit, parentId = self.id) | |
856 |
|
865 | |||
857 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
866 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj | |
858 | n += 1 |
|
867 | n += 1 | |
859 |
|
868 | |||
860 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
869 | self.procUnitConfObjDict = newProcUnitConfObjDict | |
861 |
|
870 | |||
862 | def setup(self, id, name, description): |
|
871 | def setup(self, id, name, description): | |
863 |
|
872 | |||
864 | self.id = str(id) |
|
873 | self.id = str(id) | |
865 | self.name = name |
|
874 | self.name = name | |
866 | self.description = description |
|
875 | self.description = description | |
867 |
|
876 | |||
868 | def update(self, name, description): |
|
877 | def update(self, name, description): | |
869 |
|
878 | |||
870 | self.name = name |
|
879 | self.name = name | |
871 | self.description = description |
|
880 | self.description = description | |
872 |
|
881 | |||
873 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): |
|
882 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): | |
874 |
|
883 | |||
875 | if id is None: |
|
884 | if id is None: | |
876 | idReadUnit = self.__getNewId() |
|
885 | idReadUnit = self.__getNewId() | |
877 | else: |
|
886 | else: | |
878 | idReadUnit = str(id) |
|
887 | idReadUnit = str(id) | |
879 |
|
888 | |||
880 | readUnitConfObj = ReadUnitConf() |
|
889 | readUnitConfObj = ReadUnitConf() | |
881 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) |
|
890 | readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs) | |
882 |
|
891 | |||
883 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
892 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
884 |
|
893 | |||
885 | return readUnitConfObj |
|
894 | return readUnitConfObj | |
886 |
|
895 | |||
887 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
896 | def addProcUnit(self, inputId='0', datatype=None, name=None): | |
888 |
|
897 | |||
889 | idProcUnit = self.__getNewId() |
|
898 | idProcUnit = self.__getNewId() | |
890 |
|
899 | |||
891 | procUnitConfObj = ProcUnitConf() |
|
900 | procUnitConfObj = ProcUnitConf() | |
892 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) |
|
901 | procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id) | |
893 |
|
902 | |||
894 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
903 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
895 |
|
904 | |||
896 | return procUnitConfObj |
|
905 | return procUnitConfObj | |
897 |
|
906 | |||
898 | def removeProcUnit(self, id): |
|
907 | def removeProcUnit(self, id): | |
899 |
|
908 | |||
900 | if id in self.procUnitConfObjDict.keys(): |
|
909 | if id in self.procUnitConfObjDict.keys(): | |
901 | self.procUnitConfObjDict.pop(id) |
|
910 | self.procUnitConfObjDict.pop(id) | |
902 |
|
911 | |||
903 | def getReadUnitId(self): |
|
912 | def getReadUnitId(self): | |
904 |
|
913 | |||
905 | readUnitConfObj = self.getReadUnitObj() |
|
914 | readUnitConfObj = self.getReadUnitObj() | |
906 |
|
915 | |||
907 | return readUnitConfObj.id |
|
916 | return readUnitConfObj.id | |
908 |
|
917 | |||
909 | def getReadUnitObj(self): |
|
918 | def getReadUnitObj(self): | |
910 |
|
919 | |||
911 | for obj in self.procUnitConfObjDict.values(): |
|
920 | for obj in self.procUnitConfObjDict.values(): | |
912 | if obj.getElementName() == "ReadUnit": |
|
921 | if obj.getElementName() == "ReadUnit": | |
913 | return obj |
|
922 | return obj | |
914 |
|
923 | |||
915 | return None |
|
924 | return None | |
916 |
|
925 | |||
917 | def getProcUnitObj(self, id=None, name=None): |
|
926 | def getProcUnitObj(self, id=None, name=None): | |
918 |
|
927 | |||
919 | if id != None: |
|
928 | if id != None: | |
920 | return self.procUnitConfObjDict[id] |
|
929 | return self.procUnitConfObjDict[id] | |
921 |
|
930 | |||
922 | if name != None: |
|
931 | if name != None: | |
923 | return self.getProcUnitObjByName(name) |
|
932 | return self.getProcUnitObjByName(name) | |
924 |
|
933 | |||
925 | return None |
|
934 | return None | |
926 |
|
935 | |||
927 | def getProcUnitObjByName(self, name): |
|
936 | def getProcUnitObjByName(self, name): | |
928 |
|
937 | |||
929 | for obj in self.procUnitConfObjDict.values(): |
|
938 | for obj in self.procUnitConfObjDict.values(): | |
930 | if obj.name == name: |
|
939 | if obj.name == name: | |
931 | return obj |
|
940 | return obj | |
932 |
|
941 | |||
933 | return None |
|
942 | return None | |
934 |
|
943 | |||
935 | def procUnitItems(self): |
|
944 | def procUnitItems(self): | |
936 |
|
945 | |||
937 | return self.procUnitConfObjDict.items() |
|
946 | return self.procUnitConfObjDict.items() | |
938 |
|
947 | |||
939 | def makeXml(self): |
|
948 | def makeXml(self): | |
940 |
|
949 | |||
941 | projectElement = Element('Project') |
|
950 | projectElement = Element('Project') | |
942 | projectElement.set('id', str(self.id)) |
|
951 | projectElement.set('id', str(self.id)) | |
943 | projectElement.set('name', self.name) |
|
952 | projectElement.set('name', self.name) | |
944 | projectElement.set('description', self.description) |
|
953 | projectElement.set('description', self.description) | |
945 |
|
954 | |||
946 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
955 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
947 | procUnitConfObj.makeXml(projectElement) |
|
956 | procUnitConfObj.makeXml(projectElement) | |
948 |
|
957 | |||
949 | self.projectElement = projectElement |
|
958 | self.projectElement = projectElement | |
950 |
|
959 | |||
951 | def writeXml(self, filename): |
|
960 | def writeXml(self, filename): | |
952 |
|
961 | |||
953 | abs_file = os.path.abspath(filename) |
|
962 | abs_file = os.path.abspath(filename) | |
954 |
|
963 | |||
955 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
964 | if not os.access(os.path.dirname(abs_file), os.W_OK): | |
956 | print "No write permission on %s" %os.path.dirname(abs_file) |
|
965 | print "No write permission on %s" %os.path.dirname(abs_file) | |
957 | return 0 |
|
966 | return 0 | |
958 |
|
967 | |||
959 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
968 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): | |
960 | print "File %s already exists and it could not be overwriten" %abs_file |
|
969 | print "File %s already exists and it could not be overwriten" %abs_file | |
961 | return 0 |
|
970 | return 0 | |
962 |
|
971 | |||
963 | self.makeXml() |
|
972 | self.makeXml() | |
964 |
|
973 | |||
965 | ElementTree(self.projectElement).write(abs_file, method='xml') |
|
974 | ElementTree(self.projectElement).write(abs_file, method='xml') | |
966 |
|
975 | |||
967 | self.filename = abs_file |
|
976 | self.filename = abs_file | |
968 |
|
977 | |||
969 | return 1 |
|
978 | return 1 | |
970 |
|
979 | |||
971 | def readXml(self, filename): |
|
980 | def readXml(self, filename): | |
972 |
|
981 | |||
973 | abs_file = os.path.abspath(filename) |
|
982 | abs_file = os.path.abspath(filename) | |
974 |
|
983 | |||
975 | if not os.path.isfile(abs_file): |
|
984 | if not os.path.isfile(abs_file): | |
976 | print "%s does not exist" %abs_file |
|
985 | print "%s does not exist" %abs_file | |
977 | return 0 |
|
986 | return 0 | |
978 |
|
987 | |||
979 | self.projectElement = None |
|
988 | self.projectElement = None | |
980 | self.procUnitConfObjDict = {} |
|
989 | self.procUnitConfObjDict = {} | |
981 |
|
990 | |||
982 | self.projectElement = ElementTree().parse(abs_file) |
|
991 | self.projectElement = ElementTree().parse(abs_file) | |
983 |
|
992 | |||
984 | self.project = self.projectElement.tag |
|
993 | self.project = self.projectElement.tag | |
985 |
|
994 | |||
986 | self.id = self.projectElement.get('id') |
|
995 | self.id = self.projectElement.get('id') | |
987 | self.name = self.projectElement.get('name') |
|
996 | self.name = self.projectElement.get('name') | |
988 | self.description = self.projectElement.get('description') |
|
997 | self.description = self.projectElement.get('description') | |
989 |
|
998 | |||
990 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
999 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) | |
991 |
|
1000 | |||
992 | for readUnitElement in readUnitElementList: |
|
1001 | for readUnitElement in readUnitElementList: | |
993 | readUnitConfObj = ReadUnitConf() |
|
1002 | readUnitConfObj = ReadUnitConf() | |
994 | readUnitConfObj.readXml(readUnitElement) |
|
1003 | readUnitConfObj.readXml(readUnitElement) | |
995 |
|
1004 | |||
996 | if readUnitConfObj.parentId == None: |
|
1005 | if readUnitConfObj.parentId == None: | |
997 | readUnitConfObj.parentId = self.id |
|
1006 | readUnitConfObj.parentId = self.id | |
998 |
|
1007 | |||
999 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1008 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj | |
1000 |
|
1009 | |||
1001 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
1010 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) | |
1002 |
|
1011 | |||
1003 | for procUnitElement in procUnitElementList: |
|
1012 | for procUnitElement in procUnitElementList: | |
1004 | procUnitConfObj = ProcUnitConf() |
|
1013 | procUnitConfObj = ProcUnitConf() | |
1005 | procUnitConfObj.readXml(procUnitElement) |
|
1014 | procUnitConfObj.readXml(procUnitElement) | |
1006 |
|
1015 | |||
1007 | if procUnitConfObj.parentId == None: |
|
1016 | if procUnitConfObj.parentId == None: | |
1008 | procUnitConfObj.parentId = self.id |
|
1017 | procUnitConfObj.parentId = self.id | |
1009 |
|
1018 | |||
1010 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1019 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj | |
1011 |
|
1020 | |||
1012 | return 1 |
|
1021 | return 1 | |
1013 |
|
1022 | |||
1014 | def printattr(self): |
|
1023 | def printattr(self): | |
1015 |
|
1024 | |||
1016 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
1025 | print "Project[%s]: name = %s, description = %s" %(self.id, | |
1017 | self.name, |
|
1026 | self.name, | |
1018 | self.description) |
|
1027 | self.description) | |
1019 |
|
1028 | |||
1020 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1029 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1021 | procUnitConfObj.printattr() |
|
1030 | procUnitConfObj.printattr() | |
1022 |
|
1031 | |||
1023 | def createObjects(self): |
|
1032 | def createObjects(self): | |
1024 |
|
1033 | |||
1025 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1034 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
1026 | procUnitConfObj.createObjects() |
|
1035 | procUnitConfObj.createObjects(self.__plotterQueue) | |
1027 |
|
1036 | |||
1028 | def __connect(self, objIN, thisObj): |
|
1037 | def __connect(self, objIN, thisObj): | |
1029 |
|
1038 | |||
1030 | thisObj.setInput(objIN.getOutputObj()) |
|
1039 | thisObj.setInput(objIN.getOutputObj()) | |
1031 |
|
1040 | |||
1032 | def connectObjects(self): |
|
1041 | def connectObjects(self): | |
1033 |
|
1042 | |||
1034 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
1043 | for thisPUConfObj in self.procUnitConfObjDict.values(): | |
1035 |
|
1044 | |||
1036 | inputId = thisPUConfObj.getInputId() |
|
1045 | inputId = thisPUConfObj.getInputId() | |
1037 |
|
1046 | |||
1038 | if int(inputId) == 0: |
|
1047 | if int(inputId) == 0: | |
1039 | continue |
|
1048 | continue | |
1040 |
|
1049 | |||
1041 | #Get input object |
|
1050 | #Get input object | |
1042 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1051 | puConfINObj = self.procUnitConfObjDict[inputId] | |
1043 | puObjIN = puConfINObj.getProcUnitObj() |
|
1052 | puObjIN = puConfINObj.getProcUnitObj() | |
1044 |
|
1053 | |||
1045 | #Get current object |
|
1054 | #Get current object | |
1046 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1055 | thisPUObj = thisPUConfObj.getProcUnitObj() | |
1047 |
|
1056 | |||
1048 | self.__connect(puObjIN, thisPUObj) |
|
1057 | self.__connect(puObjIN, thisPUObj) | |
1049 |
|
1058 | |||
1050 | def __handleError(self, procUnitConfObj): |
|
1059 | def __handleError(self, procUnitConfObj): | |
1051 |
|
1060 | |||
1052 | import socket |
|
1061 | import socket | |
1053 |
|
1062 | |||
1054 | err = traceback.format_exception(sys.exc_info()[0], |
|
1063 | err = traceback.format_exception(sys.exc_info()[0], | |
1055 | sys.exc_info()[1], |
|
1064 | sys.exc_info()[1], | |
1056 | sys.exc_info()[2]) |
|
1065 | sys.exc_info()[2]) | |
1057 |
|
1066 | |||
1058 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) |
|
1067 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, procUnitConfObj.name) | |
1059 |
|
1068 | |||
1060 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) |
|
1069 | subtitle = "%s: %s\n" %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |
1061 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) |
|
1070 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |
1062 | subtitle += "Working directory: %s\n" %os.path.abspath("./") |
|
1071 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |
1063 | subtitle += "Configuration file: %s\n" %self.filename |
|
1072 | subtitle += "Configuration file: %s\n" %self.filename | |
1064 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) |
|
1073 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) | |
1065 |
|
1074 | |||
1066 | readUnitConfObj = self.getReadUnitObj() |
|
1075 | readUnitConfObj = self.getReadUnitObj() | |
1067 | if readUnitConfObj: |
|
1076 | if readUnitConfObj: | |
1068 | subtitle += "\nInput parameters:\n" |
|
1077 | subtitle += "\nInput parameters:\n" | |
1069 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path |
|
1078 | subtitle += "[Data path = %s]\n" %readUnitConfObj.path | |
1070 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype |
|
1079 | subtitle += "[Data type = %s]\n" %readUnitConfObj.datatype | |
1071 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate |
|
1080 | subtitle += "[Start date = %s]\n" %readUnitConfObj.startDate | |
1072 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate |
|
1081 | subtitle += "[End date = %s]\n" %readUnitConfObj.endDate | |
1073 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime |
|
1082 | subtitle += "[Start time = %s]\n" %readUnitConfObj.startTime | |
1074 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime |
|
1083 | subtitle += "[End time = %s]\n" %readUnitConfObj.endTime | |
1075 |
|
1084 | |||
1076 | message = "".join(err) |
|
1085 | message = "".join(err) | |
1077 |
|
1086 | |||
1078 | sys.stderr.write(message) |
|
1087 | sys.stderr.write(message) | |
1079 |
|
1088 | |||
1080 | adminObj = schainpy.admin.SchainNotify() |
|
1089 | adminObj = schainpy.admin.SchainNotify() | |
1081 | adminObj.sendAlert(message=message, |
|
1090 | adminObj.sendAlert(message=message, | |
1082 | subject=subject, |
|
1091 | subject=subject, | |
1083 | subtitle=subtitle, |
|
1092 | subtitle=subtitle, | |
1084 | filename=self.filename) |
|
1093 | filename=self.filename) | |
1085 |
|
1094 | |||
1086 | def isPaused(self): |
|
1095 | def isPaused(self): | |
1087 | return 0 |
|
1096 | return 0 | |
1088 |
|
1097 | |||
1089 | def isStopped(self): |
|
1098 | def isStopped(self): | |
1090 | return 0 |
|
1099 | return 0 | |
1091 |
|
1100 | |||
1092 | def runController(self): |
|
1101 | def runController(self): | |
1093 | """ |
|
1102 | """ | |
1094 | returns 0 when this process has been stopped, 1 otherwise |
|
1103 | returns 0 when this process has been stopped, 1 otherwise | |
1095 | """ |
|
1104 | """ | |
1096 |
|
1105 | |||
1097 | if self.isPaused(): |
|
1106 | if self.isPaused(): | |
1098 | print "Process suspended" |
|
1107 | print "Process suspended" | |
1099 |
|
1108 | |||
1100 | while True: |
|
1109 | while True: | |
1101 | sleep(0.1) |
|
1110 | sleep(0.1) | |
1102 |
|
1111 | |||
1103 | if not self.isPaused(): |
|
1112 | if not self.isPaused(): | |
1104 | break |
|
1113 | break | |
1105 |
|
1114 | |||
1106 | if self.isStopped(): |
|
1115 | if self.isStopped(): | |
1107 | break |
|
1116 | break | |
1108 |
|
1117 | |||
1109 | print "Process reinitialized" |
|
1118 | print "Process reinitialized" | |
1110 |
|
1119 | |||
1111 | if self.isStopped(): |
|
1120 | if self.isStopped(): | |
1112 | print "Process stopped" |
|
1121 | print "Process stopped" | |
1113 | return 0 |
|
1122 | return 0 | |
1114 |
|
1123 | |||
1115 | return 1 |
|
1124 | return 1 | |
|
1125 | ||||
|
1126 | def setFilename(self, filename): | |||
|
1127 | ||||
|
1128 | self.filename = filename | |||
|
1129 | ||||
|
1130 | def setPlotterQueue(self, plotter_queue): | |||
|
1131 | ||||
|
1132 | self.__plotterQueue = plotter_queue | |||
1116 |
|
1133 | |||
|
1134 | def getPlotterQueue(self): | |||
|
1135 | ||||
|
1136 | return self.__plotterQueue | |||
|
1137 | ||||
1117 | def run(self): |
|
1138 | def run(self): | |
1118 |
|
1139 | |||
1119 |
|
1140 | |||
1120 | print "*"*60 |
|
1141 | print "*"*60 | |
1121 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ |
|
1142 | print " Starting SIGNAL CHAIN PROCESSING v%s " %schainpy.__version__ | |
1122 | print "*"*60 |
|
1143 | print "*"*60 | |
1123 |
|
1144 | |||
1124 |
|
1145 | |||
1125 | keyList = self.procUnitConfObjDict.keys() |
|
1146 | keyList = self.procUnitConfObjDict.keys() | |
1126 | keyList.sort() |
|
1147 | keyList.sort() | |
1127 |
|
1148 | |||
1128 | while(True): |
|
1149 | while(True): | |
1129 |
|
1150 | |||
1130 | is_ok = False |
|
1151 | is_ok = False | |
1131 |
|
1152 | |||
1132 | for procKey in keyList: |
|
1153 | for procKey in keyList: | |
1133 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) |
|
1154 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
1134 |
|
1155 | |||
1135 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1156 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1136 |
|
1157 | |||
1137 | try: |
|
1158 | try: | |
1138 | sts = procUnitConfObj.run() |
|
1159 | sts = procUnitConfObj.run() | |
1139 | is_ok = is_ok or sts |
|
1160 | is_ok = is_ok or sts | |
1140 | except ValueError, e: |
|
1161 | except ValueError, e: | |
1141 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1162 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1142 | sleep(0.5) |
|
1163 | sleep(0.5) | |
1143 | print e |
|
1164 | print e | |
1144 | is_ok = False |
|
1165 | is_ok = False | |
1145 | break |
|
1166 | break | |
1146 | except: |
|
1167 | except: | |
1147 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) |
|
1168 | print "***** Error occurred in %s *****" %(procUnitConfObj.name) | |
1148 | sleep(0.5) |
|
1169 | sleep(0.5) | |
1149 | self.__handleError(procUnitConfObj) |
|
1170 | self.__handleError(procUnitConfObj) | |
1150 | is_ok = False |
|
1171 | is_ok = False | |
1151 | break |
|
1172 | break | |
1152 |
|
1173 | |||
1153 | #If every process unit finished so end process |
|
1174 | #If every process unit finished so end process | |
1154 | if not(is_ok): |
|
1175 | if not(is_ok): | |
1155 | print "Every process unit have finished" |
|
1176 | print "Every process unit have finished" | |
1156 | break |
|
1177 | break | |
1157 |
|
1178 | |||
1158 | if not self.runController(): |
|
1179 | if not self.runController(): | |
1159 | break |
|
1180 | break | |
1160 |
|
1181 | |||
1161 | #Closing every process |
|
1182 | #Closing every process | |
1162 | for procKey in keyList: |
|
1183 | for procKey in keyList: | |
1163 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1184 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
1164 | procUnitConfObj.close() |
|
1185 | procUnitConfObj.close() | |
1165 |
|
1186 | |||
1166 | print "Process finished" |
|
1187 | print "Process finished" | |
1167 |
|
||||
1168 | def start(self, filename): |
|
|||
1169 |
|
1188 | |||
1170 | if not self.writeXml(filename): |
|
1189 | def start(self): | |
1171 | return |
|
|||
1172 |
|
1190 | |||
1173 |
if not self.re |
|
1191 | if not self.writeXml(self.filename): | |
1174 | return |
|
1192 | return | |
1175 |
|
1193 | |||
1176 | self.createObjects() |
|
1194 | self.createObjects() | |
1177 | self.connectObjects() |
|
1195 | self.connectObjects() | |
1178 | self.run() |
|
1196 | self.run() | |
1179 |
|
1197 | |||
1180 | if __name__ == '__main__': |
|
1198 | if __name__ == '__main__': | |
1181 |
|
1199 | |||
1182 | desc = "Segundo Test" |
|
1200 | desc = "Segundo Test" | |
1183 | filename = "schain.xml" |
|
1201 | filename = "schain.xml" | |
1184 |
|
1202 | |||
1185 | controllerObj = Project() |
|
1203 | controllerObj = Project() | |
1186 |
|
1204 | |||
1187 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
1205 | controllerObj.setup(id = '191', name='test01', description=desc) | |
1188 |
|
1206 | |||
1189 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
1207 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
1190 | path='data/rawdata/', |
|
1208 | path='data/rawdata/', | |
1191 | startDate='2011/01/01', |
|
1209 | startDate='2011/01/01', | |
1192 | endDate='2012/12/31', |
|
1210 | endDate='2012/12/31', | |
1193 | startTime='00:00:00', |
|
1211 | startTime='00:00:00', | |
1194 | endTime='23:59:59', |
|
1212 | endTime='23:59:59', | |
1195 | online=1, |
|
1213 | online=1, | |
1196 | walk=1) |
|
1214 | walk=1) | |
1197 |
|
1215 | |||
1198 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
1216 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
1199 |
|
1217 | |||
1200 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
1218 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') | |
1201 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
1219 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') | |
1202 |
|
1220 | |||
1203 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
1221 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
1204 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
1222 | opObj10.addParameter(name='minHei', value='90', format='float') | |
1205 | opObj10.addParameter(name='maxHei', value='180', format='float') |
|
1223 | opObj10.addParameter(name='maxHei', value='180', format='float') | |
1206 |
|
1224 | |||
1207 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') |
|
1225 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
1208 | opObj12.addParameter(name='n', value='10', format='int') |
|
1226 | opObj12.addParameter(name='n', value='10', format='int') | |
1209 |
|
1227 | |||
1210 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
1228 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
1211 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
1229 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') | |
1212 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') |
|
1230 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') | |
1213 |
|
1231 | |||
1214 |
|
1232 | |||
1215 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
1233 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
1216 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
1234 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
1217 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
1235 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') | |
1218 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
1236 | opObj11.addParameter(name='zmin', value='40', format='int') | |
1219 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
1237 | opObj11.addParameter(name='zmax', value='90', format='int') | |
1220 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
1238 | opObj11.addParameter(name='showprofile', value='1', format='int') | |
1221 |
|
1239 | |||
1222 | print "Escribiendo el archivo XML" |
|
1240 | print "Escribiendo el archivo XML" | |
1223 |
|
1241 | |||
1224 | controllerObj.writeXml(filename) |
|
1242 | controllerObj.writeXml(filename) | |
1225 |
|
1243 | |||
1226 | print "Leyendo el archivo XML" |
|
1244 | print "Leyendo el archivo XML" | |
1227 | controllerObj.readXml(filename) |
|
1245 | controllerObj.readXml(filename) | |
1228 | #controllerObj.printattr() |
|
1246 | #controllerObj.printattr() | |
1229 |
|
1247 | |||
1230 | controllerObj.createObjects() |
|
1248 | controllerObj.createObjects() | |
1231 | controllerObj.connectObjects() |
|
1249 | controllerObj.connectObjects() | |
1232 | controllerObj.run() |
|
1250 | controllerObj.run() | |
1233 |
|
1251 | |||
1234 | No newline at end of file |
|
1252 |
@@ -1,141 +1,139 | |||||
1 | import threading |
|
1 | import threading | |
2 |
|
2 | |||
3 | from schainpy.controller import Project |
|
3 | from schainpy.controller import Project | |
4 |
|
4 | |||
5 | class ControllerThread(threading.Thread, Project): |
|
5 | class ControllerThread(threading.Thread, Project): | |
6 |
|
6 | |||
7 | def __init__(self, filename): |
|
7 | def __init__(self, filename=None, plotter_queue=None): | |
8 |
|
8 | |||
9 | threading.Thread.__init__(self) |
|
9 | threading.Thread.__init__(self) | |
10 | Project.__init__(self) |
|
10 | Project.__init__(self, filename, plotter_queue) | |
11 |
|
11 | |||
12 | self.setDaemon(True) |
|
12 | self.setDaemon(True) | |
13 |
|
13 | |||
14 | self.filename = filename |
|
|||
15 |
|
||||
16 | self.lock = threading.Lock() |
|
14 | self.lock = threading.Lock() | |
17 | self.control = {'stop':False, 'pause':False} |
|
15 | self.control = {'stop':False, 'pause':False} | |
18 |
|
16 | |||
19 | def __del__(self): |
|
17 | def __del__(self): | |
20 |
|
18 | |||
21 | self.control['stop'] = True |
|
19 | self.control['stop'] = True | |
22 |
|
20 | |||
23 | def stop(self): |
|
21 | def stop(self): | |
24 |
|
22 | |||
25 | self.lock.acquire() |
|
23 | self.lock.acquire() | |
26 |
|
24 | |||
27 | self.control['stop'] = True |
|
25 | self.control['stop'] = True | |
28 |
|
26 | |||
29 | self.lock.release() |
|
27 | self.lock.release() | |
30 |
|
28 | |||
31 | def pause(self): |
|
29 | def pause(self): | |
32 |
|
30 | |||
33 | self.lock.acquire() |
|
31 | self.lock.acquire() | |
34 |
|
32 | |||
35 | self.control['pause'] = not(self.control['pause']) |
|
33 | self.control['pause'] = not(self.control['pause']) | |
36 | paused = self.control['pause'] |
|
34 | paused = self.control['pause'] | |
37 |
|
35 | |||
38 | self.lock.release() |
|
36 | self.lock.release() | |
39 |
|
37 | |||
40 | return paused |
|
38 | return paused | |
41 |
|
39 | |||
42 | def isPaused(self): |
|
40 | def isPaused(self): | |
43 |
|
41 | |||
44 | self.lock.acquire() |
|
42 | self.lock.acquire() | |
45 | paused = self.control['pause'] |
|
43 | paused = self.control['pause'] | |
46 | self.lock.release() |
|
44 | self.lock.release() | |
47 |
|
45 | |||
48 | return paused |
|
46 | return paused | |
49 |
|
47 | |||
50 | def isStopped(self): |
|
48 | def isStopped(self): | |
51 |
|
49 | |||
52 | self.lock.acquire() |
|
50 | self.lock.acquire() | |
53 | stopped = self.control['stop'] |
|
51 | stopped = self.control['stop'] | |
54 | self.lock.release() |
|
52 | self.lock.release() | |
55 |
|
53 | |||
56 | return stopped |
|
54 | return stopped | |
57 |
|
55 | |||
58 | def run(self): |
|
56 | def run(self): | |
59 | self.control['stop'] = False |
|
57 | self.control['stop'] = False | |
60 | self.control['pause'] = False |
|
58 | self.control['pause'] = False | |
61 |
|
59 | |||
62 | self.readXml(self.filename) |
|
60 | self.readXml(self.filename) | |
63 | self.createObjects() |
|
61 | self.createObjects() | |
64 | self.connectObjects() |
|
62 | self.connectObjects() | |
65 | Project.run(self) |
|
63 | Project.run(self) | |
66 |
|
64 | |||
67 | def isRunning(self): |
|
65 | def isRunning(self): | |
68 |
|
66 | |||
69 | return self.is_alive() |
|
67 | return self.is_alive() | |
70 |
|
68 | |||
71 | def isFinished(self): |
|
69 | def isFinished(self): | |
72 |
|
70 | |||
73 | return not self.is_alive() |
|
71 | return not self.is_alive() | |
74 |
|
72 | |||
75 | # from PyQt4 import QtCore |
|
73 | # from PyQt4 import QtCore | |
76 | # from PyQt4.QtCore import SIGNAL |
|
74 | # from PyQt4.QtCore import SIGNAL | |
77 | # |
|
75 | # | |
78 | # class ControllerQThread(QtCore.QThread, Project): |
|
76 | # class ControllerQThread(QtCore.QThread, Project): | |
79 | # |
|
77 | # | |
80 | # def __init__(self, filename): |
|
78 | # def __init__(self, filename): | |
81 | # |
|
79 | # | |
82 | # QtCore.QThread.__init__(self) |
|
80 | # QtCore.QThread.__init__(self) | |
83 | # Project.__init__(self) |
|
81 | # Project.__init__(self) | |
84 | # |
|
82 | # | |
85 | # self.filename = filename |
|
83 | # self.filename = filename | |
86 | # |
|
84 | # | |
87 | # self.lock = threading.Lock() |
|
85 | # self.lock = threading.Lock() | |
88 | # self.control = {'stop':False, 'pause':False} |
|
86 | # self.control = {'stop':False, 'pause':False} | |
89 | # |
|
87 | # | |
90 | # def __del__(self): |
|
88 | # def __del__(self): | |
91 | # |
|
89 | # | |
92 | # self.control['stop'] = True |
|
90 | # self.control['stop'] = True | |
93 | # self.wait() |
|
91 | # self.wait() | |
94 | # |
|
92 | # | |
95 | # def stop(self): |
|
93 | # def stop(self): | |
96 | # |
|
94 | # | |
97 | # self.lock.acquire() |
|
95 | # self.lock.acquire() | |
98 | # |
|
96 | # | |
99 | # self.control['stop'] = True |
|
97 | # self.control['stop'] = True | |
100 | # |
|
98 | # | |
101 | # self.lock.release() |
|
99 | # self.lock.release() | |
102 | # |
|
100 | # | |
103 | # def pause(self): |
|
101 | # def pause(self): | |
104 | # |
|
102 | # | |
105 | # self.lock.acquire() |
|
103 | # self.lock.acquire() | |
106 | # |
|
104 | # | |
107 | # self.control['pause'] = not(self.control['pause']) |
|
105 | # self.control['pause'] = not(self.control['pause']) | |
108 | # paused = self.control['pause'] |
|
106 | # paused = self.control['pause'] | |
109 | # |
|
107 | # | |
110 | # self.lock.release() |
|
108 | # self.lock.release() | |
111 | # |
|
109 | # | |
112 | # return paused |
|
110 | # return paused | |
113 | # |
|
111 | # | |
114 | # def isPaused(self): |
|
112 | # def isPaused(self): | |
115 | # |
|
113 | # | |
116 | # self.lock.acquire() |
|
114 | # self.lock.acquire() | |
117 | # paused = self.control['pause'] |
|
115 | # paused = self.control['pause'] | |
118 | # self.lock.release() |
|
116 | # self.lock.release() | |
119 | # |
|
117 | # | |
120 | # return paused |
|
118 | # return paused | |
121 | # |
|
119 | # | |
122 | # def isStopped(self): |
|
120 | # def isStopped(self): | |
123 | # |
|
121 | # | |
124 | # self.lock.acquire() |
|
122 | # self.lock.acquire() | |
125 | # stopped = self.control['stop'] |
|
123 | # stopped = self.control['stop'] | |
126 | # self.lock.release() |
|
124 | # self.lock.release() | |
127 | # |
|
125 | # | |
128 | # return stopped |
|
126 | # return stopped | |
129 | # |
|
127 | # | |
130 | # def run(self): |
|
128 | # def run(self): | |
131 | # |
|
129 | # | |
132 | # self.control['stop'] = False |
|
130 | # self.control['stop'] = False | |
133 | # self.control['pause'] = False |
|
131 | # self.control['pause'] = False | |
134 | # |
|
132 | # | |
135 | # self.readXml(self.filename) |
|
133 | # self.readXml(self.filename) | |
136 | # self.createObjects() |
|
134 | # self.createObjects() | |
137 | # self.connectObjects() |
|
135 | # self.connectObjects() | |
138 | # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) |
|
136 | # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1) | |
139 | # Project.run(self) |
|
137 | # Project.run(self) | |
140 | # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) |
|
138 | # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1) | |
141 | # No newline at end of file |
|
139 | # |
@@ -1,5 +1,6 | |||||
1 | from jroplot_voltage import * |
|
1 | from jroplot_voltage import * | |
2 | from jroplot_spectra import * |
|
2 | from jroplot_spectra import * | |
3 | from jroplot_heispectra import * |
|
3 | from jroplot_heispectra import * | |
4 | from jroplot_correlation import * |
|
4 | from jroplot_correlation import * | |
5 | from jroplot_parameters import * No newline at end of file |
|
5 | from jroplot_parameters import * | |
|
6 | from jroplotter import * No newline at end of file |
@@ -1,286 +1,294 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $ |
|
4 | $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | class ProcessingUnit(object): |
|
7 | class ProcessingUnit(object): | |
8 |
|
8 | |||
9 | """ |
|
9 | """ | |
10 | Esta es la clase base para el procesamiento de datos. |
|
10 | Esta es la clase base para el procesamiento de datos. | |
11 |
|
11 | |||
12 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
12 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
13 | - Metodos internos (callMethod) |
|
13 | - Metodos internos (callMethod) | |
14 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
14 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
15 | tienen que ser agreagados con el metodo "add". |
|
15 | tienen que ser agreagados con el metodo "add". | |
16 |
|
16 | |||
17 | """ |
|
17 | """ | |
18 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
18 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
19 | dataIn = None |
|
19 | dataIn = None | |
20 | dataInList = [] |
|
20 | dataInList = [] | |
21 |
|
21 | |||
22 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
22 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
23 | dataOut = None |
|
23 | dataOut = None | |
24 |
|
24 | |||
25 | operations2RunDict = None |
|
25 | operations2RunDict = None | |
26 |
|
26 | |||
27 | isConfig = False |
|
27 | isConfig = False | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | def __init__(self): |
|
30 | def __init__(self): | |
31 |
|
31 | |||
32 | self.dataIn = None |
|
32 | self.dataIn = None | |
33 | self.dataInList = [] |
|
33 | self.dataInList = [] | |
34 |
|
34 | |||
35 | self.dataOut = None |
|
35 | self.dataOut = None | |
36 |
|
36 | |||
37 | self.operations2RunDict = {} |
|
37 | self.operations2RunDict = {} | |
38 |
|
38 | |||
39 | self.isConfig = False |
|
39 | self.isConfig = False | |
40 |
|
40 | |||
41 | def addOperation(self, opObj, objId): |
|
41 | def addOperation(self, opObj, objId): | |
42 |
|
42 | |||
43 | """ |
|
43 | """ | |
44 | Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el |
|
44 | Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el | |
45 | identificador asociado a este objeto. |
|
45 | identificador asociado a este objeto. | |
46 |
|
46 | |||
47 | Input: |
|
47 | Input: | |
48 |
|
48 | |||
49 | object : objeto de la clase "Operation" |
|
49 | object : objeto de la clase "Operation" | |
50 |
|
50 | |||
51 | Return: |
|
51 | Return: | |
52 |
|
52 | |||
53 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
53 | objId : identificador del objeto, necesario para ejecutar la operacion | |
54 | """ |
|
54 | """ | |
55 |
|
55 | |||
56 | self.operations2RunDict[objId] = opObj |
|
56 | self.operations2RunDict[objId] = opObj | |
57 |
|
57 | |||
58 | return objId |
|
58 | return objId | |
59 |
|
59 | |||
60 | def getOperationObj(self, objId): |
|
60 | def getOperationObj(self, objId): | |
61 |
|
61 | |||
62 | if objId not in self.operations2RunDict.keys(): |
|
62 | if objId not in self.operations2RunDict.keys(): | |
63 | return None |
|
63 | return None | |
64 |
|
64 | |||
65 | return self.operations2RunDict[objId] |
|
65 | return self.operations2RunDict[objId] | |
66 |
|
66 | |||
67 | def operation(self, **kwargs): |
|
67 | def operation(self, **kwargs): | |
68 |
|
68 | |||
69 | """ |
|
69 | """ | |
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los | |
71 | atributos del objeto dataOut |
|
71 | atributos del objeto dataOut | |
72 |
|
72 | |||
73 | Input: |
|
73 | Input: | |
74 |
|
74 | |||
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
76 | """ |
|
76 | """ | |
77 |
|
77 | |||
78 | raise NotImplementedError |
|
78 | raise NotImplementedError | |
79 |
|
79 | |||
80 | def callMethod(self, name, **kwargs): |
|
80 | def callMethod(self, name, **kwargs): | |
81 |
|
81 | |||
82 | """ |
|
82 | """ | |
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | name : nombre del metodo a ejecutar |
|
86 | name : nombre del metodo a ejecutar | |
87 |
|
87 | |||
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
89 |
|
89 | |||
90 | """ |
|
90 | """ | |
91 |
|
91 | |||
92 | #Checking the inputs |
|
92 | #Checking the inputs | |
93 | if name == 'run': |
|
93 | if name == 'run': | |
94 |
|
94 | |||
95 | if not self.checkInputs(): |
|
95 | if not self.checkInputs(): | |
96 | self.dataOut.flagNoData = True |
|
96 | self.dataOut.flagNoData = True | |
97 | return False |
|
97 | return False | |
98 | else: |
|
98 | else: | |
99 | #Si no es un metodo RUN la entrada es la misma dataOut (interna) |
|
99 | #Si no es un metodo RUN la entrada es la misma dataOut (interna) | |
100 | if self.dataOut.isEmpty(): |
|
100 | if self.dataOut.isEmpty(): | |
101 | return False |
|
101 | return False | |
102 |
|
102 | |||
103 | #Getting the pointer to method |
|
103 | #Getting the pointer to method | |
104 | methodToCall = getattr(self, name) |
|
104 | methodToCall = getattr(self, name) | |
105 |
|
105 | |||
106 | #Executing the self method |
|
106 | #Executing the self method | |
107 | methodToCall(**kwargs) |
|
107 | methodToCall(**kwargs) | |
108 |
|
108 | |||
109 | #Checkin the outputs |
|
109 | #Checkin the outputs | |
110 |
|
110 | |||
111 | # if name == 'run': |
|
111 | # if name == 'run': | |
112 | # pass |
|
112 | # pass | |
113 | # else: |
|
113 | # else: | |
114 | # pass |
|
114 | # pass | |
115 | # |
|
115 | # | |
116 | # if name != 'run': |
|
116 | # if name != 'run': | |
117 | # return True |
|
117 | # return True | |
118 |
|
118 | |||
119 | if self.dataOut is None: |
|
119 | if self.dataOut is None: | |
120 | return False |
|
120 | return False | |
121 |
|
121 | |||
122 | if self.dataOut.isEmpty(): |
|
122 | if self.dataOut.isEmpty(): | |
123 | return False |
|
123 | return False | |
124 |
|
124 | |||
125 | return True |
|
125 | return True | |
126 |
|
126 | |||
127 | def callObject(self, objId, **kwargs): |
|
127 | def callObject(self, objId, **kwargs): | |
128 |
|
128 | |||
129 | """ |
|
129 | """ | |
130 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
130 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
131 |
|
131 | |||
132 | Input: |
|
132 | Input: | |
133 |
|
133 | |||
134 | objId : identificador del objeto a ejecutar |
|
134 | objId : identificador del objeto a ejecutar | |
135 |
|
135 | |||
136 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
136 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
137 |
|
137 | |||
138 | Return: |
|
138 | Return: | |
139 |
|
139 | |||
140 | None |
|
140 | None | |
141 | """ |
|
141 | """ | |
142 |
|
142 | |||
143 | if self.dataOut.isEmpty(): |
|
143 | if self.dataOut.isEmpty(): | |
144 | return False |
|
144 | return False | |
145 |
|
145 | |||
146 | externalProcObj = self.operations2RunDict[objId] |
|
146 | externalProcObj = self.operations2RunDict[objId] | |
147 |
|
147 | |||
148 | externalProcObj.run(self.dataOut, **kwargs) |
|
148 | externalProcObj.run(self.dataOut, **kwargs) | |
149 |
|
149 | |||
150 | return True |
|
150 | return True | |
151 |
|
151 | |||
152 | def call(self, opType, opName=None, opId=None, **kwargs): |
|
152 | def call(self, opType, opName=None, opId=None, **kwargs): | |
153 |
|
153 | |||
154 | """ |
|
154 | """ | |
155 | Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa |
|
155 | Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa | |
156 | identificada con el id "opId"; con los argumentos "**kwargs". |
|
156 | identificada con el id "opId"; con los argumentos "**kwargs". | |
157 |
|
157 | |||
158 | False si la operacion no se ha ejecutado. |
|
158 | False si la operacion no se ha ejecutado. | |
159 |
|
159 | |||
160 | Input: |
|
160 | Input: | |
161 |
|
161 | |||
162 | opType : Puede ser "self" o "external" |
|
162 | opType : Puede ser "self" o "external" | |
163 |
|
163 | |||
164 |
|
|
164 | Depende del tipo de operacion para llamar a:callMethod or callObject: | |
165 |
|
165 | |||
166 |
1. |
|
166 | 1. If opType = "self": Llama a un metodo propio de esta clase: | |
|
167 | ||||
|
168 | name_method = getattr(self, name) | |||
|
169 | name_method(**kwargs) | |||
167 |
|
170 | |||
168 | opType = "self" |
|
|||
169 |
|
171 | |||
170 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
172 | 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la | |
|
173 | clase "Operation" o de un derivado de ella: | |||
171 |
|
174 | |||
172 | opType = "other" or "external". |
|
175 | instanceName = self.operationList[opId] | |
|
176 | instanceName.run(**kwargs) | |||
173 |
|
177 | |||
174 | opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera |
|
178 | opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera | |
175 | usada para llamar a un metodo interno de la clase Processing |
|
179 | usada para llamar a un metodo interno de la clase Processing | |
176 |
|
180 | |||
177 |
opId : Si la operacion es externa (opType = 'other'), entonces el |
|
181 | opId : Si la operacion es externa (opType = 'other' o 'external), entonces el | |
178 |
usada para llamar al metodo "run" de la clase Operation |
|
182 | "opId" sera usada para llamar al metodo "run" de la clase Operation | |
|
183 | registrada anteriormente con ese Id | |||
179 |
|
184 | |||
180 | Exception: |
|
185 | Exception: | |
181 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
186 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
182 | "addOperation" e identificado con el valor "opId" = el id de la operacion. |
|
187 | "addOperation" e identificado con el valor "opId" = el id de la operacion. | |
183 |
De lo contrario retornara un error del tipo |
|
188 | De lo contrario retornara un error del tipo ValueError | |
184 |
|
189 | |||
185 | """ |
|
190 | """ | |
186 |
|
191 | |||
187 | if opType == 'self': |
|
192 | if opType == 'self': | |
188 |
|
193 | |||
189 | if not opName: |
|
194 | if not opName: | |
190 | raise ValueError, "opName parameter should be defined" |
|
195 | raise ValueError, "opName parameter should be defined" | |
191 |
|
196 | |||
192 | sts = self.callMethod(opName, **kwargs) |
|
197 | sts = self.callMethod(opName, **kwargs) | |
193 |
|
198 | |||
194 | if opType == 'other' or opType == 'external': |
|
199 | elif opType == 'other' or opType == 'external' or opType == 'plotter': | |
195 |
|
200 | |||
196 | if not opId: |
|
201 | if not opId: | |
197 | raise ValueError, "opId parameter should be defined" |
|
202 | raise ValueError, "opId parameter should be defined" | |
198 |
|
203 | |||
199 | if opId not in self.operations2RunDict.keys(): |
|
204 | if opId not in self.operations2RunDict.keys(): | |
200 |
raise ValueError, " |
|
205 | raise ValueError, "Any operation with id=%s has been added" %str(opId) | |
201 |
|
206 | |||
202 | sts = self.callObject(opId, **kwargs) |
|
207 | sts = self.callObject(opId, **kwargs) | |
203 |
|
208 | |||
|
209 | else: | |||
|
210 | raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType | |||
|
211 | ||||
204 | return sts |
|
212 | return sts | |
205 |
|
213 | |||
206 | def setInput(self, dataIn): |
|
214 | def setInput(self, dataIn): | |
207 |
|
215 | |||
208 | self.dataIn = dataIn |
|
216 | self.dataIn = dataIn | |
209 | self.dataInList.append(dataIn) |
|
217 | self.dataInList.append(dataIn) | |
210 |
|
218 | |||
211 | def getOutputObj(self): |
|
219 | def getOutputObj(self): | |
212 |
|
220 | |||
213 | return self.dataOut |
|
221 | return self.dataOut | |
214 |
|
222 | |||
215 | def checkInputs(self): |
|
223 | def checkInputs(self): | |
216 |
|
224 | |||
217 | for thisDataIn in self.dataInList: |
|
225 | for thisDataIn in self.dataInList: | |
218 |
|
226 | |||
219 | if thisDataIn.isEmpty(): |
|
227 | if thisDataIn.isEmpty(): | |
220 | return False |
|
228 | return False | |
221 |
|
229 | |||
222 | return True |
|
230 | return True | |
223 |
|
231 | |||
224 | def setup(self): |
|
232 | def setup(self): | |
225 |
|
233 | |||
226 | raise NotImplementedError |
|
234 | raise NotImplementedError | |
227 |
|
235 | |||
228 | def run(self): |
|
236 | def run(self): | |
229 |
|
237 | |||
230 | raise NotImplementedError |
|
238 | raise NotImplementedError | |
231 |
|
239 | |||
232 | def close(self): |
|
240 | def close(self): | |
233 | #Close every thread, queue or any other object here is it is neccesary. |
|
241 | #Close every thread, queue or any other object here is it is neccesary. | |
234 | return |
|
242 | return | |
235 |
|
243 | |||
236 | class Operation(object): |
|
244 | class Operation(object): | |
237 |
|
245 | |||
238 | """ |
|
246 | """ | |
239 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
247 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
240 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
248 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
241 | acumulacion dentro de esta clase |
|
249 | acumulacion dentro de esta clase | |
242 |
|
250 | |||
243 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
251 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
244 |
|
252 | |||
245 | """ |
|
253 | """ | |
246 |
|
254 | |||
247 | __buffer = None |
|
255 | __buffer = None | |
248 | isConfig = False |
|
256 | isConfig = False | |
249 |
|
257 | |||
250 | def __init__(self): |
|
258 | def __init__(self): | |
251 |
|
259 | |||
252 | self.__buffer = None |
|
260 | self.__buffer = None | |
253 | self.isConfig = False |
|
261 | self.isConfig = False | |
254 |
|
262 | |||
255 | def setup(self): |
|
263 | def setup(self): | |
256 |
|
264 | |||
257 | self.isConfig = True |
|
265 | self.isConfig = True | |
258 |
|
266 | |||
259 | raise NotImplementedError |
|
267 | raise NotImplementedError | |
260 |
|
268 | |||
261 | def run(self, dataIn, **kwargs): |
|
269 | def run(self, dataIn, **kwargs): | |
262 |
|
270 | |||
263 | """ |
|
271 | """ | |
264 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los |
|
272 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los | |
265 | atributos del objeto dataIn. |
|
273 | atributos del objeto dataIn. | |
266 |
|
274 | |||
267 | Input: |
|
275 | Input: | |
268 |
|
276 | |||
269 | dataIn : objeto del tipo JROData |
|
277 | dataIn : objeto del tipo JROData | |
270 |
|
278 | |||
271 | Return: |
|
279 | Return: | |
272 |
|
280 | |||
273 | None |
|
281 | None | |
274 |
|
282 | |||
275 | Affected: |
|
283 | Affected: | |
276 | __buffer : buffer de recepcion de datos. |
|
284 | __buffer : buffer de recepcion de datos. | |
277 |
|
285 | |||
278 | """ |
|
286 | """ | |
279 | if not self.isConfig: |
|
287 | if not self.isConfig: | |
280 | self.setup(**kwargs) |
|
288 | self.setup(**kwargs) | |
281 |
|
289 | |||
282 | raise NotImplementedError |
|
290 | raise NotImplementedError | |
283 |
|
291 | |||
284 | def close(self): |
|
292 | def close(self): | |
285 |
|
293 | |||
286 | pass No newline at end of file |
|
294 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now