00001
00002 #ifndef LIB_GEOMETRYINFOPLUS_H
00003 #define LIB_GEOMETRYINFOPLUS_H 1
00004
00005
00007 #include <iostream>
00008 #include <string>
00009 #include <functional>
00010 #include <algorithm>
00011
00012 #include "GaudiKernel/IMessageSvc.h"
00013 #include "GaudiKernel/ISvcLocator.h"
00014 #include "GaudiKernel/StatusCode.h"
00016 #include "DetDesc/Services.h"
00017 #include "DetDesc/ILVolume.h"
00018 #include "DetDesc/IPVolume.h"
00019 #include "DetDesc/IGeometryInfo.h"
00020 #include "DetDesc/IDetectorElement.h"
00021 #include "GeometryInfoException.h"
00022
00024 class GaudiException ;
00025 class IDataProviderSvc ;
00026 class ISvcLocator;
00027 class IUpdateManagerSvc;
00028 class AlignmentCondition;
00029
00045 class GeometryInfoPlus : public IGeometryInfo {
00046
00048 friend class DetectorElement;
00049
00050 public:
00051
00053 typedef std::vector<std::string> ChildName;
00054
00055 typedef std::vector<Gaudi::Transform3D>::const_iterator matrix_iterator;
00056
00057 typedef std::vector<IGeometryInfo*> IGIChildren;
00058 typedef IGeometryInfo::IGIChildrens::iterator iGInfo_iterator;
00059
00063 GeometryInfoPlus( IDetectorElement* de );
00064
00069 GeometryInfoPlus( IDetectorElement* de ,
00070 const std::string& LogVol );
00071
00079 GeometryInfoPlus( IDetectorElement* de,
00080 const std::string& LogVol,
00081 const std::string& Support,
00082 const ILVolume::ReplicaPath& ReplicaPath,
00083 const std::string& alignmentPath="");
00084
00092 GeometryInfoPlus( IDetectorElement* de,
00093 const std::string& LogVol,
00094 const std::string& Support,
00095 const std::string& ReplicaNamePath,
00096 const std::string& alignmentPath="");
00097
00098 virtual ~GeometryInfoPlus( );
00099
00100 public:
00101
00102 StatusCode initialize();
00103
00104 StatusCode cache();
00105
00106 StatusCode updateChildren();
00107
00108 bool hasLVolume() const;
00109
00110 bool hasSupport() const;
00111
00112 const AlignmentCondition* alignmentCondition() const ;
00113
00114 const Gaudi::Transform3D& toLocalMatrix() const;
00115
00116 const Gaudi::Transform3D& toGlobalMatrix() const;
00117
00118 const Gaudi::Transform3D& toLocalMatrixNominal() const;
00119
00120 const Gaudi::Transform3D& toGlobalMatrixNominal() const;
00121
00122 const Gaudi::Transform3D& ownToLocalMatrixNominal() const;
00123
00124 const Gaudi::Transform3D& ownToNominalMatrix() const;
00125
00126 Gaudi::Transform3D ownToOffNominalMatrix() const;
00127
00128 Gaudi::Transform3D ownMatrix() const;
00129
00130 StatusCode ownToOffNominalMatrix(const Gaudi::Transform3D&);
00131
00132 StatusCode ownToOffNominalParams(const std::vector<double>& trans,
00133 const std::vector<double>& rot,
00134 const std::vector<double>& pivot =
00135 std::vector<double>(3) );
00136
00137 Gaudi::XYZPoint toLocal( const Gaudi::XYZPoint& globalPoint ) const;
00138
00139 Gaudi::XYZPoint toGlobal( const Gaudi::XYZPoint& localPoint ) const;
00140
00141 Gaudi::XYZVector toLocal( const Gaudi::XYZVector& globalDirection ) const;
00142
00143 Gaudi::XYZVector toGlobal( const Gaudi::XYZVector& localDirection ) const;
00144
00145 bool isInside( const Gaudi::XYZPoint& globalPoint ) const ;
00146
00149 std::string belongsToPath( const Gaudi::XYZPoint& globalPoint );
00150
00154 IGeometryInfo* belongsTo( const Gaudi::XYZPoint& globalPoint );
00155
00159 std::string belongsToPath( const Gaudi::XYZPoint& globalPoint ,
00160 const int level );
00161
00165 IGeometryInfo* belongsTo( const Gaudi::XYZPoint& globalPoint ,
00166 const int level );
00167
00171 StatusCode fullGeoInfoForPoint( const Gaudi::XYZPoint& point ,
00172 const int level ,
00173 IGeometryInfo*& start ,
00174 ILVolume::PVolumePath& volumePath );
00175
00179 StatusCode fullGeoInfoForPoint( const Gaudi::XYZPoint& point ,
00180 const int level ,
00181 IGeometryInfo*& start ,
00182 ILVolume::ReplicaPath& volumePath );
00183
00187 StatusCode fullGeoInfoForPoint( const Gaudi::XYZPoint& point ,
00188 const int level ,
00189 std::string& start ,
00190 ILVolume::PVolumePath& volumePath );
00191
00195 StatusCode fullGeoInfoForPoint( const Gaudi::XYZPoint& point ,
00196 const int level ,
00197 std::string& start ,
00198 ILVolume::ReplicaPath& volumePath );
00199
00201 inline const std::string& lvolumeName() const { return m_gi_lvolumeName; }
00202
00203
00205 const ILVolume* lvolume() const ;
00206
00208 StatusCode location( IGeometryInfo*& start ,
00209 ILVolume::ReplicaPath& replicaPath ) const ;
00210
00212 StatusCode location( std::string& start ,
00213 ILVolume::ReplicaPath& replicaPath ) const ;
00214
00216 IGeometryInfo* supportIGeometryInfo() const;
00217
00218
00220 std::string lvolumePath( const std::string& start ,
00221 const ILVolume::ReplicaPath& replicaPath );
00222
00224 const ILVolume* lvolume( const std::string& start ,
00225 const ILVolume::ReplicaPath& replicaPath );
00226
00228 std::string lvolumePath( IGeometryInfo* start ,
00229 const ILVolume::ReplicaPath& replicaPath );
00230
00232 const ILVolume* lvolume( IGeometryInfo* start ,
00233 const ILVolume::ReplicaPath& replicaPath );
00234
00236 const ILVolume::ReplicaPath& supportPath() const ;
00237
00238
00240 IGeometryInfo* parentIGeometryInfo();
00241
00243 const IGeometryInfo* parentIGeometryInfo() const;
00244
00246 inline IGeometryInfo::IGIChildrens& childIGeometryInfos()
00247 {
00248 if( !m_gi_childLoaded ) loadChildren();
00249 return m_gi_childrens;
00250 }
00252 inline const IGeometryInfo::IGIChildrens& childIGeometryInfos() const
00253 {
00254 if( !m_gi_childLoaded ) loadChildren();
00255 return m_gi_childrens;
00256 }
00259 inline IGeometryInfo::IGIChildrens::const_iterator childBegin() const
00260 {
00261 if( !m_gi_childLoaded ) {
00262 try{ loadChildren(); }
00263 catch(...) { return m_gi_childrens.end(); }
00264 }
00265 return m_gi_childrens.begin();
00266 }
00267
00268
00270 inline IGeometryInfo::IGIChildrens::iterator childBegin()
00271 {
00272 if( !m_gi_childLoaded )
00273 { try{ loadChildren(); } catch(...){ return m_gi_childrens.end(); } }
00274 return m_gi_childrens.begin();
00275 }
00276
00278 inline IGeometryInfo::IGIChildrens::iterator childEnd()
00279 {
00280 if( !m_gi_childLoaded )
00281 { try{ loadChildren(); } catch(...){ return m_gi_childrens.end(); } }
00282 return m_gi_childrens.end();
00283 }
00284
00285
00287 inline IGeometryInfo::IGIChildrens::const_iterator childEnd() const
00288 {
00289 if( !m_gi_childLoaded )
00290 { try{ loadChildren(); } catch(...){ return m_gi_childrens.end(); } }
00291 return m_gi_childrens.end();
00292 }
00293
00295 std::ostream& printOut ( std::ostream& ) const;
00297 MsgStream& printOut ( MsgStream& ) const;
00299 IGeometryInfo* reset();
00300
00306 StatusCode queryInterface( const InterfaceID& ID , void** ppI ) ;
00308 unsigned long addRef()
00309 {
00310 return 0;
00311 }
00312
00314 unsigned long release()
00315 {
00316 return 0;
00317 }
00318
00319
00320
00321
00322 protected:
00323
00324
00325 private:
00326
00327 inline IMessageSvc* msgSvc() const {
00328 return m_services->msgSvc();
00329 }
00330 inline IDataProviderSvc* dataSvc() const {
00331 return m_services->detSvc();
00332 }
00333 inline ISvcLocator* svcLocator() const {
00334 return m_services->svcLocator();
00335 }
00336 inline IUpdateManagerSvc* updMgrSvc(bool create = false) const {
00337 return m_services->updMgrSvc(create);
00338 }
00339
00340 inline MsgStream& log() const { return *m_log; }
00341
00342 inline bool isInsideDaughter( const Gaudi::XYZPoint& globalPoint ) const
00343 {
00344 if( !childLoaded() || loadChildren().isFailure() ) return false;
00345 IGeometryInfo::IGIChildrens::const_iterator it =
00346 std::find_if( childBegin() , childEnd () ,
00347 IGeometryInfo_isInside( globalPoint ) ) ;
00348 return ( ( childEnd() == it ) ? false : true );
00349 }
00350
00351 inline bool childLoaded() const { return m_gi_childLoaded ; }
00352
00355 StatusCode registerSupportGI();
00356
00357 StatusCode calculateMatrices();
00358
00359 StatusCode combineMatrices(matrix_iterator deltaFirst,
00360 matrix_iterator deltaEnd,
00361 matrix_iterator pvFirst,
00362 matrix_iterator pvEnd);
00363
00367 StatusCode calculateFullMatrices(matrix_iterator deltaFirst,
00368 matrix_iterator deltaEnd,
00369 matrix_iterator pvFirst);
00370
00374 void calculateIdealMatrix(matrix_iterator pvFirst,
00375 matrix_iterator pvEnd);
00376
00379 StatusCode setLocalOffNominalDeltaMatrix(const Gaudi::Transform3D&
00380 newDelta);
00381
00382
00383 StatusCode getAlignmentCondition();
00384
00385 StatusCode registerCondition();
00386
00387 void clearMatrices();
00388
00389 inline bool needsAlignmentCondition() const
00390 {
00391 return m_hasAlignmentPath;
00392 }
00393
00394 inline void needsAlignmentCondition(const bool& needsAlignment)
00395 {
00396 m_hasAlignmentPath = needsAlignment;
00397 }
00398
00399 inline bool hasAlignmentCondition() const
00400 {
00401 return m_hasAlignment;
00402 }
00403
00404 inline void hasAlignmentCondition(const bool& hasAlignment)
00405 {
00406 m_hasAlignment = hasAlignment;
00407 }
00408
00409 inline AlignmentCondition* myAlignmentCondition() const
00410 {
00411 return m_alignmentCondition;
00412 }
00413
00414 IDetectorElement* parentIDetectorElement(IDetectorElement* iDetElem)
00415 {
00416 return (0!=iDetElem) ? iDetElem->parentIDetectorElement() : 0;
00417 }
00418
00419 IGeometryInfo* geoByName ( const std::string& name ) const ;
00420
00421 ILVolume* findLogical() const ;
00423 StatusCode loadChildren() const ;
00424
00425 inline IDetectorElement* detElem() const {
00426 return m_gi_iDetectorElement ;
00427 }
00428
00430 inline void Assert( bool assertion,
00431 const std::string& name ) const {
00432 if( !assertion ) { throw GeometryInfoException( name , this ); }
00433 };
00434
00436 inline void Assert( bool assertion, const std::string& name,
00437 const GaudiException& ge ) const {
00438 if( !assertion ) { throw GeometryInfoException( name , ge , this ); }
00439 };
00440
00441 Gaudi::Transform3D* accumulateMatrices(const ILVolume::PVolumePath& volumePath) const;
00442
00443
00444
00445 bool idealMatrixLoaded() { return (0!= m_idealMatrix); }
00446
00447 private:
00448
00449 MsgStream* m_log;
00450
00452 bool m_gi_has_logical ;
00456 std::string m_gi_lvolumeName ;
00458 mutable ILVolume* m_gi_lvolume;
00459
00460 bool m_hasAlignment;
00461
00462 std::string m_alignmentPath;
00463
00464 bool m_hasAlignmentPath;
00465
00466 AlignmentCondition* m_alignmentCondition;
00467
00471 mutable Gaudi::Transform3D* m_matrix;
00472
00476 mutable Gaudi::Transform3D* m_idealMatrix;
00477
00478 mutable Gaudi::Transform3D* m_localIdealMatrix;
00479 mutable Gaudi::Transform3D* m_localDeltaMatrix;
00480
00489 mutable Gaudi::Transform3D* m_matrixInv;
00490 mutable Gaudi::Transform3D* m_idealMatrixInv;
00491
00493 bool m_gi_has_support ;
00497 std::string m_gi_supportName ;
00499 mutable IGeometryInfo* m_gi_support ;
00501 mutable ILVolume::ReplicaPath m_gi_supportPath ;
00503 std::string m_gi_supportNamePath ;
00504
00506 mutable IDetectorElement* m_gi_iDetectorElement ;
00507
00509 mutable bool m_gi_parentLoaded ;
00511 mutable IGeometryInfo* m_gi_parent ;
00513 mutable bool m_gi_childLoaded ;
00517 mutable IGeometryInfo::IGIChildrens m_gi_childrens ;
00521 mutable GeometryInfoPlus::ChildName m_gi_childrensNames ;
00522
00524 static unsigned long m_count;
00525
00527 DetDesc::Services* m_services;
00528
00533 std::vector<Gaudi::Transform3D> m_pvMatrices;
00534 std::vector<Gaudi::Transform3D> m_deltaMatrices;
00535
00536
00538 bool m_has_condition ;
00540 std::string m_gi_condPath ;
00541
00542
00543 inline matrix_iterator idealBegin() const
00544 {
00545 return m_pvMatrices.begin();
00546 }
00547
00548 inline matrix_iterator idealEnd() const
00549 {
00550 return m_pvMatrices.end();
00551 }
00552
00553 inline matrix_iterator deltaBegin() const
00554 {
00555 return m_deltaMatrices.begin();
00556 }
00557
00558 inline matrix_iterator deltaEnd() const
00559 {
00560 return m_deltaMatrices.end();
00561 }
00562 };
00563 #endif // LIB_GEOMETRYINFOPLUS_H