MPositionable.h
Go to the documentation of this file.
1 #ifndef _det_MPositionable_h
2 #define _det_MPositionable_h
3 
4 #include <utl/ShadowPtr.h>
5 #include <utl/Point.h>
6 #include <utl/Vector.h>
7 #include <utl/CoordinateSystemPtr.h>
8 #include <utl/TransformationMatrix.h>
9 #include <fwk/LocalCoordinateSystem.h>
10 
11 #include <string>
12 
13 
14 namespace det {
15 
119  template<class Config>
121  public:
126  MPositionable(const Config& cp) : fConfig(cp) { }
127 
128  virtual ~MPositionable() { }
129 
132 
137  utl::Point GetPosition() const;
138 
139  protected:
143  static const std::string kCoordinateTypeTag;
145  static const std::string kComponent1Tag;
147  static const std::string kComponent2Tag;
149  static const std::string kComponent3Tag;
151  static const std::string kEulerPhiTag;
153  static const std::string kEulerThetaTag;
155  static const std::string kEulerPsiTag;
157  typedef std::string CoordinateType;
158  /*
159  * Discarded by now: CoordinateSystem is also prepared for this.
160  * Seems clearer the use of a string tag instead of an integral value.
161  *
162  * typedef int CoordinateType;
163  */
164  /*
165  * In the following there are several virtual methods that are thought to
166  * allow deriving classes to fill some holes (ie in a Template pattern fashion)
167  * regarding the coordinates of this object coordinate system.
168  *
169  * One of them is even a pure virtual method without an implementation provided
170  * here, the others have an implementation by this class.
171  *
172  * Currently most of them are protected methods, tough it may be enough to have them
173  * just private (ie the deriving classes just need to overrided / define any of
174  * these methods, but no do an actual call to one of them). Making these methods
175  * privated would follow the guideline given by Herb Sutter in
176  *
177  * "Virtuality"
178  * C/C++ Users Journal, 19(9), September 2001.
179  * (http://www.gotw.ca/publications/mill18.htm) where it's said:
180  * Guideline #2: Prefer to make virtual functions private.
181  * Guideline #3: Only if derived classes need to invoke the base implementation of a virtual function, make the virtual function protected.
182  *
183  * On the other hand, all these functions are getters that doesn't perform any operation but to retrieve a value (maybe accesing configuration),
184  * so there's no workflow to be ensured by this class (ie there's on risk to call them in some not foreseen situation): so at last
185  * it seems reasonable to leave them protected so as to allow deriving classes a (probably necessary) call to one of them.
186  *
187  * But, at last, for the pure virtual function case there's no point to have it protected: it has to be defined by deriving classes, and so when
188  * defined "down the hierarchy" the accesss control modifier here specified is overrided; conversely, if not defined, it couldn't be called: it has
189  * no definition provided (remember that a __pure__ virtual function may have, anyway, a definition provided: the, say, "purity" just enforces
190  * deriving classes to provide an implementation by themselves)!
191  */
212  virtual double GetComponent1() const;
213 
219  virtual double GetComponent2() const;
220 
226  virtual double GetComponent3() const;
227 
231  virtual double GetEulerPhi() const;
232 
237  virtual double GetEulerTheta() const;
238 
243  virtual double GetEulerPsi() const;
244 
250  virtual CoordinateType GetCoordinateType() const;
252 
253  private:
258 
276  const Config& fConfig;
278  };
279 
280 
281  template<class Config>
282  const std::string MPositionable<Config>::kComponent1Tag = "positionComponent1";
283 
284  template<class Config>
285  const std::string MPositionable<Config>::kComponent2Tag = "positionComponent2";
286 
287  template<class Config>
288  const std::string MPositionable<Config>::kComponent3Tag = "positionComponent3";
289 
290  template<class Config>
291  const std::string MPositionable<Config>::kEulerPhiTag = "eulerPhi";
292 
293  template<class Config>
294  const std::string MPositionable<Config>::kEulerThetaTag = "eulerTheta";
295 
296  template<class Config>
297  const std::string MPositionable<Config>::kEulerPsiTag = "eulerPsi";
298 
299  template<class Config>
300  const std::string MPositionable<Config>::kCoordinateTypeTag = "coordinateType";
301 
302  template<class Config>
303  double
305  const
306  {
307  /* Hack to fix compilation using g++ 4.1.2 on SL 5.5 (present in most GRID nodes) RFG 2013
308  See: http://www.gotw.ca/publications/mill17.htm */
309  return fConfig.template GetData<double, utl::ThrowOnZeroDereference, utl::ShadowPtr>(fComponent1, kComponent1Tag);
310  }
311 
312  template<class Config>
314  { return fConfig.template GetData<double, utl::ThrowOnZeroDereference, utl::ShadowPtr>(fComponent2, kComponent2Tag); }
315 
316  template<class Config>
318  { return fConfig.template GetData<double, utl::ThrowOnZeroDereference, utl::ShadowPtr>(fComponent3, kComponent3Tag); }
319 
320  template<class Config>
322  { return fConfig.template GetData<double, utl::ThrowOnZeroDereference, utl::ShadowPtr>(fEulerPhi, kEulerPhiTag); }
323 
324  template<class Config>
326  { return fConfig.template GetData<double, utl::ThrowOnZeroDereference, utl::ShadowPtr>(fEulerTheta, kEulerThetaTag); }
327 
328  template<class Config>
330  { return fConfig.template GetData<double, utl::ThrowOnZeroDereference, utl::ShadowPtr>(fEulerPsi, kEulerPsiTag); }
331 
332  template<class Config>
334  { return fConfig.template GetData<CoordinateType, utl::ThrowOnZeroDereference, utl::ShadowPtr>(fCoordinateType, kCoordinateTypeTag); }
335 
336  template<class Config>
338  { return utl::Point(0, 0, 0, GetLocalCoordinateSystem()); }
339 
340  template<class Config>
343  const
344  {
345  if (!fLocalCoordinateSystem) {
346  // Alias for convenience.
348  // Retrieve the reference one and the apply the pertaining transformations.
349  auto cs = GetReferenceCoordinateSystem();
350  // Displacement components.
351  const double c1 = GetComponent1();
352  const double c2 = GetComponent2();
353  const double c3 = GetComponent3();
354  // Now the rotation part.
355  const double phi = GetEulerPhi();
356  const double theta = GetEulerTheta();
357  const double psi = GetEulerPsi();
358  // Check if there is something to be done (if not cs stays the same)...
359  if (c1 || c2 || c3 || phi || theta || psi) {
360  // Create the given coordinate type (the innermost creation may throw).
361  const Type& ct = Type::Create(Type::KindCreator::Create(GetCoordinateType()));
362  // Construct the displacement vector.
363  const utl::Vector trans(c1, c2, c3, cs, ct);
364  // Move the system.
365  cs = utl::CoordinateSystem::Translation(trans, cs);
366  /*
367  * Apply the rotations in the established conventional order and
368  * to the correspoding axes (some of them being the result of
369  * previously applied rotations). See this class' main comment.
370  *
371  * The rotations are finally forwarded to CLHEP rotation classes,
372  * which state that they are counterclockwise (see Transform3D.h
373  * in there).
374  */
375  if (phi)
376  cs = utl::CoordinateSystem::RotationZ(phi, cs);
377  if (theta)
378  cs = utl::CoordinateSystem::RotationX(theta, cs);
379  if (psi)
380  cs = utl::CoordinateSystem::RotationZ(psi, cs);
381  }
382  fLocalCoordinateSystem = cs;
383  }
384  return fLocalCoordinateSystem;
385  }
386 
387 }
388 
389 
390 #endif
virtual double GetComponent1() const
First component of the position vector.
Point object.
Definition: Point.h:32
const Config & fConfig
Hold a reference to the configuration proxy.
virtual utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const =0
virtual double GetEulerPsi() const
Third Euler angle for rotation over (intermediate) z.
utl::ShadowPtr< CoordinateType > fCoordinateType
virtual CoordinateType GetCoordinateType() const
Coordinate type.
Mixin class to be inherited from objects that have a position.
static const std::string kCoordinateTypeTag
utl::ShadowPtr< double > fEulerTheta
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Local system based on position and configured rotations.
utl::ShadowPtr< double > fComponent1
virtual double GetComponent2() const
Second component of the position vector.
utl::Point GetPosition() const
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
virtual double GetEulerTheta() const
Second Euler angle for rotation over (intermediate) x.
static const std::string kEulerPsiTag
Tag for third rotation&#39;s Euler angle in config.
virtual double GetComponent3() const
Third component of the position vector.
static Policy::type RotationZ(const double angle, const CoordinateSystemPtr &theCS)
Construct from rotation about Z axis.
utl::ShadowPtr< double > fComponent2
virtual double GetEulerPhi() const
First Euler angle for rotation over (original) z.
static const std::string kComponent2Tag
Tag for second vector component in config.
MPositionable(const Config &cp)
static Policy::type Translation(const Vector &theTranslation, const CoordinateSystemPtr &theCS)
Construct from translation by vector.
static const std::string kComponent3Tag
Tag for third vector component in config.
utl::ShadowPtr< double > fEulerPsi
Base class for classes indicating coordinate types.
Definition: BasicVector.h:48
Vector object.
Definition: Vector.h:30
virtual ~MPositionable()
utl::CoordinateSystemPtr fLocalCoordinateSystem
static const std::string kEulerPhiTag
Tag for first rotation&#39;s Euler angle in config.
utl::ShadowPtr< double > fEulerPhi
static const std::string kComponent1Tag
Tag for first vector component in config.
utl::ShadowPtr< double > fComponent3
std::string CoordinateType
Simple internal typedef to emulate the actual enumeration via a type handled in the configuration mec...
Type
The type of file that we are acutally opening.
Definition: IoCodes.h:33
static Policy::type RotationX(const double angle, const CoordinateSystemPtr &theCS)
Construct from rotation about X axis.
static const std::string kEulerThetaTag
Tag for second rotation&#39;s Euler angle in config.
void Config(const std::string &infile)
Definition: fwkPython.cc:13

, generated on Tue Sep 26 2023.