Package com.opengamma.engine.view.impl

Examples of com.opengamma.engine.view.impl.InMemoryViewComputationResultModel


      s_logger.info("Execution of {} complete", _calculationConfiguration);
      final ExecutingCalculationConfiguration calcConfig = executor._executing.remove(_calculationConfiguration);

      if (calcConfig != null) {
        SingleComputationCycle cycle = executor.getCycle();
        final InMemoryViewComputationResultModel fragmentResultModel = cycle.constructTemplateResultModel();
        calcConfig.buildResults(fragmentResultModel, cycle.getResultModel());
        cycle.notifyFragmentCompleted(fragmentResultModel);
      }
    }
View Full Code Here


    return message;
  }

  @Override
  public ViewComputationResultModel buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
    final InMemoryViewComputationResultModel resultModel = (InMemoryViewComputationResultModel) bootstrapCommonDataFromMessage(deserializer, message);
    for (final FudgeField field : message.getFieldValue(FudgeMsg.class, message.getByName(FIELD_LIVEDATA))) {
      final ComputedValue liveData = deserializer.fieldValueToObject(ComputedValue.class, field);
      resultModel.addMarketData(liveData);
    }
    return resultModel;
  }
View Full Code Here

    return resultModel;
  }

  @Override
  protected InMemoryViewResultModel constructImpl() {
    return new InMemoryViewComputationResultModel();
  }
View Full Code Here

    _versionCorrection = versionCorrection;
    _resultModel = constructTemplateResultModel();
  }

  protected InMemoryViewComputationResultModel constructTemplateResultModel() {
    final InMemoryViewComputationResultModel result = new InMemoryViewComputationResultModel();
    result.setViewCycleId(getCycleId());
    result.setViewProcessId(getViewProcessId());
    result.setViewCycleExecutionOptions(getExecutionOptions());
    result.setVersionCorrection(getVersionCorrection());
    return result;
  }
View Full Code Here

  /**
   * Adds suppressed output markers to the result model for all terminal outputs.
   */
  private void generateSuppressedOutputs() {
    final InMemoryViewComputationResultModel fullResultModel = getResultModel();
    final InMemoryViewComputationResultModel fragmentResultModel = constructTemplateResultModel();
    for (CompiledViewCalculationConfiguration compiledCalcConfig : getCompiledViewDefinition().getCompiledCalculationConfigurations()) {
      String calcConfigName = compiledCalcConfig.getName();
      for (ValueSpecification valueSpec : compiledCalcConfig.getTerminalOutputSpecifications().keySet()) {
        ComputedValue value = new ComputedValue(valueSpec, MissingOutput.SUPPRESSED);
        ComputedValueResult valueResult = new ComputedValueResult(value, AggregatedExecutionLog.EMPTY);
        fragmentResultModel.addValue(calcConfigName, valueResult);
        fullResultModel.addValue(calcConfigName, valueResult);
      }
    }
    notifyFragmentCompleted(fragmentResultModel);
  }
