# Path: cosmoHammer/ChainContext.py
# class ChainContext(object):
#     """
#     Context holding a dict to store data and information durring the computation of the likelihood
#     """
#     
#     def __init__(self, parent, params):
#         """
#         Constructor of the context
#         """
#         
#         self._data = dict()
#         self.add(PARENT_KEY, parent)
#         self.add(PARAMS_KEY, params)
#         self.add(DATA_KEY, dict())
#         
#     def add(self, key, value):
#         """
#         Adds the value to the context using the key
#         
#         :param key: string
#             key to use
#         :param value: object
#             the value to store
#             
#         """
#         self._data[key] = value
#         
#     def remove(self, key):
#         """
#         Removes the value from the context
#         
#         :param key: string
#             key to remove from the context
#         """
#         assert key != None
#         del(self._data[key])
#         
#     def contains(self, key):
#         """
#         Checks if the key is in the context
#         
#         :param key: string
#             key to check
#             
#         :return: True if the key is in the context
#         """
#         return key in self._data
#     
#     def get(self, key, default=None):
#         """
#         Returns the value stored in the context at the key or the default value in the 
#         context doesn't contain the key
#         
#         :param key: string
#             key to use
#         :param default: string
#             the default value to use if the key is not available
#         """
#         if(self.contains(key)):
#             return self._data[key]
#         
#         return default
#         
#     def getParams(self):
#         """
#         Returns the currently processed parameters
#         
#         :return: The param of this context
#         """
#         return self.get(PARAMS_KEY)
#     
#     def getParent(self):
#         """
#         Returns the parent
#         
#         :return: The parent chain of this context
#         """
#         return self.get(PARENT_KEY)
#     
#     def getData(self):
#         """
#         Returns the data
#         
#         :return: The data of this context
#         """
#         return self.get(DATA_KEY)


from wmap3Wrapper import WmapLikelihoodModule as wmap3
from wmap5Wrapper import WmapLikelihoodModule as wmap5
from wmap7Wrapper import WmapLikelihoodModule as wmap7
from wmap9Wrapper import WmapLikelihoodModule as wmap9
from pycambWrapper import PyCambCoreModule
from cambWrapper import CambCoreModule
from cosmoHammer.ChainContext import ChainContext
pyCambCore = PyCambCoreModule.PyCambCoreModule()
cambCore = CambCoreModule()
wmap3Likelihood = wmap3.WmapLikelihoodModule()
wmap5Likelihood = wmap5.WmapLikelihoodModule()
wmap7Likelihood = wmap7.WmapLikelihoodModule()
wmap9Likelihood = wmap9.WmapLikelihoodModule()
#setting up wrappers
cambCore.setup()
pyCambCore.setup()

wmap3Likelihood.setup()
wmap5Likelihood.setup()
wmap7Likelihood.setup()
wmap9Likelihood.setup()

#camb wrapper
print("setup done. calling CAMB power spectrum computation")

paramValues = [70, 0.0226, 0.122, 2.1E-009, 0.96, 0.09]

ctx = ChainContext(None, paramValues)
cambCore(ctx)

print("cls computation done. calling WMAP likelihood")
print("Likelihood WMAP 3: %s"%wmap3Likelihood.computeLikelihood(ctx))
print("Likelihood WMAP 5: %s"%wmap5Likelihood.computeLikelihood(ctx))
print("Likelihood WMAP 7: %s"%wmap7Likelihood.computeLikelihood(ctx))
print("Likelihood WMAP 9: %s"%wmap9Likelihood.computeLikelihood(ctx))

#pycamb

# Path: cosmoHammer/ChainContext.py
# class ChainContext(object):
#     """
#     Context holding a dict to store data and information durring the computation of the likelihood
#     """
#     
#     def __init__(self, parent, params):
#         """
#         Constructor of the context
#         """
#         
#         self._data = dict()
#         self.add(PARENT_KEY, parent)
#         self.add(PARAMS_KEY, params)
#         self.add(DATA_KEY, dict())
#         
#     def add(self, key, value):
#         """
#         Adds the value to the context using the key
#         
#         :param key: string
#             key to use
#         :param value: object
#             the value to store
#             
#         """
#         self._data[key] = value
#         
#     def remove(self, key):
#         """
#         Removes the value from the context
#         
#         :param key: string
#             key to remove from the context
#         """
#         assert key != None
#         del(self._data[key])
#         
#     def contains(self, key):
#         """
#         Checks if the key is in the context
#         
#         :param key: string
#             key to check
#             
#         :return: True if the key is in the context
#         """
#         return key in self._data
#     
#     def get(self, key, default=None):
#         """
#         Returns the value stored in the context at the key or the default value in the 
#         context doesn't contain the key
#         
#         :param key: string
#             key to use
#         :param default: string
#             the default value to use if the key is not available
#         """
#         if(self.contains(key)):
#             return self._data[key]
#         
#         return default
#         
#     def getParams(self):
#         """
#         Returns the currently processed parameters
#         
#         :return: The param of this context
#         """
#         return self.get(PARAMS_KEY)
#     
#     def getParent(self):
#         """
#         Returns the parent
#         
#         :return: The parent chain of this context
#         """
#         return self.get(PARENT_KEY)
#     
#     def getData(self):
#         """
#         Returns the data
#         
#         :return: The data of this context
#         """
#         return self.get(DATA_KEY)


# Path: examples/wmap_tester.py
from wmap3Wrapper import WmapLikelihoodModule as wmap3
from wmap5Wrapper import WmapLikelihoodModule as wmap5
from wmap7Wrapper import WmapLikelihoodModule as wmap7
from wmap9Wrapper import WmapLikelihoodModule as wmap9
from pycambWrapper import PyCambCoreModule
from cambWrapper import CambCoreModule
from cosmoHammer.ChainContext import ChainContext

pyCambCore = PyCambCoreModule.PyCambCoreModule()
cambCore = CambCoreModule()
wmap3Likelihood = wmap3.WmapLikelihoodModule()
wmap5Likelihood = wmap5.WmapLikelihoodModule()
wmap7Likelihood = wmap7.WmapLikelihoodModule()
wmap9Likelihood = wmap9.WmapLikelihoodModule()
#setting up wrappers
cambCore.setup()
pyCambCore.setup()

wmap3Likelihood.setup()
wmap5Likelihood.setup()
wmap7Likelihood.setup()
wmap9Likelihood.setup()

#camb wrapper
print("setup done. calling CAMB power spectrum computation")

paramValues = [70, 0.0226, 0.122, 2.1E-009, 0.96, 0.09]

ctx = ChainContext(None, paramValues)
cambCore(ctx)

print("cls computation done. calling WMAP likelihood")
print("Likelihood WMAP 3: %s"%wmap3Likelihood.computeLikelihood(ctx))
print("Likelihood WMAP 5: %s"%wmap5Likelihood.computeLikelihood(ctx))
print("Likelihood WMAP 7: %s"%wmap7Likelihood.computeLikelihood(ctx))
print("Likelihood WMAP 9: %s"%wmap9Likelihood.computeLikelihood(ctx))

#pycamb

ctx = ChainContext(None, paramValues)