#!/usr/bin/env python3




##################################################
## DEPENDENCIES
import sys
import os
import os.path
try:
    import builtins as builtin
except ImportError:
    import __builtin__ as builtin
from os.path import getmtime, exists
import time
import types
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import *
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
from Cheetah.compat import unicode
from xpdeint.Vectors._ComputedVector import _ComputedVector

##################################################
## MODULE CONSTANTS
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '3.2.6.post2'
__CHEETAH_versionTuple__ = (3, 2, 6, 'post', 2)
__CHEETAH_genTime__ = 1634954792.6469352
__CHEETAH_genTimestamp__ = 'Sat Oct 23 13:06:32 2021'
__CHEETAH_src__ = '/home/mattias/xmds-3.0.0/admin/staging/xmds-3.1.0/xpdeint/Vectors/ComputedVector.tmpl'
__CHEETAH_srcLastModified__ = 'Thu Apr  4 16:29:24 2019'
__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'

if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
    raise AssertionError(
      'This template was compiled with Cheetah version'
      ' %s. Templates compiled before version %s must be recompiled.'%(
         __CHEETAH_version__, RequiredCheetahVersion))

##################################################
## CLASSES

class ComputedVector(_ComputedVector):

    ##################################################
    ## CHEETAH GENERATED METHODS


    def __init__(self, *args, **KWs):

        super(ComputedVector, self).__init__(*args, **KWs)
        if not self._CHEETAH__instanceInitialized:
            cheetahKWArgs = {}
            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
            for k,v in KWs.items():
                if k in allowedKWs: cheetahKWArgs[k] = v
            self._initCheetahInstance(**cheetahKWArgs)
        

    def description(self, **KWS):



        ## Generated from @def description: computed vector $name at line 29, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write('''computed vector ''')
        _v = VFFSL(SL,"name",True) # '$name' on line 29, col 35
        if _v is not None: write(_filter(_v, rawExpr='$name')) # from line 29, col 35.
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def evaluateFunctionContents(self, function, **KWS):


        """
        This function returns the code for the calculated vector's ``evaluate()`` function.
          
          The ``evaluate()`` function executes the code that defines the calculated vector.
        """

        ## CHEETAH: generated from @def evaluateFunctionContents($function) at line 31, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        if VFFSL(SL,"integratingComponents",True): # generated from line 38, col 3
            #  If this vector is constructed through an integral, then we first
            #  need to initialise ourselves to zero.
            _v = VFFSL(SL,"initialise",True) # '${initialise}' on line 41, col 1
            if _v is not None: write(_filter(_v, rawExpr='${initialise}')) # from line 41, col 1.
            write('''
''')
        # 
        featureOrdering = ['Stochastic']
        featureDict = {'codeBlock': VFFSL(SL,"codeBlocks",True)['evaluation']}
        # 
        vectorOverrides = []
        if VFFSL(SL,"integratingComponents",True): # generated from line 49, col 3
            vectorOverrides.append(self)
        # 
        _v = VFFSL(SL,"insertCodeForFeatures",False)('computedVectorEvaluationBegin', VFFSL(SL,"featureOrdering",True), featureDict) # "${insertCodeForFeatures('computedVectorEvaluationBegin', $featureOrdering, featureDict)}" on line 53, col 1
        if _v is not None: write(_filter(_v, rawExpr="${insertCodeForFeatures('computedVectorEvaluationBegin', $featureOrdering, featureDict)}")) # from line 53, col 1.
        _v = VFN(VFFSL(SL,"codeBlocks",True)['evaluation'],"loop",False)(self.insideEvaluationLoops, vectorOverrides=vectorOverrides) # "${codeBlocks['evaluation'].loop(self.insideEvaluationLoops, vectorOverrides=vectorOverrides)}" on line 54, col 1
        if _v is not None: write(_filter(_v, rawExpr="${codeBlocks['evaluation'].loop(self.insideEvaluationLoops, vectorOverrides=vectorOverrides)}")) # from line 54, col 1.
        _v = VFFSL(SL,"insertCodeForFeaturesInReverseOrder",False)('computedVectorEvaluationEnd', VFFSL(SL,"featureOrdering",True), featureDict) # "${insertCodeForFeaturesInReverseOrder('computedVectorEvaluationEnd', $featureOrdering, featureDict)}" on line 55, col 1
        if _v is not None: write(_filter(_v, rawExpr="${insertCodeForFeaturesInReverseOrder('computedVectorEvaluationEnd', $featureOrdering, featureDict)}")) # from line 55, col 1.
        # 
        if VFFSL(SL,"needsTransforms",True): # generated from line 57, col 3
            write('''
_''')
            _v = VFFSL(SL,"id",True) # '${id}' on line 59, col 2
            if _v is not None: write(_filter(_v, rawExpr='${id}')) # from line 59, col 2.
            write('''_basis = ''')
            _v = VFFSL(SL,"basisIndexForBasis",False)(self.initialBasis) # '$basisIndexForBasis(self.initialBasis)' on line 59, col 16
            if _v is not None: write(_filter(_v, rawExpr='$basisIndexForBasis(self.initialBasis)')) # from line 59, col 16.
            write(''';
''')
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def insideEvaluationLoops(self, codeString, **KWS):



        ## CHEETAH: generated from @def insideEvaluationLoops(codeString) at line 64, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        # 
        write('''// ************* Evaluation code ****************
''')
        _v = VFFSL(SL,"codeString",True) # '${codeString}' on line 67, col 1
        if _v is not None: write(_filter(_v, rawExpr='${codeString}')) # from line 67, col 1.
        write('''// **********************************************
''')
        # 
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def writeBody(self, **KWS):



        ## CHEETAH: main method generated for this template
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        write('''
''')
        # 
        # ComputedVector.tmpl
        # 
        # Created by Graham Dennis on 2008-03-12.
        # 
        # Copyright (c) 2008-2012, Graham Dennis
        # 
        # This program is free software: you can redistribute it and/or modify
        # it under the terms of the GNU General Public License as published by
        # the Free Software Foundation, either version 2 of the License, or
        # (at your option) any later version.
        # 
        # This program is distributed in the hope that it will be useful,
        # but WITHOUT ANY WARRANTY; without even the implied warranty of
        # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        # GNU General Public License for more details.
        # 
        # You should have received a copy of the GNU General Public License
        # along with this program.  If not, see <http://www.gnu.org/licenses/>.
        # 
        write('''
''')
        # 
        #   Description of template
        write('''

''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        
    ##################################################
    ## CHEETAH GENERATED ATTRIBUTES


    _CHEETAH__instanceInitialized = False

    _CHEETAH_version = __CHEETAH_version__

    _CHEETAH_versionTuple = __CHEETAH_versionTuple__

    _CHEETAH_genTime = __CHEETAH_genTime__

    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__

    _CHEETAH_src = __CHEETAH_src__

    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__

    _mainCheetahMethod_for_ComputedVector = 'writeBody'

## END CLASS DEFINITION

if not hasattr(ComputedVector, '_initCheetahAttributes'):
    templateAPIClass = getattr(ComputedVector,
                               '_CHEETAH_templateClass',
                               Template)
    templateAPIClass._addCheetahPlumbingCodeToClass(ComputedVector)


# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit https://cheetahtemplate.org/

##################################################
## if run from command line:
if __name__ == '__main__':
    from Cheetah.TemplateCmdLineIface import CmdLineIface
    CmdLineIface(templateObj=ComputedVector()).run()


