/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

PositionerTool.cc
Go to the documentation of this file.
00001 #include "PositionerTool.h"
00002 
00003 #include "GaudiKernel/SmartDataPtr.h"
00004 #include "GaudiKernel/MsgStream.h"
00005 
00006 #include "DetDesc/LVolume.h"
00007 #include "DetDesc/PVolume.h"
00008 #include "DetDesc/DetectorElement.h"
00009 #include "GaudiKernel/Point3DTypes.h"
00010 #include "GaudiKernel/Transform3DTypes.h"
00011 
00012 #include <string>
00013 
00014 PositionerTool::PositionerTool(const std::string& type,
00015                                const std::string& name,
00016                                const IInterface* parent)
00017   : GaudiTool(type, name, parent)
00018   , m_detSvc(0)
00019 {
00020   declareProperty("PhysicalVolume",m_physVolName="",
00021                   "Name of the physical volume to add to geometry");
00022   declareProperty("LogicalVolume",m_logVolName="",
00023                   "Name of the logical volume to associate with the physical");
00024   declareProperty("MotherVolume",m_motherLVolName="",
00025                   "Name of the mother logical volume where the physical volume is placed");
00026   declareProperty("Position",m_position=std::vector<double>(3,0.),
00027                   "Position of the new volume in the parent coordinates");
00028   double identity[] = {1., 0., 0., 
00029                        0., 1., 0.,
00030                        0., 0., 1.};
00031   declareProperty("Rotation",m_rotation=std::vector<double>(identity,
00032                                                             identity+9),
00033                   "Rotation of the new volume in the parent coordinates");
00034   declareProperty("Element",m_detElemPath="",
00035                   "Name of the detector element to place in the TDS");
00036   declareProperty("Support",m_support="",
00037                   "Path+Name of the supporting detector element in the TDS");
00038 }
00039 
00040 PositionerTool::~PositionerTool()
00041 {
00042 }
00043 
00044 
00045 
00046 StatusCode PositionerTool::initialize()
00047 {
00048     this->GaudiTool::initialize();
00049 
00050     debug() << "PositionerTool::initialize()" << endreq;
00051     StatusCode sc = service("DetectorDataSvc",m_detSvc,true);
00052     if (sc.isFailure()) return sc;
00053 
00054     return sc;
00055 }
00056 
00057 StatusCode PositionerTool::reinitialize()
00058 {
00059     return StatusCode::SUCCESS;
00060 }
00061 
00062 StatusCode PositionerTool::finalize()
00063 {
00064     m_detSvc->release();
00065     return this->GaudiTool::finalize();
00066 }
00067 
00068 StatusCode PositionerTool::queryInterface(const InterfaceID& riid, 
00069                                           void** ppvInterface)
00070 {
00071   StatusCode sc = StatusCode::FAILURE;
00072   if (ppvInterface) {
00073     *ppvInterface = 0;
00074     
00075     if (IPositionerTool::interfaceID().versionMatch(riid)) {
00076       *ppvInterface = static_cast<IPositionerTool*>(this);
00077       sc = StatusCode::SUCCESS;
00078       addRef();
00079     }
00080     else sc = GaudiTool::queryInterface( riid, ppvInterface );    
00081   }
00082   return sc;
00083 }
00084 
00085 
00087 
00089 StatusCode PositionerTool::placeVolume()
00090 {
00091 
00092   // Find parent logical volume for physical volume
00093   SmartDataPtr<LVolume> parentLogVol(m_detSvc, m_motherLVolName);
00094   if(!parentLogVol){
00095     error() << "PositionerTool::placeVolume(): "
00096             << "could not find parent volume of name: " << m_motherLVolName
00097             << endreq;
00098     return StatusCode::FAILURE;
00099   }
00100 
00101   // Check if physical volume already exists in parent logical volume
00102   ILVolume::PVolumes::const_iterator pvIter = parentLogVol->pvBegin();
00103   for(;pvIter != parentLogVol->pvEnd(); pvIter++){
00104     if((*pvIter)->name() == m_physVolName){
00105       warning() << "PositionerTool::placeVolume(): "
00106                 << "physical volume " << m_physVolName
00107                 << " already exists in mother volume " << m_motherLVolName
00108                 << endreq;
00109       return StatusCode::SUCCESS;
00110     }
00111   }
00112 
00113   // Create the physical volume
00114   Gaudi::Rotation3D rotation(m_rotation.begin(), m_rotation.end());
00115   Gaudi::XYZVector position(m_position[0],m_position[1],m_position[2]);
00116   IPVolume* pv = 
00117     parentLogVol->createPVolume(m_physVolName, m_logVolName, 
00118                                 Gaudi::Transform3D(rotation, 
00119                                                    Gaudi::XYZVector(position)));
00120   
00121   if( 0 == pv ) {
00122     error() << "PositionerTool::placeVolume(): "
00123             << "could not create volume: " << m_physVolName
00124             << endreq;
00125     return StatusCode::FAILURE;
00126   }
00127 
00128   StatusCode sc;
00129   
00130   if(m_detElemPath != ""){
00131     // Add the corresponding detector element
00132     DetectorElement* detElem = new DetectorElement;
00133     sc = m_detSvc->registerObject( m_support, m_detElemPath, detElem);
00134     if( sc.isFailure() ){
00135       error() << "Failed to register object with support / path: " 
00136               << m_support << " / " << m_detElemPath << endreq;
00137     }
00138     detElem->createGeometryInfo( m_logVolName, m_support, m_physVolName);
00139   }
00140 
00141   return sc;
00142 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:56:27 for DetHelpers by doxygen 1.7.4