]> SALOME platform Git repositories - modules/adao.git/blob - src/daEficas/generator_adao.py
Salome HOME
Updating version and copyright date information
[modules/adao.git] / src / daEficas / generator_adao.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2020 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,appli=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.items():
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.debug("EFICAS case is not valid, 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 = open( str(filename), 'w')
81       f.write( self.text_da )
82       f.close()
83
84   def generMCSIMP(self,obj) :
85     """
86     Convertit un objet MCSIMP en texte python
87     """
88     clef=""
89     for i in obj.getGenealogie() :
90       clef=clef+"__"+i
91     self.dictMCVal[clef]=obj.valeur
92
93     s=PythonGenerator.generMCSIMP(self,obj)
94     return s
95
96   def generate_da(self):
97
98     if "__CHECKING_STUDY__StudyName" in self.dictMCVal.keys():
99       self.type_of_study = "CHECKING_STUDY"
100     else:
101       self.type_of_study = "ASSIMILATION_STUDY"
102
103     self.text_da += "#-*- coding: utf-8 -*-\n"
104     self.text_da += "study_config = {}\n"
105
106     # Extraction de Study_type
107     self.text_da += "study_config['StudyType'] = '" + self.type_of_study + "'\n"
108     # Extraction de StudyName
109     self.text_da += "study_config['Name'] = '" + self.dictMCVal["__"+self.type_of_study+"__StudyName"] + "'\n"
110     # Extraction de Debug
111     if "__"+self.type_of_study+"__Debug" in self.dictMCVal.keys():
112       self.text_da += "study_config['Debug'] = '" + str(self.dictMCVal["__"+self.type_of_study+"__Debug"]) + "'\n"
113     else:
114       self.text_da += "study_config['Debug'] = '0'\n"
115
116     # Extraction de Algorithm et de ses parametres
117     if "__"+self.type_of_study+"__AlgorithmParameters__Algorithm" in self.dictMCVal.keys():
118       self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Algorithm"] + "'\n"
119       self.add_AlgorithmParameters()
120     elif "__"+self.type_of_study+"__Algorithm" in self.dictMCVal.keys():
121       self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__Algorithm"] + "'\n"
122
123     if "__"+self.type_of_study+"__Background__INPUT_TYPE" in self.dictMCVal.keys():
124       self.add_data("Background")
125     if "__"+self.type_of_study+"__BackgroundError__INPUT_TYPE" in self.dictMCVal.keys():
126       self.add_data("BackgroundError")
127     if "__"+self.type_of_study+"__Observation__INPUT_TYPE" in self.dictMCVal.keys():
128       self.add_data("Observation")
129     if "__"+self.type_of_study+"__ObservationError__INPUT_TYPE" in self.dictMCVal.keys():
130       self.add_data("ObservationError")
131     if "__"+self.type_of_study+"__CheckingPoint__INPUT_TYPE" in self.dictMCVal.keys():
132       self.add_data("CheckingPoint")
133     if "__"+self.type_of_study+"__ObservationOperator__INPUT_TYPE" in self.dictMCVal.keys():
134       self.add_data("ObservationOperator")
135     if "__"+self.type_of_study+"__EvolutionModel__INPUT_TYPE" in self.dictMCVal.keys():
136       self.add_data("EvolutionModel")
137     if "__"+self.type_of_study+"__EvolutionError__INPUT_TYPE" in self.dictMCVal.keys():
138       self.add_data("EvolutionError")
139     if "__"+self.type_of_study+"__ControlInput__INPUT_TYPE" in self.dictMCVal.keys():
140       self.add_data("ControlInput")
141
142     self.add_variables()
143     # Parametres optionnels
144
145     # Extraction du StudyRepertory
146     if "__"+self.type_of_study+"__StudyRepertory" in self.dictMCVal.keys():
147       self.text_da += "study_config['Repertory'] = '" + self.dictMCVal["__"+self.type_of_study+"__StudyRepertory"] + "'\n"
148     # Extraction de UserPostAnalysis
149     if "__"+self.type_of_study+"__UserPostAnalysis__FROM" in self.dictMCVal.keys():
150       self.add_UserPostAnalysis()
151     if "__"+self.type_of_study+"__UserDataInit__INIT_FILE" in self.dictMCVal.keys():
152       self.add_init()
153     if "__"+self.type_of_study+"__Observers__SELECTION" in self.dictMCVal.keys():
154       self.add_observers()
155
156   def add_data(self, data_name):
157
158     # Extraction des donnees
159     search_text = "__"+self.type_of_study+"__" + data_name + "__"
160     data_type = self.dictMCVal[search_text + "INPUT_TYPE"]
161     search_type = search_text + data_type + "__data__"
162     from_type = self.dictMCVal[search_type + "FROM"]
163     data = ""
164     if from_type == "String":
165       data = self.dictMCVal[search_type + "STRING_DATA__STRING"]
166     elif from_type == "Script":
167       data = self.dictMCVal[search_type + "SCRIPT_DATA__SCRIPT_FILE"]
168     elif from_type == "DataFile":
169       data = self.dictMCVal[search_type + "DATA_DATA__DATA_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" or from_type == "DataFile":
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       if search_type+"DATA_DATA__ColMajor" in self.dictMCVal.keys():
189         self.text_da += data_name + "_config['ColMajor'] = '" +  str(self.dictMCVal[search_type+"DATA_DATA__ColMajor"])  + "'\n"
190       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
191
192     if from_type == "ScriptWithSwitch":
193       self.text_da += data_name + "_ScriptWithSwitch = {}\n"
194       self.text_da += data_name + "_ScriptWithSwitch['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
195       self.text_da += data_name + "_ScriptWithSwitch['Script'] = {}\n"
196       self.text_da += data_name + "_ScriptWithSwitch['Script']['Direct'] = '"  + data + "'\n"
197       self.text_da += data_name + "_ScriptWithSwitch['Script']['Tangent'] = '" + data + "'\n"
198       self.text_da += data_name + "_ScriptWithSwitch['Script']['Adjoint'] = '" + data + "'\n"
199       self.text_da += data_name + "_config = {}\n"
200       self.text_da += data_name + "_config['Type'] = 'Function'\n"
201       self.text_da += data_name + "_config['From'] = 'ScriptWithSwitch'\n"
202       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithSwitch\n"
203       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
204
205     if from_type == "ScriptWithFunctions":
206       self.text_da += data_name + "_ScriptWithFunctions = {}\n"
207       self.text_da += data_name + "_ScriptWithFunctions['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
208       self.text_da += data_name + "_ScriptWithFunctions['Script'] = {}\n"
209       self.text_da += data_name + "_ScriptWithFunctions['Script']['Direct'] = '"  + data + "'\n"
210       self.text_da += data_name + "_ScriptWithFunctions['Script']['Tangent'] = '" + data + "'\n"
211       self.text_da += data_name + "_ScriptWithFunctions['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'] = 'ScriptWithFunctions'\n"
215       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithFunctions\n"
216       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
217
218     if from_type == "ScriptWithOneFunction":
219       self.text_da += data_name + "_ScriptWithOneFunction = {}\n"
220       self.text_da += data_name + "_ScriptWithOneFunction['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
221       self.text_da += data_name + "_ScriptWithOneFunction['Script'] = {}\n"
222       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Direct'] = '"  + data + "'\n"
223       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Tangent'] = '" + data + "'\n"
224       self.text_da += data_name + "_ScriptWithOneFunction['Script']['Adjoint'] = '" + data + "'\n"
225       self.text_da += data_name + "_ScriptWithOneFunction['DifferentialIncrement'] = " + str(float(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__DifferentialIncrement"])) + "\n"
226       self.text_da += data_name + "_ScriptWithOneFunction['CenteredFiniteDifference'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__CenteredFiniteDifference"]) + "\n"
227       if search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing" in self.dictMCVal.keys():
228         self.text_da += data_name + "_ScriptWithOneFunction['EnableMultiProcessing'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing"]) + "\n"
229       if search_type + "SCRIPTWITHONEFUNCTION_DATA__NumberOfProcesses" in self.dictMCVal.keys():
230         self.text_da += data_name + "_ScriptWithOneFunction['NumberOfProcesses'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__NumberOfProcesses"]) + "\n"
231       self.text_da += data_name + "_config = {}\n"
232       self.text_da += data_name + "_config['Type'] = 'Function'\n"
233       self.text_da += data_name + "_config['From'] = 'ScriptWithOneFunction'\n"
234       self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithOneFunction\n"
235       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
236
237     if from_type == "FunctionDict":
238       self.text_da += data_name + "_FunctionDict = {}\n"
239       self.text_da += data_name + "_FunctionDict['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"
240       self.text_da += data_name + "_FunctionDict['Script'] = {}\n"
241       self.text_da += data_name + "_FunctionDict['Script']['Direct'] = '"  + data + "'\n"
242       self.text_da += data_name + "_FunctionDict['Script']['Tangent'] = '" + data + "'\n"
243       self.text_da += data_name + "_FunctionDict['Script']['Adjoint'] = '" + data + "'\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'] = 'FunctionDict'\n"
247       self.text_da += data_name + "_config['Data'] = " + data_name + "_FunctionDict\n"
248       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
249
250   def add_init(self):
251
252       init_file_data = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__INIT_FILE"]
253       init_target_list = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__TARGET_LIST"]
254
255       self.text_da += "Init_config = {}\n"
256       self.text_da += "Init_config['Type'] = 'Dict'\n"
257       self.text_da += "Init_config['From'] = 'Script'\n"
258       self.text_da += "Init_config['Data'] = '" + init_file_data + "'\n"
259       self.text_da += "Init_config['Target'] = ["
260       if isinstance(init_target_list, "str"):
261         self.text_da +=  "'" + init_target_list + "',"
262       else:
263         for target in init_target_list:
264           self.text_da += "'" + target + "',"
265       self.text_da += "]\n"
266       self.text_da += "study_config['UserDataInit'] = Init_config\n"
267
268   def add_UserPostAnalysis(self):
269
270     from_type = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__FROM"]
271     data = ""
272     if from_type == "String":
273       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__STRING_DATA__STRING"]
274       self.text_da += "Analysis_config = {}\n"
275       self.text_da += "Analysis_config['From'] = 'String'\n"
276       self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n"
277       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
278     elif from_type == "Script":
279       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__SCRIPT_DATA__SCRIPT_FILE"]
280       self.text_da += "Analysis_config = {}\n"
281       self.text_da += "Analysis_config['From'] = 'Script'\n"
282       self.text_da += "Analysis_config['Data'] = '" + data + "'\n"
283       self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n"
284     elif from_type == "Template":
285       tmpl = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__Template"]
286       data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__%s__ValueTemplate"%tmpl]
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     else:
292       raise Exception('From Type unknown', from_type)
293
294   def add_AlgorithmParameters(self):
295
296     data_name = "AlgorithmParameters"
297     data_type = "Dict"
298     #
299     if "__"+self.type_of_study+"__AlgorithmParameters__Parameters" in self.dictMCVal:
300         para_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Parameters"]
301     else:
302         para_type = "Defaults"
303     #
304     if para_type == "Defaults":
305         from_type = para_type
306     elif para_type == "Dict":
307         from_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__FROM"]
308     else:
309         return
310
311     if from_type == "Script":
312       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__SCRIPT_DATA__SCRIPT_FILE"]
313       self.text_da += data_name + "_config = {}\n"
314       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
315       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
316       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
317       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
318     elif from_type == "String":
319       data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__STRING_DATA__STRING"]
320       self.text_da += data_name + "_config = {}\n"
321       self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
322       self.text_da += data_name + "_config['From'] = '" + from_type + "'\n"
323       self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
324       self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
325     elif from_type == "Defaults":
326       base = "__"+self.type_of_study+"__AlgorithmParameters__Parameters"
327       keys = [k for k in self.dictMCVal.keys() if base in k]
328       if base in keys: keys.remove(base)
329       keys = [k.replace(base,'') for k in keys]
330       data  = '{'
331       for k in keys:
332         key = k.split('__')[-1]
333         val = self.dictMCVal[base+k]
334         # print key," = ",val,"    ",type(val)
335         if isinstance(val, str) and key == "SetSeed":
336             data += '"%s":%s,'%(key,int(val))
337         elif isinstance(val, str) and not (val.count('[')>=2 or val.count('(')>=2):
338             data += '"%s":"%s",'%(key,val)
339         else:
340             data += '"%s":%s,'%(key,val)
341       data = data.replace("'",'"')
342       data += '}'
343       if data != '{}':
344           self.text_da += data_name + "_config = {}\n"
345           self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n"
346           self.text_da += data_name + "_config['From'] = 'String'\n"
347           self.text_da += data_name + "_config['Data'] = '" + data + "'\n"
348           self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n"
349
350   def add_variables(self):
351
352     # Input variables
353     if "__"+self.type_of_study+"__InputVariables__NAMES" in self.dictMCVal.keys():
354       names = []
355       sizes = []
356       if isinstance(self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"], type("")):
357         names.append(self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"])
358       else:
359         names = self.dictMCVal["__"+self.type_of_study+"__InputVariables__NAMES"]
360       if isinstance(self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"], type(1)):
361         sizes.append(self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"])
362       else:
363         sizes = self.dictMCVal["__"+self.type_of_study+"__InputVariables__SIZES"]
364
365       self.text_da += "inputvariables_config = {}\n"
366       self.text_da += "inputvariables_config['Order'] = %s\n" % list(names)
367       for name, size in zip(names, sizes):
368         self.text_da += "inputvariables_config['%s'] = %s\n" % (name,size)
369       self.text_da += "study_config['InputVariables'] = inputvariables_config\n"
370     else:
371       self.text_da += "inputvariables_config = {}\n"
372       self.text_da += "inputvariables_config['Order'] =['adao_default']\n"
373       self.text_da += "inputvariables_config['adao_default'] = -1\n"
374       self.text_da += "study_config['InputVariables'] = inputvariables_config\n"
375
376     # Output variables
377     if "__"+self.type_of_study+"__OutputVariables__NAMES" in self.dictMCVal.keys():
378       names = []
379       sizes = []
380       if isinstance(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"], type("")):
381         names.append(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"])
382       else:
383         names = self.dictMCVal["__"+self.type_of_study+"__OutputVariables__NAMES"]
384       if isinstance(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"], type(1)):
385         sizes.append(self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"])
386       else:
387         sizes = self.dictMCVal["__"+self.type_of_study+"__OutputVariables__SIZES"]
388
389       self.text_da += "outputvariables_config = {}\n"
390       self.text_da += "outputvariables_config['Order'] = %s\n" % list(names)
391       for name, size in zip(names, sizes):
392         self.text_da += "outputvariables_config['%s'] = %s\n" % (name,size)
393       self.text_da += "study_config['OutputVariables'] = outputvariables_config\n"
394     else:
395       self.text_da += "outputvariables_config = {}\n"
396       self.text_da += "outputvariables_config['Order'] = ['adao_default']\n"
397       self.text_da += "outputvariables_config['adao_default'] = -1\n"
398       self.text_da += "study_config['OutputVariables'] = outputvariables_config\n"
399
400   def add_observers(self):
401     observers = {}
402     observer = self.dictMCVal["__"+self.type_of_study+"__Observers__SELECTION"]
403     if isinstance(observer, type("")):
404       self.add_observer_in_dict(observer, observers)
405     else:
406       for observer in self.dictMCVal["__"+self.type_of_study+"__Observers__SELECTION"]:
407         self.add_observer_in_dict(observer, observers)
408
409     # Write observers in the python command file
410     number = 2
411     self.text_da += "observers = {}\n"
412     for observer in observers.keys():
413       number += 1
414       self.text_da += "observers[\"" + observer + "\"] = {}\n"
415       self.text_da += "observers[\"" + observer + "\"][\"number\"] = " + str(number) + "\n"
416       self.text_da += "observers[\"" + observer + "\"][\"nodetype\"] = \"" + observers[observer]["nodetype"] + "\"\n"
417       if observers[observer]["nodetype"] == "String":
418         self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n"
419       elif observers[observer]["nodetype"] == "Template":
420         self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n"
421         self.text_da += "observers[\"" + observer + "\"][\"Template\"] = \"\"\"" + observers[observer]["template"] + "\"\"\"\n"
422       else:
423         self.text_da += "observers[\"" + observer + "\"][\"Script\"] = \"" + observers[observer]["file"] + "\"\n"
424       if "scheduler" in observers[observer].keys():
425         self.text_da += "observers[\"" + observer + "\"][\"scheduler\"] = \"\"\"" + observers[observer]["scheduler"] + "\"\"\"\n"
426       if "info" in observers[observer].keys():
427         self.text_da += "observers[\"" + observer + "\"][\"info\"] = \"\"\"" + observers[observer]["info"] + "\"\"\"\n"
428     self.text_da += "study_config['Observers'] = observers\n"
429
430   def add_observer_in_dict(self, observer, observers):
431     """
432       Add observer in the observers dict.
433     """
434     observers[observer] = {}
435     observers[observer]["name"] = observer
436     observer_eficas_name = "__"+self.type_of_study+"__Observers__" + observer + "__" + observer + "_data__"
437     # NodeType
438     node_type_key_name = observer_eficas_name + "NodeType"
439     observers[observer]["nodetype"] = self.dictMCVal[node_type_key_name]
440
441     # NodeType script/file
442     if observers[observer]["nodetype"] == "String":
443       observers[observer]["script"] = self.dictMCVal[observer_eficas_name + "PythonScript__Value"]
444     elif observers[observer]["nodetype"] == "Template":
445       observers[observer]["nodetype"] = "String"
446       observer_template_key = observer_eficas_name + "ObserverTemplate__"
447       observers[observer]["template"] = self.dictMCVal[observer_template_key + "Template"]
448       observers[observer]["script"]   = self.dictMCVal[observer_template_key + observers[observer]["template"] + "__ValueTemplate"]
449     else:
450       observers[observer]["file"] = self.dictMCVal[observer_eficas_name + "UserFile__Value"]
451
452     # Scheduler
453     scheduler_key_name = observer_eficas_name + "Scheduler"
454     if scheduler_key_name in self.dictMCVal.keys():
455       observers[observer]["scheduler"] = self.dictMCVal[scheduler_key_name]
456
457     # Info
458     info_key_name = observer_eficas_name + "Info"
459     if info_key_name in self.dictMCVal.keys():
460       observers[observer]["info"] = self.dictMCVal[info_key_name]