<commit_before>/*
 Flexisip, a flexible SIP proxy server with media capabilities.
 Copyright (C) 2018 Belledonne Communications SARL.

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "participant-registration-subscription.hh"

using namespace flexisip;
using namespace std;

ParticipantRegistrationSubscription::ParticipantRegistrationSubscription (
	const shared_ptr<const linphone::Address> &address,
	const shared_ptr<linphone::ChatRoom> &chatRoom
) : mParticipantAddress(address), mChatRoom(chatRoom) {}

void ParticipantRegistrationSubscription::onContactRegistered (const string &key, const string &uid) {
	url_t *url = url_make(mHome.home(), mParticipantAddress->asStringUriOnly().c_str());
	RegistrarDb::get()->fetchForGruu(url, uid, shared_from_this());
}

void ParticipantRegistrationSubscription::onRecordFound (Record *r) {
	if (!r)
		return;

	for (const shared_ptr<ExtendedContact> &ec : r->getExtendedContacts()) {
		string uri = ExtendedContact::urlToString(ec->mSipContact->m_url);
		shared_ptr<linphone::Address> addr = linphone::Factory::get()->createAddress(uri);
		if (!addr->getUriParam("gr").empty()
			&& (ec->getOrgLinphoneSpecs().find("groupchat") != string::npos)
		) {
			shared_ptr<linphone::Address> deviceAddress = mParticipantAddress->clone();
			deviceAddress->setUriParam("gr", addr->getUriParam("gr"));
			SLOGI << "Notify registration of " << deviceAddress->asString() << " to chatroom " << mChatRoom->getLocalAddress()->asString();
			mChatRoom->addParticipantDevice(mParticipantAddress, deviceAddress);
		}
	}
}
<commit_msg>Always give the full list of devices to the chatroom when a device gets registered.<commit_after>/*
 Flexisip, a flexible SIP proxy server with media capabilities.
 Copyright (C) 2018 Belledonne Communications SARL.

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "participant-registration-subscription.hh"

using namespace flexisip;
using namespace std;

ParticipantRegistrationSubscription::ParticipantRegistrationSubscription (
	const shared_ptr<const linphone::Address> &address,
	const shared_ptr<linphone::ChatRoom> &chatRoom
) : mParticipantAddress(address), mChatRoom(chatRoom) {}

void ParticipantRegistrationSubscription::onContactRegistered (const string &key, const string &uid) {
	url_t *url = url_make(mHome.home(), mParticipantAddress->asStringUriOnly().c_str());
	RegistrarDb::get()->fetch(url, shared_from_this());
}

void ParticipantRegistrationSubscription::onRecordFound (Record *r) {
	if (!r)
		return;

	list<shared_ptr<linphone::Address>> listDevices;
	for (const shared_ptr<ExtendedContact> &ec : r->getExtendedContacts()) {
		string uri = ExtendedContact::urlToString(ec->mSipContact->m_url);
		shared_ptr<linphone::Address> addr = linphone::Factory::get()->createAddress(uri);
		if (!addr->getUriParam("gr").empty()
			&& (ec->getOrgLinphoneSpecs().find("groupchat") != string::npos)
		) {
			shared_ptr<linphone::Address> deviceAddress = mParticipantAddress->clone();
			deviceAddress->setUriParam("gr", addr->getUriParam("gr"));
			listDevices.push_back(deviceAddress);
			SLOGI << "Notify registration of " << deviceAddress->asString() << " to chatroom " << mChatRoom->getLocalAddress()->asString();
		}
	}

	mChatRoom->setParticipantDevices(mParticipantAddress, listDevices);
}
<|endoftext|>


<commit_before><commit_msg>Simplify code and correct the erroneous length parameter for "macro:///" and align text<commit_after><|endoftext|>


<commit_before>/****************************************************************/
/*               DO NOT MODIFY THIS HEADER                      */
/* MOOSE - Multiphysics Object Oriented Simulation Environment  */
/*                                                              */
/*           (c) 2010 Battelle Energy Alliance, LLC             */
/*                   ALL RIGHTS RESERVED                        */
/*                                                              */
/*          Prepared by Battelle Energy Alliance, LLC           */
/*            Under Contract No. DE-AC07-05ID14517              */
/*            With the U. S. Department of Energy               */
/*                                                              */
/*            See COPYRIGHT for full restrictions               */
/****************************************************************/

#include "PointSamplerBase.h"

template<>
InputParameters validParams<PointSamplerBase>()
{
  InputParameters params = validParams<GeneralVectorPostprocessor>();

  params += validParams<SamplerBase>();

  params.addRequiredCoupledVar("variable", "The names of the variables that this VectorPostprocessor operates on");

  return params;
}

PointSamplerBase::PointSamplerBase(const std::string & name, InputParameters parameters) :
    GeneralVectorPostprocessor(name, parameters),
    CoupleableMooseVariableDependencyIntermediateInterface(parameters, false),
    SamplerBase(name, parameters, this, _communicator),
    _mesh(_subproblem.mesh()),
    _point_vec(1) // Only going to evaluate one point at a time for now
{
  std::vector<std::string> var_names(_coupled_moose_vars.size());
  _values.resize(_coupled_moose_vars.size());

  for (unsigned int i=0; i<_coupled_moose_vars.size(); i++)
    var_names[i] = _coupled_moose_vars[i]->name();

  // Initialize the datastructions in SamplerBase
  SamplerBase::setupVariables(var_names);
}

void
PointSamplerBase::initialize()
{
  SamplerBase::initialize();

  // We do this here just in case it's been destroyed and recreated becaue of mesh adaptivity.
  _pl = _mesh.getMesh().sub_point_locator();
}

void
PointSamplerBase::execute()
{
  for (unsigned int i=0; i<_points.size(); i++)
  {
    Point & p = _points[i];

    // First find the element the hit lands in
    const Elem * elem = getLocalElemContainingPoint(p, i);

    // We have to pass a vector of points into reinitElemPhys
    _point_vec[0] = p;

    if (elem)
    {
      _subproblem.reinitElemPhys(elem, _point_vec, 0); // Zero is for tid

      for (unsigned int i=0; i<_coupled_moose_vars.size(); i++)
        _values[i] = _coupled_moose_vars[i]->sln()[0]; // The zero is for the "qp"

      SamplerBase::addSample(p, _ids[i], _values);
    }
  }
}

void
PointSamplerBase::finalize()
{
  SamplerBase::finalize();
}

void
PointSamplerBase::threadJoin(const UserObject & y)
{
  const PointSamplerBase & vpp = static_cast<const PointSamplerBase &>(y);

  SamplerBase::threadJoin(vpp);
}

const Elem *
PointSamplerBase::getLocalElemContainingPoint(const Point & p, unsigned int id)
{
  const Elem * elem = (*_pl)(p);

  if (elem && elem->processor_id() == processor_id())
    return elem;

  return NULL;
}
<commit_msg>Fixing variable shadowing warning.<commit_after>/****************************************************************/
/*               DO NOT MODIFY THIS HEADER                      */
/* MOOSE - Multiphysics Object Oriented Simulation Environment  */
/*                                                              */
/*           (c) 2010 Battelle Energy Alliance, LLC             */
/*                   ALL RIGHTS RESERVED                        */
/*                                                              */
/*          Prepared by Battelle Energy Alliance, LLC           */
/*            Under Contract No. DE-AC07-05ID14517              */
/*            With the U. S. Department of Energy               */
/*                                                              */
/*            See COPYRIGHT for full restrictions               */
/****************************************************************/

#include "PointSamplerBase.h"

template<>
InputParameters validParams<PointSamplerBase>()
{
  InputParameters params = validParams<GeneralVectorPostprocessor>();

  params += validParams<SamplerBase>();

  params.addRequiredCoupledVar("variable", "The names of the variables that this VectorPostprocessor operates on");

  return params;
}

PointSamplerBase::PointSamplerBase(const std::string & name, InputParameters parameters) :
    GeneralVectorPostprocessor(name, parameters),
    CoupleableMooseVariableDependencyIntermediateInterface(parameters, false),
    SamplerBase(name, parameters, this, _communicator),
    _mesh(_subproblem.mesh()),
    _point_vec(1) // Only going to evaluate one point at a time for now
{
  std::vector<std::string> var_names(_coupled_moose_vars.size());
  _values.resize(_coupled_moose_vars.size());

  for (unsigned int i=0; i<_coupled_moose_vars.size(); i++)
    var_names[i] = _coupled_moose_vars[i]->name();

  // Initialize the datastructions in SamplerBase
  SamplerBase::setupVariables(var_names);
}

void
PointSamplerBase::initialize()
{
  SamplerBase::initialize();

  // We do this here just in case it's been destroyed and recreated becaue of mesh adaptivity.
  _pl = _mesh.getMesh().sub_point_locator();
}

void
PointSamplerBase::execute()
{
  for (unsigned int i=0; i<_points.size(); i++)
  {
    Point & p = _points[i];

    // First find the element the hit lands in
    const Elem * elem = getLocalElemContainingPoint(p, i);

    // We have to pass a vector of points into reinitElemPhys
    _point_vec[0] = p;

    if (elem)
    {
      _subproblem.reinitElemPhys(elem, _point_vec, 0); // Zero is for tid

      for (unsigned int j=0; j<_coupled_moose_vars.size(); j++)
        _values[j] = _coupled_moose_vars[j]->sln()[0]; // The zero is for the "qp"

      SamplerBase::addSample(p, _ids[i], _values);
    }
  }
}

