ATLAS Offline Software
SurfaceCnv_p2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //-----------------------------------------------------------------------------
6 //
7 // file: SurfaceCnv_p2.cxx
8 //
9 // ----------------------------------------------------------------------------
10 
11 #include "TrkSurfaces/Surface.h"
21 
22 template <class SURFACE>
23 SURFACE* SurfaceCnv_p2<SURFACE>::createTransient( const Trk::Surface_p2 * persObj,MsgStream& ){
24  SURFACE* surface=nullptr;
25  if (persObj->m_transform.empty()) {
26  // det element surface
28  const SURFACE* detSurf = static_cast<const SURFACE*>(m_eventCnvTool->getSurface(id));
29  // In this case, we return a surface object held by detdescr.
30  // We need to cast away const to match the createTransient interface.
31  // This is ugly, but in practice should be ok.
32  // FIXME: can this be done better?
33  SURFACE* surface_nc ATLAS_THREAD_SAFE = const_cast<SURFACE*>(detSurf);
34  surface= surface_nc; // Needed to fulfill interface...
35  } else {
36  // Not Det element surface, so need to create surface & fill transform
39  surface=new SURFACE(transform);
40  }
41  return surface;
42 }
43 
44 template <class SURFACE>
45 void SurfaceCnv_p2<SURFACE>::persToTrans( const Trk::Surface_p2 * , SURFACE * , MsgStream &) {
46  throw std::runtime_error("SurfaceCnv_p2::persToTrans shouldn't be called any more!");
47  // The reason for this is that persToTrans relies on an object being created already.
48  // But for det element surfaces, we will return one which already exists and belongs to the detector elements.
49 }
50 
51 template <class SURFACE>
52 void SurfaceCnv_p2<SURFACE>::transToPers( const SURFACE * transObj,
53  Trk::Surface_p2 * persObj,
54  MsgStream & log)
55 {
56  if (not transObj){
57  log<<MSG::WARNING<<"SurfaceCnv_p2<SURFACE>::transToPers - null pointer for transient object."<<endmsg;
58  return;
59  }
60  persObj->m_associatedDetElementId = transObj->associatedDetectorElementIdentifier().get_identifier32().get_compact();
61  if (transObj->isFree() ) {
62  // if this is a free surface, write it out 'as is'
63  // - otherwise we're relying on the fact that the Identifier is there (and valid!) to reconstruct it on reading
64  EigenHelpers::eigenTransform3DToVector( *transObj->cachedTransform(),persObj->m_transform );
65 
66  } else {
67  if (!transObj->associatedDetectorElementIdentifier().is_valid()) {
68  log<<MSG::WARNING<<"SurfaceCnv_p2<SURFACE>::transToPers - invalid detector element for non-free surface: "<<*transObj<<endmsg;
69  }
70  }
71  persObj->m_surfaceType = static_cast<uint8_t>(transObj->type());
72 }
73 
74 // Specialisation for SaggedLineSurface - hopefully this will only ever be a DetEl surface, otherwise we need a new persistent type.
75 template <>
77  Trk::Surface_p2 * persObj,
78  MsgStream &log)
79 {
81  persObj->m_surfaceType = static_cast<uint8_t>(transObj->type());
82  if (transObj->isFree() ) {
83  log << MSG::WARNING<<"Not expecting these to be Free!"<<endmsg;
84  }
85 }
86 
87 template class SurfaceCnv_p2<Trk::ConeSurface>;
89 template class SurfaceCnv_p2<Trk::DiscSurface>;
Identifier32
Definition: Identifier32.h:25
SurfaceCnv_p2::createTransient
SURFACE * createTransient(const Trk::Surface_p2 *persObj, MsgStream &log)
Definition: SurfaceCnv_p2.cxx:23
StraightLineSurface.h
PerigeeSurface.h
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
Surface.h
Trk::Surface::associatedDetectorElementIdentifier
Identifier associatedDetectorElementIdentifier() const
return Identifier of the associated Detector Element
Trk::StraightLineSurface::type
constexpr virtual SurfaceType type() const override final
Return the surface type.
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Trk::Surface_p2::m_associatedDetElementId
Identifier32::value_type m_associatedDetElementId
Definition: Surface_p2.h:24
EigenHelpers::eigenTransform3DToVector
static void eigenTransform3DToVector(const Amg::Transform3D &trans, T &vec)
Convert HepGeom::Transform3D to std :: vector<double>
Definition: EigenHelpers.h:55
Trk::Surface_p2
Definition: Surface_p2.h:20
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
Trk::Surface_p2::m_transform
std::vector< float > m_transform
Definition: Surface_p2.h:25
SurfaceCnv_p2::transToPers
void transToPers(const SURFACE *, Trk::Surface_p2 *, MsgStream &)
Definition: SurfaceCnv_p2.cxx:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
CylinderSurface.h
EigenHelpers.h
EigenHelpers::vectorToEigenTransform3D
static void vectorToEigenTransform3D(const T &vec, Amg::Transform3D &trans)
Convert std :: vector<double> to Amg::Transform3D.
Definition: EigenHelpers.h:36
SurfaceCnv_p2.h
SurfaceCnv_p2< Trk::ConeSurface >
Trk::Surface::isFree
bool isFree() const
Returns 'true' if this surface is 'free', i.e.
SaggedLineSurface.h
PlaneSurface.h
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
DiscSurface.h
Trk::SaggedLineSurface
Definition: SaggedLineSurface.h:35
SurfaceCnv_p2::persToTrans
void persToTrans(const Trk::Surface_p2 *, SURFACE *, MsgStream &)
Definition: SurfaceCnv_p2.cxx:45
Trk::Surface_p2::m_surfaceType
uint8_t m_surfaceType
Definition: Surface_p2.h:26
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
checker_macros.h
Define macros for attributes used to control the static checker.
Identifier
Definition: IdentifierFieldParser.cxx:14