Exemplo n.º 1
0
/**
Overriden process groups.
*/
bool SaveNexus::processGroups() {
  this->exec();

  // We finished successfully.
  setExecuted(true);
  notificationCenter().postNotification(
      new FinishedNotification(this, isExecuted()));

  return true;
}
Exemplo n.º 2
0
        void TimerTask::execute()
        {
            if (isExecuted()) return;

            ExpiryTimerImpl::Id id { m_id };
            m_id = INVALID_ID;

            std::thread(std::move(m_callback), id).detach();

            m_callback = ExpiryTimerImpl::Callback{ };
        }
Exemplo n.º 3
0
/** Fits each spectrum in the workspace to f(x) = A * sin( w * x + p)
* @param ws :: [input] The workspace to fit
* @param freq :: [input] Hint for the frequency (w)
* @param groupName :: [input] The name of the output workspace group
* @param resTab :: [output] Table workspace storing the asymmetries and phases
* @param resGroup :: [output] Workspace group storing the fitting results
*/
void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws,
                                         double freq, std::string groupName,
                                         API::ITableWorkspace_sptr &resTab,
                                         API::WorkspaceGroup_sptr &resGroup) {

  int nhist = static_cast<int>(ws->getNumberHistograms());

  // Create the fitting function f(x) = A * sin ( w * x + p )
  // The same function and initial parameters are used for each fit
  std::string funcStr = createFittingFunction(freq, true);

  // Set up results table
  resTab->addColumn("int", "Spectrum number");
  resTab->addColumn("double", "Asymmetry");
  resTab->addColumn("double", "Phase");

  // Loop through fitting all spectra individually
  const static std::string success = "success";
  for (int wsIndex = 0; wsIndex < nhist; wsIndex++) {
    reportProgress(wsIndex, nhist);
    auto fit = createChildAlgorithm("Fit");
    fit->initialize();
    fit->setPropertyValue("Function", funcStr);
    fit->setProperty("InputWorkspace", ws);
    fit->setProperty("WorkspaceIndex", wsIndex);
    fit->setProperty("CreateOutput", true);
    fit->setPropertyValue("Output", groupName);
    fit->execute();

    std::string status = fit->getProperty("OutputStatus");
    if (!fit->isExecuted() || status != success) {
      std::ostringstream error;
      error << "Fit failed for spectrum at workspace index " << wsIndex;
      error << ": " << status;
      throw std::runtime_error(error.str());
    }

    API::MatrixWorkspace_sptr fitOut = fit->getProperty("OutputWorkspace");
    resGroup->addWorkspace(fitOut);
    API::ITableWorkspace_sptr tab = fit->getProperty("OutputParameters");
    // Now we have our fitting results stored in tab
    // but we need to extract the relevant information, i.e.
    // the detector phases (parameter 'p') and asymmetries ('A')
    const auto &spectrum = ws->getSpectrum(static_cast<size_t>(wsIndex));
    extractDetectorInfo(tab, resTab, spectrum.getSpectrumNo());
  }
}
Exemplo n.º 4
0
void DInst::doAtSimTime()
{
  I( resource );

  I(!isExecuted());

  I(resource->getCluster());

  if (!isStallOnLoad())
    resource->getCluster()->wakeUpDeps(this);

#ifdef SESC_BAAD
  setSchedTime();
#endif

  resource->simTime(this);
}
Exemplo n.º 5
0
CmdGenCompAttrInstAdd::~CmdGenCompAttrInstAdd() noexcept
{
    if (!isExecuted())
        delete mAttrInstance;
}
/** Fits each spectrum in the workspace to f(x) = A * sin( w * x + p)
 * @param ws :: [input] The workspace to fit
 * @param freq :: [input] Hint for the frequency (w)
 * @param groupName :: [input] The name of the output workspace group
 * @param resTab :: [output] Table workspace storing the asymmetries and phases
 * @param resGroup :: [output] Workspace group storing the fitting results
 */