void
PointSamplerBase::finalize()
{
  SamplerBase::finalize();
}

void
PointSamplerBase::threadJoin(const UserObject & y)
{
  const PointSamplerBase & vpp = static_cast<const PointSamplerBase &>(y);

  SamplerBase::threadJoin(vpp);
}

const Elem *
PointSamplerBase::getLocalElemContainingPoint(const Point & p, unsigned int id)
{
  const Elem * elem = (*_pl)(p);

  if (elem && elem->processor_id() == processor_id())
    return elem;

  return NULL;
}
<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkIdentColoredPainter.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkIdentColoredPainter.h"

#include "vtkActor.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkConfigure.h"
#include "vtkDataArray.h"
#include "vtkObjectFactory.h"
#include "vtkPainterDeviceAdapter.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkPolygon.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkTimerLog.h"
#include "vtkTriangle.h"
#include "vtkIdTypeArray.h"

#ifndef VTK_IMPLEMENT_MESA_CXX
#  include "vtkOpenGL.h"
#endif

//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkIdentColoredPainter, "1.14");
vtkStandardNewMacro(vtkIdentColoredPainter);

//-----------------------------------------------------------------------------
static inline int vtkIdentColoredPainterGetTotalCells(vtkPolyData* pd,
  unsigned long typeflags)
{
  int total_cells = 0;
  total_cells += (typeflags & vtkPainter::LINES)?
    pd->GetNumberOfLines() : 0;
  total_cells += (typeflags & vtkPainter::POLYS)?
    pd->GetNumberOfPolys() : 0;
  total_cells += (typeflags & vtkPainter::STRIPS)?
    pd->GetNumberOfStrips() : 0;
  return total_cells;
}

//-----------------------------------------------------------------------------
vtkIdentColoredPainter::vtkIdentColoredPainter()
{
  this->ColorMode = COLORBYIDENT;
  this->ResetCurrentId();

  this->ActorIds = NULL;
  this->PropAddrs = NULL;
}

