#ifndef TDigitProxy_hxx_seen #define TDigitProxy_hxx_seen #include #include #include "IDigit.hxx" #include "IDigitContainer.hxx" namespace COMET { /// An exception that should be thrown when the needed digit could not be /// found by the IDigitProxy. OA_EXCEPTION(EDigitNotFound,EDigit); /// An exception that should be thrown when the needed digit container /// could not be found by the IDigitProxy. OA_EXCEPTION(EDigitNotAvailable,EDigitNotFound); /// An exception that should be thrown when the salt for the digit doesn't /// match. OA_EXCEPTION(EDigitMismatch,EDigitNotFound); /// Thrown if the digit type is not valid. OA_EXCEPTION(EDigitTypeInvalid,EDigitNotFound); // A handle to reference a IDigit object that may or may not be available. class IDigitProxy; class IDigitManager; class IDigitContainer; } /// A handle to reference a IDigit object that may or may not be available. /// This differs from a IHandle in that the proxy doesn't keep the object from /// being deleted. If the object doesn't exist when accessed, this will throw /// an EDigitNotFound exception. class COMET::IDigitProxy { friend class IDigitManager; public: enum ProxyType { kInvalid = 0, kTest, kP0D, kTPC, kFGD, kECal, kSMRD, kINGRID }; // The data type used to store the signature. typedef int ProxyData; IDigitProxy(); virtual ~IDigitProxy(); /// Construct a proxy for a digit in a container. This constructs a proxy /// for a digit using the digit container, and the offset (index in the /// vector) of the digit within the container. Use this interface if you /// are iterating over the index of the digits: /// \code /// for (unsigned int offset = 0; offset T* As() const { IDigit* d = this->operator*(); if (!d) return NULL; return dynamic_cast(d); } /// Check that the digit proxy salt matchs the container and digit. bool CheckSalt(unsigned int signature, const COMET::IDigit* digit) const; /// Convert a proxy name into a proxy enum type. static enum ProxyType ConvertName(std::string name); /// Convert a proxy type into a proxy name. static std::string ConvertType(int type); /// Convert the proxy into a string. std::string AsString(void) const; private: /// Get the proxy data type out of the proxy signature. enum ProxyType GetProxyType() const; /// Get the salt out of the proxy signature. The salt is a simple check /// that the correct digit has been found. unsigned int GetProxySalt() const; /// Return the offset of the digit from the proxy signature. unsigned int GetProxyOffset() const; /// Return the cached digit pointer. COMET::IDigit* GetProxyCache() const; /// Set the cached digit pointer. void SetProxyCache(COMET::IDigit *const digit, COMET::IDigitContainer *const container) const; /// Set the proxy type in the signature. void SetProxyType(int type); /// Set the proxy salt in the signature. The salt is a simple check that /// the correct digit has been found. void SetProxySalt(int salt); /// Set the proxy offset of the digit in the proxy signature. void SetProxyOffset(int offset); /// The signature of the digit referenced in this proxy. The signature /// fits in a 32 bit field and has the following bit definitions. /// /// dddd dsss ssss ssso oooo oooo oooo oooo /// /// - d: 5 bits specifying the detector /// - s: 10 bits of salt to IcedustVerify the right digit is found. /// - o: 17 bits of offset within the collection of digits. /// ProxyData fDigitSignature; /// A cache for the digit referenced by this proxy. This is mutable so it /// can be set even if the IDigitProxy is constant. mutable COMET::IDigit* fDigit; //! Do not save. /// A cache to contain a pointer to the container that holds the digit. /// This is mutable so it can be set even if the IDigitProxy is constant. mutable COMET::IDigitContainer* fContainer; //! Do not save. virtual bool operator == (const COMET::IDigitProxy& rhs) const; ClassDef(IDigitProxy,1); }; #endif