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

In This Package:

Public Member Functions | Static Public Member Functions | Private Attributes
CoordSysSvc Class Reference

Default implementation of ICoordSysSvc. More...

#include <CoordSysSvc.h>

Inheritance diagram for CoordSysSvc:
Inheritance graph
[legend]
Collaboration diagram for CoordSysSvc:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CoordSysSvc (const std::string &name, ISvcLocator *svc)
 ~CoordSysSvc ()
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
IDetectorElement * belongsToDE (const Gaudi::XYZPoint &globalPoint, IDetectorElement *start=0, int depth=-1)
 ICoordSysSvc interface.
IDetectorElement * coordSysDE (const Gaudi::XYZPoint &globalPoint, int height=0)
 Find the smallest IDetectorElement containing the global point and who's logical volume provides a canonical coordinate system.
IDetectorElement * coordSysDE (const Gaudi::XYZPoint &globalPoint, IDetectorElement *start, int height=0)
IDetectorElement * nextHigherCoordSysDE (IDetectorElement *csde)

Static Public Member Functions

static const InterfaceID & interfaceID ()

Private Attributes

std::string m_CoordSysUserParameter
 The CoordSysUserParameter property to set what user parameter to look for to find the DetectorElement that provides the coordinate system.
std::string m_TopDetectorElementName
 The TopDetectorElementName property to set the name of the DetectorElement that holds all others.
IDataProviderSvc * m_detSvc
IGeometryInfo * m_topGI
IDetectorElement * m_lastBelongsTo
IDetectorElement * m_lastCoordSys

Detailed Description

Default implementation of ICoordSysSvc.

bv@bnl.gov Thu Oct 23 11:15:47 2008

Definition at line 22 of file CoordSysSvc.h.


Constructor & Destructor Documentation

CoordSysSvc::CoordSysSvc ( const std::string &  name,
ISvcLocator *  svc 
)

Definition at line 10 of file CoordSysSvc.cc.

    : Service(name,svc)
    , m_detSvc(0)
    , m_topGI(0)
    , m_lastBelongsTo(0)
    , m_lastCoordSys(0)
{
    declareProperty("CoordSysUserParameter",m_CoordSysUserParameter="CoordinateSystem",
                    "Name of the user parameter attached to the DetectorElement "
                    "that has the LVolume that provides the coordinate system.");
    declareProperty("TopDetectorElementName",
                    m_TopDetectorElementName="/dd/Structure/DayaBay",
                    "Name of the DetectorElement that holds all others");

}
CoordSysSvc::~CoordSysSvc ( )

Definition at line 26 of file CoordSysSvc.cc.

{
}

Member Function Documentation

StatusCode CoordSysSvc::initialize ( ) [virtual]

Definition at line 30 of file CoordSysSvc.cc.

{
    this->Service::initialize();

    MsgStream msg(msgSvc(),name());
    msg << MSG::DEBUG << "CoordSysSvc::initialize()" << endreq;

    StatusCode sc = service("DetectorDataSvc",m_detSvc,true);
    if (sc.isFailure()) return sc;

    SmartDataPtr<IDetectorElement> topDE(m_detSvc,m_TopDetectorElementName);
    if (!topDE) return StatusCode::FAILURE;

    m_topGI = topDE->geometry();

    return StatusCode::SUCCESS;
}
StatusCode CoordSysSvc::finalize ( ) [virtual]

Definition at line 47 of file CoordSysSvc.cc.

{
    m_detSvc->release();
    m_detSvc = 0;
    return StatusCode::SUCCESS;
}
StatusCode CoordSysSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvInterface 
) [virtual]

Definition at line 53 of file CoordSysSvc.cc.

{
    StatusCode sc = StatusCode::FAILURE;
    if (ppvInterface) {
        *ppvInterface = 0;
    
        if (ICoordSysSvc::interfaceID().versionMatch(riid)) {
            *ppvInterface = static_cast<ICoordSysSvc*>(this);
            sc = StatusCode::SUCCESS;
            addRef();
        }
        else sc = Service::queryInterface( riid, ppvInterface );    
    }
    return sc;
}
IDetectorElement * CoordSysSvc::belongsToDE ( const Gaudi::XYZPoint &  globalPoint,
IDetectorElement *  start = 0,
int  depth = -1 
) [virtual]

ICoordSysSvc interface.

Find the smallest IDetectorElement that contains the given global point but do not descend further than the given depth in the IDetectorElement tree which is counted from the top most IDetectorElement. If depth<0 do not limit the search. Return 0 on failure.

Implements ICoordSysSvc.

Definition at line 70 of file CoordSysSvc.cc.

{
    MsgStream msg(msgSvc(),name());

    // first check if we can try to optimize a little and get lucky
    // starting at last result.
    if (!start && depth < 0 && m_lastBelongsTo) {
        IGeometryInfo* gi = m_lastBelongsTo->geometry();
        if (gi->isInside(globalPoint)) {
            string path = gi->belongsToPath(globalPoint,-1);
            //msg << MSG::VERBOSE
            //    << "cached DE ("<< m_lastBelongsTo->name() 
            //    <<") gives belongsToPath = " << path << endreq;

            SmartDataPtr<IDetectorElement> de(m_detSvc,path);
            if (!de) {
                msg << MSG::ERROR
                    << "Failed to get DetectorElement " << path << endreq;
                return 0;
            }
            m_lastBelongsTo = de;
            return m_lastBelongsTo;
        }
        m_lastBelongsTo = 0;    // bummer
    }

    IGeometryInfo* gi = m_topGI;
    if (start) gi = start->geometry();

    string path = gi->belongsToPath(globalPoint,depth);
    if (!gi->isInside(globalPoint)) {
        MsgStream msg(msgSvc(),name());
        msg << MSG::DEBUG
            << "Failed to get DetectorElement path for point " << globalPoint << endreq;
        return 0;
    }

    SmartDataPtr<IDetectorElement> de(m_detSvc,path);
    if (!de) {
        MsgStream msg(msgSvc(),name());
        msg << MSG::WARNING
            << "No Detector Element at " << path << endreq;
        return 0;
    }
    m_lastBelongsTo = de;
    return m_lastBelongsTo;
}
IDetectorElement * CoordSysSvc::coordSysDE ( const Gaudi::XYZPoint &  globalPoint,
int  height = 0 
) [virtual]