View Full Code Here

   */
  private boolean prepareInputs(final MarketDataSnapshot snapshot, boolean suppressExecutionOnNoMarketData) {
    int missingMarketData = 0;
    final Set<ValueSpecification> allRequiredMarketData = getCompiledViewDefinition().getMarketDataRequirements();
    s_logger.debug("Populating {} market data items using snapshot {}", allRequiredMarketData.size(), snapshot);
    final InMemoryViewComputationResultModel fragmentResultModel = constructTemplateResultModel();
    final InMemoryViewComputationResultModel fullResultModel = getResultModel();
    final Map<ValueSpecification, Object> marketDataValues = snapshot.query(allRequiredMarketData);
    if (suppressExecutionOnNoMarketData && allRequiredMarketData.size() > 0 && marketDataValues.size() == 0) {
      // Market data was expected but the snapshot was empty. Don't bother doing anything else, and indicate that
      // execution should not continue.
      return false;
    }
    final ResultModelDefinition resultModel = getViewDefinition().getResultModelDefinition();
    for (CompiledViewCalculationConfiguration calcConfig : getCompiledViewDefinition().getCompiledCalculationConfigurations()) {
      final OverrideOperation operation = getCacheMarketDataOperation(getViewDefinition().getCalculationConfiguration(calcConfig.getName()));
      final ViewComputationCache cache = getComputationCache(calcConfig.getName());
      final Collection<ValueSpecification> marketDataRequirements = calcConfig.getMarketDataRequirements();
      final Set<ValueSpecification> terminalOutputs = calcConfig.getTerminalOutputSpecifications().keySet();
      final Collection<ComputedValueResult> valuesToLoad = new ArrayList<>(marketDataRequirements.size());
      for (ValueSpecification marketDataSpec : marketDataRequirements) {
        Object marketDataValue = marketDataValues.get(marketDataSpec);
        ComputedValueResult computedValueResult;
        if (operation != null) {
          if (marketDataValue != null) {
            marketDataValue = operation.apply(marketDataSpec.toRequirementSpecification(), marketDataValue);
            if (marketDataValue == null) {
              s_logger.debug("Market data {} discarded by override operation", marketDataSpec);
            }
          }
        }
        if (marketDataValue == null) {
          s_logger.debug("Unable to load market data value for {} from snapshot {}", marketDataSpec, getValuationTime());
          missingMarketData++;
          // TODO provide elevated logs if requested from market data providers
          computedValueResult = new ComputedValueResult(marketDataSpec, MissingInput.MISSING_MARKET_DATA, MARKET_DATA_LOG);
        } else {
          computedValueResult = new ComputedValueResult(marketDataSpec, marketDataValue, AggregatedExecutionLog.EMPTY);
          fragmentResultModel.addMarketData(computedValueResult);
          fullResultModel.addMarketData(computedValueResult);
        }
        if (terminalOutputs.contains(marketDataSpec) && (resultModel.getOutputMode(marketDataSpec.getTargetSpecification().getType()) != ResultOutputMode.NONE)) {
          fragmentResultModel.addValue(calcConfig.getName(), computedValueResult);
          fullResultModel.addValue(calcConfig.getName(), computedValueResult);
        }
        valuesToLoad.add(computedValueResult);
      }
      if (!valuesToLoad.isEmpty()) {
        cache.putSharedValues(valuesToLoad);
View Full Code Here

   */
  private void computeDelta(final SingleComputationCycle previousCycle) {
    if (previousCycle.getState() != ViewCycleState.EXECUTED) {
      throw new IllegalArgumentException("State of previous cycle must be " + ViewCycleState.EXECUTED);
    }
    final InMemoryViewComputationResultModel fragmentResultModel = constructTemplateResultModel();
    final InMemoryViewComputationResultModel fullResultModel = getResultModel();
    for (final DependencyGraphExplorer depGraphExplorer : getCompiledViewDefinition().getDependencyGraphExplorers()) {
      final DependencyGraph depGraph = depGraphExplorer.getWholeGraph();
      final ViewComputationCache cache = getComputationCache(depGraph.getCalculationConfigurationName());
      final ViewComputationCache previousCache = previousCycle.getComputationCache(depGraph.getCalculationConfigurationName());
      final DependencyNodeJobExecutionResultCache jobExecutionResultCache = getJobExecutionResultCache(depGraph.getCalculationConfigurationName());
      final DependencyNodeJobExecutionResultCache previousJobExecutionResultCache = previousCycle.getJobExecutionResultCache(depGraph.getCalculationConfigurationName());
      final LiveDataDeltaCalculator deltaCalculator = new LiveDataDeltaCalculator(depGraph, cache, previousCache);
      deltaCalculator.computeDelta();
      s_logger.info("Computed delta for calculation configuration '{}'. {} nodes out of {} require recomputation.",
          depGraph.getCalculationConfigurationName(),
          deltaCalculator.getChangedNodes().size(),
          depGraph.getSize());
      final Collection<ValueSpecification> specsToCopy = new LinkedList<>();
      final Collection<ComputedValue> errors = new LinkedList<>();
      for (final DependencyNode unchangedNode : deltaCalculator.getUnchangedNodes()) {
        if (unchangedNode.isMarketDataSourcingFunction()) {
          // Market data is already in the cache, so don't need to copy it across again
          continue;
        }
        final DependencyNodeJobExecutionResult previousExecutionResult = previousJobExecutionResultCache.find(unchangedNode.getOutputValues());
        if (getLogModeSource().getLogMode(unchangedNode) == ExecutionLogMode.FULL
            && (previousExecutionResult == null || previousExecutionResult.getJobResultItem().getExecutionLog().getEvents() == null)) {
          // Need to rerun calculation to collect logs, so cannot reuse
          continue;
        }
        final NodeStateFlag nodeState = previousCycle.getNodeState(unchangedNode);
        if (nodeState != null) {
          setNodeState(unchangedNode, nodeState);
          if (nodeState == NodeStateFlag.EXECUTED) {
            specsToCopy.addAll(unchangedNode.getOutputValues());
          } else {
            for (final ValueSpecification outputValue : unchangedNode.getOutputValues()) {
              errors.add(new ComputedValue(outputValue, MissingOutput.SUPPRESSED));
            }
          }
        }
      }
      if (!specsToCopy.isEmpty()) {
        final ComputationCycleQuery reusableResultsQuery = new ComputationCycleQuery();
        reusableResultsQuery.setCalculationConfigurationName(depGraph.getCalculationConfigurationName());
        reusableResultsQuery.setValueSpecifications(specsToCopy);
        final ComputationResultsResponse reusableResultsQueryResponse = previousCycle.queryResults(reusableResultsQuery);
        final Map<ValueSpecification, ComputedValueResult> resultsToReuse = reusableResultsQueryResponse.getResults();
        final Collection<ComputedValue> newValues = new ArrayList<>(resultsToReuse.size());
        for (final ComputedValueResult computedValueResult : resultsToReuse.values()) {
          final ValueSpecification valueSpec = computedValueResult.getSpecification();
          if (depGraph.getTerminalOutputSpecifications().contains(valueSpec)
              && getViewDefinition().getResultModelDefinition().shouldOutputResult(valueSpec, depGraph)) {
            fragmentResultModel.addValue(depGraph.getCalculationConfigurationName(), computedValueResult);
            fullResultModel.addValue(depGraph.getCalculationConfigurationName(), computedValueResult);
          }
          final Object previousValue = computedValueResult.getValue() != null ? computedValueResult.getValue() : MissingOutput.EVALUATION_ERROR;
          newValues.add(new ComputedValue(valueSpec, previousValue));
          final DependencyNodeJobExecutionResult previousDependencyNodeJobExecutionResult = previousJobExecutionResultCache.get(valueSpec);
          if (previousDependencyNodeJobExecutionResult != null) {
View Full Code Here

  //-------------------------------------------------------------------------
  public void testFullMerger() {
    final ViewComputationResultModelMerger merger = new ViewComputationResultModelMerger();
    assertNull(merger.getLatestResult());

    final InMemoryViewComputationResultModel result1 = new InMemoryViewComputationResultModel();
    result1.addValue(CONFIG_1, getComputedValueResult("value1", 1));
    result1.addValue(CONFIG_1, getComputedValueResult("value2", 2));
    result1.addMarketData(getComputedValueResult("vod", 250));
    merger.merge(result1);
    assertResultsEqual(result1, merger.getLatestResult());

    final InMemoryViewComputationResultModel result2 = new InMemoryViewComputationResultModel();
    result2.addValue(CONFIG_1, getComputedValueResult("value1", 3));
    result2.addMarketData(getComputedValueResult("aapl", 400));
    merger.merge(result2);

    InMemoryViewComputationResultModel expectedMergedResult = new InMemoryViewComputationResultModel();
    expectedMergedResult.addValue(CONFIG_1, getComputedValueResult("value1", 3));
    expectedMergedResult.addValue(CONFIG_1, getComputedValueResult("value2", 2));
    expectedMergedResult.addMarketData(getComputedValueResult("vod", 250));
    expectedMergedResult.addMarketData(getComputedValueResult("aapl", 400));

    assertResultsEqual(expectedMergedResult, merger.getLatestResult());

    final InMemoryViewComputationResultModel result3 = new InMemoryViewComputationResultModel();
    result3.addValue(CONFIG_2, getComputedValueResult("value3", 4));
    result3.addMarketData(getComputedValueResult("vod", 300));

    merger.merge(result1);
    merger.merge(result3);

    expectedMergedResult = new InMemoryViewComputationResultModel();
    expectedMergedResult.addValue(CONFIG_1, getComputedValueResult("value1", 1));
    expectedMergedResult.addValue(CONFIG_1, getComputedValueResult("value2", 2));
    expectedMergedResult.addValue(CONFIG_2, getComputedValueResult("value3", 4));
    result3.addMarketData(getComputedValueResult("vod", 300));

    assertResultsEqual(expectedMergedResult, merger.getLatestResult());
  }
View Full Code Here

TOP

Related Classes of com.opengamma.engine.view.impl.InMemoryViewComputationResultModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.