]> SALOME platform Git repositories - modules/adao.git/blob - src/daEficas/generator_adao.py
Salome HOME
Modifying EFICAS tree and commands, adding case translation
[modules/adao.git] / src / daEficas / generator_adao.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2015 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 traceback
27 import logging
28
29 def entryPoint():
30    """
31       Retourne les informations necessaires pour le chargeur de plugins
32
33       Ces informations sont retournees dans un dictionnaire
34    """
35    return {
36         # Le nom du plugin
37         'name' : 'adao',
38         # La factory pour creer une instance du plugin
39           'factory' : AdaoGenerator,
40           }
41
42 class AdaoGenerator(PythonGenerator):
43
44   def __init__(self,cr=None):
45     PythonGenerator.__init__(self, cr)
46     self.dictMCVal={}
47     self.text_comm = ""
48     self.text_da = ""
49     self.text_da_status = False
50     self.logger = logging.getLogger('ADAO EFICAS GENERATOR')
51     self.logger.setLevel(logging.INFO)
52     ch = logging.StreamHandler()
53     ch.setLevel(logging.INFO)
54     formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
55     ch.setFormatter(formatter)
56     self.logger.addHandler(ch)
57
58   def gener(self,obj,format='brut',config=None):
59     self.logger.debug("method gener called")
60     self.text_comm = PythonGenerator.gener(self, obj, format, config)
61     for key, value in self.dictMCVal.iteritems():
62       self.logger.debug("dictMCVAl %s %s" % (key,value))
63
64     try :
65       self.text_da_status = False
66       self.generate_da()
67       self.text_da_status = True
68     except:
69       self.logger.info("Case is not correct, python command file for YACS schema generation cannot be created")
70       self.logger.debug(self.text_da)
71       self.dictMCVal = {}
72       traceback.print_exc()
73     return self.text_comm
74
75   def writeDefault(self, fn):
76     if self.text_da_status:
77       self.logger.debug("write adao python command file")
78       filename = fn[:fn.rfind(".")] + '.py'
79       f = open( str(filename), 'wb')
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.get_genealogie() :
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     if "__CHECKING_STUDY__StudyName" in self.dictMCVal.keys():
98       self.type_of_study = "CHECKING_STUDY"
99     else:
100       self.type_of_study = "ASSIMILATION_STUDY"
101         
102     self.text_da += "#-*-coding:iso-8859-1-*- \n"
103     self.text_da += "study_config = {} \n"
104
105     # Extraction de Study_type
106     self.text_da += "study_config['StudyType'] = '" + self.type_of_study + "'\n"
107     # Extraction de StudyName
108     self.text_da += "study_config['Name'] = '" + self.dictMCVal["__"+self.type_of_study+"__StudyName"] + "'\n"
109     # Extraction de Debug
110     if "__"+self.type_of_study+"__Debug" in self.dictMCVal.keys():
111       self.text_da += "study_config['Debug'] = '" + str(self.dictMCVal["__"+self.type_of_study+"__Debug"]) + "'\n"
112     else:
113       self.text_da += "study_config['Debug'] = '0'\n"
114
115     # Extraction de Algorithm et de ses parametres
116     if "__"+self.type_of_study+"__AlgorithmChoices__Algorithm" in self.dictMCVal.keys():
117       self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__AlgorithmChoices__Algorithm"] + "'\n"
118       self.add_AlgorithmChoices()
119     elif "__"+self.type_of_study+"__Algorithm" in self.dictMCVal.keys():
120       self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__Algorithm"] + "'\n"
121
122     if "__"+self.type_of_study+"__Background__INPUT_TYPE" in self.dictMCVal.keys():
123       self.add_data("Background")
124     if "__"+self.type_of_study+"__BackgroundError__INPUT_TYPE" in self.dictMCVal.keys():
125       self.add_data("BackgroundError")
126     if "__"+self.type_of_study+"__Observation__INPUT_TYPE" in self.dictMCVal.keys():
127       self.add_data("Observation")
128     if "__"+self.type_of_study+"__ObservationError__INPUT_TYPE" in self.dictMCVal.keys():
129       self.add_data("ObservationError")
130     if "__"+self.type_of_study+"__CheckingPoint__INPUT_TYPE" in self.dictMCVal.keys():
131       self.add_data("CheckingPoint")
132     if "__"+self.type_of_study+"__ObservationOperator__INPUT_TYPE" in self.dictMCVal.keys():
133       self.add_data("ObservationOperator")
134     if "__"+self.type_of_study+"__EvolutionModel__INPUT_TYPE" in self.dictMCVal.keys():
135       self.add_data("EvolutionModel")
136     if "__"+self.type_of_study+"__EvolutionError__INPUT_TYPE" in self.dictMCVal.keys():
137       self.add_data("EvolutionError")
138     if "__"+self.type_of_study+"__ControlInput__INPUT_TYPE" in self.dictMCVal.keys():
139       self.add_data("ControlInput")
140
141     self.add_variables()
142     # Parametres optionnels
143
144     # Extraction du StudyRepertory
145     if "__"+self.type_of_study+"__StudyRepertory" in self.dictMCVal.keys():
146       self.text_da += "study_config['Repertory'] = '" + self.dictMCVal["__"+self.type_of_study+"__StudyRepertory"] + "'\n"
147     # Extraction de AlgorithmParameters
148     if "__"+self.type_of_study+"__AlgorithmParameters__INPUT_TYPE" in self.dictMCVal.keys():
149       self.add_algorithm_parameters()
150     # Extraction de UserPostAnalysis
151     if "__"+self.type_of_study+"__UserPostAnalysis__FROM" in self.dictMCVal.keys():
152       self.add_UserPostAnalysis()
153     if "__"+self.type_of_study+"__UserDataInit__INIT_FILE" in self.dictMCVal.keys():
154       self.add_init()
155     if "__"+self.type_of_study+"__Observers__SELECTION" in self.dictMCVal.keys():
156       self.add_observers()
157
158   def add_data(self, data_name):
159
160     # Extraction des données
161     search_text = "__"+self.type_of_study+"__" + data_name + "__"
162     data_type = self.dictMCVal[search_text + "INPUT_TYPE"]
163     search_type = search_text + data_type + "__data__"
164     from_type = self.dictMCVal[search_type + "FROM"]
165     data = ""
166     if from_type == "String":
167       data = self.dictMCVal[search_type + "STRING_DATA__STRING"]
168     elif from_type == "Script":
169       data = self.dictMCVal[search_type + "SCRIPT_DATA__SCRIPT_FILE"]
170     elif from_type == "ScriptWithSwitch":
171       data = self.dictMCVal[search_type + "SCRIPTWITHSWITCH_DATA__SCRIPTWITHSWITCH_FILE"]
172     elif from_type == "ScriptWithFunctions":
173       data = self.dictMCVal[search_type + "SCRIPTWITHFUNCTIONS_DATA__SCRIPTWITHFUNCTIONS_FILE"]
174     elif from_type == "ScriptWithOneFunction":
175       data = self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__SCRIPTWITHONEFUNCTION_FILE"]
176     elif from_type == "FunctionDict":
177       data = self.dictMCVal[search_type + "FUNCTIONDICT_DATA__FUNCTIONDICT_FILE"]
178     else:
179       raise Exception('From Type unknown', from_type)
180
181     if from_type == "String" or from_type == "Script":
182       self.text_da += data_name + "_config = {}\n"
183       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
184       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
185       self.text_da += data_name + "_config['Data'] = '" + data      + "'\n"
186       if search_text+"Stored" in self.dictMCVal.keys():
187         self.text_da += data_name + "_config['Stored'] = '" +  str(self.dictMCVal[search_text+"Stored"])  + "'\n"
188       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
189
190     if from_type == "ScriptWithSwitch":
191       self.text_da += data_name + "_ScriptWithSwitch = {}\n"
192       self.text_da += data_name + "_ScriptWithSwitch['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
193       self.text_da += data_name + "_ScriptWithSwitch['Script'] = {}\n"
194       self.text_da += data_name + "_ScriptWithSwitch['Script']['Direct'] = '"  + data + "'\n"
195       self.text_da += data_name + "_ScriptWithSwitch['Script']['Tangent'] = '" + data + "'\n"
196       self.text_da += data_name + "_ScriptWithSwitch['Script']['Adjoint'] = '" + data + "'\n"
197       self.text_da += data_name + "_config = {}\n"
198       self.text_da += data_name + "_config['Type'] = 'Function'\n"
199       self.text_da += data_name + "_config['From'] = 'ScriptWithSwitch'\n"
200       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithSwitch\n"
201       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
202
203     if from_type == "ScriptWithFunctions":
204       self.text_da += data_name + "_ScriptWithFunctions = {}\n"
205       self.text_da += data_name + "_ScriptWithFunctions['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
206       self.text_da += data_name + "_ScriptWithFunctions['Script'] = {}\n"
207       self.text_da += data_name + "_ScriptWithFunctions['Script']['Direct'] = '"  + data + "'\n"
208       self.text_da += data_name + "_ScriptWithFunctions['Script']['Tangent'] = '" + data + "'\n"
209       self.text_da += data_name + "_ScriptWithFunctions['Script']['Adjoint'] = '" + data + "'\n"
210       self.text_da += data_name + "_config = {}\n"
211       self.text_da += data_name + "_config['Type'] = 'Function'\n"
212       self.text_da += data_name + "_config['From'] = 'ScriptWithFunctions'\n"
213       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithFunctions\n"
214       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
215
216     if from_type == "ScriptWithOneFunction":
217       self.text_da += data_name + "_ScriptWithOneFunction = {}\n"
218       self.text_da += data_name + "_ScriptWithOneFunction['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
219       self.text_da += data_name + "_ScriptWithOneFunction['Script'] = {}\n"
220       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Direct'] = '"  + data + "'\n"
221       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Tangent'] = '" + data + "'\n"
222       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Adjoint'] = '" + data + "'\n"
223       self.text_da += data_name + "_ScriptWithOneFunction['DifferentialIncrement'] = " + str(float(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__DifferentialIncrement"])) + "\n"
224       self.text_da += data_name + "_ScriptWithOneFunction['CenteredFiniteDifference'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__CenteredFiniteDifference"]) + "\n"
225       if search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing" in self.dictMCVal.keys():
226         self.text_da += data_name + "_ScriptWithOneFunction['EnableMultiProcessing'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing"]) + "\n"
227       self.text_da += data_name + "_config = {}\n"
228       self.text_da += data_name + "_config['Type'] = 'Function'\n"
229       self.text_da += data_name + "_config['From'] = 'ScriptWithOneFunction'\n"
230       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithOneFunction\n"
231       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
232
233     if from_type == "FunctionDict":
234       self.text_da += data_name + "_FunctionDict = {}\n"
235       self.text_da += data_name + "_FunctionDict['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
236       self.text_da += data_name + "_FunctionDict['Script'] = {}\n"
237       self.text_da += data_name + "_FunctionDict['Script']['Direct'] = '"  + data + "'\n"
238       self.text_da += data_name + "_FunctionDict['Script']['Tangent'] = '" + data + "'\n"
239       self.text_da += data_name + "_FunctionDict['Script']['Adjoint'] = '" + data + "'\n"
240       self.text_da += data_name + "_config = {}\n"
241       self.text_da += data_name + "_config['Type'] = 'Function'\n"
242       self.text_da += data_name + "_config['From'] = 'FunctionDict'\n"
243       self.text_da += data_name + "_config['Data'] = " + data_name + "_FunctionDict\n"
244       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
245
246   def add_algorithm_parameters(self):
247
248     data_name = "AlgorithmParameters"
249     data_type = "Dict"
250     from_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__FROM"]
251     
252     if from_type == "Script":
253       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__SCRIPT_DATA__SCRIPT_FILE"]
254       self.text_da += data_name + "_config = {} \n"
255       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
256       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
257       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
258       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
259     
260     if from_type == "String":
261       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__STRING_DATA__STRING"]
262       self.text_da += data_name + "_config = {} \n"
263       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
264       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
265       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
266       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
267
268   def add_init(self):
269
270       init_file_data = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__INIT_FILE"]
271       init_target_list = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__TARGET_LIST"]
272
273       self.text_da += "Init_config = {}\n"
274       self.text_da += "Init_config['Type'] = 'Dict'\n"
275       self.text_da += "Init_config['From'] = 'Script'\n"
276       self.text_da += "Init_config['Data'] = '" + init_file_data + "'\n"
277       self.text_da += "Init_config['Target'] = ["
278       if type(init_target_list) is type("str"):
279         self.text_da +=  "'" + init_target_list + "',"
280       else:
281         for target in init_target_list:
282           self.text_da += "'" + target + "',"
283       self.text_da += "]\n"
284       self.text_da += "study_config['UserDataInit'] = Init_config\n"
285
286   def add_UserPostAnalysis(self):
287
288     from_type = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__FROM"]
289     data = ""
290     if from_type == "String":
291       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__STRING_DATA__STRING"]
292       self.text_da += "Analysis_config = {}\n"
293       self.text_da += "Analysis_config['From'] = 'String'\n"
294       self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n"
295       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
296     elif from_type == "Script":
297       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__SCRIPT_DATA__SCRIPT_FILE"]
298       self.text_da += "Analysis_config = {}\n"
299       self.text_da += "Analysis_config['From'] = 'Script'\n"
300       self.text_da += "Analysis_config['Data'] = '" + data + "'\n"
301       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
302     elif from_type == "Template":
303       tmpl = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__Template"]
304       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__%s__ValueTemplate"%tmpl]
305       self.text_da += "Analysis_config = {}\n"
306       self.text_da += "Analysis_config['From'] = 'String'\n"
307       self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n"
308       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
309     else:
310       raise Exception('From Type unknown', from_type)
311
312   def add_AlgorithmChoices(self):
313
314     if not self.dictMCVal.has_key("__"+self.type_of_study+"__AlgorithmChoices__Parameters"): return
315
316     data_name = "AlgorithmParameters"
317     data_type = "Dict"
318     para_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmChoices__Parameters"]
319     if para_type == "Defaults":
320         from_type = para_type
321     elif para_type == "Dict":
322         from_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmChoices__Dict__data__FROM"]
323
324     if from_type == "Script":
325       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmChoices__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+"__AlgorithmChoices__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+"__AlgorithmChoices__Parameters"
340       keys = [k for k in self.dictMCVal.keys() if base in k]
341       keys.remove(base)
342       keys = [k.replace(base,'') for k in keys]
343       data  = '{'
344       for k in keys:
345         data += '"%s":"%s",'%(k.split('__')[-1],self.dictMCVal[base+k])
346       data += '}'
347       self.text_da += data_name + "_config = {} \n"
348       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
349       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
350       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
351       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
352
353   def add_variables(self):
354
355     # Input variables
356     if "__"+self.type_of_study+"__InputVariables__NAMES" in self.dictMCVal.keys():
357       names = []
358       sizes = []
359       if isinstance(self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"], type("")):
360         names.append(self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"])
361       else:
362         names = self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"]
363       if isinstance(self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"], type(1)):
364         sizes.append(self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"])
365       else:
366         sizes = self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"]
367
368       self.text_da += "inputvariables_config = {}\n"
369       self.text_da += "inputvariables_config['Order'] = %s\n" % list(names)
370       for name, size in zip(names, sizes):
371         self.text_da += "inputvariables_config['%s'] = %s\n" % (name,size)
372       self.text_da += "study_config['InputVariables'] = inputvariables_config\n"
373     else:
374       self.text_da += "inputvariables_config = {}\n"
375       self.text_da += "inputvariables_config['Order'] =['adao_default']\n"
376       self.text_da += "inputvariables_config['adao_default'] = -1\n"
377       self.text_da += "study_config['InputVariables'] = inputvariables_config\n"
378
379     # Output variables
380     if "__"+self.type_of_study+"__OutputVariables__NAMES" in self.dictMCVal.keys():
381       names = []
382       sizes = []
383       if isinstance(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"], type("")):
384         names.append(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"])
385       else:
386         names = self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"]
387       if isinstance(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"], type(1)):
388         sizes.append(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"])
389       else:
390         sizes = self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"]
391
392       self.text_da += "outputvariables_config = {}\n"
393       self.text_da += "outputvariables_config['Order'] = %s\n" % list(names)
394       for name, size in zip(names, sizes):
395         self.text_da += "outputvariables_config['%s'] = %s\n" % (name,size)
396       self.text_da += "study_config['OutputVariables'] = outputvariables_config\n"
397     else:
398       self.text_da += "outputvariables_config = {}\n"
399       self.text_da += "outputvariables_config['Order'] = ['adao_default']\n"
400       self.text_da += "outputvariables_config['adao_default'] = -1\n"
401       self.text_da += "study_config['OutputVariables'] = outputvariables_config\n"
402
403   def add_observers(self):
404     observers = {}
405     observer = self.dictMCVal["__"+self.type_of_study+"__Observers__SELECTION"]
406     if isinstance(observer, type("")):
407       self.add_observer_in_dict(observer, observers)
408     else:
409       for observer in self.dictMCVal["__"+self.type_of_study+"__Observers__SELECTION"]:
410         self.add_observer_in_dict(observer, observers)
411
412     # Write observers in the python command file
413     number = 2
414     self.text_da += "observers = {}\n"
415     for observer in observers.keys():
416       number += 1
417       self.text_da += "observers[\"" + observer + "\"] = {}\n"
418       self.text_da += "observers[\"" + observer + "\"][\"number\"] = " + str(number) + "\n"
419       self.text_da += "observers[\"" + observer + "\"][\"nodetype\"] = \"" + observers[observer]["nodetype"] + "\"\n"
420       if observers[observer]["nodetype"] == "String":
421         self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n"
422       elif observers[observer]["nodetype"] == "Template":
423         self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n"
424         self.text_da += "observers[\"" + observer + "\"][\"Template\"] = \"\"\"" + observers[observer]["template"] + "\"\"\"\n"
425       else:
426         self.text_da += "observers[\"" + observer + "\"][\"Script\"] = \"" + observers[observer]["file"] + "\"\n"
427       if "scheduler" in observers[observer].keys():
428         self.text_da += "observers[\"" + observer + "\"][\"scheduler\"] = \"\"\"" + observers[observer]["scheduler"] + "\"\"\"\n"
429       if "info" in observers[observer].keys():
430         self.text_da += "observers[\"" + observer + "\"][\"info\"] = \"\"\"" + observers[observer]["info"] + "\"\"\"\n"
431     self.text_da += "study_config['Observers'] = observers\n"
432
433   def add_observer_in_dict(self, observer, observers):
434     """
435       Add observer in the observers dict.
436     """
437     observers[observer] = {}
438     observers[observer]["name"] = observer
439     observer_eficas_name = "__"+self.type_of_study+"__Observers__" + observer + "__" + observer + "_data__"
440     # NodeType
441     node_type_key_name = observer_eficas_name + "NodeType"
442     observers[observer]["nodetype"] = self.dictMCVal[node_type_key_name]
443
444     # NodeType script/file
445     if observers[observer]["nodetype"] == "String":
446       observers[observer]["script"] = self.dictMCVal[observer_eficas_name + "PythonScript__Value"]
447     elif observers[observer]["nodetype"] == "Template":
448       observers[observer]["nodetype"] = "String"
449       observer_template_key = observer_eficas_name + "ObserverTemplate__"
450       observers[observer]["template"] = self.dictMCVal[observer_template_key + "Template"]
451       observers[observer]["script"]   = self.dictMCVal[observer_template_key + observers[observer]["template"] + "__ValueTemplate"]
452     else:
453       observers[observer]["file"] = self.dictMCVal[observer_eficas_name + "UserFile__Value"]
454
455     # Scheduler
456     scheduler_key_name = observer_eficas_name + "Scheduler"
457     if scheduler_key_name in self.dictMCVal.keys():
458       observers[observer]["scheduler"] = self.dictMCVal[scheduler_key_name]
459
460     # Info
461     info_key_name = observer_eficas_name + "Info"
462     if info_key_name in self.dictMCVal.keys():
463       observers[observer]["info"] = self.dictMCVal[info_key_name]