//-----------------------------------------------------------------------------
vtkIdentColoredPainter::~vtkIdentColoredPainter()
{
  if (this->ActorIds != NULL)
    {
    this->ActorIds->Delete();
    this->ActorIds = NULL;
    delete[] this->PropAddrs;
    this->PropAddrs = NULL;
    }
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::ColorByConstant(unsigned int constant)
{
  this->ColorMode = COLORBYCONST;
  this->ResetCurrentId();
  this->CurrentIdPlane0 = constant;
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::MakeActorLookupTable(vtkProp **props, vtkIdTypeArray *ids)
{
  //free whatever we were given before this
  if (this->ActorIds != NULL)
    {
    this->ActorIds->Delete();
    this->ActorIds = NULL;
    delete[] this->PropAddrs;
    this->PropAddrs = NULL;
    }

  //sanity checking
  if (props == NULL ||
      ids == NULL ||
      (ids->GetNumberOfComponents() != 1) ||
      (ids->GetNumberOfTuples() == 0))
    {
    vtkWarningMacro("Invalid actor-id lookup table supplied.");
    return;
    }

  //copy over the new lookup table
  this->ActorIds = ids;
  this->ActorIds->Register(this);
  this->PropAddrs = new vtkProp*[ids->GetNumberOfTuples()];
  for (int i = 0; i < ids->GetNumberOfTuples(); i++)
    {
    this->PropAddrs[i] = props[i];
    }
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::ColorByActorId(vtkProp *actorAddr)
{
  this->ColorMode = COLORBYCONST;
  this->ResetCurrentId();

  vtkIdType maxId = 0;
  int numIds = 0;
  if (this->ActorIds != NULL)
    {
    numIds = this->ActorIds->GetNumberOfTuples();
    for (int i = 0; i< numIds; i++)
      {
      vtkIdType nextId = this->ActorIds->GetValue(i);
      if (actorAddr == this->PropAddrs[i])
        {
        this->CurrentIdPlane0 = nextId + 1;
        return;
        }
      if (nextId > maxId)
        {
        maxId = nextId;
        }
      }
    }

  //we didn't find the actor in the table, make up an ID and add it
  //cerr << "ID not found for actor " << actorAddr
  //     << " using " << maxId+1 << endl;
  vtkIdTypeArray *arr = vtkIdTypeArray::New();
  arr->SetNumberOfComponents(1);
  arr->SetNumberOfTuples(numIds+1);
  vtkProp **SaveProps = new vtkProp*[numIds+1];
  if (this->ActorIds != NULL)
    {
    for (int i = 0; i< numIds; i++)
      {
      arr->SetValue(i, this->ActorIds->GetValue(i));
      SaveProps[i] = this->PropAddrs[i];
      }
    }
  arr->SetValue(numIds, maxId+1);
  SaveProps[numIds] = actorAddr;
  this->MakeActorLookupTable(SaveProps, arr);
  arr->Delete();

  this->CurrentIdPlane0 = maxId+1;
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::ColorByIncreasingIdent(unsigned int plane)
{
  this->ColorMode = COLORBYIDENT;
  this->Plane = (plane < 3)?plane:2;
  this->ResetCurrentId();
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::ResetCurrentId()
{
  //do not use 0, it is reserved for miss
  this->CurrentIdPlane0 = 1;
  this->CurrentIdPlane1 = 1;
  this->CurrentIdPlane2 = 1;
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::IncrementCurrentId()
{
  if (this->ColorMode == COLORBYCONST)
    {
    return;
    }

  //the limits are set up assuming 24 bits total for each for RGB pixel
  //do not use A because the parallel compositing code does not support Alpha
  this->CurrentIdPlane0++;
  if (this->CurrentIdPlane0 >= 0x01000000)
    {
    this->CurrentIdPlane0 = 0x00000001;
    this->CurrentIdPlane1++;
    if (this->CurrentIdPlane1 >= 0x01000000)
      {
      this->CurrentIdPlane1 = 0x00000001;
      this->CurrentIdPlane2++;
      }
    }
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::GetCurrentColor(unsigned char *RGB)
{
  unsigned int val = this->CurrentIdPlane0;
  if (this->ColorMode == COLORBYIDENT)
    {
    if (this->Plane == 1)
      {
      val = this->CurrentIdPlane1;
      }
    else if (this->Plane == 2)
      {
      val = this->CurrentIdPlane2;
      }
    }

  //cerr << "Curr Color is "
  //     << this->ColorMode << " "
  //     << this->CurrentIdPlane2 << ":"
  //     << this->CurrentIdPlane1 << ":"
  //     << this->CurrentIdPlane0 << endl;

  RGB[0] = (val & 0x00FF0000)>>16;
  RGB[1] = (val & 0x0000FF00)>>8;
  RGB[2] = (val & 0x000000FF);
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::RenderInternal(vtkRenderer* renderer,
                                            vtkActor* actor,
                                            unsigned long typeflags)
{
  if (typeflags == 0)
    {
    // No primitive to render.
    return;
    }

  vtkPainterDeviceAdapter* device = renderer->GetRenderWindow()->
    GetPainterDeviceAdapter();

  if (!device)
    {
    vtkErrorMacro("Painter Device Adapter missing!");
    return;
    }

  this->TotalCells =
    vtkIdentColoredPainterGetTotalCells(this->PolyData, typeflags);

  this->Timer->StartTimer();

  //turn off antialising and lighting so that the colors we draw will be the
  //colors we read back
  int origMultisample = device->QueryMultisampling();
  int origLighting = device->QueryLighting();
  int origBlending = device->QueryBlending();

  device->MakeMultisampling(0);
  device->MakeLighting(0);
  device->MakeBlending(0);

  vtkIdType startCell = 0;
  startCell += this->PolyData->GetNumberOfVerts();

  if (typeflags & vtkPainter::LINES)
    {
    this->DrawCells(VTK_POLY_LINE, this->PolyData->GetLines(), startCell,
      renderer);
    }
  startCell += this->PolyData->GetNumberOfLines();

  if (typeflags & vtkPainter::POLYS)
    {
#if defined(__APPLE__) && (defined(VTK_USE_CARBON) || defined(VTK_USE_COCOA))
    if (actor->GetProperty()->GetRepresentation() == VTK_WIREFRAME)
      {
      this->DrawCells(VTK_TETRA, this->PolyData->GetPolys(), startCell,
        renderer);
      }
    else
#endif
      {
      this->DrawCells(VTK_POLYGON, this->PolyData->GetPolys(), startCell,
        renderer);
      }
    }

  startCell += this->PolyData->GetNumberOfPolys();
  if (typeflags & vtkPainter::STRIPS)
    {
    this->DrawCells(VTK_TRIANGLE_STRIP, this->PolyData->GetStrips(), startCell,
      renderer);
    }

  //reset lighting back to the default
  device->MakeBlending(origBlending);
  device->MakeLighting(origLighting);
  device->MakeMultisampling(origMultisample);

  this->Timer->StopTimer();
  this->TimeToDraw = this->Timer->GetElapsedTime();

  // let the superclass pass on the request to delegate painter.
  // Ofcouse, more than likely, this call will never have a delegate,
  // but anyways.
  this->Superclass::RenderInternal(renderer, actor, typeflags);
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::DrawCells(int mode, vtkCellArray *connectivity,
                                       vtkIdType startCellId,
                                       vtkRenderer *renderer)
{
  if (!this->PolyData)
    {
    vtkWarningMacro("No polydata to render!");
    return;
    }

  vtkPainterDeviceAdapter* device = renderer->GetRenderWindow()->
    GetPainterDeviceAdapter();

  vtkPoints* p = this->PolyData->GetPoints();
  vtkIdType npts, *pts;
  vtkIdType cellId = startCellId;

  int pointtype = p->GetDataType();
  void* voidpoints = p->GetVoidPointer(0);
  int count = 0;

  unsigned char color[3];
  for (connectivity->InitTraversal(); connectivity->GetNextCell(npts, pts); count++)
    {
    device->BeginPrimitive(mode);

    // fieldColors are same as cell colors except when rendering
    // VTK_TRIANGLE_STRIP, when they represent triangle colors.
    this->GetCurrentColor(color);

    device->SendAttribute(vtkCellData::SCALARS, 3, VTK_UNSIGNED_CHAR, color);

    this->IncrementCurrentId();

    for (vtkIdType cellpointi = 0; cellpointi < npts; cellpointi++)
      {
      vtkIdType pointId = pts[cellpointi];
      // If using field colors, then we must send triangle colors,
      // if rendering triangle strips.
      if (mode == VTK_TRIANGLE_STRIP && cellpointi > 2)
        {
        this->GetCurrentColor(color);

        device->SendAttribute(vtkCellData::SCALARS, 3, VTK_UNSIGNED_CHAR, color);

        this->IncrementCurrentId();
        }

      // Send the point position as the last attribute.
      // TODO: how to mark that point position is being sent? since,
      // vtkDataSetAttributes doesn't define point positions and hence has
      // no enum for that. For now, vtkPointData::NUM_ATTRIBUTES marks
      // point positions.
      device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
        pointtype, voidpoints, 3*pointId);
      }
    device->EndPrimitive();

    cellId++;

    if (count == 10000)
      {
      count = 0;
      // report progress
      this->UpdateProgress(static_cast<double>(cellId - startCellId)/this->TotalCells);
      // Abort render.
      if (renderer->GetRenderWindow()->CheckAbortStatus())
        {
        return;
        }
      }
    }
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}
<commit_msg>BUG: Make ident colored painter draw VERTICES. This allows them to be selected and makes sure that the vtkOriginalCellIds array matches the rendered id numbers of each cell. Fixes bug # 4733.<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkIdentColoredPainter.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkIdentColoredPainter.h"

#include "vtkActor.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkConfigure.h"
#include "vtkDataArray.h"
#include "vtkObjectFactory.h"
#include "vtkPainterDeviceAdapter.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkPolygon.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkTimerLog.h"
#include "vtkTriangle.h"
#include "vtkIdTypeArray.h"

#ifndef VTK_IMPLEMENT_MESA_CXX
#  include "vtkOpenGL.h"
#endif

//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkIdentColoredPainter, "1.15");
vtkStandardNewMacro(vtkIdentColoredPainter);

//-----------------------------------------------------------------------------
static inline int vtkIdentColoredPainterGetTotalCells(vtkPolyData* pd,
  unsigned long typeflags)
{
  int total_cells = 0;
  total_cells += (typeflags & vtkPainter::VERTS)?
    pd->GetNumberOfVerts() : 0;
  total_cells += (typeflags & vtkPainter::LINES)?
    pd->GetNumberOfLines() : 0;
  total_cells += (typeflags & vtkPainter::POLYS)?
    pd->GetNumberOfPolys() : 0;
  total_cells += (typeflags & vtkPainter::STRIPS)?
    pd->GetNumberOfStrips() : 0;
  return total_cells;
}

//-----------------------------------------------------------------------------
vtkIdentColoredPainter::vtkIdentColoredPainter()
{
  this->ColorMode = COLORBYIDENT;
  this->ResetCurrentId();

  this->ActorIds = NULL;
  this->PropAddrs = NULL;
}

//-----------------------------------------------------------------------------
vtkIdentColoredPainter::~vtkIdentColoredPainter()
{
  if (this->ActorIds != NULL)
    {
    this->ActorIds->Delete();
    this->ActorIds = NULL;
    delete[] this->PropAddrs;
    this->PropAddrs = NULL;
    }
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::ColorByConstant(unsigned int constant)
{
  this->ColorMode = COLORBYCONST;
  this->ResetCurrentId();
  this->CurrentIdPlane0 = constant;
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::MakeActorLookupTable(vtkProp **props, vtkIdTypeArray *ids)
{
  //free whatever we were given before this
  if (this->ActorIds != NULL)
    {
    this->ActorIds->Delete();
    this->ActorIds = NULL;
    delete[] this->PropAddrs;
    this->PropAddrs = NULL;
    }

  //sanity checking
  if (props == NULL ||
      ids == NULL ||
      (ids->GetNumberOfComponents() != 1) ||
      (ids->GetNumberOfTuples() == 0))
    {
    vtkWarningMacro("Invalid actor-id lookup table supplied.");
    return;
    }

  //copy over the new lookup table
  this->ActorIds = ids;
  this->ActorIds->Register(this);
  this->PropAddrs = new vtkProp*[ids->GetNumberOfTuples()];
  for (int i = 0; i < ids->GetNumberOfTuples(); i++)
    {
    this->PropAddrs[i] = props[i];
    }
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::ColorByActorId(vtkProp *actorAddr)
{
  this->ColorMode = COLORBYCONST;
  this->ResetCurrentId();

  vtkIdType maxId = 0;
  int numIds = 0;
  if (this->ActorIds != NULL)
    {
    numIds = this->ActorIds->GetNumberOfTuples();
    for (int i = 0; i< numIds; i++)
      {
      vtkIdType nextId = this->ActorIds->GetValue(i);
      if (actorAddr == this->PropAddrs[i])
        {
        this->CurrentIdPlane0 = nextId + 1;
        return;
        }
      if (nextId > maxId)
        {
        maxId = nextId;
        }
      }
    }

  //we didn't find the actor in the table, make up an ID and add it
  //cerr << "ID not found for actor " << actorAddr
  //     << " using " << maxId+1 << endl;
  vtkIdTypeArray *arr = vtkIdTypeArray::New();
  arr->SetNumberOfComponents(1);
  arr->SetNumberOfTuples(numIds+1);
  vtkProp **SaveProps = new vtkProp*[numIds+1];
  if (this->ActorIds != NULL)
    {
    for (int i = 0; i< numIds; i++)
      {
      arr->SetValue(i, this->ActorIds->GetValue(i));
      SaveProps[i] = this->PropAddrs[i];
      }
    }
  arr->SetValue(numIds, maxId+1);
  SaveProps[numIds] = actorAddr;
  this->MakeActorLookupTable(SaveProps, arr);
  arr->Delete();

  this->CurrentIdPlane0 = maxId+1;
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::ColorByIncreasingIdent(unsigned int plane)
{
  this->ColorMode = COLORBYIDENT;
  this->Plane = (plane < 3)?plane:2;
  this->ResetCurrentId();
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::ResetCurrentId()
{
  //do not use 0, it is reserved for miss
  this->CurrentIdPlane0 = 1;
  this->CurrentIdPlane1 = 1;
  this->CurrentIdPlane2 = 1;
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::IncrementCurrentId()
{
  if (this->ColorMode == COLORBYCONST)
    {
    return;
    }

  //the limits are set up assuming 24 bits total for each for RGB pixel
  //do not use A because the parallel compositing code does not support Alpha
  this->CurrentIdPlane0++;
  if (this->CurrentIdPlane0 >= 0x01000000)
    {
    this->CurrentIdPlane0 = 0x00000001;
    this->CurrentIdPlane1++;
    if (this->CurrentIdPlane1 >= 0x01000000)
      {
      this->CurrentIdPlane1 = 0x00000001;
      this->CurrentIdPlane2++;
      }
    }
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::GetCurrentColor(unsigned char *RGB)
{
  unsigned int val = this->CurrentIdPlane0;
  if (this->ColorMode == COLORBYIDENT)
    {
    if (this->Plane == 1)
      {
      val = this->CurrentIdPlane1;
      }
    else if (this->Plane == 2)
      {
      val = this->CurrentIdPlane2;
      }
    }

  //cerr << "Curr Color is "
  //     << this->ColorMode << " "
  //     << this->CurrentIdPlane2 << ":"
  //     << this->CurrentIdPlane1 << ":"
  //     << this->CurrentIdPlane0 << endl;

  RGB[0] = (val & 0x00FF0000)>>16;
  RGB[1] = (val & 0x0000FF00)>>8;
  RGB[2] = (val & 0x000000FF);
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::RenderInternal(vtkRenderer* renderer,
                                            vtkActor* actor,
                                            unsigned long typeflags)
{
  if (typeflags == 0)
    {
    // No primitive to render.
    return;
    }

  vtkPainterDeviceAdapter* device = renderer->GetRenderWindow()->
    GetPainterDeviceAdapter();

  if (!device)
    {
    vtkErrorMacro("Painter Device Adapter missing!");
    return;
    }

  this->TotalCells =
    vtkIdentColoredPainterGetTotalCells(this->PolyData, typeflags);

  this->Timer->StartTimer();

  //turn off antialising and lighting so that the colors we draw will be the
  //colors we read back
  int origMultisample = device->QueryMultisampling();
  int origLighting = device->QueryLighting();
  int origBlending = device->QueryBlending();

  device->MakeMultisampling(0);
  device->MakeLighting(0);
  device->MakeBlending(0);

  vtkIdType startCell = 0;
  if (typeflags & vtkPainter::VERTS)
    {
    this->DrawCells(VTK_POLY_VERTEX, this->PolyData->GetVerts(), startCell,
      renderer);
    }
  startCell += this->PolyData->GetNumberOfVerts();

  if (typeflags & vtkPainter::LINES)
    {
    this->DrawCells(VTK_POLY_LINE, this->PolyData->GetLines(), startCell,
      renderer);
    }
  startCell += this->PolyData->GetNumberOfLines();

  if (typeflags & vtkPainter::POLYS)
    {
#if defined(__APPLE__) && (defined(VTK_USE_CARBON) || defined(VTK_USE_COCOA))
    if (actor->GetProperty()->GetRepresentation() == VTK_WIREFRAME)
      {
      this->DrawCells(VTK_TETRA, this->PolyData->GetPolys(), startCell,
        renderer);
      }
    else
#endif
      {
      this->DrawCells(VTK_POLYGON, this->PolyData->GetPolys(), startCell,
        renderer);
      }
    }

  startCell += this->PolyData->GetNumberOfPolys();
  if (typeflags & vtkPainter::STRIPS)
    {
    this->DrawCells(VTK_TRIANGLE_STRIP, this->PolyData->GetStrips(), startCell,
      renderer);
    }

  //reset lighting back to the default
  device->MakeBlending(origBlending);
  device->MakeLighting(origLighting);
  device->MakeMultisampling(origMultisample);

  this->Timer->StopTimer();
  this->TimeToDraw = this->Timer->GetElapsedTime();

  // let the superclass pass on the request to delegate painter.
  // Ofcouse, more than likely, this call will never have a delegate,
  // but anyways.
  this->Superclass::RenderInternal(renderer, actor, typeflags);
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::DrawCells(int mode, vtkCellArray *connectivity,
                                       vtkIdType startCellId,
                                       vtkRenderer *renderer)
{
  if (!this->PolyData)
    {
    vtkWarningMacro("No polydata to render!");
    return;
    }

  vtkPainterDeviceAdapter* device = renderer->GetRenderWindow()->
    GetPainterDeviceAdapter();

  vtkPoints* p = this->PolyData->GetPoints();
  vtkIdType npts, *pts;
  vtkIdType cellId = startCellId;

  int pointtype = p->GetDataType();
  void* voidpoints = p->GetVoidPointer(0);
  int count = 0;

  unsigned char color[3];
  for (connectivity->InitTraversal(); connectivity->GetNextCell(npts, pts); count++)
    {
    device->BeginPrimitive(mode);

    // fieldColors are same as cell colors except when rendering
    // VTK_TRIANGLE_STRIP, when they represent triangle colors.
    this->GetCurrentColor(color);

    device->SendAttribute(vtkCellData::SCALARS, 3, VTK_UNSIGNED_CHAR, color);

    this->IncrementCurrentId();

    for (vtkIdType cellpointi = 0; cellpointi < npts; cellpointi++)
      {
      vtkIdType pointId = pts[cellpointi];
      // If using field colors, then we must send triangle colors,
      // if rendering triangle strips.
      if (mode == VTK_TRIANGLE_STRIP && cellpointi > 2)
        {
        this->GetCurrentColor(color);

        device->SendAttribute(vtkCellData::SCALARS, 3, VTK_UNSIGNED_CHAR, color);

        this->IncrementCurrentId();
        }

      // Send the point position as the last attribute.
      // TODO: how to mark that point position is being sent? since,
      // vtkDataSetAttributes doesn't define point positions and hence has
      // no enum for that. For now, vtkPointData::NUM_ATTRIBUTES marks
      // point positions.
      device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
        pointtype, voidpoints, 3*pointId);
      }
    device->EndPrimitive();

    cellId++;

    if (count == 10000)
      {
      count = 0;
      // report progress
      this->UpdateProgress(static_cast<double>(cellId - startCellId)/this->TotalCells);
      // Abort render.
      if (renderer->GetRenderWindow()->CheckAbortStatus())
        {
        return;
        }
      }
    }
}

//-----------------------------------------------------------------------------
void vtkIdentColoredPainter::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}
<|endoftext|>


<commit_before>/*
 *  Copyright (c) 2004-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */
#include "fboss/lib/usb/WedgeI2CBus.h"

#include "fboss/lib/usb/UsbError.h"

using folly::MutableByteRange;
using std::lock_guard;

namespace facebook { namespace fboss {

WedgeI2CBus::WedgeI2CBus() {
}

void WedgeI2CBus::initBus() {
  dev_.writeByte(ADDR_SWITCH_1, 0);
  dev_.writeByte(ADDR_SWITCH_2, 0);
}

void WedgeI2CBus::verifyBus(bool autoReset) {
  // Make sure the I2C bus is functioning, and reset the CP2112 device if not.
  //
  // Immediately after wedge is powered on, the CP2112 device appears to be in
  // a state where all I2C operations time out.  (It doesn't actually signal
  // anything on the I2C bus.)  Resetting the chip fixes it.
  //
  // We have an AT24C64B EEPROM attached at address 0xa2 which we should always
  // be able to read from successfully.
  uint8_t tmpBuf[8];
  try {
    dev_.read(ADDR_EEPROM, MutableByteRange(tmpBuf, sizeof(tmpBuf)));
  } catch (const UsbError& ex) {
    // The read failed.
    // Reset the device, and then confirm that we can read this time.
    //
    // Note: This can be slightly dangerous for other reasons.  We have seen
    // some 3M QSFP optics that can lock up and hold SDA low forever.  If we
    // reset the CP2112 chip with SDA held low it can't reset successfully,
    // and disappears from the USB bus completely.  (It never re-enumerates.)
    // If the bus is in this state resetting the chip will make it completely
    // inaccessible.
    if (autoReset) {
      try {
        dev_.resetDevice();
      } catch (const UsbDeviceResetError& ex) {
      }
    } else {
      VLOG(1) << "initial read from CP2112 failed; I2C bus appears hung";
      throw;
    }
  }
}

void WedgeI2CBus::selectQsfpImpl(unsigned int port) {
  auto oldValues = getSwitchValues(selectedPort_);
  auto newValues = getSwitchValues(port);

  // One of the new values should be 0.  Set this one first,
  // to ensure that we never have more than one port selected at a time.
  if (newValues.first == 0) {
    if (newValues.first != oldValues.first) {
      dev_.writeByte(ADDR_SWITCH_1, newValues.first);
    }
    selectedPort_ = NO_PORT; // In case the second write throws
    if (newValues.second != oldValues.second) {
      dev_.writeByte(ADDR_SWITCH_2, newValues.second);
    }
  } else {
    if (newValues.second != oldValues.second) {
      dev_.writeByte(ADDR_SWITCH_2, newValues.second);
    }
    selectedPort_ = NO_PORT; // In case the second write throws
    if (newValues.first != oldValues.first) {
      dev_.writeByte(ADDR_SWITCH_1, newValues.first);
    }
  }
  selectedPort_ = port;
}

std::pair<uint8_t, uint8_t>
WedgeI2CBus::getSwitchValues(unsigned int port) const {
  // We swapped the top and bottom port numbering after the board was
  // taped out, so each pair has to be swapped here.
  static const std::pair<uint8_t, uint8_t> map[] = {
    {0x00, 0x00}, // NO_PORT
    {0x02, 0x00}, // Module 1 (left-most top module)
    {0x01, 0x00}, // Module 2 (left-most bottom module)
    {0x08, 0x00}, // Module 3
    {0x04, 0x00}, // Module 4
    {0x20, 0x00}, // Module 5
    {0x10, 0x00}, // Module 6
    {0x80, 0x00}, // Module 7
    {0x40, 0x00}, // Module 8
    {0x00, 0x02}, // Module 9
    {0x00, 0x01}, // Module 10
    {0x00, 0x08}, // Module 11
    {0x00, 0x04}, // Module 12
    {0x00, 0x20}, // Module 13
    {0x00, 0x10}, // Module 14
    {0x00, 0x80}, // Module 15 (right-most top module)
    {0x00, 0x40}, // Module 16 (right-most bottom module)
  };

  CHECK_LE(port, 16);
  return map[port];
}

}} // facebook::fboss
<commit_msg>fboss/lib/usb/WedgeI2CBus.cpp: avoid shadowing warnings<commit_after>/*
 *  Copyright (c) 2004-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */
#include "fboss/lib/usb/WedgeI2CBus.h"

#include "fboss/lib/usb/UsbError.h"

using folly::MutableByteRange;
using std::lock_guard;

namespace facebook { namespace fboss {

WedgeI2CBus::WedgeI2CBus() {
}

void WedgeI2CBus::initBus() {
  dev_.writeByte(ADDR_SWITCH_1, 0);
  dev_.writeByte(ADDR_SWITCH_2, 0);
}

void WedgeI2CBus::verifyBus(bool autoReset) {
  // Make sure the I2C bus is functioning, and reset the CP2112 device if not.
  //
  // Immediately after wedge is powered on, the CP2112 device appears to be in
  // a state where all I2C operations time out.  (It doesn't actually signal
  // anything on the I2C bus.)  Resetting the chip fixes it.
  //
  // We have an AT24C64B EEPROM attached at address 0xa2 which we should always
  // be able to read from successfully.
  uint8_t tmpBuf[8];
  try {
    dev_.read(ADDR_EEPROM, MutableByteRange(tmpBuf, sizeof(tmpBuf)));
  } catch (const UsbError& ex) {
    // The read failed.
    // Reset the device, and then confirm that we can read this time.
    //
    // Note: This can be slightly dangerous for other reasons.  We have seen
    // some 3M QSFP optics that can lock up and hold SDA low forever.  If we
    // reset the CP2112 chip with SDA held low it can't reset successfully,
    // and disappears from the USB bus completely.  (It never re-enumerates.)
    // If the bus is in this state resetting the chip will make it completely
    // inaccessible.
    if (autoReset) {
      try {
        dev_.resetDevice();
      } catch (const UsbDeviceResetError& ex2) {
      }
    } else {
      VLOG(1) << "initial read from CP2112 failed; I2C bus appears hung";
      throw;
    }
  }
}

void WedgeI2CBus::selectQsfpImpl(unsigned int port) {
  auto oldValues = getSwitchValues(selectedPort_);
  auto newValues = getSwitchValues(port);

  // One of the new values should be 0.  Set this one first,
  // to ensure that we never have more than one port selected at a time.
  if (newValues.first == 0) {
    if (newValues.first != oldValues.first) {
      dev_.writeByte(ADDR_SWITCH_1, newValues.first);
    }
    selectedPort_ = NO_PORT; // In case the second write throws
    if (newValues.second != oldValues.second) {
      dev_.writeByte(ADDR_SWITCH_2, newValues.second);
    }
  } else {
    if (newValues.second != oldValues.second) {
      dev_.writeByte(ADDR_SWITCH_2, newValues.second);
    }
    selectedPort_ = NO_PORT; // In case the second write throws
    if (newValues.first != oldValues.first) {
      dev_.writeByte(ADDR_SWITCH_1, newValues.first);
    }
  }
  selectedPort_ = port;
}

std::pair<uint8_t, uint8_t>
WedgeI2CBus::getSwitchValues(unsigned int port) const {
  // We swapped the top and bottom port numbering after the board was
  // taped out, so each pair has to be swapped here.
  static const std::pair<uint8_t, uint8_t> map[] = {
    {0x00, 0x00}, // NO_PORT
    {0x02, 0x00}, // Module 1 (left-most top module)
    {0x01, 0x00}, // Module 2 (left-most bottom module)
    {0x08, 0x00}, // Module 3
    {0x04, 0x00}, // Module 4
    {0x20, 0x00}, // Module 5
    {0x10, 0x00}, // Module 6
    {0x80, 0x00}, // Module 7
    {0x40, 0x00}, // Module 8
    {0x00, 0x02}, // Module 9
    {0x00, 0x01}, // Module 10
    {0x00, 0x08}, // Module 11
    {0x00, 0x04}, // Module 12
    {0x00, 0x20}, // Module 13
    {0x00, 0x10}, // Module 14
    {0x00, 0x80}, // Module 15 (right-most top module)
    {0x00, 0x40}, // Module 16 (right-most bottom module)
  };

  CHECK_LE(port, 16);
  return map[port];
}

}} // facebook::fboss
<|endoftext|>


<commit_before>// Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#ifndef MFEM_LIBCEED_PAINTEG
#define MFEM_LIBCEED_PAINTEG

#include "mf_integrator.hpp"
#include "../../config/config.hpp"
#include "../fespace.hpp"
#include "../gridfunc.hpp"

namespace mfem
{

namespace ceed
{

#ifdef MFEM_USE_CEED
/** This structure contains the data to assemble a partially assembled operator
    with libCEED. See libceed/mass.cpp or libceed/diffusion.cpp for examples. */
struct PAOperator
{
   /** The finite element space for the trial and test functions. */
   const mfem::FiniteElementSpace &fes;
   /** The Integration Rule to use to compute the operator. */
   const mfem::IntegrationRule &ir;
   /** The number of quadrature data at each quadrature point. */
   int qdatasize;
   /** The path to the header containing the functions for libCEED. */
   std::string header;
   /** The name of the Qfunction to build the quadrature data. */
   std::string build_func;
   /** The Qfunction to build the quadrature data. */
   CeedQFunctionUser build_qf;
   /** The name of the Qfunction to apply the operator. */
   std::string apply_func;
   /** The Qfunction to apply the operator. */
   CeedQFunctionUser apply_qf;
   /** The evaluation mode to apply to the trial function (CEED_EVAL_INTERP,
       CEED_EVAL_GRAD, etc.) */
   EvalMode trial_op;
   /** The evaluation mode to apply to the test function ( CEED_EVAL_INTERP,
       CEED_EVAL_GRAD, etc.)*/
   EvalMode test_op;
};
#endif

/** This class represent a partially assembled operator using libCEED.*/
class PAIntegrator : public Operator
{
#ifdef MFEM_USE_CEED
protected:
   CeedBasis basis, mesh_basis;
   CeedElemRestriction restr, mesh_restr, restr_i;
   CeedQFunction build_qfunc, apply_qfunc;
   CeedVector node_coords, qdata;
   Coefficient *coeff;
   CeedQFunctionContext build_ctx;
   CeedOperator build_oper;

public:
   PAIntegrator()
      : Operator(), basis(nullptr), mesh_basis(nullptr),
        restr(nullptr), mesh_restr(nullptr),
        restr_i(nullptr),
        build_qfunc(nullptr), apply_qfunc(nullptr), node_coords(nullptr),
        qdata(nullptr), coeff(nullptr), build_ctx(nullptr), build_oper(nullptr)
   { }

   /** This method initializes the PAIntegrator with the given CeedOperatorInfo
       @a info, an mfem::FiniteElementSpace @a fes, an mfem::IntegrationRule
       @a ir, and mfem::Coefficient or mfem::VectorCoefficient @a Q.*/
   template <typename CeedOperatorInfo, typename CoeffType>
   PAOperator InitPA(CeedOperatorInfo &info,
                     const mfem::FiniteElementSpace &fes,
                     const mfem::IntegrationRule &irm,
                     CoeffType *Q)
   {
      mfem::Mesh &mesh = *fes.GetMesh();
      // Perform checks for some assumptions made in the Q-functions.
      MFEM_VERIFY(mesh.Dimension() == mesh.SpaceDimension(), "case not supported");
      MFEM_VERIFY(fes.GetVDim() == 1 || fes.GetVDim() == mesh.Dimension(),
                  "case not supported");
      InitCoefficient(Q, mesh, irm, coeff, info.ctx);
      bool const_coeff = coeff->IsConstant();
      std::string build_func = const_coeff ? info.build_func_const
                               : info.build_func_quad;
      CeedQFunctionUser build_qf = const_coeff ? info.build_qf_const
                                   : info.build_qf_quad;
      return PAOperator{fes, irm,
                        info.qdatasize, info.header,
                        build_func, build_qf,
                        info.apply_func, info.apply_qf,
                        info.trial_op,
                        info.test_op
                       };
   }

   template <typename Context>
   void Assemble(PAOperator &op, Context &ctx)
   {
      const mfem::FiniteElementSpace &fes = op.fes;
      const mfem::IntegrationRule &irm = op.ir;
      Ceed ceed(internal::ceed);
      mfem::Mesh *mesh = fes.GetMesh();
      CeedInt nqpts, nelem = mesh->GetNE();
      CeedInt dim = mesh->SpaceDimension(), vdim = fes.GetVDim();

      mesh->EnsureNodes();
      InitBasisAndRestriction(fes, irm, ceed, &basis, &restr);

      const mfem::FiniteElementSpace *mesh_fes = mesh->GetNodalFESpace();
      MFEM_VERIFY(mesh_fes, "the Mesh has no nodal FE space");
      InitBasisAndRestriction(*mesh_fes, irm, ceed, &mesh_basis,
                              &mesh_restr);

      CeedBasisGetNumQuadraturePoints(basis, &nqpts);

      const int qdatasize = op.qdatasize;
      InitStridedRestriction(*mesh_fes, nelem, nqpts, qdatasize,
                             CEED_STRIDES_BACKEND,
                             &restr_i);

      InitVector(*mesh->GetNodes(), node_coords);

      CeedVectorCreate(ceed, nelem * nqpts * qdatasize, &qdata);

      // Context data to be passed to the Q-function.
      ctx.dim = mesh->Dimension();
      ctx.space_dim = mesh->SpaceDimension();
      ctx.vdim = fes.GetVDim();

      std::string qf_file = GetCeedPath() + op.header;
      std::string qf = qf_file + op.build_func;
      CeedQFunctionCreateInterior(ceed, 1, op.build_qf, qf.c_str(),
                                  &build_qfunc);

      // Create the Q-function that builds the operator (i.e. computes its
      // quadrature data) and set its context data.
      if (VariableCoefficient *var_coeff = dynamic_cast<VariableCoefficient*>(coeff))
      {
         CeedQFunctionAddInput(build_qfunc, "coeff", coeff->ncomp, var_coeff->emode);
      }
      CeedQFunctionAddInput(build_qfunc, "dx", dim * dim, CEED_EVAL_GRAD);
      CeedQFunctionAddInput(build_qfunc, "weights", 1, CEED_EVAL_WEIGHT);
      CeedQFunctionAddOutput(build_qfunc, "qdata", qdatasize, CEED_EVAL_NONE);

      CeedQFunctionContextCreate(ceed, &build_ctx);
      CeedQFunctionContextSetData(build_ctx, CEED_MEM_HOST,
                                  CEED_COPY_VALUES,
                                  sizeof(ctx),
                                  &ctx);
      CeedQFunctionSetContext(build_qfunc, build_ctx);

      // Create the operator that builds the quadrature data for the operator.
      CeedOperatorCreate(ceed, build_qfunc, NULL, NULL, &build_oper);
      if (GridCoefficient *gridCoeff = dynamic_cast<GridCoefficient*>(coeff))
      {
         InitBasisAndRestriction(*gridCoeff->gf.FESpace(), irm, ceed,
                                 &gridCoeff->basis, &gridCoeff->restr);
         CeedOperatorSetField(build_oper, "coeff", gridCoeff->restr,
                              gridCoeff->basis, gridCoeff->coeffVector);
      }
      else if (QuadCoefficient *quadCoeff = dynamic_cast<QuadCoefficient*>(coeff))
      {
         const int ncomp = quadCoeff->ncomp;
         CeedInt strides[3] = {ncomp, 1, ncomp*nqpts};
         InitStridedRestriction(*mesh_fes, nelem, nqpts, ncomp, strides,
                                &quadCoeff->restr);
         CeedOperatorSetField(build_oper, "coeff", quadCoeff->restr,
                              CEED_BASIS_COLLOCATED, quadCoeff->coeffVector);
      }
      CeedOperatorSetField(build_oper, "dx", mesh_restr,
                           mesh_basis, CEED_VECTOR_ACTIVE);
      CeedOperatorSetField(build_oper, "weights", CEED_ELEMRESTRICTION_NONE,
                           mesh_basis, CEED_VECTOR_NONE);
      CeedOperatorSetField(build_oper, "qdata", restr_i,
                           CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);

      // Compute the quadrature data for the operator.
      CeedOperatorApply(build_oper, node_coords, qdata, CEED_REQUEST_IMMEDIATE);

      // Create the Q-function that defines the action of the operator.
      qf = qf_file + op.apply_func;
      CeedQFunctionCreateInterior(ceed, 1, op.apply_qf, qf.c_str(), &apply_qfunc);
      // input
      switch (op.trial_op)
      {
         case EvalMode::None:
            CeedQFunctionAddInput(apply_qfunc, "u", vdim, CEED_EVAL_NONE);
            break;
         case EvalMode::Interp:
            CeedQFunctionAddInput(apply_qfunc, "u", vdim, CEED_EVAL_INTERP);
            break;
         case EvalMode::Grad:
            CeedQFunctionAddInput(apply_qfunc, "gu", vdim*dim, CEED_EVAL_GRAD);
            break;
         case EvalMode::InterpAndGrad:
            CeedQFunctionAddInput(apply_qfunc, "u", vdim, CEED_EVAL_INTERP);
            CeedQFunctionAddInput(apply_qfunc, "gu", vdim*dim, CEED_EVAL_GRAD);
            break;
      }
      // qdata
      CeedQFunctionAddInput(apply_qfunc, "qdata", qdatasize, CEED_EVAL_NONE);
      // output
      switch (op.test_op)
      {
         case EvalMode::None:
            CeedQFunctionAddOutput(apply_qfunc, "v", vdim, CEED_EVAL_NONE);
            break;
         case EvalMode::Interp:
            CeedQFunctionAddOutput(apply_qfunc, "v", vdim, CEED_EVAL_INTERP);
            break;
         case EvalMode::Grad:
            CeedQFunctionAddOutput(apply_qfunc, "gv", vdim*dim, CEED_EVAL_GRAD);
            break;
         case EvalMode::InterpAndGrad:
            CeedQFunctionAddOutput(apply_qfunc, "v", vdim, CEED_EVAL_INTERP);
            CeedQFunctionAddOutput(apply_qfunc, "gv", vdim*dim, CEED_EVAL_GRAD);
            break;
      }
      CeedQFunctionSetContext(apply_qfunc, build_ctx);

      // Create the operator.
      CeedOperatorCreate(ceed, apply_qfunc, NULL, NULL, &oper);
      // input
      switch (op.trial_op)
      {
         case EvalMode::None:
            CeedOperatorSetField(oper, "u", restr,
                                 CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::Interp:
            CeedOperatorSetField(oper, "u", restr, basis, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::Grad:
            CeedOperatorSetField(oper, "gu", restr, basis, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::InterpAndGrad:
            CeedOperatorSetField(oper, "u", restr, basis, CEED_VECTOR_ACTIVE);
            CeedOperatorSetField(oper, "gu", restr, basis, CEED_VECTOR_ACTIVE);
            break;
      }
      // qdata
      CeedOperatorSetField(oper, "qdata", restr_i, CEED_BASIS_COLLOCATED, qdata);
      // output
      switch (op.test_op)
      {
         case EvalMode::None:
            CeedOperatorSetField(oper, "v", restr,
                                 CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::Interp:
            CeedOperatorSetField(oper, "v", restr, basis, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::Grad:
            CeedOperatorSetField(oper, "gv", restr, basis, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::InterpAndGrad:
            CeedOperatorSetField(oper, "v", restr, basis, CEED_VECTOR_ACTIVE);
            CeedOperatorSetField(oper, "gv", restr, basis, CEED_VECTOR_ACTIVE);
            break;
      }

      CeedVectorCreate(ceed, vdim*fes.GetNDofs(), &u);
      CeedVectorCreate(ceed, vdim*fes.GetNDofs(), &v);
   }

   ~PAIntegrator()
   {
      CeedOperatorDestroy(&build_oper);
      CeedQFunctionDestroy(&build_qfunc);
   }
#endif
};

} // namespace ceed

} // namespace mfem

#endif // MFEM_LIBCEED_PAINTEG
<commit_msg>Remove irrelevant code.<commit_after>// Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#ifndef MFEM_LIBCEED_PAINTEG
#define MFEM_LIBCEED_PAINTEG

#include "mf_integrator.hpp"
#include "../../config/config.hpp"
#include "../fespace.hpp"
#include "../gridfunc.hpp"

namespace mfem
{

namespace ceed
{

#ifdef MFEM_USE_CEED
/** This structure contains the data to assemble a partially assembled operator
    with libCEED. See libceed/mass.cpp or libceed/diffusion.cpp for examples. */
struct PAOperator
{
   /** The finite element space for the trial and test functions. */
   const mfem::FiniteElementSpace &fes;
   /** The Integration Rule to use to compute the operator. */
   const mfem::IntegrationRule &ir;
   /** The number of quadrature data at each quadrature point. */
   int qdatasize;
   /** The path to the header containing the functions for libCEED. */
   std::string header;
   /** The name of the Qfunction to build the quadrature data. */
   std::string build_func;
   /** The Qfunction to build the quadrature data. */
   CeedQFunctionUser build_qf;
   /** The name of the Qfunction to apply the operator. */
   std::string apply_func;
   /** The Qfunction to apply the operator. */
   CeedQFunctionUser apply_qf;
   /** The evaluation mode to apply to the trial function (CEED_EVAL_INTERP,
       CEED_EVAL_GRAD, etc.) */
   EvalMode trial_op;
   /** The evaluation mode to apply to the test function ( CEED_EVAL_INTERP,
       CEED_EVAL_GRAD, etc.)*/
   EvalMode test_op;
};
#endif

/** This class represent a partially assembled operator using libCEED.*/
class PAIntegrator : public Operator
{
#ifdef MFEM_USE_CEED
protected:
   CeedBasis basis, mesh_basis;
   CeedElemRestriction restr, mesh_restr, restr_i;
   CeedQFunction build_qfunc, apply_qfunc;
   CeedVector node_coords, qdata;
   Coefficient *coeff;
   CeedQFunctionContext build_ctx;
   CeedOperator build_oper;

public:
   PAIntegrator()
      : Operator(), basis(nullptr), mesh_basis(nullptr),
        restr(nullptr), mesh_restr(nullptr),
        restr_i(nullptr),
        build_qfunc(nullptr), apply_qfunc(nullptr), node_coords(nullptr),
        qdata(nullptr), coeff(nullptr), build_ctx(nullptr), build_oper(nullptr)
   { }

   /** This method initializes the PAIntegrator with the given CeedOperatorInfo
       @a info, an mfem::FiniteElementSpace @a fes, an mfem::IntegrationRule
       @a ir, and mfem::Coefficient or mfem::VectorCoefficient @a Q.*/
   template <typename CeedOperatorInfo, typename CoeffType>
   PAOperator InitPA(CeedOperatorInfo &info,
                     const mfem::FiniteElementSpace &fes,
                     const mfem::IntegrationRule &irm,
                     CoeffType *Q)
   {
      mfem::Mesh &mesh = *fes.GetMesh();
      InitCoefficient(Q, mesh, irm, coeff, info.ctx);
      bool const_coeff = coeff->IsConstant();
      std::string build_func = const_coeff ? info.build_func_const
                               : info.build_func_quad;
      CeedQFunctionUser build_qf = const_coeff ? info.build_qf_const
                                   : info.build_qf_quad;
      return PAOperator{fes, irm,
                        info.qdatasize, info.header,
                        build_func, build_qf,
                        info.apply_func, info.apply_qf,
                        info.trial_op,
                        info.test_op
                       };
   }

   template <typename Context>
   void Assemble(PAOperator &op, Context &ctx)
   {
      const mfem::FiniteElementSpace &fes = op.fes;
      const mfem::IntegrationRule &irm = op.ir;
      Ceed ceed(internal::ceed);
      mfem::Mesh *mesh = fes.GetMesh();
      CeedInt nqpts, nelem = mesh->GetNE();
      CeedInt dim = mesh->SpaceDimension(), vdim = fes.GetVDim();

      mesh->EnsureNodes();
      InitBasisAndRestriction(fes, irm, ceed, &basis, &restr);

      const mfem::FiniteElementSpace *mesh_fes = mesh->GetNodalFESpace();
      MFEM_VERIFY(mesh_fes, "the Mesh has no nodal FE space");
      InitBasisAndRestriction(*mesh_fes, irm, ceed, &mesh_basis,
                              &mesh_restr);

      CeedBasisGetNumQuadraturePoints(basis, &nqpts);

      const int qdatasize = op.qdatasize;
      InitStridedRestriction(*mesh_fes, nelem, nqpts, qdatasize,
                             CEED_STRIDES_BACKEND,
                             &restr_i);

      InitVector(*mesh->GetNodes(), node_coords);

      CeedVectorCreate(ceed, nelem * nqpts * qdatasize, &qdata);

      // Context data to be passed to the Q-function.
      ctx.dim = mesh->Dimension();
      ctx.space_dim = mesh->SpaceDimension();
      ctx.vdim = fes.GetVDim();

      std::string qf_file = GetCeedPath() + op.header;
      std::string qf = qf_file + op.build_func;
      CeedQFunctionCreateInterior(ceed, 1, op.build_qf, qf.c_str(),
                                  &build_qfunc);

      // Create the Q-function that builds the operator (i.e. computes its
      // quadrature data) and set its context data.
      if (VariableCoefficient *var_coeff = dynamic_cast<VariableCoefficient*>(coeff))
      {
         CeedQFunctionAddInput(build_qfunc, "coeff", coeff->ncomp, var_coeff->emode);
      }
      CeedQFunctionAddInput(build_qfunc, "dx", dim * dim, CEED_EVAL_GRAD);
      CeedQFunctionAddInput(build_qfunc, "weights", 1, CEED_EVAL_WEIGHT);
      CeedQFunctionAddOutput(build_qfunc, "qdata", qdatasize, CEED_EVAL_NONE);

      CeedQFunctionContextCreate(ceed, &build_ctx);
      CeedQFunctionContextSetData(build_ctx, CEED_MEM_HOST,
                                  CEED_COPY_VALUES,
                                  sizeof(ctx),
                                  &ctx);
      CeedQFunctionSetContext(build_qfunc, build_ctx);

      // Create the operator that builds the quadrature data for the operator.
      CeedOperatorCreate(ceed, build_qfunc, NULL, NULL, &build_oper);
      if (GridCoefficient *gridCoeff = dynamic_cast<GridCoefficient*>(coeff))
      {
         InitBasisAndRestriction(*gridCoeff->gf.FESpace(), irm, ceed,
                                 &gridCoeff->basis, &gridCoeff->restr);
         CeedOperatorSetField(build_oper, "coeff", gridCoeff->restr,
                              gridCoeff->basis, gridCoeff->coeffVector);
      }
      else if (QuadCoefficient *quadCoeff = dynamic_cast<QuadCoefficient*>(coeff))
      {
         const int ncomp = quadCoeff->ncomp;
         CeedInt strides[3] = {ncomp, 1, ncomp*nqpts};
         InitStridedRestriction(*mesh_fes, nelem, nqpts, ncomp, strides,
                                &quadCoeff->restr);
         CeedOperatorSetField(build_oper, "coeff", quadCoeff->restr,
                              CEED_BASIS_COLLOCATED, quadCoeff->coeffVector);
      }
      CeedOperatorSetField(build_oper, "dx", mesh_restr,
                           mesh_basis, CEED_VECTOR_ACTIVE);
      CeedOperatorSetField(build_oper, "weights", CEED_ELEMRESTRICTION_NONE,
                           mesh_basis, CEED_VECTOR_NONE);
      CeedOperatorSetField(build_oper, "qdata", restr_i,
                           CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);

      // Compute the quadrature data for the operator.
      CeedOperatorApply(build_oper, node_coords, qdata, CEED_REQUEST_IMMEDIATE);

      // Create the Q-function that defines the action of the operator.
      qf = qf_file + op.apply_func;
      CeedQFunctionCreateInterior(ceed, 1, op.apply_qf, qf.c_str(), &apply_qfunc);
      // input
      switch (op.trial_op)
      {
         case EvalMode::None:
            CeedQFunctionAddInput(apply_qfunc, "u", vdim, CEED_EVAL_NONE);
            break;
         case EvalMode::Interp:
            CeedQFunctionAddInput(apply_qfunc, "u", vdim, CEED_EVAL_INTERP);
            break;
         case EvalMode::Grad:
            CeedQFunctionAddInput(apply_qfunc, "gu", vdim*dim, CEED_EVAL_GRAD);
            break;
         case EvalMode::InterpAndGrad:
            CeedQFunctionAddInput(apply_qfunc, "u", vdim, CEED_EVAL_INTERP);
            CeedQFunctionAddInput(apply_qfunc, "gu", vdim*dim, CEED_EVAL_GRAD);
            break;
      }
      // qdata
      CeedQFunctionAddInput(apply_qfunc, "qdata", qdatasize, CEED_EVAL_NONE);
      // output
      switch (op.test_op)
      {
         case EvalMode::None:
            CeedQFunctionAddOutput(apply_qfunc, "v", vdim, CEED_EVAL_NONE);
            break;
         case EvalMode::Interp:
            CeedQFunctionAddOutput(apply_qfunc, "v", vdim, CEED_EVAL_INTERP);
            break;
         case EvalMode::Grad:
            CeedQFunctionAddOutput(apply_qfunc, "gv", vdim*dim, CEED_EVAL_GRAD);
            break;
         case EvalMode::InterpAndGrad:
            CeedQFunctionAddOutput(apply_qfunc, "v", vdim, CEED_EVAL_INTERP);
            CeedQFunctionAddOutput(apply_qfunc, "gv", vdim*dim, CEED_EVAL_GRAD);
            break;
      }
      CeedQFunctionSetContext(apply_qfunc, build_ctx);

      // Create the operator.
      CeedOperatorCreate(ceed, apply_qfunc, NULL, NULL, &oper);
      // input
      switch (op.trial_op)
      {
         case EvalMode::None:
            CeedOperatorSetField(oper, "u", restr,
                                 CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::Interp:
            CeedOperatorSetField(oper, "u", restr, basis, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::Grad:
            CeedOperatorSetField(oper, "gu", restr, basis, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::InterpAndGrad:
            CeedOperatorSetField(oper, "u", restr, basis, CEED_VECTOR_ACTIVE);
            CeedOperatorSetField(oper, "gu", restr, basis, CEED_VECTOR_ACTIVE);
            break;
      }
      // qdata
      CeedOperatorSetField(oper, "qdata", restr_i, CEED_BASIS_COLLOCATED, qdata);
      // output
      switch (op.test_op)
      {
         case EvalMode::None:
            CeedOperatorSetField(oper, "v", restr,
                                 CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::Interp:
            CeedOperatorSetField(oper, "v", restr, basis, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::Grad:
            CeedOperatorSetField(oper, "gv", restr, basis, CEED_VECTOR_ACTIVE);
            break;
         case EvalMode::InterpAndGrad:
            CeedOperatorSetField(oper, "v", restr, basis, CEED_VECTOR_ACTIVE);
            CeedOperatorSetField(oper, "gv", restr, basis, CEED_VECTOR_ACTIVE);
            break;
      }

      CeedVectorCreate(ceed, vdim*fes.GetNDofs(), &u);
      CeedVectorCreate(ceed, vdim*fes.GetNDofs(), &v);
   }

   ~PAIntegrator()
   {
      CeedOperatorDestroy(&build_oper);
      CeedQFunctionDestroy(&build_qfunc);
   }
#endif
};

} // namespace ceed

} // namespace mfem

#endif // MFEM_LIBCEED_PAINTEG
<|endoftext|>


<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

//_________________________________________________________________________
// Geometry class  for PHOS : EMCA (Electromagnetic Calorimeter)
// Its data members provide geometry parametrization of EMCA
// which can be changed in the constructor only.
// Author   : Yves Schutz (SUBATECH)
// Modified : Yuri Kharlov (IHEP, Protvino)
// 13 September 2000

// --- AliRoot header files ---

#include "AliPHOSEMCAGeometry.h"

ClassImp(AliPHOSEMCAGeometry) ;

//____________________________________________________________________________
AliPHOSEMCAGeometry::AliPHOSEMCAGeometry()
{

  // Initializes the EMC parameters

  fNPhi       = 64 ;
  fNZ         = 64 ;

  fXtlSize[0] =  2.2 ;
  fXtlSize[1] = 22.0 ;
  fXtlSize[2] =  2.2 ;

  // all these numbers coming next are subject to changes

  fOuterBoxThickness[0] = 2.5 ;
  fOuterBoxThickness[1] = 5.0 ;
  fOuterBoxThickness[2] = 5.0 ;

  fUpperPlateThickness  = 4.0 ;

  fSecondUpperPlateThickness = 5.0 ;

  fCrystalSupportHeight   = 6.95 ;
  fCrystalWrapThickness   = 0.01 ;
  fCrystalHolderThickness = 0.005 ;
  fModuleBoxThickness     = 2.0 ;
  fIPtoOuterCoverDistance = 447.0 ;
  fIPtoCrystalSurface     = 460.0 ;

  //fPinDiodeSize[0] = 1.71 ;   //Values of ame PIN diode
  //fPinDiodeSize[1] = 0.0280 ; // 0.0280 is the depth of active layer
  //fPinDiodeSize[2] = 1.61 ;

  fPinDiodeSize[0] = 0.5000 ;    // APD 5 mm side
  //fPinDiodeSize[1] = 0.0200 ;  // APD bulk thickness
  fPinDiodeSize[1] = 0.0100 ;    // APD bulk thickness
  //According to Y. M. (cms) is it 50 micrometer I use 100 micrometers
  fPinDiodeSize[2] = 0.5000 ;    // APD 5 mm side

  fUpperCoolingPlateThickness   = 0.06 ;
  fSupportPlateThickness        = 10.0 ;
  fLowerThermoPlateThickness    =  3.0 ;
  fLowerTextolitPlateThickness  =  1.0 ;
  fGapBetweenCrystals           = 0.03 ;

  fTextolitBoxThickness[0] = 1.5 ;
  fTextolitBoxThickness[1] = 0.0 ;
  fTextolitBoxThickness[2] = 3.0 ;

  fAirThickness[0] =  0.4   ;
  fAirThickness[1] = 20.5175 ;
  fAirThickness[2] =  2.48   ;

  Float_t xtalModulePhiSize =  fNPhi * ( fXtlSize[0] + 2 * fGapBetweenCrystals ) ;
  Float_t xtalModuleZSize   =  fNZ   * ( fXtlSize[2] + 2 * fGapBetweenCrystals ) ;

  // The next dimensions are calculated from the above parameters

  fOuterBoxSize[0] =  xtalModulePhiSize + 2 * ( fAirThickness[0] + fModuleBoxThickness
						+ fTextolitBoxThickness[0] + fOuterBoxThickness[0] ) ;
  fOuterBoxSize[1] = ( fXtlSize[1] + fCrystalSupportHeight + fCrystalWrapThickness + fCrystalHolderThickness )
    + 2 * (fAirThickness[1] +  fModuleBoxThickness + fTextolitBoxThickness[1] + fOuterBoxThickness[1] ) ;
  fOuterBoxSize[2] =  xtalModuleZSize   + 2 * ( fAirThickness[2] + fModuleBoxThickness
						+ fTextolitBoxThickness[2] + fOuterBoxThickness[2] ) ;

  fTextolitBoxSize[0]  = fOuterBoxSize[0] - 2 * fOuterBoxThickness[0] ;
  fTextolitBoxSize[1]  = fOuterBoxSize[1] -  fOuterBoxThickness[1] - fUpperPlateThickness ;
  fTextolitBoxSize[2]  = fOuterBoxSize[2] - 2 * fOuterBoxThickness[2] ;

  fAirFilledBoxSize[0] =  fTextolitBoxSize[0] - 2 * fTextolitBoxThickness[0] ;
  fAirFilledBoxSize[1] =  fTextolitBoxSize[1] - fSecondUpperPlateThickness ;
  fAirFilledBoxSize[2] =  fTextolitBoxSize[2] - 2 * fTextolitBoxThickness[2] ;
  fRotMatrixArray = 0;
}
//____________________________________________________________________________
<commit_msg>changed Xtal length from 22cm to 18cm<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

//_________________________________________________________________________
// Geometry class  for PHOS : EMCA (Electromagnetic Calorimeter)
// Its data members provide geometry parametrization of EMCA
// which can be changed in the constructor only.
// Author   : Yves Schutz (SUBATECH)
// Modified : Yuri Kharlov (IHEP, Protvino)
// 13 September 2000

// --- AliRoot header files ---

#include "AliPHOSEMCAGeometry.h"

ClassImp(AliPHOSEMCAGeometry) ;

//____________________________________________________________________________
AliPHOSEMCAGeometry::AliPHOSEMCAGeometry()
{

  // Initializes the EMC parameters

  fNPhi       = 64 ;
  fNZ         = 64 ;

  fXtlSize[0] =  2.2 ;
  fXtlSize[1] = 18.0 ;
  fXtlSize[2] =  2.2 ;

  // all these numbers coming next are subject to changes

  fOuterBoxThickness[0] = 2.5 ;
  fOuterBoxThickness[1] = 5.0 ;
  fOuterBoxThickness[2] = 5.0 ;

  fUpperPlateThickness  = 4.0 ;

  fSecondUpperPlateThickness = 5.0 ;

  fCrystalSupportHeight   = 6.95 ;
  fCrystalWrapThickness   = 0.01 ;
  fCrystalHolderThickness = 0.005 ;
  fModuleBoxThickness     = 2.0 ;
  fIPtoOuterCoverDistance = 447.0 ;
  fIPtoCrystalSurface     = 460.0 ;

  //fPinDiodeSize[0] = 1.71 ;   //Values of ame PIN diode
  //fPinDiodeSize[1] = 0.0280 ; // OHO 0.0280 is the depth of active layer
  //fPinDiodeSize[2] = 1.61 ;

  fPinDiodeSize[0] = 0.5000 ;    // APD 5 mm side
  //fPinDiodeSize[1] = 0.0200 ;  // APD bulk thickness
  fPinDiodeSize[1] = 0.0100 ;    // APD bulk thickness
  //According to Y. M. (cms) is it 50 micrometer I use 100 micrometers OHO
  fPinDiodeSize[2] = 0.5000 ;    // APD 5 mm side

  fUpperCoolingPlateThickness   = 0.06 ;
  fSupportPlateThickness        = 10.0 ;
  fLowerThermoPlateThickness    =  3.0 ;
  fLowerTextolitPlateThickness  =  1.0 ;
  fGapBetweenCrystals           = 0.03 ;

  fTextolitBoxThickness[0] = 1.5 ;
  fTextolitBoxThickness[1] = 0.0 ;
  fTextolitBoxThickness[2] = 3.0 ;

  fAirThickness[0] =  0.4   ;
  fAirThickness[1] = 20.5175 ;
  fAirThickness[2] =  2.48   ;

  Float_t xtalModulePhiSize =  fNPhi * ( fXtlSize[0] + 2 * fGapBetweenCrystals ) ;
  Float_t xtalModuleZSize   =  fNZ   * ( fXtlSize[2] + 2 * fGapBetweenCrystals ) ;

  // The next dimensions are calculated from the above parameters

  fOuterBoxSize[0] =  xtalModulePhiSize + 2 * ( fAirThickness[0] + fModuleBoxThickness
						+ fTextolitBoxThickness[0] + fOuterBoxThickness[0] ) ;
  fOuterBoxSize[1] = ( fXtlSize[1] + fCrystalSupportHeight + fCrystalWrapThickness + fCrystalHolderThickness )
    + 2 * (fAirThickness[1] +  fModuleBoxThickness + fTextolitBoxThickness[1] + fOuterBoxThickness[1] ) ;
  fOuterBoxSize[2] =  xtalModuleZSize   + 2 * ( fAirThickness[2] + fModuleBoxThickness
						+ fTextolitBoxThickness[2] + fOuterBoxThickness[2] ) ;

  fTextolitBoxSize[0]  = fOuterBoxSize[0] - 2 * fOuterBoxThickness[0] ;
  fTextolitBoxSize[1]  = fOuterBoxSize[1] -  fOuterBoxThickness[1] - fUpperPlateThickness ;
  fTextolitBoxSize[2]  = fOuterBoxSize[2] - 2 * fOuterBoxThickness[2] ;

  fAirFilledBoxSize[0] =  fTextolitBoxSize[0] - 2 * fTextolitBoxThickness[0] ;
  fAirFilledBoxSize[1] =  fTextolitBoxSize[1] - fSecondUpperPlateThickness ;
  fAirFilledBoxSize[2] =  fTextolitBoxSize[2] - 2 * fTextolitBoxThickness[2] ;
  fRotMatrixArray = 0;
}
//____________________________________________________________________________
<|endoftext|>