void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws,
                                         double freq, std::string groupName,
                                         API::ITableWorkspace_sptr resTab,
                                         API::WorkspaceGroup_sptr &resGroup) {

  int nhist = static_cast<int>(ws->getNumberHistograms());

  // Create the fitting function f(x) = A * sin ( w * x + p )
  // The same function and initial parameters are used for each fit
  std::string funcStr = createFittingFunction(freq, true);

  // Set up results table
  resTab->addColumn("int", "Spectrum number");
  resTab->addColumn("double", "Asymmetry");
  resTab->addColumn("double", "Phase");

  const auto &indexInfo = ws->indexInfo();

  // Loop through fitting all spectra individually
  const static std::string success = "success";
  for (int wsIndex = 0; wsIndex < nhist; wsIndex++) {
    reportProgress(wsIndex, nhist);
    const auto &yValues = ws->y(wsIndex);
    auto emptySpectrum = std::all_of(yValues.begin(), yValues.end(),
                                     [](double value) { return value == 0.; });
    if (emptySpectrum) {
      g_log.warning("Spectrum " + std::to_string(wsIndex) + " is empty");
      TableWorkspace_sptr tab = boost::make_shared<TableWorkspace>();
      tab->addColumn("str", "Name");
      tab->addColumn("double", "Value");
      tab->addColumn("double", "Error");
      for (int j = 0; j < 4; j++) {
        API::TableRow row = tab->appendRow();
        if (j == PHASE_ROW) {
          row << "dummy" << 0.0 << 0.0;
        } else {
          row << "dummy" << ASYMM_ERROR << 0.0;
        }
      }

      extractDetectorInfo(*tab, *resTab, indexInfo.spectrumNumber(wsIndex));

    } else {
      auto fit = createChildAlgorithm("Fit");
      fit->initialize();
      fit->setPropertyValue("Function", funcStr);
      fit->setProperty("InputWorkspace", ws);
      fit->setProperty("WorkspaceIndex", wsIndex);
      fit->setProperty("CreateOutput", true);
      fit->setPropertyValue("Output", groupName);
      fit->execute();

      std::string status = fit->getProperty("OutputStatus");
      if (!fit->isExecuted()) {
        std::ostringstream error;
        error << "Fit failed for spectrum at workspace index " << wsIndex;
        error << ": " << status;
        throw std::runtime_error(error.str());
      } else if (status != success) {
        g_log.warning("Fit failed for spectrum at workspace index " +
                      std::to_string(wsIndex) + ": " + status);
      }

      API::MatrixWorkspace_sptr fitOut = fit->getProperty("OutputWorkspace");
      resGroup->addWorkspace(fitOut);
      API::ITableWorkspace_sptr tab = fit->getProperty("OutputParameters");
      // Now we have our fitting results stored in tab
      // but we need to extract the relevant information, i.e.
      // the detector phases (parameter 'p') and asymmetries ('A')
      extractDetectorInfo(*tab, *resTab, indexInfo.spectrumNumber(wsIndex));
    }
  }
}
CmdSchematicNetLineRemove::~CmdSchematicNetLineRemove() noexcept
{
    if (isExecuted())
        delete &mNetLine;
}
CmdSymbolInstanceRemove::~CmdSymbolInstanceRemove() noexcept
{
    if (isExecuted())
        delete &mSymbol;
}
Exemplo n.º 9
0
CmdNetSignalRemove::~CmdNetSignalRemove() noexcept
{
    if (isExecuted())
        delete &mNetSignal;
}
Exemplo n.º 10
0
CmdComponentInstanceAdd::~CmdComponentInstanceAdd() noexcept
{
    if (!isExecuted())
        delete mComponentInstance;
}
Exemplo n.º 11
0
CmdDeviceInstanceRemove::~CmdDeviceInstanceRemove() noexcept
{
    if (isExecuted())
        delete &mDevice;
}
Exemplo n.º 12
0
CmdSchematicNetPointAdd::~CmdSchematicNetPointAdd() noexcept
{
    if ((mNetPoint) && (!isExecuted()))
        delete mNetPoint;
}
Exemplo n.º 13
0
CmdComponentInstanceRemove::~CmdComponentInstanceRemove() noexcept
{
    if (isExecuted())
        delete &mComponentInstance;
}
Exemplo n.º 14
0
CmdNetClassRemove::~CmdNetClassRemove() noexcept
{
    if (isExecuted())
        delete &mNetClass;
}
Exemplo n.º 15
0
CmdNetSignalAdd::~CmdNetSignalAdd() noexcept
{
    if (!isExecuted())
        delete mNetSignal;
}
bool ReflectometryReductionOneAuto::processGroups() {
  // isPolarizationCorrectionOn is used to decide whether
  // we should process our Transmission WorkspaceGroup members
  // as individuals (not multiperiod) when PolarizationCorrection is off,
  // or sum over all of the workspaces in the group
  // and used that sum as our TransmissionWorkspace when PolarizationCorrection
  // is on.
  const bool isPolarizationCorrectionOn =
      this->getPropertyValue("PolarizationAnalysis") !=
      noPolarizationCorrectionMode();
  // Get our input workspace group
  auto group = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
      getPropertyValue("InputWorkspace"));
  // Get name of IvsQ workspace
  const std::string outputIvsQ = this->getPropertyValue("OutputWorkspace");
  // Get name of IvsLam workspace
  const std::string outputIvsLam =
      this->getPropertyValue("OutputWorkspaceWavelength");

  // Create a copy of ourselves
  Algorithm_sptr alg = this->createChildAlgorithm(
      this->name(), -1, -1, this->isLogging(), this->version());
  alg->setChild(false);
  alg->setRethrows(true);

  // Copy all the non-workspace properties over
  std::vector<Property *> props = this->getProperties();
  for (auto &prop : props) {
    if (prop) {
      IWorkspaceProperty *wsProp = dynamic_cast<IWorkspaceProperty *>(prop);
      if (!wsProp)
        alg->setPropertyValue(prop->name(), prop->value());
    }
  }

  // Check if the transmission runs are groups or not
  const std::string firstTrans = this->getPropertyValue("FirstTransmissionRun");
  WorkspaceGroup_sptr firstTransG;
  if (!firstTrans.empty()) {
    auto firstTransWS =
        AnalysisDataService::Instance().retrieveWS<Workspace>(firstTrans);
    firstTransG = boost::dynamic_pointer_cast<WorkspaceGroup>(firstTransWS);

    if (!firstTransG) {
      // we only have one transmission workspace, so we use it as it is.
      alg->setProperty("FirstTransmissionRun", firstTrans);
    } else if (group->size() != firstTransG->size() &&
               !isPolarizationCorrectionOn) {
      // if they are not the same size then we cannot associate a transmission
      // group workspace member with every input group workpspace member.
      throw std::runtime_error("FirstTransmissionRun WorkspaceGroup must be "
                               "the same size as the InputWorkspace "
                               "WorkspaceGroup");
    }
  }

  const std::string secondTrans =
      this->getPropertyValue("SecondTransmissionRun");
  WorkspaceGroup_sptr secondTransG;
  if (!secondTrans.empty()) {
    auto secondTransWS =
        AnalysisDataService::Instance().retrieveWS<Workspace>(secondTrans);
    secondTransG = boost::dynamic_pointer_cast<WorkspaceGroup>(secondTransWS);

    if (!secondTransG)
      // we only have one transmission workspace, so we use it as it is.
      alg->setProperty("SecondTransmissionRun", secondTrans);

    else if (group->size() != secondTransG->size() &&
             !isPolarizationCorrectionOn) {
      // if they are not the same size then we cannot associate a transmission
      // group workspace member with every input group workpspace member.
      throw std::runtime_error("SecondTransmissionRun WorkspaceGroup must be "
                               "the same size as the InputWorkspace "
                               "WorkspaceGroup");
    }
  }
  std::vector<std::string> IvsQGroup, IvsLamGroup;

  // Execute algorithm over each group member (or period, if this is
  // multiperiod)
  size_t numMembers = group->size();
  for (size_t i = 0; i < numMembers; ++i) {
    const std::string IvsQName =
        outputIvsQ + "_" + boost::lexical_cast<std::string>(i + 1);
    const std::string IvsLamName =
        outputIvsLam + "_" + boost::lexical_cast<std::string>(i + 1);

    // If our transmission run is a group and PolarizationCorrection is on
    // then we sum our transmission group members.
    //
    // This is done inside of the for loop to avoid the wrong workspace being
    // used when these arguments are passed through to the exec() method.
    // If this is not set in the loop, exec() will fetch the first workspace
    // from the specified Transmission Group workspace that the user entered.
    if (firstTransG && isPolarizationCorrectionOn) {
      auto firstTransmissionSum = sumOverTransmissionGroup(firstTransG);
      alg->setProperty("FirstTransmissionRun", firstTransmissionSum);
    }
    if (secondTransG && isPolarizationCorrectionOn) {
      auto secondTransmissionSum = sumOverTransmissionGroup(secondTransG);
      alg->setProperty("SecondTransmissionRun", secondTransmissionSum);
    }

    // Otherwise, if polarization correction is off, we process them
    // using one transmission group member at a time.
    if (firstTransG && !isPolarizationCorrectionOn) // polarization off
      alg->setProperty("FirstTransmissionRun", firstTransG->getItem(i)->name());
    if (secondTransG && !isPolarizationCorrectionOn) // polarization off
      alg->setProperty("SecondTransmissionRun",
                       secondTransG->getItem(i)->name());

    alg->setProperty("InputWorkspace", group->getItem(i)->name());
    alg->setProperty("OutputWorkspace", IvsQName);
    alg->setProperty("OutputWorkspaceWavelength", IvsLamName);
    alg->execute();

    MatrixWorkspace_sptr tempFirstTransWS =
        alg->getProperty("FirstTransmissionRun");

    IvsQGroup.push_back(IvsQName);
    IvsLamGroup.push_back(IvsLamName);

    // We use the first group member for our thetaout value
    if (i == 0)
      this->setPropertyValue("ThetaOut", alg->getPropertyValue("ThetaOut"));
  }

  // Group the IvsQ and IvsLam workspaces
  Algorithm_sptr groupAlg = this->createChildAlgorithm("GroupWorkspaces");
  groupAlg->setChild(false);
  groupAlg->setRethrows(true);

  groupAlg->setProperty("InputWorkspaces", IvsLamGroup);
  groupAlg->setProperty("OutputWorkspace", outputIvsLam);
  groupAlg->execute();

  groupAlg->setProperty("InputWorkspaces", IvsQGroup);
  groupAlg->setProperty("OutputWorkspace", outputIvsQ);
  groupAlg->execute();

  // If this is a multiperiod workspace and we have polarization corrections
  // enabled
  if (isPolarizationCorrectionOn) {
    if (group->isMultiperiod()) {
      // Perform polarization correction over the IvsLam group
      Algorithm_sptr polAlg =
          this->createChildAlgorithm("PolarizationCorrection");
      polAlg->setChild(false);
      polAlg->setRethrows(true);

      polAlg->setProperty("InputWorkspace", outputIvsLam);
      polAlg->setProperty("OutputWorkspace", outputIvsLam);
      polAlg->setProperty("PolarizationAnalysis",
                          this->getPropertyValue("PolarizationAnalysis"));
      polAlg->setProperty("CPp", this->getPropertyValue(cppLabel()));
      polAlg->setProperty("CRho", this->getPropertyValue(crhoLabel()));
      polAlg->setProperty("CAp", this->getPropertyValue(cApLabel()));
      polAlg->setProperty("CAlpha", this->getPropertyValue(cAlphaLabel()));
      polAlg->execute();

      // Now we've overwritten the IvsLam workspaces, we'll need to recalculate
      // the IvsQ ones
      alg->setProperty("FirstTransmissionRun", "");
      alg->setProperty("SecondTransmissionRun", "");
      for (size_t i = 0; i < numMembers; ++i) {
        const std::string IvsQName =
            outputIvsQ + "_" + boost::lexical_cast<std::string>(i + 1);
        const std::string IvsLamName =
            outputIvsLam + "_" + boost::lexical_cast<std::string>(i + 1);
        alg->setProperty("InputWorkspace", IvsLamName);
        alg->setProperty("OutputWorkspace", IvsQName);
        alg->setProperty("CorrectionAlgorithm", "None");
        alg->setProperty("OutputWorkspaceWavelength", IvsLamName);
        alg->execute();
      }
    } else {
      g_log.warning("Polarization corrections can only be performed on "
                    "multiperiod workspaces.");
    }
  }

  // We finished successfully
  this->setPropertyValue("OutputWorkspace", outputIvsQ);
  this->setPropertyValue("OutputWorkspaceWavelength", outputIvsLam);
  setExecuted(true);
  notificationCenter().postNotification(
      new FinishedNotification(this, isExecuted()));
  return true;
}
Exemplo n.º 17
0
CmdSymbolInstanceAdd::~CmdSymbolInstanceAdd() noexcept
{
    if (!isExecuted())
        delete mSymbol;
}
CmdSchematicNetPointRemove::~CmdSchematicNetPointRemove() noexcept
{
    if (isExecuted())
        delete &mNetPoint;
}
bool ReflectometryReductionOneAuto::processGroups() {
    auto group = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
                     getPropertyValue("InputWorkspace"));
    const std::string outputIvsQ = this->getPropertyValue("OutputWorkspace");
    const std::string outputIvsLam =
        this->getPropertyValue("OutputWorkspaceWavelength");

    // Create a copy of ourselves
    Algorithm_sptr alg = this->createChildAlgorithm(
                             this->name(), -1, -1, this->isLogging(), this->version());
    alg->setChild(false);
    alg->setRethrows(true);

    // Copy all the non-workspace properties over
    std::vector<Property *> props = this->getProperties();
    for (auto prop = props.begin(); prop != props.end(); ++prop) {
        if (*prop) {
            IWorkspaceProperty *wsProp = dynamic_cast<IWorkspaceProperty *>(*prop);
            if (!wsProp)
                alg->setPropertyValue((*prop)->name(), (*prop)->value());
        }
    }

    // Check if the transmission runs are groups or not
    const std::string firstTrans = this->getPropertyValue("FirstTransmissionRun");
    WorkspaceGroup_sptr firstTransG;
    if (!firstTrans.empty()) {
        auto firstTransWS =
            AnalysisDataService::Instance().retrieveWS<Workspace>(firstTrans);
        firstTransG = boost::dynamic_pointer_cast<WorkspaceGroup>(firstTransWS);

        if (!firstTransG)
            alg->setProperty("FirstTransmissionRun", firstTrans);
        else if (group->size() != firstTransG->size())
            throw std::runtime_error("FirstTransmissionRun WorkspaceGroup must be "
                                     "the same size as the InputWorkspace "
                                     "WorkspaceGroup");
    }

    const std::string secondTrans =
        this->getPropertyValue("SecondTransmissionRun");
    WorkspaceGroup_sptr secondTransG;
    if (!secondTrans.empty()) {
        auto secondTransWS =
            AnalysisDataService::Instance().retrieveWS<Workspace>(secondTrans);
        secondTransG = boost::dynamic_pointer_cast<WorkspaceGroup>(secondTransWS);

        if (!secondTransG)
            alg->setProperty("SecondTransmissionRun", secondTrans);
        else if (group->size() != secondTransG->size())
            throw std::runtime_error("SecondTransmissionRun WorkspaceGroup must be "
                                     "the same size as the InputWorkspace "
                                     "WorkspaceGroup");
    }

    std::vector<std::string> IvsQGroup, IvsLamGroup;

    // Execute algorithm over each group member (or period, if this is
    // multiperiod)
    size_t numMembers = group->size();
    for (size_t i = 0; i < numMembers; ++i) {
        const std::string IvsQName =
            outputIvsQ + "_" + boost::lexical_cast<std::string>(i + 1);
        const std::string IvsLamName =
            outputIvsLam + "_" + boost::lexical_cast<std::string>(i + 1);

        alg->setProperty("InputWorkspace", group->getItem(i)->name());
        alg->setProperty("OutputWorkspace", IvsQName);
        alg->setProperty("OutputWorkspaceWavelength", IvsLamName);

        // Handle transmission runs
        if (firstTransG)
            alg->setProperty("FirstTransmissionRun", firstTransG->getItem(i)->name());
        if (secondTransG)
            alg->setProperty("SecondTransmissionRun",
                             secondTransG->getItem(i)->name());

        alg->execute();

        IvsQGroup.push_back(IvsQName);
        IvsLamGroup.push_back(IvsLamName);

        // We use the first group member for our thetaout value
        if (i == 0)
            this->setPropertyValue("ThetaOut", alg->getPropertyValue("ThetaOut"));
    }

    // Group the IvsQ and IvsLam workspaces
    Algorithm_sptr groupAlg = this->createChildAlgorithm("GroupWorkspaces");
    groupAlg->setChild(false);
    groupAlg->setRethrows(true);

    groupAlg->setProperty("InputWorkspaces", IvsLamGroup);
    groupAlg->setProperty("OutputWorkspace", outputIvsLam);
    groupAlg->execute();

    groupAlg->setProperty("InputWorkspaces", IvsQGroup);
    groupAlg->setProperty("OutputWorkspace", outputIvsQ);
    groupAlg->execute();

    // If this is a multiperiod workspace and we have polarization corrections
    // enabled
    if (this->getPropertyValue("PolarizationAnalysis") !=
            noPolarizationCorrectionMode()) {
        if (group->isMultiperiod()) {
            // Perform polarization correction over the IvsLam group
            Algorithm_sptr polAlg =
                this->createChildAlgorithm("PolarizationCorrection");
            polAlg->setChild(false);
            polAlg->setRethrows(true);

            polAlg->setProperty("InputWorkspace", outputIvsLam);
            polAlg->setProperty("OutputWorkspace", outputIvsLam);
            polAlg->setProperty("PolarizationAnalysis",
                                this->getPropertyValue("PolarizationAnalysis"));
            polAlg->setProperty("CPp", this->getPropertyValue(cppLabel()));
            polAlg->setProperty("CRho", this->getPropertyValue(crhoLabel()));
            polAlg->setProperty("CAp", this->getPropertyValue(cApLabel()));
            polAlg->setProperty("CAlpha", this->getPropertyValue(cAlphaLabel()));
            polAlg->execute();

            // Now we've overwritten the IvsLam workspaces, we'll need to recalculate
            // the IvsQ ones
            alg->setProperty("FirstTransmissionRun", "");
            alg->setProperty("SecondTransmissionRun", "");
            for (size_t i = 0; i < numMembers; ++i) {
                const std::string IvsQName =
                    outputIvsQ + "_" + boost::lexical_cast<std::string>(i + 1);
                const std::string IvsLamName =
                    outputIvsLam + "_" + boost::lexical_cast<std::string>(i + 1);
                alg->setProperty("InputWorkspace", IvsLamName);
                alg->setProperty("OutputWorkspace", IvsQName);
                alg->setProperty("OutputWorkspaceWavelength", IvsLamName);
                alg->execute();
            }
        } else {
            g_log.warning("Polarization corrections can only be performed on "
                          "multiperiod workspaces.");
        }
    }

    // We finished successfully
    this->setPropertyValue("OutputWorkspace", outputIvsQ);
    this->setPropertyValue("OutputWorkspaceWavelength", outputIvsLam);
    setExecuted(true);
    notificationCenter().postNotification(
        new FinishedNotification(this, isExecuted()));
    return true;
}
Exemplo n.º 20
0
void RequestParseTask::operator()() {
  assert((_responseTask != nullptr) && "Response needs to be set");
  const auto& scheduler = SharedScheduler::getInstance().getScheduler();

  performance_vector_t& performance_data = _responseTask->getPerformanceData();

  bool recordPerformance = false;
  std::vector<std::shared_ptr<Task> > tasks;

  int priority = Task::DEFAULT_PRIORITY;
  int sessionId = 0;

  if (_connection->hasBody()) {
    // The body is a wellformed HTTP Post body, with key value pairs
    std::string body(_connection->getBody());
    std::map<std::string, std::string> body_data = parseHTTPFormData(body);

    boost::optional<tx::TXContext> ctx;
    auto ctx_it = body_data.find("session_context");
    if (ctx_it != body_data.end()) {
      boost::optional<tx::transaction_id_t> tid;
      if ((tid = parseNumeric<tx::transaction_id_t>(ctx_it->second)) &&
          (tx::TransactionManager::isRunningTransaction(*tid))) {
        LOG4CXX_DEBUG(_logger, "Picking up transaction id " << *tid);
        ctx = tx::TransactionManager::getContext(*tid);
      } else {
        LOG4CXX_ERROR(_logger, "Invalid transaction id " << *tid);
        _responseTask->addErrorMessage("Invalid transaction id set, aborting execution.");
      }
    } else {
      ctx = tx::TransactionManager::beginTransaction();
      LOG4CXX_DEBUG(_logger, "Creating new transaction context " << (*ctx).tid);
    }

    Json::Value request_data;
    Json::Reader reader;

    const std::string& query_string = urldecode(body_data["query"]);

    if (ctx && reader.parse(query_string, request_data)) {
      _responseTask->setTxContext(*ctx);
      recordPerformance = getOrDefault(body_data, "performance", "false") == "true";

      // the performance attribute for this operation (at [0])
      if (recordPerformance) {
        performance_data.push_back(std::unique_ptr<performance_attributes_t>(new performance_attributes_t));
      }

      LOG4CXX_DEBUG(_query_logger, request_data);

      const std::string& final_hash = hash(query_string);
      std::shared_ptr<Task> result = nullptr;

      if(request_data.isMember("priority"))
        priority = request_data["priority"].asInt();
      if(request_data.isMember("sessionId"))
        sessionId = request_data["sessionId"].asInt();
      _responseTask->setPriority(priority);
      _responseTask->setSessionId(sessionId);
      _responseTask->setRecordPerformanceData(recordPerformance);
      try {
        tasks = QueryParser::instance().deserialize(
                  QueryTransformationEngine::getInstance()->transform(request_data),
                  &result);

      } catch (const std::exception &ex) {
        // clean up, so we don't end up with a whole mess due to thrown exceptions
        LOG4CXX_ERROR(_logger, "Received\n:" << request_data);
        LOG4CXX_ERROR(_logger, "Exception thrown during query deserialization:\n" << ex.what());
        _responseTask->addErrorMessage(std::string("RequestParseTask: ") + ex.what());
        tasks.clear();
        result = nullptr;
      }

      auto autocommit_it = body_data.find("autocommit");
      if (autocommit_it != body_data.end() && (autocommit_it->second == "true")) {
        auto commit = std::make_shared<Commit>();
        commit->setOperatorId("__autocommit");
        commit->setPlanOperationName("Commit");
        commit->addDependency(result);
        result = commit;
        tasks.push_back(commit);
      }


      if (result != nullptr) {
        _responseTask->addDependency(result);
      } else {
        LOG4CXX_ERROR(_logger, "Json did not yield tasks");
      }

      for (const auto & func: tasks) {
        if (auto task = std::dynamic_pointer_cast<PlanOperation>(func)) {
          task->setPriority(priority);
          task->setSessionId(sessionId);
          task->setPlanId(final_hash);
          task->setTXContext(*ctx);
	  task->setId((*ctx).tid);
	  _responseTask->registerPlanOperation(task);
          if (!task->hasSuccessors()) {
            // The response has to depend on all tasks, ie. we don't
            // want to respond before all tasks finished running, even
            // if they don't contribute to the result. This prevents
            // dangling tasks
            _responseTask->addDependency(task);
          }
        }
      }
    } else {
      LOG4CXX_ERROR(_logger, "Failed to parse: "
                    << urldecode(body_data["query"]) << "\n"
                    << body_data["query"] << "\n"
                    << reader.getFormatedErrorMessages());
    }
    // Update the transmission limit for the response task
    if (atoi(body_data["limit"].c_str()) > 0)
      _responseTask->setTransmitLimit(atol(body_data["limit"].c_str()));

    if (atoi(body_data["offset"].c_str()) > 0)
      _responseTask->setTransmitOffset(atol(body_data["offset"].c_str()));

  } else {
    LOG4CXX_WARN(_logger, "no body received!");
  }




  // high priority tasks are expected to be scheduled sequentially
  if(priority == Task::HIGH_PRIORITY){
    if (recordPerformance) {
      *(performance_data.at(0)) = { 0, 0, "NO_PAPI", "RequestParseTask", 
                                    "requestParse", _queryStart, get_epoch_nanoseconds(), 
                                    boost::lexical_cast<std::string>(std::this_thread::get_id()) };
    }

    int number_of_tasks = tasks.size();
    std::vector<bool> isExecuted(number_of_tasks, false);
    int executedTasks = 0;
    while(executedTasks < number_of_tasks){
      for(int i = 0; i < number_of_tasks; i++){
        if(!isExecuted[i] && tasks[i]->isReady()){
          (*tasks[i])();
          tasks[i]->notifyDoneObservers();
          executedTasks++;
          isExecuted[i] = true;
        }
      }
    }
    _responseTask->setQueryStart(_queryStart);
    (*_responseTask)();
    _responseTask.reset();  // yield responsibility

  } else {
    scheduler->schedule(_responseTask);
    scheduler->scheduleQuery(tasks);

    if (recordPerformance) {
      *(performance_data.at(0)) = { 0, 0, "NO_PAPI", "RequestParseTask", "requestParse", 
                                    _queryStart, get_epoch_nanoseconds(), 
                                    boost::lexical_cast<std::string>(std::this_thread::get_id()) };
    }
    _responseTask->setQueryStart(_queryStart);
    _responseTask.reset();  // yield responsibility
  }
}