]> SALOME platform Git repositories - modules/adao.git/blob - src/daEficas/generator_adao.py
Salome HOME
Documentation corrections and code performance update
[modules/adao.git] / src / daEficas / generator_adao.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 EDF R&D
4 #
5 # This file is part of SALOME ADAO module
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
24
25 from generator.generator_python import PythonGenerator
26 import logging
27
28 def entryPoint():
29    """
30       Retourne les informations necessaires pour le chargeur de plugins
31
32       Ces informations sont retournees dans un dictionnaire
33    """
34    return {
35         # Le nom du plugin
36         'name' : 'adao',
37         # La factory pour creer une instance du plugin
38           'factory' : AdaoGenerator,
39           }
40
41 class AdaoGenerator(PythonGenerator):
42
43   def __init__(self,cr=None):
44     PythonGenerator.__init__(self, cr)
45     self.dictMCVal={}
46     self.text_comm = ""
47     self.text_da = ""
48     self.text_da_status = False
49     self.logger = logging.getLogger('ADAO EFICAS GENERATOR')
50     self.logger.setLevel(logging.INFO)
51     ch = logging.StreamHandler()
52     ch.setLevel(logging.INFO)
53     formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
54     ch.setFormatter(formatter)
55     self.logger.addHandler(ch)
56
57   def gener(self,obj,format='brut',config=None,appliEficas=None):
58     self.logger.debug("method gener called")
59     self.text_comm = PythonGenerator.gener(self, obj, format, config, appliEficas)
60     for key, value in self.dictMCVal.items():
61       self.logger.debug("dictMCVAl %s %s" % (key,value))
62
63     try :
64       self.text_da_status = False
65       self.generate_da()
66       self.text_da_status = True
67     except:
68       self.logger.debug("EFICAS case is not valid, python command file for YACS schema generation cannot be created")
69       self.logger.debug(self.text_da)
70       self.dictMCVal = {}
71       # import traceback ; traceback.print_exc()
72     return self.text_comm
73
74   def writeDefault(self, fn):
75     if self.text_da_status:
76       self.logger.debug("write adao python command file")
77       filename = fn[:fn.rfind(".")] + '.py'
78       #~ f = open( str(filename), 'wb')
79       f = open( str(filename), 'w')
80       f.write( self.text_da )
81       f.close()
82
83   def generMCSIMP(self,obj) :
84     """
85     Convertit un objet MCSIMP en texte python
86     """
87     clef=""
88     for i in obj.getGenealogie() :
89       clef=clef+"__"+i
90     self.dictMCVal[clef]=obj.valeur
91
92     s=PythonGenerator.generMCSIMP(self,obj)
93     return s
94
95   def generate_da(self):
96
97     self.text_da += "#-*- coding: utf-8 -*-\n"
98     self.text_da += "study_config = {}\n"
99
100     # Extraction de Study_type
101     if "__CHECKING_STUDY__StudyName" in self.dictMCVal.keys():
102       self.type_of_study = "CHECKING_STUDY"
103       self.text_da += "study_config['StudyType'] = '\"CHECKING_STUDY\"'\n"
104     elif "__OPTIMIZATION_STUDY__StudyName" in self.dictMCVal.keys():
105       self.type_of_study = "OPTIMIZATION_STUDY"
106       self.text_da += "study_config['StudyType'] = '\"ASSIMILATION_STUDY\"'\n"
107     elif "__REDUCTION_STUDY__StudyName" in self.dictMCVal.keys():
108       self.type_of_study = "REDUCTION_STUDY"
109       self.text_da += "study_config['StudyType'] = '\"ASSIMILATION_STUDY\"'\n"
110     else:
111       self.type_of_study = "ASSIMILATION_STUDY"
112       self.text_da += "study_config['StudyType'] = '\"ASSIMILATION_STUDY\"'\n"
113
114     # Extraction de StudyName
115     self.text_da += "study_config['Name'] = '" + self.dictMCVal["__"+self.type_of_study+"__StudyName"] + "'\n"
116     # Extraction de Debug
117     if "__"+self.type_of_study+"__Debug" in self.dictMCVal.keys():
118       self.text_da += "study_config['Debug'] = '" + str(self.dictMCVal["__"+self.type_of_study+"__Debug"]) + "'\n"
119     else:
120       self.text_da += "study_config['Debug'] = '0'\n"
121
122     # Extraction de Algorithm et de ses parametres
123     if "__"+self.type_of_study+"__AlgorithmParameters__Algorithm" in self.dictMCVal.keys():
124       self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Algorithm"] + "'\n"
125       self.add_AlgorithmParameters()
126     elif "__"+self.type_of_study+"__Algorithm" in self.dictMCVal.keys():
127       self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__Algorithm"] + "'\n"
128
129     if "__"+self.type_of_study+"__Background__INPUT_TYPE" in self.dictMCVal.keys():
130       self.add_data("Background")
131     if "__"+self.type_of_study+"__BackgroundError__INPUT_TYPE" in self.dictMCVal.keys():
132       self.add_data("BackgroundError")
133     if "__"+self.type_of_study+"__Observation__INPUT_TYPE" in self.dictMCVal.keys():
134       self.add_data("Observation")
135     if "__"+self.type_of_study+"__ObservationError__INPUT_TYPE" in self.dictMCVal.keys():
136       self.add_data("ObservationError")
137     if "__"+self.type_of_study+"__CheckingPoint__INPUT_TYPE" in self.dictMCVal.keys():
138       self.add_data("CheckingPoint")
139     if "__"+self.type_of_study+"__ObservationOperator__INPUT_TYPE" in self.dictMCVal.keys():
140       self.add_data("ObservationOperator")
141     if "__"+self.type_of_study+"__EvolutionModel__INPUT_TYPE" in self.dictMCVal.keys():
142       self.add_data("EvolutionModel")
143     if "__"+self.type_of_study+"__EvolutionError__INPUT_TYPE" in self.dictMCVal.keys():
144       self.add_data("EvolutionError")
145     if "__"+self.type_of_study+"__ControlInput__INPUT_TYPE" in self.dictMCVal.keys():
146       self.add_data("ControlInput")
147
148     self.add_variables()
149     # Parametres optionnels
150
151     # Extraction du StudyRepertory
152     if "__"+self.type_of_study+"__StudyRepertory" in self.dictMCVal.keys():
153       self.text_da += "study_config['Repertory'] = '" + self.dictMCVal["__"+self.type_of_study+"__StudyRepertory"] + "'\n"
154
155     # Extraction du ExecuteInContainer
156     if "__"+self.type_of_study+"__ExecuteInContainer" in self.dictMCVal.keys():
157       self.text_da += "study_config['ExecuteInContainer'] = '" + str(self.dictMCVal["__"+self.type_of_study+"__ExecuteInContainer"]) + "'\n"
158     else:
159       self.text_da += "study_config['ExecuteInContainer'] = 'No'\n"
160
161     # Extraction de UserPostAnalysis
162     if "__"+self.type_of_study+"__UserPostAnalysis__FROM" in self.dictMCVal.keys():
163       self.add_UserPostAnalysis()
164     if "__"+self.type_of_study+"__UserDataInit__INIT_FILE" in self.dictMCVal.keys():
165       self.add_init()
166     if "__"+self.type_of_study+"__Observers__SELECTION" in self.dictMCVal.keys():
167       self.add_observers()
168
169   def add_data(self, data_name):
170
171     # Extraction des donnees
172     search_text = "__"+self.type_of_study+"__" + data_name + "__"
173     data_type = self.dictMCVal[search_text + "INPUT_TYPE"]
174     search_type = search_text + data_type + "__data__"
175     from_type = self.dictMCVal[search_type + "FROM"]
176     data = ""
177     if from_type == "String":
178       data = self.dictMCVal[search_type + "STRING_DATA__STRING"]
179     elif from_type == "Script":
180       data = self.dictMCVal[search_type + "SCRIPT_DATA__SCRIPT_FILE"]
181     elif from_type == "DataFile":
182       data = self.dictMCVal[search_type + "DATA_DATA__DATA_FILE"]
183     elif from_type == "ScriptWithSwitch":
184       data = self.dictMCVal[search_type + "SCRIPTWITHSWITCH_DATA__SCRIPTWITHSWITCH_FILE"]
185     elif from_type == "ScriptWithFunctions":
186       data = self.dictMCVal[search_type + "SCRIPTWITHFUNCTIONS_DATA__SCRIPTWITHFUNCTIONS_FILE"]
187     elif from_type == "ScriptWithOneFunction":
188       data = self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__SCRIPTWITHONEFUNCTION_FILE"]
189     elif from_type == "FunctionDict":
190       data = self.dictMCVal[search_type + "FUNCTIONDICT_DATA__FUNCTIONDICT_FILE"]
191     else:
192       raise Exception('From Type unknown', from_type)
193
194     if from_type == "String" or from_type == "Script" or from_type == "DataFile":
195       self.text_da += data_name + "_config = {}\n"
196       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
197       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
198       self.text_da += data_name + "_config['Data'] = '" + data      + "'\n"
199       if search_text+"Stored" in self.dictMCVal.keys():
200         self.text_da += data_name + "_config['Stored'] = '" +  str(self.dictMCVal[search_text+"Stored"])  + "'\n"
201       if search_type+"DATA_DATA__ColMajor" in self.dictMCVal.keys():
202         self.text_da += data_name + "_config['ColMajor'] = '" +  str(self.dictMCVal[search_type+"DATA_DATA__ColMajor"])  + "'\n"
203       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
204
205     if from_type == "ScriptWithSwitch":
206       self.text_da += data_name + "_ScriptWithSwitch = {}\n"
207       self.text_da += data_name + "_ScriptWithSwitch['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
208       self.text_da += data_name + "_ScriptWithSwitch['Script'] = {}\n"
209       self.text_da += data_name + "_ScriptWithSwitch['Script']['Direct'] = '"  + data + "'\n"
210       self.text_da += data_name + "_ScriptWithSwitch['Script']['Tangent'] = '" + data + "'\n"
211       self.text_da += data_name + "_ScriptWithSwitch['Script']['Adjoint'] = '" + data + "'\n"
212       self.text_da += data_name + "_config = {}\n"
213       self.text_da += data_name + "_config['Type'] = 'Function'\n"
214       self.text_da += data_name + "_config['From'] = 'ScriptWithSwitch'\n"
215       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithSwitch\n"
216       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
217
218     if from_type == "ScriptWithFunctions":
219       self.text_da += data_name + "_ScriptWithFunctions = {}\n"
220       self.text_da += data_name + "_ScriptWithFunctions['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
221       self.text_da += data_name + "_ScriptWithFunctions['Script'] = {}\n"
222       self.text_da += data_name + "_ScriptWithFunctions['Script']['Direct'] = '"  + data + "'\n"
223       self.text_da += data_name + "_ScriptWithFunctions['Script']['Tangent'] = '" + data + "'\n"
224       self.text_da += data_name + "_ScriptWithFunctions['Script']['Adjoint'] = '" + data + "'\n"
225       self.text_da += data_name + "_config = {}\n"
226       self.text_da += data_name + "_config['Type'] = 'Function'\n"
227       self.text_da += data_name + "_config['From'] = 'ScriptWithFunctions'\n"
228       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithFunctions\n"
229       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
230
231     if from_type == "ScriptWithOneFunction":
232       self.text_da += data_name + "_ScriptWithOneFunction = {}\n"
233       self.text_da += data_name + "_ScriptWithOneFunction['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
234       self.text_da += data_name + "_ScriptWithOneFunction['Script'] = {}\n"
235       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Direct'] = '"  + data + "'\n"
236       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Tangent'] = '" + data + "'\n"
237       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Adjoint'] = '" + data + "'\n"
238       self.text_da += data_name + "_ScriptWithOneFunction['DifferentialIncrement'] = " + str(float(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__DifferentialIncrement"])) + "\n"
239       self.text_da += data_name + "_ScriptWithOneFunction['CenteredFiniteDifference'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__CenteredFiniteDifference"]) + "\n"
240       if search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing" in self.dictMCVal.keys():
241         self.text_da += data_name + "_ScriptWithOneFunction['EnableWiseParallelism'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing"]) + "\n"
242       if search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableWiseParallelism" in self.dictMCVal.keys():
243         self.text_da += data_name + "_ScriptWithOneFunction['EnableWiseParallelism'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableWiseParallelism"]) + "\n"
244       if search_type + "SCRIPTWITHONEFUNCTION_DATA__NumberOfProcesses" in self.dictMCVal.keys():
245         self.text_da += data_name + "_ScriptWithOneFunction['NumberOfProcesses'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__NumberOfProcesses"]) + "\n"
246       self.text_da += data_name + "_config = {}\n"
247       self.text_da += data_name + "_config['Type'] = 'Function'\n"
248       self.text_da += data_name + "_config['From'] = 'ScriptWithOneFunction'\n"
249       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithOneFunction\n"
250       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
251
252     if from_type == "FunctionDict":
253       self.text_da += data_name + "_FunctionDict = {}\n"
254       self.text_da += data_name + "_FunctionDict['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
255       self.text_da += data_name + "_FunctionDict['Script'] = {}\n"
256       self.text_da += data_name + "_FunctionDict['Script']['Direct'] = '"  + data + "'\n"
257       self.text_da += data_name + "_FunctionDict['Script']['Tangent'] = '" + data + "'\n"
258       self.text_da += data_name + "_FunctionDict['Script']['Adjoint'] = '" + data + "'\n"
259       self.text_da += data_name + "_config = {}\n"
260       self.text_da += data_name + "_config['Type'] = 'Function'\n"
261       self.text_da += data_name + "_config['From'] = 'FunctionDict'\n"
262       self.text_da += data_name + "_config['Data'] = " + data_name + "_FunctionDict\n"
263       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
264
265   def add_init(self):
266
267       init_file_data = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__INIT_FILE"]
268       init_target_list = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__TARGET_LIST"]
269
270       self.text_da += "Init_config = {}\n"
271       self.text_da += "Init_config['Type'] = 'Dict'\n"
272       self.text_da += "Init_config['From'] = 'Script'\n"
273       self.text_da += "Init_config['Data'] = '" + init_file_data + "'\n"
274       self.text_da += "Init_config['Target'] = ["
275       if isinstance(init_target_list, "str"):
276         self.text_da +=  "'" + init_target_list + "',"
277       else:
278         for target in init_target_list:
279           self.text_da += "'" + target + "',"
280       self.text_da += "]\n"
281       self.text_da += "study_config['UserDataInit'] = Init_config\n"
282
283   def add_UserPostAnalysis(self):
284
285     from_type = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__FROM"]
286     data = ""
287     if from_type == "String":
288       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__STRING_DATA__STRING"]
289       self.text_da += "Analysis_config = {}\n"
290       self.text_da += "Analysis_config['From'] = 'String'\n"
291       self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n"
292       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
293     elif from_type == "Script":
294       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__SCRIPT_DATA__SCRIPT_FILE"]
295       self.text_da += "Analysis_config = {}\n"
296       self.text_da += "Analysis_config['From'] = 'Script'\n"
297       self.text_da += "Analysis_config['Data'] = '" + data + "'\n"
298       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
299     elif from_type == "Template":
300       tmpl = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__Template"]
301       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__%s__ValueTemplate"%tmpl]
302       self.text_da += "Analysis_config = {}\n"
303       self.text_da += "Analysis_config['From'] = 'String'\n"
304       self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n"
305       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
306     else:
307       raise Exception('From Type unknown', from_type)
308
309   def add_AlgorithmParameters(self):
310
311     data_name = "AlgorithmParameters"
312     data_type = "Dict"
313     #
314     if "__"+self.type_of_study+"__AlgorithmParameters__Parameters" in self.dictMCVal:
315         para_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Parameters"]
316     else:
317         para_type = "Defaults"
318     #
319     if para_type == "Defaults":
320         from_type = para_type
321     elif para_type == "Dict":
322         from_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__FROM"]
323     else:
324         return
325
326     if from_type == "Script":
327       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__SCRIPT_DATA__SCRIPT_FILE"]
328       self.text_da += data_name + "_config = {}\n"
329       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
330       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
331       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
332       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
333     elif from_type == "String":
334       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__STRING_DATA__STRING"]
335       self.text_da += data_name + "_config = {}\n"
336       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
337       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
338       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
339       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
340     elif from_type == "Defaults":
341       base = "__"+self.type_of_study+"__AlgorithmParameters__Parameters"
342       keys = [k for k in self.dictMCVal.keys() if base in k]
343       if base in keys: keys.remove(base)
344       keys = [k.replace(base,'') for k in keys]
345       data  = '{'
346       for k in keys:
347         key = k.split('__')[-1]
348         val = self.dictMCVal[base+k]
349         # print key," = ",val,"    ",type(val)
350         if isinstance(val, str) and key == "SetSeed":
351             data += '"%s":%s,'%(key,int(val))
352         elif isinstance(val, str) and not (val.count('[')>=2 or val.count('(')>=2):
353             data += '"%s":"%s",'%(key,val)
354         else:
355             data += '"%s":%s,'%(key,val)
356       data = data.replace("'",'"')
357       data += '}'
358       if data != '{}':
359           self.text_da += data_name + "_config = {}\n"
360           self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
361           self.text_da += data_name + "_config['From'] = 'String'\n"
362           self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
363           self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
364
365   def add_variables(self):
366
367     # Input variables
368     if "__"+self.type_of_study+"__InputVariables__NAMES" in self.dictMCVal.keys():
369       names = []
370       sizes = []
371       if isinstance(self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"], type("")):
372         names.append(self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"])
373       else:
374         names = self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"]
375       if isinstance(self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"], type(1)):
376         sizes.append(self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"])
377       else:
378         sizes = self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"]
379
380       self.text_da += "inputvariables_config = {}\n"
381       self.text_da += "inputvariables_config['Order'] = %s\n" % list(names)
382       for name, size in zip(names, sizes):
383         self.text_da += "inputvariables_config['%s'] = %s\n" % (name,size)
384       self.text_da += "study_config['InputVariables'] = inputvariables_config\n"
385     else:
386       self.text_da += "inputvariables_config = {}\n"
387       self.text_da += "inputvariables_config['Order'] =['adao_default']\n"
388       self.text_da += "inputvariables_config['adao_default'] = -1\n"
389       self.text_da += "study_config['InputVariables'] = inputvariables_config\n"
390
391     # Output variables
392     if "__"+self.type_of_study+"__OutputVariables__NAMES" in self.dictMCVal.keys():
393       names = []
394       sizes = []
395       if isinstance(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"], type("")):
396         names.append(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"])
397       else:
398         names = self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"]
399       if isinstance(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"], type(1)):
400         sizes.append(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"])
401       else:
402         sizes = self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"]
403
404       self.text_da += "outputvariables_config = {}\n"
405       self.text_da += "outputvariables_config['Order'] = %s\n" % list(names)
406       for name, size in zip(names, sizes):
407         self.text_da += "outputvariables_config['%s'] = %s\n" % (name,size)
408       self.text_da += "study_config['OutputVariables'] = outputvariables_config\n"
409     else:
410       self.text_da += "outputvariables_config = {}\n"
411       self.text_da += "outputvariables_config['Order'] = ['adao_default']\n"
412       self.text_da += "outputvariables_config['adao_default'] = -1\n"
413       self.text_da += "study_config['OutputVariables'] = outputvariables_config\n"
414
415   def add_observers(self):
416     observers = {}
417     observer = self.dictMCVal["__"+self.type_of_study+"__Observers__SELECTION"]
418     if isinstance(observer, type("")):
419       self.add_observer_in_dict(observer, observers)
420     else:
421       for observer in self.dictMCVal["__"+self.type_of_study+"__Observers__SELECTION"]:
422         self.add_observer_in_dict(observer, observers)
423
424     # Write observers in the python command file
425     number = 2
426     self.text_da += "observers = {}\n"
427     for observer in observers.keys():
428       number += 1
429       self.text_da += "observers[\"" + observer + "\"] = {}\n"
430       self.text_da += "observers[\"" + observer + "\"][\"number\"] = " + str(number) + "\n"
431       self.text_da += "observers[\"" + observer + "\"][\"nodetype\"] = \"" + observers[observer]["nodetype"] + "\"\n"
432       if observers[observer]["nodetype"] == "String":
433         self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n"
434       elif observers[observer]["nodetype"] == "Template":
435         self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n"
436         self.text_da += "observers[\"" + observer + "\"][\"Template\"] = \"\"\"" + observers[observer]["template"] + "\"\"\"\n"
437       else:
438         self.text_da += "observers[\"" + observer + "\"][\"Script\"] = \"" + observers[observer]["file"] + "\"\n"
439       if "scheduler" in observers[observer].keys():
440         self.text_da += "observers[\"" + observer + "\"][\"scheduler\"] = \"\"\"" + observers[observer]["scheduler"] + "\"\"\"\n"
441       if "info" in observers[observer].keys():
442         self.text_da += "observers[\"" + observer + "\"][\"info\"] = \"\"\"" + observers[observer]["info"] + "\"\"\"\n"
443     self.text_da += "study_config['Observers'] = observers\n"
444
445   def add_observer_in_dict(self, observer, observers):
446     """
447       Add observer in the observers dict.
448     """
449     observers[observer] = {}
450     observers[observer]["name"] = observer
451     observer_eficas_name = "__"+self.type_of_study+"__Observers__" + observer + "__" + observer + "_data__"
452     # NodeType
453     node_type_key_name = observer_eficas_name + "NodeType"
454     observers[observer]["nodetype"] = self.dictMCVal[node_type_key_name]
455
456     # NodeType script/file
457     if observers[observer]["nodetype"] == "String":
458       observers[observer]["script"] = self.dictMCVal[observer_eficas_name + "PythonScript__Value"]
459     elif observers[observer]["nodetype"] == "Template":
460       observers[observer]["nodetype"] = "String"
461       observer_template_key = observer_eficas_name + "ObserverTemplate__"
462       observers[observer]["template"] = self.dictMCVal[observer_template_key + "Template"]
463       observers[observer]["script"]   = self.dictMCVal[observer_template_key + observers[observer]["template"] + "__ValueTemplate"]
464     else:
465       observers[observer]["file"] = self.dictMCVal[observer_eficas_name + "UserFile__Value"]
466
467     # Scheduler
468     scheduler_key_name = observer_eficas_name + "Scheduler"
469     if scheduler_key_name in self.dictMCVal.keys():
470       observers[observer]["scheduler"] = self.dictMCVal[scheduler_key_name]
471
472     # Info
473     info_key_name = observer_eficas_name + "Info"
474     if info_key_name in self.dictMCVal.keys():
475       observers[observer]["info"] = self.dictMCVal[info_key_name]