]> SALOME platform Git repositories - modules/adao.git/blob - src/daEficas/generator_adao.py
Salome HOME
bfeee83d467c772cce89d4b0ed9a5549d053b6d1
[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['EnableMultiProcessing'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing"]) + "\n"
242       if search_type + "SCRIPTWITHONEFUNCTION_DATA__NumberOfProcesses" in self.dictMCVal.keys():
243         self.text_da += data_name + "_ScriptWithOneFunction['NumberOfProcesses'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__NumberOfProcesses"]) + "\n"
244       self.text_da += data_name + "_config = {}\n"
245       self.text_da += data_name + "_config['Type'] = 'Function'\n"
246       self.text_da += data_name + "_config['From'] = 'ScriptWithOneFunction'\n"
247       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithOneFunction\n"
248       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
249
250     if from_type == "FunctionDict":
251       self.text_da += data_name + "_FunctionDict = {}\n"
252       self.text_da += data_name + "_FunctionDict['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
253       self.text_da += data_name + "_FunctionDict['Script'] = {}\n"
254       self.text_da += data_name + "_FunctionDict['Script']['Direct'] = '"  + data + "'\n"
255       self.text_da += data_name + "_FunctionDict['Script']['Tangent'] = '" + data + "'\n"
256       self.text_da += data_name + "_FunctionDict['Script']['Adjoint'] = '" + data + "'\n"
257       self.text_da += data_name + "_config = {}\n"
258       self.text_da += data_name + "_config['Type'] = 'Function'\n"
259       self.text_da += data_name + "_config['From'] = 'FunctionDict'\n"
260       self.text_da += data_name + "_config['Data'] = " + data_name + "_FunctionDict\n"
261       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
262
263   def add_init(self):
264
265       init_file_data = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__INIT_FILE"]
266       init_target_list = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__TARGET_LIST"]
267
268       self.text_da += "Init_config = {}\n"
269       self.text_da += "Init_config['Type'] = 'Dict'\n"
270       self.text_da += "Init_config['From'] = 'Script'\n"
271       self.text_da += "Init_config['Data'] = '" + init_file_data + "'\n"
272       self.text_da += "Init_config['Target'] = ["
273       if isinstance(init_target_list, "str"):
274         self.text_da +=  "'" + init_target_list + "',"
275       else:
276         for target in init_target_list:
277           self.text_da += "'" + target + "',"
278       self.text_da += "]\n"
279       self.text_da += "study_config['UserDataInit'] = Init_config\n"
280
281   def add_UserPostAnalysis(self):
282
283     from_type = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__FROM"]
284     data = ""
285     if from_type == "String":
286       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__STRING_DATA__STRING"]
287       self.text_da += "Analysis_config = {}\n"
288       self.text_da += "Analysis_config['From'] = 'String'\n"
289       self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n"
290       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
291     elif from_type == "Script":
292       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__SCRIPT_DATA__SCRIPT_FILE"]
293       self.text_da += "Analysis_config = {}\n"
294       self.text_da += "Analysis_config['From'] = 'Script'\n"
295       self.text_da += "Analysis_config['Data'] = '" + data + "'\n"
296       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
297     elif from_type == "Template":
298       tmpl = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__Template"]
299       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__%s__ValueTemplate"%tmpl]
300       self.text_da += "Analysis_config = {}\n"
301       self.text_da += "Analysis_config['From'] = 'String'\n"
302       self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n"
303       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
304     else:
305       raise Exception('From Type unknown', from_type)
306
307   def add_AlgorithmParameters(self):
308
309     data_name = "AlgorithmParameters"
310     data_type = "Dict"
311     #
312     if "__"+self.type_of_study+"__AlgorithmParameters__Parameters" in self.dictMCVal:
313         para_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Parameters"]
314     else:
315         para_type = "Defaults"
316     #
317     if para_type == "Defaults":
318         from_type = para_type
319     elif para_type == "Dict":
320         from_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__FROM"]
321     else:
322         return
323
324     if from_type == "Script":
325       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__SCRIPT_DATA__SCRIPT_FILE"]
326       self.text_da += data_name + "_config = {}\n"
327       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
328       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
329       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
330       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
331     elif from_type == "String":
332       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__STRING_DATA__STRING"]
333       self.text_da += data_name + "_config = {}\n"
334       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
335       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
336       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
337       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
338     elif from_type == "Defaults":
339       base = "__"+self.type_of_study+"__AlgorithmParameters__Parameters"
340       keys = [k for k in self.dictMCVal.keys() if base in k]
341       if base in keys: keys.remove(base)
342       keys = [k.replace(base,'') for k in keys]
343       data  = '{'
344       for k in keys:
345         key = k.split('__')[-1]
346         val = self.dictMCVal[base+k]
347         # print key," = ",val,"    ",type(val)
348         if isinstance(val, str) and key == "SetSeed":
349             data += '"%s":%s,'%(key,int(val))
350         elif isinstance(val, str) and not (val.count('[')>=2 or val.count('(')>=2):
351             data += '"%s":"%s",'%(key,val)
352         else:
353             data += '"%s":%s,'%(key,val)
354       data = data.replace("'",'"')
355       data += '}'
356       if data != '{}':
357           self.text_da += data_name + "_config = {}\n"
358           self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
359           self.text_da += data_name + "_config['From'] = 'String'\n"
360           self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
361           self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
362
363   def add_variables(self):
364
365     # Input variables
366     if "__"+self.type_of_study+"__InputVariables__NAMES" in self.dictMCVal.keys():
367       names = []
368       sizes = []
369       if isinstance(self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"], type("")):
370         names.append(self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"])
371       else:
372         names = self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"]
373       if isinstance(self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"], type(1)):
374         sizes.append(self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"])
375       else:
376         sizes = self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"]
377
378       self.text_da += "inputvariables_config = {}\n"
379       self.text_da += "inputvariables_config['Order'] = %s\n" % list(names)
380       for name, size in zip(names, sizes):
381         self.text_da += "inputvariables_config['%s'] = %s\n" % (name,size)
382       self.text_da += "study_config['InputVariables'] = inputvariables_config\n"
383     else:
384       self.text_da += "inputvariables_config = {}\n"
385       self.text_da += "inputvariables_config['Order'] =['adao_default']\n"
386       self.text_da += "inputvariables_config['adao_default'] = -1\n"
387       self.text_da += "study_config['InputVariables'] = inputvariables_config\n"
388
389     # Output variables
390     if "__"+self.type_of_study+"__OutputVariables__NAMES" in self.dictMCVal.keys():
391       names = []
392       sizes = []
393       if isinstance(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"], type("")):
394         names.append(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"])
395       else:
396         names = self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"]
397       if isinstance(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"], type(1)):
398         sizes.append(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"])
399       else:
400         sizes = self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"]
401
402       self.text_da += "outputvariables_config = {}\n"
403       self.text_da += "outputvariables_config['Order'] = %s\n" % list(names)
404       for name, size in zip(names, sizes):
405         self.text_da += "outputvariables_config['%s'] = %s\n" % (name,size)
406       self.text_da += "study_config['OutputVariables'] = outputvariables_config\n"
407     else:
408       self.text_da += "outputvariables_config = {}\n"
409       self.text_da += "outputvariables_config['Order'] = ['adao_default']\n"
410       self.text_da += "outputvariables_config['adao_default'] = -1\n"
411       self.text_da += "study_config['OutputVariables'] = outputvariables_config\n"
412
413   def add_observers(self):
414     observers = {}
415     observer = self.dictMCVal["__"+self.type_of_study+"__Observers__SELECTION"]
416     if isinstance(observer, type("")):
417       self.add_observer_in_dict(observer, observers)
418     else:
419       for observer in self.dictMCVal["__"+self.type_of_study+"__Observers__SELECTION"]:
420         self.add_observer_in_dict(observer, observers)
421
422     # Write observers in the python command file
423     number = 2
424     self.text_da += "observers = {}\n"
425     for observer in observers.keys():
426       number += 1
427       self.text_da += "observers[\"" + observer + "\"] = {}\n"
428       self.text_da += "observers[\"" + observer + "\"][\"number\"] = " + str(number) + "\n"
429       self.text_da += "observers[\"" + observer + "\"][\"nodetype\"] = \"" + observers[observer]["nodetype"] + "\"\n"
430       if observers[observer]["nodetype"] == "String":
431         self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n"
432       elif observers[observer]["nodetype"] == "Template":
433         self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n"
434         self.text_da += "observers[\"" + observer + "\"][\"Template\"] = \"\"\"" + observers[observer]["template"] + "\"\"\"\n"
435       else:
436         self.text_da += "observers[\"" + observer + "\"][\"Script\"] = \"" + observers[observer]["file"] + "\"\n"
437       if "scheduler" in observers[observer].keys():
438         self.text_da += "observers[\"" + observer + "\"][\"scheduler\"] = \"\"\"" + observers[observer]["scheduler"] + "\"\"\"\n"
439       if "info" in observers[observer].keys():
440         self.text_da += "observers[\"" + observer + "\"][\"info\"] = \"\"\"" + observers[observer]["info"] + "\"\"\"\n"
441     self.text_da += "study_config['Observers'] = observers\n"
442
443   def add_observer_in_dict(self, observer, observers):
444     """
445       Add observer in the observers dict.
446     """
447     observers[observer] = {}
448     observers[observer]["name"] = observer
449     observer_eficas_name = "__"+self.type_of_study+"__Observers__" + observer + "__" + observer + "_data__"
450     # NodeType
451     node_type_key_name = observer_eficas_name + "NodeType"
452     observers[observer]["nodetype"] = self.dictMCVal[node_type_key_name]
453
454     # NodeType script/file
455     if observers[observer]["nodetype"] == "String":
456       observers[observer]["script"] = self.dictMCVal[observer_eficas_name + "PythonScript__Value"]
457     elif observers[observer]["nodetype"] == "Template":
458       observers[observer]["nodetype"] = "String"
459       observer_template_key = observer_eficas_name + "ObserverTemplate__"
460       observers[observer]["template"] = self.dictMCVal[observer_template_key + "Template"]
461       observers[observer]["script"]   = self.dictMCVal[observer_template_key + observers[observer]["template"] + "__ValueTemplate"]
462     else:
463       observers[observer]["file"] = self.dictMCVal[observer_eficas_name + "UserFile__Value"]
464
465     # Scheduler
466     scheduler_key_name = observer_eficas_name + "Scheduler"
467     if scheduler_key_name in self.dictMCVal.keys():
468       observers[observer]["scheduler"] = self.dictMCVal[scheduler_key_name]
469
470     # Info
471     info_key_name = observer_eficas_name + "Info"
472     if info_key_name in self.dictMCVal.keys():
473       observers[observer]["info"] = self.dictMCVal[info_key_name]