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