<commit_before>// EnrichmentFacility.cpp
// Implements the EnrichmentFacility class
#include "EnrichmentFacility.h"

#include "MarketModel.h"
#include "QueryEngine.h"
#include "Logger.h"
#include "CycException.h"
#include "CycLimits.h"
#include "GenericResource.h"
#include "Material.h"
#include "Timer.h"
#include "EventManager.h"

#include <sstream>
#include <limits>
#include <cmath>

#include <boost/lexical_cast.hpp>

using namespace std;
using namespace boost;
using boost::lexical_cast;
using namespace enrichment;

int EnrichmentFacility::entry_ = 0;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EnrichmentFacility::EnrichmentFacility() :
  commodity_price_(0),
  tails_assay_(0),
  feed_assay_(0),
  in_commodity_(""),
  in_recipe_(""),
  out_commodity_("")
{}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EnrichmentFacility::~EnrichmentFacility()
{}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::initModuleMembers(QueryEngine* qe)
{
  string data;

  QueryEngine* input = qe->queryElement("input");
  set_in_commodity(input->getElementContent("incommodity"));
  set_in_recipe(input->getElementContent("inrecipe"));

  try
    {
      data = input->getElementContent("inventorysize");
      setMaxInventorySize(lexical_cast<double>(data));
    }
  catch (CycNullQueryException e)
    {
      setMaxInventorySize(numeric_limits<double>::max());
    }

  QueryEngine* output = qe->queryElement("output");
  set_out_commodity(output->getElementContent("outcommodity"));

  data = output->getElementContent("tails_assay");
  set_tails_assay(lexical_cast<double>(data));

  mat_rsrc_ptr feed = mat_rsrc_ptr(new Material(RecipeLibrary::Recipe(in_recipe())));
  set_feed_assay(uranium_assay(feed));
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::string EnrichmentFacility::str()
{
  std::stringstream ss;
  ss << FacilityModel::str()
     << " with enrichment facility parameters:"
     << " * Tails assay: " << tails_assay()
     << " * Feed assay: " << feed_assay()
     << " * Input Commodity: " << in_commodity()
     << " * Output Commodity: " << out_commodity();
  return ss.str();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::cloneModuleMembersFrom(FacilityModel* sourceModel)
{
  EnrichmentFacility* source = dynamic_cast<EnrichmentFacility*>(sourceModel);
  set_tails_assay(source->tails_assay());
  set_feed_assay(source->feed_assay());
  set_in_commodity(source->in_commodity());
  set_in_recipe(source->in_recipe());
  set_out_commodity(source->out_commodity());
  setMaxInventorySize(source->maxInventorySize());
  set_commodity_price(source->commodity_price());

  LOG(LEV_DEBUG1, "EnrFac") << "Cloned - " << str();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::addResource(Transaction trans, std::vector<rsrc_ptr> manifest)
{
  LOG(LEV_INFO5, "EnrFac") << name() << " adding material qty: " << manifest.at(0)->quantity();
  inventory_.pushAll(MatBuff::toMat(manifest));
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::vector<rsrc_ptr> EnrichmentFacility::removeResource(Transaction order)
{
  rsrc_ptr prsrc = order.resource();
  if (!Material::isMaterial(prsrc))
    throw CycOverrideException("Can't remove a resource as a non-material");

  mat_rsrc_ptr rsrc = dynamic_pointer_cast<Material>(prsrc);

  Assays assays = getAssays(rsrc);
  double product_qty = uranium_qty(rsrc);
  double swu = swu_required(product_qty,assays);
  double natural_u = feed_qty(product_qty,assays);
  inventory_.popQty(natural_u);

  LOG(LEV_INFO5, "EnrFac") << name() << " has performed an enrichment: ";
  LOG(LEV_INFO5, "EnrFac") << "   * Feed Qty: " << feed_qty(product_qty,assays);
  LOG(LEV_INFO5, "EnrFac") << "   * Feed Assay: " << assays.feed() * 100;
  LOG(LEV_INFO5, "EnrFac") << "   * Product Qty: " << product_qty;
  LOG(LEV_INFO5, "EnrFac") << "   * Product Assay: " << assays.product() * 100;
  LOG(LEV_INFO5, "EnrFac") << "   * Tails Qty: " << tails_qty(product_qty,assays);
  LOG(LEV_INFO5, "EnrFac") << "   * Tails Assay: " << assays.tails() * 100;
  recordEnrichment(natural_u,swu);

  vector<rsrc_ptr> ret;
  ret.push_back(order.resource());
  return ret;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::receiveMessage(msg_ptr msg)
{
  // is this a message from on high?
  if(msg->trans().supplier() == this)
    {
      // file the order
      orders_.push_back(msg);
      LOG(LEV_INFO5, "EnrFac") << name() << " just received an order for: ";
      msg->trans().resource()->print();
    }
  else
    {
      throw CycException("EnrFacility is not the supplier of this msg.");
    }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::handleTick(int time)
{
  LOG(LEV_INFO3, "EnrFac") << facName() << " is ticking {";

  makeRequest();
  makeOffer();

  LOG(LEV_INFO3, "EnrFac") << "}";
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::handleTock(int time)
{
  LOG(LEV_INFO3, "EnrFac") << facName() << " is tocking {";

  processOutgoingMaterial();

  LOG(LEV_INFO3, "EnrFac") << "}";
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::makeRequest()
{
  double amt = inventory_.space();
  double min_amt = 0;
  string commodity = in_commodity();

  if (amt > cyclus::eps())
    {
      LOG(LEV_INFO4, "EnrFac") << " requests "<< amt << " kg of " << commodity << ".";

      MarketModel* market = MarketModel::marketForCommod(commodity);
      Communicator* recipient = dynamic_cast<Communicator*>(market);

      // create a material resource
      // @MJGFlag note that this doesn't matter in the current state
      mat_rsrc_ptr request_res =
        mat_rsrc_ptr(new Material(RecipeLibrary::Recipe(in_recipe_)));
      request_res->setQuantity(amt);

      // build the transaction and message
      Transaction trans(this, REQUEST);
      trans.setCommod(commodity);
      trans.setMinFrac(min_amt/amt);
      trans.setPrice(commodity_price_);
      trans.setResource(request_res);

      msg_ptr request(new Message(this, recipient, trans));
      request->sendOn();
    }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Transaction EnrichmentFacility::buildTransaction()
{
  // there is no minimum amount a source facility may send
  double min_amt = 0;
  double offer_amt = inventory_.quantity();

  mat_rsrc_ptr offer_res = mat_rsrc_ptr(new Material());
  offer_res->setQuantity(offer_amt);
  Transaction trans(this, OFFER);

  trans.setCommod(out_commodity());
  trans.setMinFrac(min_amt/offer_amt);
  trans.setPrice(commodity_price());
  trans.setResource(offer_res);

  return trans;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::makeOffer()
{
  MarketModel* market = MarketModel::marketForCommod(out_commodity());

  Communicator* recipient = dynamic_cast<Communicator*>(market);

  // note that this is a hack. the amount of the resource being offered
  // is greater than the possible amount that can be serviced
  Transaction trans = buildTransaction();

  msg_ptr msg(new Message(this, recipient, trans));

  if (trans.resource()->quantity() > 0)
    {
      LOG(LEV_INFO4, "EnrFac") << "offers "<< trans.resource()->quantity() << " kg of "
                               << out_commodity_ << ".";

      msg->sendOn();
    }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::processOutgoingMaterial()
{
  double remove_total = 0;
  while (!orders_.empty())
    {
      Transaction trans = orders_.front()->trans();

      rsrc_ptr prsrc = trans.resource();
      if (!Material::isMaterial(prsrc))
       throw CycOverrideException("Can't process a resource as a non-material");

      mat_rsrc_ptr rsrc = dynamic_pointer_cast<Material>(prsrc);

      LOG(LEV_DEBUG1, "EnrFac") << "Processing material: ";
      rsrc->print();

      Assays assays = getAssays(rsrc);
      double product_qty = uranium_qty(rsrc);
      remove_total += feed_qty(product_qty,assays);

      if (remove_total < inventory_.quantity())
        {
          trans.approveTransfer();
        }
      // else
      //   {
      //     throw CycOverrideException("Can't process more than an EnrFac's inventory size");
      //   }

      orders_.pop_front();
    }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
enrichment::Assays EnrichmentFacility::getAssays(mat_rsrc_ptr rsrc)
{
  double product_assay = uranium_assay(rsrc);
  return Assays(feed_assay(),product_assay,tails_assay());
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::recordEnrichment(double natural_u, double swu)
{
  LOG(LEV_DEBUG1, "EnrFac") << name() << " has enriched a material:";
  LOG(LEV_DEBUG1, "EnrFac") << "  * Amount: " << natural_u;
  LOG(LEV_DEBUG1, "EnrFac") << "  *    SWU: " << swu;

  EM->newEvent(this, "Enrichments")
    ->addVal("ENTRY", ++entry_)
    ->addVal("ID", ID())
    ->addVal("Time", TI->time())
    ->addVal("Natural_Uranium", natural_u)
    ->addVal("SWU", swu)
    ->record();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
extern "C" Model* constructEnrichmentFacility()
{
  return new EnrichmentFacility();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
extern "C" void destructEnrichmentFacility(Model* model)
{
      delete model;
}
<commit_msg>simplified enrichment facility EM->newEvent call<commit_after>// EnrichmentFacility.cpp
// Implements the EnrichmentFacility class
#include "EnrichmentFacility.h"

#include "MarketModel.h"
#include "QueryEngine.h"
#include "Logger.h"
#include "CycException.h"
#include "CycLimits.h"
#include "GenericResource.h"
#include "Material.h"
#include "Timer.h"
#include "EventManager.h"

#include <sstream>
#include <limits>
#include <cmath>

#include <boost/lexical_cast.hpp>

using namespace std;
using namespace boost;
using boost::lexical_cast;
using namespace enrichment;

int EnrichmentFacility::entry_ = 0;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EnrichmentFacility::EnrichmentFacility() :
  commodity_price_(0),
  tails_assay_(0),
  feed_assay_(0),
  in_commodity_(""),
  in_recipe_(""),
  out_commodity_("")
{}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EnrichmentFacility::~EnrichmentFacility()
{}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::initModuleMembers(QueryEngine* qe)
{
  string data;

  QueryEngine* input = qe->queryElement("input");
  set_in_commodity(input->getElementContent("incommodity"));
  set_in_recipe(input->getElementContent("inrecipe"));

  try
    {
      data = input->getElementContent("inventorysize");
      setMaxInventorySize(lexical_cast<double>(data));
    }
  catch (CycNullQueryException e)
    {
      setMaxInventorySize(numeric_limits<double>::max());
    }

  QueryEngine* output = qe->queryElement("output");
  set_out_commodity(output->getElementContent("outcommodity"));

  data = output->getElementContent("tails_assay");
  set_tails_assay(lexical_cast<double>(data));

  mat_rsrc_ptr feed = mat_rsrc_ptr(new Material(RecipeLibrary::Recipe(in_recipe())));
  set_feed_assay(uranium_assay(feed));
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::string EnrichmentFacility::str()
{
  std::stringstream ss;
  ss << FacilityModel::str()
     << " with enrichment facility parameters:"
     << " * Tails assay: " << tails_assay()
     << " * Feed assay: " << feed_assay()
     << " * Input Commodity: " << in_commodity()
     << " * Output Commodity: " << out_commodity();
  return ss.str();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::cloneModuleMembersFrom(FacilityModel* sourceModel)
{
  EnrichmentFacility* source = dynamic_cast<EnrichmentFacility*>(sourceModel);
  set_tails_assay(source->tails_assay());
  set_feed_assay(source->feed_assay());
  set_in_commodity(source->in_commodity());
  set_in_recipe(source->in_recipe());
  set_out_commodity(source->out_commodity());
  setMaxInventorySize(source->maxInventorySize());
  set_commodity_price(source->commodity_price());

  LOG(LEV_DEBUG1, "EnrFac") << "Cloned - " << str();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::addResource(Transaction trans, std::vector<rsrc_ptr> manifest)
{
  LOG(LEV_INFO5, "EnrFac") << name() << " adding material qty: " << manifest.at(0)->quantity();
  inventory_.pushAll(MatBuff::toMat(manifest));
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::vector<rsrc_ptr> EnrichmentFacility::removeResource(Transaction order)
{
  rsrc_ptr prsrc = order.resource();
  if (!Material::isMaterial(prsrc))
    throw CycOverrideException("Can't remove a resource as a non-material");

  mat_rsrc_ptr rsrc = dynamic_pointer_cast<Material>(prsrc);

  Assays assays = getAssays(rsrc);
  double product_qty = uranium_qty(rsrc);
  double swu = swu_required(product_qty,assays);
  double natural_u = feed_qty(product_qty,assays);
  inventory_.popQty(natural_u);

  LOG(LEV_INFO5, "EnrFac") << name() << " has performed an enrichment: ";
  LOG(LEV_INFO5, "EnrFac") << "   * Feed Qty: " << feed_qty(product_qty,assays);
  LOG(LEV_INFO5, "EnrFac") << "   * Feed Assay: " << assays.feed() * 100;
  LOG(LEV_INFO5, "EnrFac") << "   * Product Qty: " << product_qty;
  LOG(LEV_INFO5, "EnrFac") << "   * Product Assay: " << assays.product() * 100;
  LOG(LEV_INFO5, "EnrFac") << "   * Tails Qty: " << tails_qty(product_qty,assays);
  LOG(LEV_INFO5, "EnrFac") << "   * Tails Assay: " << assays.tails() * 100;
  recordEnrichment(natural_u,swu);

  vector<rsrc_ptr> ret;
  ret.push_back(order.resource());
  return ret;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::receiveMessage(msg_ptr msg)
{
  // is this a message from on high?
  if(msg->trans().supplier() == this)
    {
      // file the order
      orders_.push_back(msg);
      LOG(LEV_INFO5, "EnrFac") << name() << " just received an order for: ";
      msg->trans().resource()->print();
    }
  else
    {
      throw CycException("EnrFacility is not the supplier of this msg.");
    }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::handleTick(int time)
{
  LOG(LEV_INFO3, "EnrFac") << facName() << " is ticking {";

  makeRequest();
  makeOffer();

  LOG(LEV_INFO3, "EnrFac") << "}";
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::handleTock(int time)
{
  LOG(LEV_INFO3, "EnrFac") << facName() << " is tocking {";

  processOutgoingMaterial();

  LOG(LEV_INFO3, "EnrFac") << "}";
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::makeRequest()
{
  double amt = inventory_.space();
  double min_amt = 0;
  string commodity = in_commodity();

  if (amt > cyclus::eps())
    {
      LOG(LEV_INFO4, "EnrFac") << " requests "<< amt << " kg of " << commodity << ".";

      MarketModel* market = MarketModel::marketForCommod(commodity);
      Communicator* recipient = dynamic_cast<Communicator*>(market);

      // create a material resource
      // @MJGFlag note that this doesn't matter in the current state
      mat_rsrc_ptr request_res =
        mat_rsrc_ptr(new Material(RecipeLibrary::Recipe(in_recipe_)));
      request_res->setQuantity(amt);

      // build the transaction and message
      Transaction trans(this, REQUEST);
      trans.setCommod(commodity);
      trans.setMinFrac(min_amt/amt);
      trans.setPrice(commodity_price_);
      trans.setResource(request_res);

      msg_ptr request(new Message(this, recipient, trans));
      request->sendOn();
    }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Transaction EnrichmentFacility::buildTransaction()
{
  // there is no minimum amount a source facility may send
  double min_amt = 0;
  double offer_amt = inventory_.quantity();

  mat_rsrc_ptr offer_res = mat_rsrc_ptr(new Material());
  offer_res->setQuantity(offer_amt);
  Transaction trans(this, OFFER);

  trans.setCommod(out_commodity());
  trans.setMinFrac(min_amt/offer_amt);
  trans.setPrice(commodity_price());
  trans.setResource(offer_res);

  return trans;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::makeOffer()
{
  MarketModel* market = MarketModel::marketForCommod(out_commodity());

  Communicator* recipient = dynamic_cast<Communicator*>(market);

  // note that this is a hack. the amount of the resource being offered
  // is greater than the possible amount that can be serviced
  Transaction trans = buildTransaction();

  msg_ptr msg(new Message(this, recipient, trans));

  if (trans.resource()->quantity() > 0)
    {
      LOG(LEV_INFO4, "EnrFac") << "offers "<< trans.resource()->quantity() << " kg of "
                               << out_commodity_ << ".";

      msg->sendOn();
    }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::processOutgoingMaterial()
{
  double remove_total = 0;
  while (!orders_.empty())
    {
      Transaction trans = orders_.front()->trans();

      rsrc_ptr prsrc = trans.resource();
      if (!Material::isMaterial(prsrc))
       throw CycOverrideException("Can't process a resource as a non-material");

      mat_rsrc_ptr rsrc = dynamic_pointer_cast<Material>(prsrc);

      LOG(LEV_DEBUG1, "EnrFac") << "Processing material: ";
      rsrc->print();

      Assays assays = getAssays(rsrc);
      double product_qty = uranium_qty(rsrc);
      remove_total += feed_qty(product_qty,assays);

      if (remove_total < inventory_.quantity())
        {
          trans.approveTransfer();
        }
      // else
      //   {
      //     throw CycOverrideException("Can't process more than an EnrFac's inventory size");
      //   }

      orders_.pop_front();
    }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
enrichment::Assays EnrichmentFacility::getAssays(mat_rsrc_ptr rsrc)
{
  double product_assay = uranium_assay(rsrc);
  return Assays(feed_assay(),product_assay,tails_assay());
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentFacility::recordEnrichment(double natural_u, double swu)
{
  LOG(LEV_DEBUG1, "EnrFac") << name() << " has enriched a material:";
  LOG(LEV_DEBUG1, "EnrFac") << "  * Amount: " << natural_u;
  LOG(LEV_DEBUG1, "EnrFac") << "  *    SWU: " << swu;

  EM->newEvent(modelImpl() + "_Enrichments")
    ->addVal("ENTRY", ++entry_)
    ->addVal("ID", ID())
    ->addVal("Time", TI->time())
    ->addVal("Natural_Uranium", natural_u)
    ->addVal("SWU", swu)
    ->record();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
extern "C" Model* constructEnrichmentFacility()
{
  return new EnrichmentFacility();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
extern "C" void destructEnrichmentFacility(Model* model)
{
      delete model;
}
<|endoftext|>


<commit_before>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "geocodingtab.h"
#include "placepresenter.h"

#include <QTreeWidget>
#include <QLineEdit>
#include <QString>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QMessageBox>
#include <QDialogButtonBox>

#include <qgeoaddress.h>

GeoCodingInputDialog::GeoCodingInputDialog(QString &obloc, QGeoAddress &address, QWidget *parent)
    : QDialog(parent), m_oblocStr(obloc), m_address(address)
{
    setWindowTitle(tr("Geocoding Parameters"));
    QLabel *obloclbl = new QLabel(tr("OneBox-Search:"));
    m_obloc = new QLineEdit(m_oblocStr);
    m_obloc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);

    QLabel *addressSearchlbl = new QLabel(tr("Search by address (Leave OneBox empty):"));
    QLabel *countrylbl = new QLabel(tr("Country:"));
    m_country = new QLineEdit(address.country());
    m_country->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *statelbl = new QLabel(tr("State:"));
    m_state = new QLineEdit(address.state());
    m_state->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *citylbl = new QLabel(tr("City:"));
    m_city = new QLineEdit(address.city());
    m_city->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *ziplbl = new QLabel(tr("Zip:"));
    m_zip = new QLineEdit(address.postCode());
    m_zip->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *streetlbl = new QLabel(tr("Street:"));
    m_street = new QLineEdit(address.street());
    m_street->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *streetnumlbl = new QLabel(tr("Street number:"));

    QHBoxLayout *firstrow = new QHBoxLayout;
    firstrow->setSpacing(2);
    firstrow->setContentsMargins(2, 1, 2, 1);
    firstrow->addWidget(m_obloc);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel,Qt::Horizontal);
    connect(buttonBox,SIGNAL(accepted()),this,SLOT(accept()));
    connect(buttonBox,SIGNAL(rejected()),this,SLOT(reject()));

    QGridLayout *gridLayout = new QGridLayout ;
    gridLayout->setSizeConstraint(QLayout::SetMinimumSize);
    gridLayout->setSpacing(2);
    gridLayout->setContentsMargins(2, 1, 2, 1);

    gridLayout->addWidget(streetlbl, 1, 0);
    gridLayout->addWidget(streetnumlbl, 1, 1);
    gridLayout->addWidget(m_street, 2, 0,1,2);

    gridLayout->addWidget(ziplbl, 3, 0);
    gridLayout->addWidget(citylbl, 3, 1);
    gridLayout->addWidget(m_zip, 4, 0);
    gridLayout->addWidget(m_city, 4, 1);

    gridLayout->addWidget(statelbl, 5, 0);
    gridLayout->addWidget(countrylbl, 5, 1);
    gridLayout->addWidget(m_state, 6, 0);
    gridLayout->addWidget(m_country, 6, 1);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
    mainLayout->setSpacing(2);
    mainLayout->setContentsMargins(2, 1, 2, 1);
    mainLayout->addWidget(obloclbl);
    mainLayout->addLayout(firstrow);
    mainLayout->addWidget(addressSearchlbl);
    mainLayout->addLayout(gridLayout);
    mainLayout->addWidget(buttonBox);
    setLayout(mainLayout);

}

void GeoCodingInputDialog::accept()
{
    m_oblocStr = m_obloc->text();

    m_address.setCountry(m_country->text());
    m_address.setState(m_state->text());
    m_address.setCity(m_city->text());
    m_address.setPostCode(m_zip->text());
    m_address.setStreet(m_street->text());

    QDialog::accept();
}

GeocodingTab::GeocodingTab(QWidget *parent) :
        QWidget(parent),
        m_searchManager(NULL)
{

    m_oblocStr="Deutschland, Mnchen";

    m_requestBtn = new QPushButton(tr("Search By Address"));
    m_requestBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    m_requestBtn->setDisabled(true);
    QObject::connect(m_requestBtn, SIGNAL(clicked(bool)), this, SLOT(on_btnRequest_clicked()));

    m_resultTree = new QTreeWidget();
    QStringList labels;
    labels << tr("Elements") << tr("Value");
    m_resultTree->setHeaderLabels(labels);
    m_resultTree->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    m_resultTree->setColumnWidth(0, 240);

    QHBoxLayout *firstrow = new QHBoxLayout;
    firstrow->setSpacing(2);
    firstrow->setContentsMargins(2, 1, 2, 1);
    firstrow->addWidget(m_requestBtn);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setSpacing(2);
    mainLayout->setContentsMargins(2, 1, 2, 1);
    mainLayout->addLayout(firstrow);
    mainLayout->addWidget(m_resultTree);
    setLayout(mainLayout);
}

GeocodingTab::~GeocodingTab()
{
}

void GeocodingTab::initialize(QGeoSearchManager *searchManager)
{
    m_resultTree->clear();
    m_searchManager = searchManager;
    if (m_searchManager) {
        QObject::connect(m_searchManager, SIGNAL(finished(QGeoSearchReply*)), this,
                         SLOT(replyFinished(QGeoSearchReply*)));
        QObject::connect(m_searchManager,
                         SIGNAL(error(QGeoSearchReply*, QGeoSearchReply::Error, QString)), this,
                         SLOT(resultsError(QGeoSearchReply*, QGeoSearchReply::Error, QString)));
        if (m_searchManager->supportsGeocoding())
            m_requestBtn->setDisabled(false);
    } else
        m_requestBtn->setDisabled(true);

}

void GeocodingTab::on_btnRequest_clicked()
{
    if (m_searchManager) {
        GeoCodingInputDialog dlg(m_oblocStr,m_address,this);
        if(dlg.exec()==QDialog::Accepted) {
            m_resultTree->clear();
            QTreeWidgetItem* top = new QTreeWidgetItem(m_resultTree);
            top->setText(0, tr("Geocode"));
            top->setText(1, tr("Requesting data"));

            if (!m_oblocStr.isEmpty()) {
                m_searchManager->search(m_oblocStr, QGeoSearchManager::SearchGeocode);
            } else {
                m_searchManager->geocode(m_address);
            }
        }
    } else {
        QMessageBox::warning(this, tr("Geocoding"), tr("No search manager available."));
    }
}

void GeocodingTab::replyFinished(QGeoSearchReply* reply)
{
    if (!isHidden() && reply->error() == QGeoSearchReply::NoError) {
        PlacePresenter presenter(m_resultTree, reply);
        presenter.show();
        reply->deleteLater();
    }
}

void GeocodingTab::resultsError(QGeoSearchReply* reply, QGeoSearchReply::Error errorCode, QString errorString)
{
    Q_UNUSED(errorCode)

    if (!isHidden()) {
        QTreeWidgetItem* errorResultItem = new QTreeWidgetItem(m_resultTree);
        errorResultItem->setText(0, tr("Error"));
        errorResultItem->setText(1, errorString);
        reply->deleteLater();
    }
}
<commit_msg>forgot to remove street number from geoservicedemo<commit_after>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "geocodingtab.h"
#include "placepresenter.h"

#include <QTreeWidget>
#include <QLineEdit>
#include <QString>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QMessageBox>
#include <QDialogButtonBox>

#include <qgeoaddress.h>

GeoCodingInputDialog::GeoCodingInputDialog(QString &obloc, QGeoAddress &address, QWidget *parent)
    : QDialog(parent), m_oblocStr(obloc), m_address(address)
{
    setWindowTitle(tr("Geocoding Parameters"));
    QLabel *obloclbl = new QLabel(tr("OneBox-Search:"));
    m_obloc = new QLineEdit(m_oblocStr);
    m_obloc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);

    QLabel *addressSearchlbl = new QLabel(tr("Search by address (Leave OneBox empty):"));
    QLabel *countrylbl = new QLabel(tr("Country:"));
    m_country = new QLineEdit(address.country());
    m_country->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *statelbl = new QLabel(tr("State:"));
    m_state = new QLineEdit(address.state());
    m_state->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *citylbl = new QLabel(tr("City:"));
    m_city = new QLineEdit(address.city());
    m_city->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *ziplbl = new QLabel(tr("Zip:"));
    m_zip = new QLineEdit(address.postCode());
    m_zip->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    QLabel *streetlbl = new QLabel(tr("Street:"));
    m_street = new QLineEdit(address.street());
    m_street->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    QHBoxLayout *firstrow = new QHBoxLayout;
    firstrow->setSpacing(2);
    firstrow->setContentsMargins(2, 1, 2, 1);
    firstrow->addWidget(m_obloc);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel,Qt::Horizontal);
    connect(buttonBox,SIGNAL(accepted()),this,SLOT(accept()));
    connect(buttonBox,SIGNAL(rejected()),this,SLOT(reject()));

    QGridLayout *gridLayout = new QGridLayout ;
    gridLayout->setSizeConstraint(QLayout::SetMinimumSize);
    gridLayout->setSpacing(2);
    gridLayout->setContentsMargins(2, 1, 2, 1);

    gridLayout->addWidget(streetlbl, 1, 0);
    gridLayout->addWidget(m_street, 2, 0,1,2);

    gridLayout->addWidget(ziplbl, 3, 0);
    gridLayout->addWidget(citylbl, 3, 1);
    gridLayout->addWidget(m_zip, 4, 0);
    gridLayout->addWidget(m_city, 4, 1);

    gridLayout->addWidget(statelbl, 5, 0);
    gridLayout->addWidget(countrylbl, 5, 1);
    gridLayout->addWidget(m_state, 6, 0);
    gridLayout->addWidget(m_country, 6, 1);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
    mainLayout->setSpacing(2);
    mainLayout->setContentsMargins(2, 1, 2, 1);
    mainLayout->addWidget(obloclbl);
    mainLayout->addLayout(firstrow);
    mainLayout->addWidget(addressSearchlbl);
    mainLayout->addLayout(gridLayout);
    mainLayout->addWidget(buttonBox);
    setLayout(mainLayout);

}

void GeoCodingInputDialog::accept()
{
    m_oblocStr = m_obloc->text();

    m_address.setCountry(m_country->text());
    m_address.setState(m_state->text());
    m_address.setCity(m_city->text());
    m_address.setPostCode(m_zip->text());
    m_address.setStreet(m_street->text());

    QDialog::accept();
}

GeocodingTab::GeocodingTab(QWidget *parent) :
        QWidget(parent),
        m_searchManager(NULL)
{

    m_oblocStr="Deutschland, Mnchen";

    m_requestBtn = new QPushButton(tr("Search By Address"));
    m_requestBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    m_requestBtn->setDisabled(true);
    QObject::connect(m_requestBtn, SIGNAL(clicked(bool)), this, SLOT(on_btnRequest_clicked()));

    m_resultTree = new QTreeWidget();
    QStringList labels;
    labels << tr("Elements") << tr("Value");
    m_resultTree->setHeaderLabels(labels);
    m_resultTree->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    m_resultTree->setColumnWidth(0, 240);

    QHBoxLayout *firstrow = new QHBoxLayout;
    firstrow->setSpacing(2);
    firstrow->setContentsMargins(2, 1, 2, 1);
    firstrow->addWidget(m_requestBtn);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setSpacing(2);
    mainLayout->setContentsMargins(2, 1, 2, 1);
    mainLayout->addLayout(firstrow);
    mainLayout->addWidget(m_resultTree);
    setLayout(mainLayout);
}

GeocodingTab::~GeocodingTab()
{
}

void GeocodingTab::initialize(QGeoSearchManager *searchManager)
{
    m_resultTree->clear();
    m_searchManager = searchManager;
    if (m_searchManager) {
        QObject::connect(m_searchManager, SIGNAL(finished(QGeoSearchReply*)), this,
                         SLOT(replyFinished(QGeoSearchReply*)));
        QObject::connect(m_searchManager,
                         SIGNAL(error(QGeoSearchReply*, QGeoSearchReply::Error, QString)), this,
                         SLOT(resultsError(QGeoSearchReply*, QGeoSearchReply::Error, QString)));
        if (m_searchManager->supportsGeocoding())
            m_requestBtn->setDisabled(false);
    } else
        m_requestBtn->setDisabled(true);

}

void GeocodingTab::on_btnRequest_clicked()
{
    if (m_searchManager) {
        GeoCodingInputDialog dlg(m_oblocStr,m_address,this);
        if(dlg.exec()==QDialog::Accepted) {
            m_resultTree->clear();
            QTreeWidgetItem* top = new QTreeWidgetItem(m_resultTree);
            top->setText(0, tr("Geocode"));
            top->setText(1, tr("Requesting data"));

            if (!m_oblocStr.isEmpty()) {
                m_searchManager->search(m_oblocStr, QGeoSearchManager::SearchGeocode);
            } else {
                m_searchManager->geocode(m_address);
            }
        }
    } else {
        QMessageBox::warning(this, tr("Geocoding"), tr("No search manager available."));
    }
}

void GeocodingTab::replyFinished(QGeoSearchReply* reply)
{
    if (!isHidden() && reply->error() == QGeoSearchReply::NoError) {
        PlacePresenter presenter(m_resultTree, reply);
        presenter.show();
        reply->deleteLater();
    }
}

void GeocodingTab::resultsError(QGeoSearchReply* reply, QGeoSearchReply::Error errorCode, QString errorString)
{
    Q_UNUSED(errorCode)

    if (!isHidden()) {
        QTreeWidgetItem* errorResultItem = new QTreeWidgetItem(m_resultTree);
        errorResultItem->setText(0, tr("Error"));
        errorResultItem->setText(1, errorString);
        reply->deleteLater();
    }
}
<|endoftext|>


<commit_before>/* Siconos-Kernel, Copyright INRIA 2005-2012.
* Siconos is a program dedicated to modeling, simulation and control
* of non smooth dynamical systems.
* Siconos is a 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.
* Siconos 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 Siconos; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*
* Contact: Vincent ACARY, siconos-team@lists.gforge.inria.fr
*/

#include "NewtonEulerFrom3DLocalFrameR.hpp"
#include "NewtonEulerDS.hpp"
#include <boost/math/quaternion.hpp>
#include "Interaction.hpp"
#include "BlockVector.hpp"

#include "op3x3.h"

// #define DEBUG_STDOUT
// #define DEBUG_MESSAGES
#include "debug.h"

/*
See devNotes.pdf for details. A detailed documentation is available in DevNotes.pdf: chapter 'NewtonEulerR: computation of \nabla q H'. Subsection 'Case FC3D: using the local frame local velocities'
*/
void NewtonEulerFrom3DLocalFrameR::initComponents(Interaction& inter, VectorOfBlockVectors& DSlink, VectorOfVectors& workV, VectorOfSMatrices& workM)
{
  NewtonEulerFrom1DLocalFrameR::initComponents(inter, DSlink, workV, workM);
  unsigned int qSize = 7 * (inter.getSizeOfDS() / 6);
  /*keep only the distance.*/
  _jachq.reset(new SimpleMatrix(3, qSize));

  _AUX2.reset(new SimpleMatrix(3, 3));
  //  _isContact=1;
}
void NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts(SP::SiconosVector q1)
{

  double Nx = _Nc->getValue(0);
  double Ny = _Nc->getValue(1);
  double Nz = _Nc->getValue(2);
  double Px = _Pc1->getValue(0);
  double Py = _Pc1->getValue(1);
  double Pz = _Pc1->getValue(2);
  double G1x = q1->getValue(0);
  double G1y = q1->getValue(1);
  double G1z = q1->getValue(2);

  DEBUG_PRINT("contact normal:\n");
  DEBUG_EXPR(_Nc->display(););
  DEBUG_PRINT("contact point :\n");
  DEBUG_EXPR(_Pc1->display(););
  DEBUG_PRINT("center of mass :\n");
  DEBUG_EXPR(q1->display(););

  assert(_Nc->norm2() >0.0 && "NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts. Normal vector not consistent ") ;

  double t[6];
  double * pt = t;
  orthoBaseFromVector(&Nx, &Ny, &Nz, pt, pt + 1, pt + 2, pt + 3, pt + 4, pt + 5);
  pt = t;
  _Mabs_C->setValue(0, 0, Nx);
  _Mabs_C->setValue(1, 0, *pt);
  _Mabs_C->setValue(2, 0, *(pt + 3));
  _Mabs_C->setValue(0, 1, Ny);
  _Mabs_C->setValue(1, 1, *(pt + 1));
  _Mabs_C->setValue(2, 1, *(pt + 4));
  _Mabs_C->setValue(0, 2, Nz);
  _Mabs_C->setValue(1, 2, *(pt + 2));
  _Mabs_C->setValue(2, 2, *(pt + 5));

  DEBUG_PRINT("_Mabs_C:\n");
  DEBUG_EXPR(_Mabs_C->display(););

  _NPG1->zero();

  (*_NPG1)(0, 0) = 0;
  (*_NPG1)(0, 1) = -(G1z - Pz);
  (*_NPG1)(0, 2) = (G1y - Py);
  (*_NPG1)(1, 0) = (G1z - Pz);
  (*_NPG1)(1, 1) = 0;
  (*_NPG1)(1, 2) = -(G1x - Px);
  (*_NPG1)(2, 0) = -(G1y - Py);
  (*_NPG1)(2, 1) = (G1x - Px);
  (*_NPG1)(2, 2) = 0;

//  d1->computeMObjToAbs();
//  SimpleMatrix& Mobj1_abs = *d1->MObjToAbs();

  computeMObjToAbs(q1,_MObjToAbs);

  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, _MObjToAbs:");
  DEBUG_EXPR(_MObjToAbs->display(););

  prod(*_NPG1, *_MObjToAbs, *_AUX1, true);

  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, *_MObjToAbs:");
  DEBUG_EXPR_WE(_MObjToAbs->display(););
  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, AUX1:");
  DEBUG_EXPR_WE(_AUX1->display(););
  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, AUX2:");
  DEBUG_EXPR(_AUX2->display(););

  prod(*_Mabs_C, *_AUX1, *_AUX2, true);

  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, Mabs_C:");
  DEBUG_EXPR_WE(_Mabs_C->display(););
  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, AUX1:");
  DEBUG_EXPR_WE(_AUX1->display(););
  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, AUX2:");
  DEBUG_EXPR_WE(_AUX2->display(););

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 0; jj < 3; jj++)
      _jachqT->setValue(ii, jj, _Mabs_C->getValue(ii, jj));

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 3; jj < 6; jj++)
      _jachqT->setValue(ii, jj, _AUX2->getValue(ii, jj - 3));

  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, _jahcqT:\n");
  DEBUG_EXPR(_jachqT->display(););
  // DEBUG_EXPR_WE(
  //   SP::SimpleMatrix jaux(new SimpleMatrix(*_jachqT));
  //   jaux->trans();
  //   SP::SiconosVector v(new SiconosVector(3));
  //   SP::SiconosVector vRes(new SiconosVector(6));
  //   v->zero();
  //   v->setValue(0, 1);
  //   prod(*jaux, *v, *vRes, true);
  //   vRes->display();
  //   v->zero();
  //   v->setValue(1, 1);
  //   prod(*jaux, *v, *vRes, true);
  //   vRes->display();
  //   v->zero();
  //   v->setValue(2, 1);
  //   prod(*jaux, *v, *vRes, true);
  //   vRes->display();
  //   );
}

void NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts(SP::SiconosVector q1, SP::SiconosVector q2)
{
  double Nx = _Nc->getValue(0);
  double Ny = _Nc->getValue(1);
  double Nz = _Nc->getValue(2);
  double Px = _Pc1->getValue(0);
  double Py = _Pc1->getValue(1);
  double Pz = _Pc1->getValue(2);
  double G1x = q1->getValue(0);
  double G1y = q1->getValue(1);
  double G1z = q1->getValue(2);
  double G2x = q2->getValue(0);
  double G2y = q2->getValue(1);
  double G2z = q2->getValue(2);

  DEBUG_PRINT("contact normal:\n");
  DEBUG_EXPR(_Nc->display(););
  DEBUG_PRINT("contact point :\n");
  DEBUG_EXPR(_Pc1->display(););
  DEBUG_PRINT("center of mass :\n");
  DEBUG_EXPR(q1->display(););

  double t[6];
  double * pt = t;
  orthoBaseFromVector(&Nx, &Ny, &Nz, pt, pt + 1, pt + 2, pt + 3, pt + 4, pt + 5);
  pt = t;
  _Mabs_C->setValue(0, 0, Nx);
  _Mabs_C->setValue(1, 0, *pt);
  _Mabs_C->setValue(2, 0, *(pt + 3));
  _Mabs_C->setValue(0, 1, Ny);
  _Mabs_C->setValue(1, 1, *(pt + 1));
  _Mabs_C->setValue(2, 1, *(pt + 4));
  _Mabs_C->setValue(0, 2, Nz);
  _Mabs_C->setValue(1, 2, *(pt + 2));
  _Mabs_C->setValue(2, 2, *(pt + 5));

  _NPG1->zero();

  (*_NPG1)(0, 0) = 0;
  (*_NPG1)(0, 1) = -(G1z - Pz);
  (*_NPG1)(0, 2) = (G1y - Py);
  (*_NPG1)(1, 0) = (G1z - Pz);
  (*_NPG1)(1, 1) = 0;
  (*_NPG1)(1, 2) = -(G1x - Px);
  (*_NPG1)(2, 0) = -(G1y - Py);
  (*_NPG1)(2, 1) = (G1x - Px);
  (*_NPG1)(2, 2) = 0;

  _NPG2->zero();

  (*_NPG2)(0, 0) = 0;
  (*_NPG2)(0, 1) = -(G2z - Pz);
  (*_NPG2)(0, 2) = (G2y - Py);
  (*_NPG2)(1, 0) = (G2z - Pz);
  (*_NPG2)(1, 1) = 0;
  (*_NPG2)(1, 2) = -(G2x - Px);
  (*_NPG2)(2, 0) = -(G2y - Py);
  (*_NPG2)(2, 1) = (G2x - Px);
  (*_NPG2)(2, 2) = 0;

//  d1->computeMObjToAbs();
//  SimpleMatrix& Mobj1_abs = *d1->MObjToAbs();

  computeMObjToAbs(q1,_MObjToAbs);

  prod(*_NPG1, *_MObjToAbs, *_AUX1, true);
  prod(*_Mabs_C, *_AUX1, *_AUX2, true);

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 0; jj < 3; jj++)
      _jachqT->setValue(ii, jj, _Mabs_C->getValue(ii, jj));

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 3; jj < 6; jj++)
      _jachqT->setValue(ii, jj, _AUX2->getValue(ii, jj - 3));

//  d2->computeMObjToAbs();
//  SimpleMatrix& Mobj2_abs = *d2->MObjToAbs();

  computeMObjToAbs(q2,_MObjToAbs);

  prod(*_NPG2, *_MObjToAbs, *_AUX1, true);
  prod(*_Mabs_C, *_AUX1, *_AUX2, true);

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 0; jj < 3; jj++)
      _jachqT->setValue(ii, jj + 6, -_Mabs_C->getValue(ii, jj));

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 3; jj < 6; jj++)
      _jachqT->setValue(ii, jj + 6, -_AUX2->getValue(ii, jj - 3));

}

void NewtonEulerFrom3DLocalFrameR::computeJachqT(Interaction& inter, VectorOfBlockVectors& DSlink)
{
  DEBUG_BEGIN("NewtonEulerFrom3DLocalFrameR::computeJachqT(Interaction& inter, VectorOfBlockVectors& DSlink) \n")
  SP::BlockVector BlockX = DSlink[NewtonEulerR::q0];
  if (inter.has2Bodies())
  {
    FC3DcomputeJachqTFromContacts((BlockX->getAllVect())[0], (BlockX->getAllVect())[1]);
  }
  else
  {
    FC3DcomputeJachqTFromContacts((BlockX->getAllVect())[0]);
  }

  DEBUG_END("NewtonEulerFrom3DLocalFrameR::computeJachqT(Interaction& inter, VectorOfBlockVectors& DSlink) \n");

}
<commit_msg>[kernel] too fast simplification<commit_after>/* Siconos-Kernel, Copyright INRIA 2005-2012.
* Siconos is a program dedicated to modeling, simulation and control
* of non smooth dynamical systems.
* Siconos is a 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.
* Siconos 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 Siconos; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*
* Contact: Vincent ACARY, siconos-team@lists.gforge.inria.fr
*/

#include "NewtonEulerFrom3DLocalFrameR.hpp"
#include "NewtonEulerDS.hpp"
#include <boost/math/quaternion.hpp>
#include "Interaction.hpp"
#include "BlockVector.hpp"

#include "op3x3.h"

// #define DEBUG_STDOUT
// #define DEBUG_MESSAGES
#include "debug.h"

/*
See devNotes.pdf for details. A detailed documentation is available in DevNotes.pdf: chapter 'NewtonEulerR: computation of \nabla q H'. Subsection 'Case FC3D: using the local frame local velocities'
*/
void NewtonEulerFrom3DLocalFrameR::initComponents(Interaction& inter, VectorOfBlockVectors& DSlink, VectorOfVectors& workV, VectorOfSMatrices& workM)
{
  NewtonEulerFrom1DLocalFrameR::initComponents(inter, DSlink, workV, workM);
  unsigned int qSize = 7 * (inter.getSizeOfDS() / 6);
  /*keep only the distance.*/
  _jachq.reset(new SimpleMatrix(3, qSize));

  _Mabs_C.reset(new SimpleMatrix(3, 3));
  _AUX2.reset(new SimpleMatrix(3, 3));
  //  _isContact=1;
}
void NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts(SP::SiconosVector q1)
{

  double Nx = _Nc->getValue(0);
  double Ny = _Nc->getValue(1);
  double Nz = _Nc->getValue(2);
  double Px = _Pc1->getValue(0);
  double Py = _Pc1->getValue(1);
  double Pz = _Pc1->getValue(2);
  double G1x = q1->getValue(0);
  double G1y = q1->getValue(1);
  double G1z = q1->getValue(2);

  DEBUG_PRINT("contact normal:\n");
  DEBUG_EXPR(_Nc->display(););
  DEBUG_PRINT("contact point :\n");
  DEBUG_EXPR(_Pc1->display(););
  DEBUG_PRINT("center of mass :\n");
  DEBUG_EXPR(q1->display(););

  assert(_Nc->norm2() >0.0 && "NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts. Normal vector not consistent ") ;

  double t[6];
  double * pt = t;
  orthoBaseFromVector(&Nx, &Ny, &Nz, pt, pt + 1, pt + 2, pt + 3, pt + 4, pt + 5);
  pt = t;
  _Mabs_C->setValue(0, 0, Nx);
  _Mabs_C->setValue(1, 0, *pt);
  _Mabs_C->setValue(2, 0, *(pt + 3));
  _Mabs_C->setValue(0, 1, Ny);
  _Mabs_C->setValue(1, 1, *(pt + 1));
  _Mabs_C->setValue(2, 1, *(pt + 4));
  _Mabs_C->setValue(0, 2, Nz);
  _Mabs_C->setValue(1, 2, *(pt + 2));
  _Mabs_C->setValue(2, 2, *(pt + 5));

  DEBUG_PRINT("_Mabs_C:\n");
  DEBUG_EXPR(_Mabs_C->display(););

  _NPG1->zero();

  (*_NPG1)(0, 0) = 0;
  (*_NPG1)(0, 1) = -(G1z - Pz);
  (*_NPG1)(0, 2) = (G1y - Py);
  (*_NPG1)(1, 0) = (G1z - Pz);
  (*_NPG1)(1, 1) = 0;
  (*_NPG1)(1, 2) = -(G1x - Px);
  (*_NPG1)(2, 0) = -(G1y - Py);
  (*_NPG1)(2, 1) = (G1x - Px);
  (*_NPG1)(2, 2) = 0;

//  d1->computeMObjToAbs();
//  SimpleMatrix& Mobj1_abs = *d1->MObjToAbs();

  computeMObjToAbs(q1,_MObjToAbs);

  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, _MObjToAbs:");
  DEBUG_EXPR(_MObjToAbs->display(););

  prod(*_NPG1, *_MObjToAbs, *_AUX1, true);

  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, *_MObjToAbs:");
  DEBUG_EXPR_WE(_MObjToAbs->display(););
  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, AUX1:");
  DEBUG_EXPR_WE(_AUX1->display(););
  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, AUX2:");
  DEBUG_EXPR(_AUX2->display(););

  prod(*_Mabs_C, *_AUX1, *_AUX2, true);

  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, Mabs_C:");
  DEBUG_EXPR_WE(_Mabs_C->display(););
  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, AUX1:");
  DEBUG_EXPR_WE(_AUX1->display(););
  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, AUX2:");
  DEBUG_EXPR_WE(_AUX2->display(););

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 0; jj < 3; jj++)
      _jachqT->setValue(ii, jj, _Mabs_C->getValue(ii, jj));

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 3; jj < 6; jj++)
      _jachqT->setValue(ii, jj, _AUX2->getValue(ii, jj - 3));

  DEBUG_PRINT("NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts, _jahcqT:\n");
  DEBUG_EXPR(_jachqT->display(););
  // DEBUG_EXPR_WE(
  //   SP::SimpleMatrix jaux(new SimpleMatrix(*_jachqT));
  //   jaux->trans();
  //   SP::SiconosVector v(new SiconosVector(3));
  //   SP::SiconosVector vRes(new SiconosVector(6));
  //   v->zero();
  //   v->setValue(0, 1);
  //   prod(*jaux, *v, *vRes, true);
  //   vRes->display();
  //   v->zero();
  //   v->setValue(1, 1);
  //   prod(*jaux, *v, *vRes, true);
  //   vRes->display();
  //   v->zero();
  //   v->setValue(2, 1);
  //   prod(*jaux, *v, *vRes, true);
  //   vRes->display();
  //   );
}

void NewtonEulerFrom3DLocalFrameR::FC3DcomputeJachqTFromContacts(SP::SiconosVector q1, SP::SiconosVector q2)
{
  double Nx = _Nc->getValue(0);
  double Ny = _Nc->getValue(1);
  double Nz = _Nc->getValue(2);
  double Px = _Pc1->getValue(0);
  double Py = _Pc1->getValue(1);
  double Pz = _Pc1->getValue(2);
  double G1x = q1->getValue(0);
  double G1y = q1->getValue(1);
  double G1z = q1->getValue(2);
  double G2x = q2->getValue(0);
  double G2y = q2->getValue(1);
  double G2z = q2->getValue(2);

  DEBUG_PRINT("contact normal:\n");
  DEBUG_EXPR(_Nc->display(););
  DEBUG_PRINT("contact point :\n");
  DEBUG_EXPR(_Pc1->display(););
  DEBUG_PRINT("center of mass :\n");
  DEBUG_EXPR(q1->display(););

  double t[6];
  double * pt = t;
  orthoBaseFromVector(&Nx, &Ny, &Nz, pt, pt + 1, pt + 2, pt + 3, pt + 4, pt + 5);
  pt = t;
  _Mabs_C->setValue(0, 0, Nx);
  _Mabs_C->setValue(1, 0, *pt);
  _Mabs_C->setValue(2, 0, *(pt + 3));
  _Mabs_C->setValue(0, 1, Ny);
  _Mabs_C->setValue(1, 1, *(pt + 1));
  _Mabs_C->setValue(2, 1, *(pt + 4));
  _Mabs_C->setValue(0, 2, Nz);
  _Mabs_C->setValue(1, 2, *(pt + 2));
  _Mabs_C->setValue(2, 2, *(pt + 5));

  _NPG1->zero();

  (*_NPG1)(0, 0) = 0;
  (*_NPG1)(0, 1) = -(G1z - Pz);
  (*_NPG1)(0, 2) = (G1y - Py);
  (*_NPG1)(1, 0) = (G1z - Pz);
  (*_NPG1)(1, 1) = 0;
  (*_NPG1)(1, 2) = -(G1x - Px);
  (*_NPG1)(2, 0) = -(G1y - Py);
  (*_NPG1)(2, 1) = (G1x - Px);
  (*_NPG1)(2, 2) = 0;

  _NPG2->zero();

  (*_NPG2)(0, 0) = 0;
  (*_NPG2)(0, 1) = -(G2z - Pz);
  (*_NPG2)(0, 2) = (G2y - Py);
  (*_NPG2)(1, 0) = (G2z - Pz);
  (*_NPG2)(1, 1) = 0;
  (*_NPG2)(1, 2) = -(G2x - Px);
  (*_NPG2)(2, 0) = -(G2y - Py);
  (*_NPG2)(2, 1) = (G2x - Px);
  (*_NPG2)(2, 2) = 0;

//  d1->computeMObjToAbs();
//  SimpleMatrix& Mobj1_abs = *d1->MObjToAbs();

  computeMObjToAbs(q1,_MObjToAbs);

  prod(*_NPG1, *_MObjToAbs, *_AUX1, true);
  prod(*_Mabs_C, *_AUX1, *_AUX2, true);

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 0; jj < 3; jj++)
      _jachqT->setValue(ii, jj, _Mabs_C->getValue(ii, jj));

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 3; jj < 6; jj++)
      _jachqT->setValue(ii, jj, _AUX2->getValue(ii, jj - 3));

//  d2->computeMObjToAbs();
//  SimpleMatrix& Mobj2_abs = *d2->MObjToAbs();

  computeMObjToAbs(q2,_MObjToAbs);

  prod(*_NPG2, *_MObjToAbs, *_AUX1, true);
  prod(*_Mabs_C, *_AUX1, *_AUX2, true);

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 0; jj < 3; jj++)
      _jachqT->setValue(ii, jj + 6, -_Mabs_C->getValue(ii, jj));

  for (unsigned int ii = 0; ii < 3; ii++)
    for (unsigned int jj = 3; jj < 6; jj++)
      _jachqT->setValue(ii, jj + 6, -_AUX2->getValue(ii, jj - 3));

}

void NewtonEulerFrom3DLocalFrameR::computeJachqT(Interaction& inter, VectorOfBlockVectors& DSlink)
{
  DEBUG_BEGIN("NewtonEulerFrom3DLocalFrameR::computeJachqT(Interaction& inter, VectorOfBlockVectors& DSlink) \n")
  SP::BlockVector BlockX = DSlink[NewtonEulerR::q0];
  if (inter.has2Bodies())
  {
    FC3DcomputeJachqTFromContacts((BlockX->getAllVect())[0], (BlockX->getAllVect())[1]);
  }
  else
  {
    FC3DcomputeJachqTFromContacts((BlockX->getAllVect())[0]);
  }

  DEBUG_END("NewtonEulerFrom3DLocalFrameR::computeJachqT(Interaction& inter, VectorOfBlockVectors& DSlink) \n");

}
<|endoftext|>


<commit_before>//
//  This class works as generic interface to each candidate resonance daughter.
//  Its main purpose is to provide a unique reference which includes all the
//  facilities available in the AliVParticle generic base class, plus all info
//  which could be needed during analysis, which are not in AliVParticle but
//  need to be accessed from ESD or AOD objects, usually in different ways.
//  When MC is available, AliRsnDaughter matches each reconstructed object with
//  its corresponding MC particle.
//
//  Currently, this interface can point to all kinds of single-particle object
//  which one can have in the reconstructed event: charged tracks, V0s and
//  cascades. It is care of the user to treat each of them in the correct way,
//  regarding cuts, functions to be computed, etc.
//
//  authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
//           M. Vala (martin.vala@cern.ch)
//

#include <TParticle.h>
#include <TDatabasePDG.h>

#include "AliRsnDaughter.h"

ClassImp(AliRsnDaughter)

//_____________________________________________________________________________
AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter &copy) :
   TObject(copy),
   fOK(copy.fOK),
   fLabel(copy.fLabel),
   fMotherPDG(copy.fMotherPDG),
   fRsnID(copy.fRsnID),
   fPrec(copy.fPrec),
   fPsim(copy.fPsim),
   fRef(copy.fRef),
   fRefMC(copy.fRefMC),
   fOwnerEvent(copy.fOwnerEvent)
{
//
// Copy constructor.
// Pointers are NOT duplicated, since they don't come from a 'new'
// statement, but from just referencing something in the data source.
//
}

//_____________________________________________________________________________
AliRsnDaughter &AliRsnDaughter::operator=(const AliRsnDaughter &copy)
{
//
// Assignment operator.
// Pointers are NOT duplicated, since they don't come from a 'new'
// statement, but from just referencing something in the data source.
//
   if (this == &copy)
      return *this;

   fOK         = copy.fOK;
   fLabel      = copy.fLabel;
   fMotherPDG  = copy.fMotherPDG;
   fRsnID      = copy.fRsnID;
   fPsim       = copy.fPsim;
   fPrec       = copy.fPrec;
   fRef        = copy.fRef;
   fRefMC      = copy.fRefMC;
   fOwnerEvent = copy.fOwnerEvent;

   return (*this);
}

//_____________________________________________________________________________
void AliRsnDaughter::Reset()
{
//
// Reset this track to meaningless values and to a 'bad' status.
// After this has been done, this object should not be used
// for analysis unless initialized properly.
//

   fOK        = kFALSE;
   fLabel     = -1;
   fMotherPDG =  0;
   fRsnID     = -1;

   fPsim.SetXYZT(0.0, 0.0, 0.0, 0.0);
   fPrec.SetXYZT(0.0, 0.0, 0.0, 0.0);

   fRef = fRefMC = 0x0;
   fOwnerEvent = 0x0;
}

//_____________________________________________________________________________
Long_t AliRsnDaughter::GetPDG()
{
//
// Return the PDG code of the particle from MC ref (if any).
// If argument is kTRUE, returns its absolute value.
//

   if (Match(fRefMC, AliMCParticle::Class()))
      return ((AliMCParticle *)fRefMC)->Particle()->GetPdgCode();
   else if (Match(fRefMC, AliAODMCParticle::Class()))
      return ((AliAODMCParticle *)fRefMC)->GetPdgCode();
   else {
      AliWarning("Cannot retrieve PDG");
      return 0;
   }
}

//_____________________________________________________________________________
Int_t AliRsnDaughter::GetID()
{
//
// Return reference index, using the "GetID" method
// of the possible source object.
// When this method is unsuccessful (e.g.: V0s), return the label.
//

   // ESD tracks
   AliESDtrack *esd = Ref2ESDtrack();
   if (esd) return esd->GetID();

   // AOD tracks
   AliAODTrack *aod = Ref2AODtrack();
   if (aod) return aod->GetID();

   // whatever else
   return GetLabel();
}

//_____________________________________________________________________________
Int_t AliRsnDaughter::GetMother()
{
//
// Return index of the first mother of the MC reference, if any.
// Otherwise, returns -1 (the same as for primary tracks)
//

   if (!fRefMC) return -1;

   if (fRefMC->InheritsFrom(AliMCParticle::Class())) {
      AliMCParticle *mc = (AliMCParticle *)fRefMC;
      return mc->Particle()->GetFirstMother();
   } else if (fRefMC->InheritsFrom(AliAODMCParticle::Class())) {
      AliAODMCParticle *mc = (AliAODMCParticle *)fRefMC;
      return mc->GetMother();
   }
   else
      return -1;
}

//______________________________________________________________________________
void AliRsnDaughter::Print(Option_t *) const
{
//
// Override of TObject::Print()
//

   AliInfo("=== DAUGHTER INFO ======================================================================");
   AliInfo(Form(" (sim) px,py,pz = %6.2f %6.2f %6.2f", fPsim.X(), fPsim.Y(), fPsim.Z()));
   AliInfo(Form(" (rec) px,py,pz = %6.2f %6.2f %6.2f", fPrec.X(), fPrec.Y(), fPrec.Z()));
   AliInfo(Form(" OK, RsnID, Label, MotherPDG = %s, %5d, %5d, %4ld", (fOK ? "true " : "false"), fRsnID, fLabel, fMotherPDG));
   AliInfo("========================================================================================");
}

//______________________________________________________________________________
const char *AliRsnDaughter::SpeciesName(ESpecies species)
{
//
// Return a string with the short name of the particle
//

   switch (species) {
      case kElectron: return "E";
      case kMuon:     return "Mu";
      case kPion:     return "Pi";
      case kKaon:     return "K";
      case kProton:   return "P";
      case kKaon0:    return "K0s";
      case kLambda:   return "Lambda";
      case kXi:       return "Xi";
      case kOmega:    return "Omega";
      case kKstar0:   return "Kstar0";
      case kPhi:      return "Phi";
      case kLambdastar: return "Lambdastar";
      case kKstarpm:    return "Kstarpm";
      case kSigmastarp: return "Sigmastarp";
      case kSigmastarm: return "Sigmastarm";
      default:        return "Undef";
   }
}

//______________________________________________________________________________
Long_t AliRsnDaughter::SpeciesPDG(ESpecies species)
{
//
// Return the PDG code of a particle species (abs value)
//

   switch (species) {
      case kElectron: return 11;
      case kMuon:     return 13;
      case kPion:     return 211;
      case kKaon:     return 321;
      case kProton:   return 2212;
      case kKaon0:    return 311;
      case kLambda:   return 3122;
      case kXi:       return 3312;
      case kOmega:    return 3334;
      case kKstar0:   return 313;
      case kPhi:      return 333;
      case kLambdastar: return 3124;
      case kKstarpm:    return 323;
      case kSigmastarp: return 3224;
      case kSigmastarm: return 3114;
      default:        return 0;
   }
}

//______________________________________________________________________________
Double_t AliRsnDaughter::SpeciesMass(ESpecies species)
{
//
// Return the mass of a particle species
//

   TDatabasePDG *db = TDatabasePDG::Instance();
   TParticlePDG *part = 0x0;

   Long_t pdg = SpeciesPDG(species);
   if (pdg) {
      part = db->GetParticle(pdg);
      return part->Mass();
   }
   else
      return 0.0;
}

//______________________________________________________________________________
EPARTYPE AliRsnDaughter::ToAliPID(ESpecies species)
{
//
// Convert an enum element from this object
// into the enumeration of AliPID.
// If no match is found 'kUnknown' is returned.
//

   switch (species) {
      case kElectron: return AliPID::kElectron;
      case kMuon:     return AliPID::kMuon;
      case kPion:     return AliPID::kPion;
      case kKaon:     return AliPID::kKaon;
      case kProton:   return AliPID::kProton;
      case kKaon0:    return AliPID::kKaon0;
      default:        return AliPID::kUnknown;
   }
}

//______________________________________________________________________________
AliRsnDaughter::ESpecies AliRsnDaughter::FromAliPID(EPARTYPE pid)
{
//
// Convert an enum element from AliPID
// into the enumeration of this object.
// If no match is found 'kUnknown' is returned.
//

   switch (pid) {
      case AliPID::kElectron: return kElectron;
      case AliPID::kMuon:     return kMuon;
      case AliPID::kPion:     return kPion;
      case AliPID::kKaon:     return kKaon;
      case AliPID::kProton:   return kProton;
      case AliPID::kKaon0:    return kKaon0;
      default:                return kUnknown;
   }
}

//______________________________________________________________________________
Bool_t AliRsnDaughter::IsEquivalentPDGCode(Long_t i1, Long_t i2)
{
//
// Check to see if i1 and i2 are equal, with special treatment for K0.
//

   if(i1==i2) return kTRUE;
   if( (i1==130 || i1==310) && TMath::Abs(i2)==311) return kTRUE;
   if( (i2==130 || i2==310) && TMath::Abs(i1)==311) return kTRUE;
   return kFALSE;
}
<commit_msg>Apply new MC accessing method at AliRsnDaughter.cxx<commit_after>//
//  This class works as generic interface to each candidate resonance daughter.
//  Its main purpose is to provide a unique reference which includes all the
//  facilities available in the AliVParticle generic base class, plus all info
//  which could be needed during analysis, which are not in AliVParticle but
//  need to be accessed from ESD or AOD objects, usually in different ways.
//  When MC is available, AliRsnDaughter matches each reconstructed object with
//  its corresponding MC particle.
//
//  Currently, this interface can point to all kinds of single-particle object
//  which one can have in the reconstructed event: charged tracks, V0s and
//  cascades. It is care of the user to treat each of them in the correct way,
//  regarding cuts, functions to be computed, etc.
//
//  authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
//           M. Vala (martin.vala@cern.ch)
//

#include <TParticle.h>
#include <TDatabasePDG.h>

#include "AliRsnDaughter.h"

ClassImp(AliRsnDaughter)

//_____________________________________________________________________________
AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter &copy) :
   TObject(copy),
   fOK(copy.fOK),
   fLabel(copy.fLabel),
   fMotherPDG(copy.fMotherPDG),
   fRsnID(copy.fRsnID),
   fPrec(copy.fPrec),
   fPsim(copy.fPsim),
   fRef(copy.fRef),
   fRefMC(copy.fRefMC),
   fOwnerEvent(copy.fOwnerEvent)
{
//
// Copy constructor.
// Pointers are NOT duplicated, since they don't come from a 'new'
// statement, but from just referencing something in the data source.
//
}

//_____________________________________________________________________________
AliRsnDaughter &AliRsnDaughter::operator=(const AliRsnDaughter &copy)
{
//
// Assignment operator.
// Pointers are NOT duplicated, since they don't come from a 'new'
// statement, but from just referencing something in the data source.
//
   if (this == &copy)
      return *this;

   fOK         = copy.fOK;
   fLabel      = copy.fLabel;
   fMotherPDG  = copy.fMotherPDG;
   fRsnID      = copy.fRsnID;
   fPsim       = copy.fPsim;
   fPrec       = copy.fPrec;
   fRef        = copy.fRef;
   fRefMC      = copy.fRefMC;
   fOwnerEvent = copy.fOwnerEvent;

   return (*this);
}

//_____________________________________________________________________________
void AliRsnDaughter::Reset()
{
//
// Reset this track to meaningless values and to a 'bad' status.
// After this has been done, this object should not be used
// for analysis unless initialized properly.
//

   fOK        = kFALSE;
   fLabel     = -1;
   fMotherPDG =  0;
   fRsnID     = -1;

   fPsim.SetXYZT(0.0, 0.0, 0.0, 0.0);
   fPrec.SetXYZT(0.0, 0.0, 0.0, 0.0);

   fRef = fRefMC = 0x0;
   fOwnerEvent = 0x0;
}

//_____________________________________________________________________________
Long_t AliRsnDaughter::GetPDG()
{
//
// Return the PDG code of the particle from MC ref (if any).
// If argument is kTRUE, returns its absolute value.
//

   if (Match(fRefMC, AliMCParticle::Class()))
      return ((AliMCParticle *)fRefMC)->Particle()->GetPdgCode();
   else if (Match(fRefMC, AliAODMCParticle::Class()))
      return ((AliAODMCParticle *)fRefMC)->GetPdgCode();
   else {
      AliWarning("Cannot retrieve PDG");
      return 0;
   }
}

//_____________________________________________________________________________
Int_t AliRsnDaughter::GetID()
{
//
// Return reference index, using the "GetID" method
// of the possible source object.
// When this method is unsuccessful (e.g.: V0s), return the label.
//

   // ESD tracks
   AliESDtrack *esd = Ref2ESDtrack();
   if (esd) return esd->GetID();

   // AOD tracks
   AliAODTrack *aod = Ref2AODtrack();
   if (aod) return aod->GetID();

   // whatever else
   return GetLabel();
}

//_____________________________________________________________________________
Int_t AliRsnDaughter::GetMother()
{
//
// Return index of the first mother of the MC reference, if any.
// Otherwise, returns -1 (the same as for primary tracks)
//

   if (!fRefMC) return -1;

   if (fRefMC->InheritsFrom(AliMCParticle::Class())) {
      AliMCParticle *mc = (AliMCParticle *)fRefMC;
    //return mc->Particle()->GetFirstMother(); // Before Change in accessing MC infor in AliRoot v5-09-46
      return mc->GetMother();

   } else if (fRefMC->InheritsFrom(AliAODMCParticle::Class())) {
      AliAODMCParticle *mc = (AliAODMCParticle *)fRefMC;
      return mc->GetMother();
   }
   else
      return -1;
}

//______________________________________________________________________________
void AliRsnDaughter::Print(Option_t *) const
{
//
// Override of TObject::Print()
//

   AliInfo("=== DAUGHTER INFO ======================================================================");
   AliInfo(Form(" (sim) px,py,pz = %6.2f %6.2f %6.2f", fPsim.X(), fPsim.Y(), fPsim.Z()));
   AliInfo(Form(" (rec) px,py,pz = %6.2f %6.2f %6.2f", fPrec.X(), fPrec.Y(), fPrec.Z()));
   AliInfo(Form(" OK, RsnID, Label, MotherPDG = %s, %5d, %5d, %4ld", (fOK ? "true " : "false"), fRsnID, fLabel, fMotherPDG));
   AliInfo("========================================================================================");
}

//______________________________________________________________________________
const char *AliRsnDaughter::SpeciesName(ESpecies species)
{
//
// Return a string with the short name of the particle
//

   switch (species) {
      case kElectron: return "E";
      case kMuon:     return "Mu";
      case kPion:     return "Pi";
      case kKaon:     return "K";
      case kProton:   return "P";
      case kKaon0:    return "K0s";
      case kLambda:   return "Lambda";
      case kXi:       return "Xi";
      case kOmega:    return "Omega";
      case kKstar0:   return "Kstar0";
      case kPhi:      return "Phi";
      case kLambdastar: return "Lambdastar";
      case kKstarpm:    return "Kstarpm";
      case kSigmastarp: return "Sigmastarp";
      case kSigmastarm: return "Sigmastarm";
      default:        return "Undef";
   }
}

//______________________________________________________________________________
Long_t AliRsnDaughter::SpeciesPDG(ESpecies species)
{
//
// Return the PDG code of a particle species (abs value)
//

   switch (species) {
      case kElectron: return 11;
      case kMuon:     return 13;
      case kPion:     return 211;
      case kKaon:     return 321;
      case kProton:   return 2212;
      case kKaon0:    return 311;
      case kLambda:   return 3122;
      case kXi:       return 3312;
      case kOmega:    return 3334;
      case kKstar0:   return 313;
      case kPhi:      return 333;
      case kLambdastar: return 3124;
      case kKstarpm:    return 323;
      case kSigmastarp: return 3224;
      case kSigmastarm: return 3114;
      default:        return 0;
   }
}

//______________________________________________________________________________
Double_t AliRsnDaughter::SpeciesMass(ESpecies species)
{
//
// Return the mass of a particle species
//

   TDatabasePDG *db = TDatabasePDG::Instance();
   TParticlePDG *part = 0x0;

   Long_t pdg = SpeciesPDG(species);
   if (pdg) {
      part = db->GetParticle(pdg);
      return part->Mass();
   }
   else
      return 0.0;
}

//______________________________________________________________________________
EPARTYPE AliRsnDaughter::ToAliPID(ESpecies species)
{
//
// Convert an enum element from this object
// into the enumeration of AliPID.
// If no match is found 'kUnknown' is returned.
//

   switch (species) {
      case kElectron: return AliPID::kElectron;
      case kMuon:     return AliPID::kMuon;
      case kPion:     return AliPID::kPion;
      case kKaon:     return AliPID::kKaon;
      case kProton:   return AliPID::kProton;
      case kKaon0:    return AliPID::kKaon0;
      default:        return AliPID::kUnknown;
   }
}

//______________________________________________________________________________
AliRsnDaughter::ESpecies AliRsnDaughter::FromAliPID(EPARTYPE pid)
{
//
// Convert an enum element from AliPID
// into the enumeration of this object.
// If no match is found 'kUnknown' is returned.
//

   switch (pid) {
      case AliPID::kElectron: return kElectron;
      case AliPID::kMuon:     return kMuon;
      case AliPID::kPion:     return kPion;
      case AliPID::kKaon:     return kKaon;
      case AliPID::kProton:   return kProton;
      case AliPID::kKaon0:    return kKaon0;
      default:                return kUnknown;
   }
}

//______________________________________________________________________________
Bool_t AliRsnDaughter::IsEquivalentPDGCode(Long_t i1, Long_t i2)
{
//
// Check to see if i1 and i2 are equal, with special treatment for K0.
//

   if(i1==i2) return kTRUE;
   if( (i1==130 || i1==310) && TMath::Abs(i2)==311) return kTRUE;
   if( (i2==130 || i2==310) && TMath::Abs(i1)==311) return kTRUE;
   return kFALSE;
}
<|endoftext|>


<commit_before>/**
 * @mainpage Birch Developer Reference
 *
 * Birch is a compiled, imperative, object-oriented, and probabilistic
 * programming language. The latter is its primary research concern.
 *
 * It consists of three components:
 *
 * @li the @c birch driver program,
 * @li the @c birchc compiler program, and
 * @li the @c libbirch.* compiler library and associated header files.
 *
 * This documentation relates to these components and is only of
 * interest to @em developers of the above; @em users will be more
 * interested in the standard library, documented separately.
 *
 * The @em Modules page is a good place to start.
 *
 * @defgroup driver Driver program
 *
 * @defgroup compiler Compiler program
 * @defgroup compiler_common Common
 * @ingroup compiler
 * @defgroup compiler_expression Expressions
 * @ingroup compiler
 * @defgroup compiler_statement Statements
 * @ingroup compiler
 * @defgroup compiler_type Types
 * @ingroup compiler
 * @defgroup compiler_io Code generation
 * @ingroup compiler
 * @defgroup compiler_visitor Visitors
 * @ingroup compiler
 * @defgroup compiler_exception Exceptions
 * @ingroup compiler
 *
 * @defgroup library Compiler library
 */
<commit_msg>Removed birchc mention from main page of doxygen docs.<commit_after>/**
 * @mainpage Birch Developer Reference
 *
 * Birch is a compiled, imperative, object-oriented, and probabilistic
 * programming language. The latter is its primary research concern.
 *
 * It consists of:
 *
 * @li the @c birch driver program, and
 * @li the @c libbirch.* compiler library and associated header files.
 *
 * This documentation relates to these components and is only of
 * interest to @em developers of the above; @em users will be more
 * interested in the standard library, documented separately.
 *
 * The @em Modules page is a good place to start.
 *
 * @defgroup driver Driver
 * @defgroup library Library
 * @defgroup compiler Compiler
 * @defgroup compiler_common Common
 * @ingroup compiler
 * @defgroup compiler_expression Expressions
 * @ingroup compiler
 * @defgroup compiler_statement Statements
 * @ingroup compiler
 * @defgroup compiler_type Types
 * @ingroup compiler
 * @defgroup compiler_io Code generation
 * @ingroup compiler
 * @defgroup compiler_visitor Visitors
 * @ingroup compiler
 * @defgroup compiler_exception Exceptions
 * @ingroup compiler
 */
<|endoftext|>