Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:33

0001 #ifndef Alignment_CommonAlignment_AlignableDetOrUnitPtr_H
0002 #define Alignment_CommonAlignment_AlignableDetOrUnitPtr_H
0003 
0004 /** \class AlignableDetOrUnitPtr
0005  *
0006  * Class to hold either a pointer to an AlignableDet or to an AlignableDetUnit.
0007  * As such it is like a pointer to an Alignable of that hierarchy level
0008  * on which hits can exists. Therefore it should be used whenever it should be
0009  * ensured by C++ type safety that a lowest level Alignable* is dealt with.
0010  * 
0011  * Conversion and '->' operators exist to use this class as a pointer to the base
0012  * class Alignable. On the other hand, the accessors alignableDet() and
0013  * alignableDetUnit() can be used to check which concrete type it is.
0014  *
0015  * Since this class is very light weighted, it can be used by value.
0016  *
0017  *  Original author: Gero Flucke, April 2007
0018  *
0019  *  $Date: 2009/02/28 21:04:59 $
0020  *  $Revision: 1.3 $
0021  *  (last update by $Author: flucke $)
0022  */
0023 
0024 class Alignable;
0025 class AlignableBeamSpot;
0026 class AlignableDet;
0027 class AlignableDetUnit;
0028 class AlignmentPositionError;
0029 
0030 class AlignableDetOrUnitPtr {
0031 public:
0032   /// Constructor from AlignableBeamSpot* (non-explicit: for automatic conversions)
0033   inline AlignableDetOrUnitPtr(AlignableBeamSpot* aliBeamSpot)
0034       : theAliBeamSpot(aliBeamSpot), theAliDet(nullptr), theAliDetUnit(nullptr) {}
0035 
0036   /// Constructor from AlignableDet* (non-explicit: for automatic conversions)
0037   inline AlignableDetOrUnitPtr(AlignableDet* aliDet)
0038       : theAliBeamSpot(nullptr), theAliDet(aliDet), theAliDetUnit(nullptr) {}
0039 
0040   /// Constructor from AlignableDetUnit* (non-explicit: for automatic conversions)
0041   inline AlignableDetOrUnitPtr(AlignableDetUnit* aliDetUnit)
0042       : theAliBeamSpot(nullptr), theAliDet(nullptr), theAliDetUnit(aliDetUnit) {}
0043   /// Non-virtual destructor: do not use as base class
0044   inline ~AlignableDetOrUnitPtr() {}
0045 
0046   inline AlignableDetOrUnitPtr& operator=(AlignableBeamSpot* aliBeamSpot) {
0047     theAliBeamSpot = aliBeamSpot;
0048     theAliDet = nullptr;
0049     theAliDetUnit = nullptr;
0050     return *this;
0051   }
0052   inline AlignableDetOrUnitPtr& operator=(AlignableDet* aliDet) {
0053     theAliBeamSpot = nullptr;
0054     theAliDet = aliDet;
0055     theAliDetUnit = nullptr;
0056     return *this;
0057   }
0058   inline AlignableDetOrUnitPtr& operator=(AlignableDetUnit* aliDetUnit) {
0059     theAliBeamSpot = nullptr;
0060     theAliDet = nullptr;
0061     theAliDetUnit = aliDetUnit;
0062     return *this;
0063   }
0064   // Default operator= and default copy constructor are fine, no need to code them here.
0065 
0066   // conversions to Alignable* etc.
0067   operator Alignable*();
0068   operator const Alignable*() const;
0069   inline Alignable* operator->() { return this->operator Alignable*(); }
0070   inline const Alignable* operator->() const { return this->operator const Alignable*(); }
0071   // explicit call if needed:
0072   inline Alignable* alignable() { return this->operator Alignable*(); }
0073   inline const Alignable* alignable() const { return this->operator const Alignable*(); }
0074 
0075   // explicit access to specific types
0076   inline AlignableBeamSpot* alignableBeamSpot() { return theAliBeamSpot; }
0077   inline const AlignableBeamSpot* alignableBeamSpot() const { return theAliBeamSpot; }
0078   inline AlignableDet* alignableDet() { return theAliDet; }
0079   inline const AlignableDet* alignableDet() const { return theAliDet; }
0080   inline AlignableDetUnit* alignableDetUnit() { return theAliDetUnit; }
0081   inline const AlignableDetUnit* alignableDetUnit() const { return theAliDetUnit; }
0082 
0083   /// check for empty pointer
0084   inline bool isNull() const { return (!theAliBeamSpot && !theAliDet && !theAliDetUnit); }
0085 
0086   // interface to methods specific for AlignableDet(Unit),
0087   // slightly breaking idea of 'pointerness' of this class
0088   /// alignment position error (see comments in specific classes)
0089   const AlignmentPositionError* alignmentPositionError() const;
0090 
0091 private:
0092   AlignableBeamSpot* theAliBeamSpot;  ///< Pointer to Alignable if it is the beam spot
0093   AlignableDet* theAliDet;            ///< Pointer to Alignable if it is a Det
0094   AlignableDetUnit* theAliDetUnit;    ///< Pointer to Alignable if it is a DetUnit
0095 };
0096 
0097 #endif