#ifndef OAEVENT_IFIELDDESCRIPTION_HXX #define OAEVENT_IFIELDDESCRIPTION_HXX #include "IDatum.hxx" #include "IHandle.hxx" #include "TRotation.h" #include "TVector3.h" namespace COMET{ class IFieldDescription; class IElementFieldDescription; class IElementField; } /// An abstract base class for an individual element of the magnetic field class COMET::IElementFieldDescription:public COMET::IDatum{ public: IElementFieldDescription(const TRotation* rotation=NULL, const TVector3* translation=NULL): COMET::IDatum("","Field element"), fTranslation(NULL), fRotation(NULL){ // Constructs from pointers so we can optionally not have // a rotation SetRotation(rotation); SetTranslation(translation); } /// Copy constructor to handle owned pointers IElementFieldDescription(const IElementFieldDescription& rhs); // Swap function for copy-and-swap idiom friend void swap(IElementFieldDescription& aDescr, IElementFieldDescription& bDescr){ using std::swap; swap(aDescr.fTranslation, bDescr.fTranslation); swap(aDescr.fRotation, bDescr.fRotation); } /// Desturctor virtual ~IElementFieldDescription(); virtual void ls(Option_t* opt = "") const=0; /// Rebuild the field represented by this component /// Note that this class will be deleted once this task is finished, so /// derived classes should give up ownership of all objects needed to /// describe the field. //virtual COMET::IElementField* Recreate()const=0; ClassDef(IElementFieldDescription,4); /// Get the translation of the field map element const TVector3* Translation()const{return fTranslation;} /// Get the rotation of the field map element const TRotation* Rotation()const{return fRotation;} /// Set center of field element void SetTranslation(const TVector3& trans){ // Delete it if its been set if (fTranslation) delete fTranslation; // Make a new one fTranslation = new TVector3(trans); }; /// Set the center of field element void SetTranslation(const TVector3* trans){ if (trans) SetTranslation(*trans); } /// Set the rotation field element void SetRotation(const TRotation& trans){ // Delete it if its been set if (fRotation) delete fRotation; // Make a new one fRotation = new TRotation(trans); }; /// Set the rotation of field element void SetRotation(const TRotation* rotation){ if (rotation) SetRotation(*rotation); } protected: /// The translation of the field map TVector3* fTranslation; /// The rotation of the field map TRotation* fRotation; }; /// A persistable list of field components that built up a complete description /// of the field across the detector class COMET::IFieldDescription:public COMET::IDatum{ public: IFieldDescription():COMET::IDatum("field_description","Description of electromagnetic field"){} virtual ~IFieldDescription(){} void AddElement(const COMET::IElementFieldDescription*); /// Rebuild the field represented by this description. /// Calls IElementField::Recreate on all elements in fDescriptionList /// /// @return true if successfully created all elements, false otherwise //bool Recreate()const; virtual void ls(Option_t* opt = "") const; size_t GetNumElements()const{return fDescriptionList.size();} const IElementFieldDescription& GetElement(int index)const{return *fDescriptionList.at(index);} private: typedef std::vector DescriptionList; std::vector fDescriptionList; ClassDef(IFieldDescription,3); }; #endif // OAEVENT_IFIELDDESCRIPTION_HXX