Find the smallest IDetectorElement containing the global point and who's logical volume provides a canonical coordinate system.

A non zero height specifies to return the IDetectorElement that satisfies this which contains this number of other satisfying IDetectorElement. Return 0 on failure.

Implements ICoordSysSvc.

Definition at line 165 of file CoordSysSvc.cc.

{
    // Try to optimize, guess that the last one is right for this one
    IDetectorElement* de = m_lastBelongsTo;

    // check to see if last found or one of its parents can be reused
    while (de) {

        // if the DE doesn't contain the point, try its parent
        if (!de->geometry()->isInside(globalPoint)) {
            de = this->nextHigherCoordSysDE(de);
            continue;
        }

        // if DE doesn't have a CoordinateSystem parameter, keep going higher
        const ParamValidDataObject* params = de->params();
        if (!(params && params->exists(m_CoordSysUserParameter))) {
            de = this->nextHigherCoordSysDE(de);
            continue;
        }

        // know the DE has a CS parameter and contains the point, so drill down...
        de = this->belongsToDE(globalPoint,de,-1);

        // and come back up
        de = this->coordSysDE(globalPoint,de,height);
        if (de) {
            m_lastBelongsTo = de;
            return de;
        }

    }

    // Got to start from the scratch...
    de = this->belongsToDE(globalPoint);
    if (!de) {
        MsgStream msg(msgSvc(),name());
        msg << MSG::DEBUG
            << "Failed to find DE belonging to point " << globalPoint << endreq;
        return 0;
    }
    m_lastBelongsTo = this->coordSysDE(globalPoint,de,height);
    if (!m_lastBelongsTo) {
        MsgStream msg(msgSvc(),name());
        msg << MSG::DEBUG
            << "Failed to find DE starting with " << de->name()
            << " and height " << height << " using global point: " << globalPoint
            << endreq;
        Gaudi::XYZPoint lpoint = de->geometry()->toLocal(globalPoint);
        msg << "In that frame the point is " << lpoint << endreq;
    }
    return m_lastBelongsTo;
}
IDetectorElement * CoordSysSvc::coordSysDE ( const Gaudi::XYZPoint &  globalPoint,
IDetectorElement *  start,
int  height = 0 
) [virtual]

Implements ICoordSysSvc.

Definition at line 131 of file CoordSysSvc.cc.

{

    IDetectorElement* de = start;

    // Start from start and work our way up, require a DE that has a
    // matching CoordinateSystem value and contains the global point.
    // If not, go to next larger CoordinateSystem DE.
    while (de) {

        const ParamValidDataObject* params = de->params();
        if (params && params->exists(m_CoordSysUserParameter)) {
            int level = params->param<int>(m_CoordSysUserParameter);
            if (!height || level == height) {
                if (de->geometry()->isInside(globalPoint)) {
                    m_lastCoordSys = de;
                    return m_lastCoordSys;
                }
            }
        }
        de = this->nextHigherCoordSysDE(de);
    }
            
    // reach here, got nuttin.
    MsgStream msg(msgSvc(),name());
    msg << MSG::DEBUG
        << "Failed to find coord sys DE starting from " 
        << start->name() << endreq;
    Gaudi::XYZPoint lpoint = start->geometry()->toLocal(globalPoint);
    msg << "In that frame the point is " << lpoint << endreq;
    return 0;
}
IDetectorElement * CoordSysSvc::nextHigherCoordSysDE ( IDetectorElement *  csde)

Definition at line 119 of file CoordSysSvc.cc.

{
    do {
        csde = csde->parentIDetectorElement();
        if (!csde) return 0;
        const ParamValidDataObject* params = csde->params();
        if (params && params->exists(m_CoordSysUserParameter)) 
            return csde;
    } while (csde);
    return 0;
}
const InterfaceID & ICoordSysSvc::interfaceID ( ) [static, inherited]

Definition at line 3 of file ICoordSysSvc.cc.

                                             {

  static const InterfaceID m_IID("ICoordSysSvc", 1, 0);

  return m_IID;
}

Member Data Documentation

std::string CoordSysSvc::m_CoordSysUserParameter [private]

The CoordSysUserParameter property to set what user parameter to look for to find the DetectorElement that provides the coordinate system.

Default is "CoordinateSystem".

Definition at line 63 of file CoordSysSvc.h.

The TopDetectorElementName property to set the name of the DetectorElement that holds all others.

Default is "/dd/Structure/DayaBay".

Definition at line 68 of file CoordSysSvc.h.

IDataProviderSvc* CoordSysSvc::m_detSvc [private]

Definition at line 70 of file CoordSysSvc.h.

IGeometryInfo* CoordSysSvc::m_topGI [private]

Definition at line 73 of file CoordSysSvc.h.

IDetectorElement* CoordSysSvc::m_lastBelongsTo [private]

Definition at line 76 of file CoordSysSvc.h.

IDetectorElement* CoordSysSvc::m_lastCoordSys [private]

Definition at line 77 of file CoordSysSvc.h.


The documentation for this class was generated from the following files:
| 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