#ifndef SCT_ADDRESSING_H #define SCT_ADDRESSING_H #include #include #include "Sct/Addressing.hh" namespace Sct { /// No two partitions within the SCT have the same PartitionIdentifier. typedef unsigned int PartitionIdentifier; /// No two crates within a given partition have the same CrateIdentifier typedef unsigned int CrateIdentifier; /// No two rods within a given crate have the same RodIdentifier typedef unsigned int RodIdentifier; // forward declarations class UniquePartitionIdentifier; class UniqueCrateIdentifier; class UniqueRodIdentifier; class UniqueTimIdentifier; // shorter forms: typedef UniquePartitionIdentifier UPID; typedef UniqueCrateIdentifier UCID; typedef UniqueRodIdentifier URID; typedef UniqueTimIdentifier UTID; // defns: /// No two partitions within ATLAS have the same UniqePartitionIdentifier. class UniquePartitionIdentifier { PartitionIdentifier m_partition; public: UniquePartitionIdentifier(const Sct::Corba::UPID & other) : m_partition(other.partition) { }; UniquePartitionIdentifier(const UniquePartitionIdentifier & other) : m_partition(other.m_partition) { }; explicit UniquePartitionIdentifier(const PartitionIdentifier p) : m_partition(p) { }; /** Constructs from a string encoded UPID. throws InvalidArgumentError if the format of UPID is not correct */ explicit UniquePartitionIdentifier(const std::string & s); UniquePartitionIdentifier() {}; UniquePartitionIdentifier & operator=(const UniquePartitionIdentifier & other) { m_partition = other.m_partition; return *this; }; bool operator==(const UniquePartitionIdentifier & other) const { return m_partition == other.m_partition; }; bool operator!=(const UniquePartitionIdentifier & other) const { return m_partition != other.m_partition; }; PartitionIdentifier partition() const { return m_partition; }; operator std::string () const; bool operator<(const UniquePartitionIdentifier & other) const { return this->m_partition < other.m_partition; }; private: std::string tag() const { return "UPID"; }; }; /// Base class for UniqueIdentifiers that live at the Crate level /// (i.e. base class for UniqueTimIdentifiers and UniqueCrateIdentifiers) class UniqueCrateLevelIdentifierBase { UniquePartitionIdentifier m_partition; CrateIdentifier m_crate; public: UniqueCrateLevelIdentifierBase(const UniquePartitionIdentifier p, const CrateIdentifier c) : m_partition(p), m_crate(c) { }; UniqueCrateLevelIdentifierBase(const PartitionIdentifier p, const CrateIdentifier c) : m_partition(p), m_crate(c) { }; UniqueCrateLevelIdentifierBase() {}; public: /// gets upid (="unique partition id") UniquePartitionIdentifier upid() const { return m_partition; }; public: /// gets pid (="partition id") PartitionIdentifier partition() const { return m_partition.partition(); }; /// gets cid (="crate id") CrateIdentifier crate() const { return m_crate; }; protected: // Protected because we don't want people to be able to compare different specialisations with each other,or work with the bases themselves. UniqueCrateLevelIdentifierBase & operator=(const UniqueCrateLevelIdentifierBase & other) { m_partition = other.m_partition; m_crate = other.m_crate; return *this; }; bool operator==(const UniqueCrateLevelIdentifierBase & other) const { return m_crate == other.m_crate && m_partition == other.m_partition; }; bool operator!=(const UniqueCrateLevelIdentifierBase & other) const { return m_crate != other.m_crate || m_partition != other.m_partition; }; bool operator<(const UniqueCrateLevelIdentifierBase & other) const { return m_partition < other.m_partition || m_partition == other.m_partition && m_crate < other.m_crate; }; const UniqueCrateLevelIdentifierBase & base() const { return *this; }; UniqueCrateLevelIdentifierBase & base() { return *this; }; }; /// No two crates within the SCT have the same UniqueCrateIdentifier. class UniqueCrateIdentifier : public UniqueCrateLevelIdentifierBase { public: UniqueCrateIdentifier(const Sct::Corba::UCID & other) : UniqueCrateLevelIdentifierBase(other.partition, other.crate) { }; UniqueCrateIdentifier(const UniquePartitionIdentifier p, const CrateIdentifier c) : UniqueCrateLevelIdentifierBase(p,c) { }; UniqueCrateIdentifier(const PartitionIdentifier p, const CrateIdentifier c) : UniqueCrateLevelIdentifierBase(p,c) { }; /** Constructs from a string encoded UCID. throws InvalidArgumentError if the format of UCID is not correct */ explicit UniqueCrateIdentifier(const std::string & s); UniqueCrateIdentifier() {}; // Not necessary: default will do! /* UniqueCrateIdentifier & operator=(const UniqueCrateIdentifier & other) { this->UniqueCrateLevelIdentifierBase::operator=(other); return *this; }; */ bool operator==(const UniqueCrateIdentifier & other) const { return this->UniqueCrateLevelIdentifierBase::operator==(other); }; bool operator!=(const UniqueCrateIdentifier & other) const { return this->UniqueCrateLevelIdentifierBase::operator!=(other); }; bool operator<(const UniqueCrateIdentifier & other) const { return this->UniqueCrateLevelIdentifierBase::operator<(other); }; operator std::string () const; private: std::string tag() const { return "UCID"; }; }; /// No two TIMs within the SCT have the same UniqueTimIdentifier. /// (Assuming there is no more than one TIM per crate!) class UniqueTimIdentifier : public UniqueCrateLevelIdentifierBase { public: UniqueTimIdentifier(const UniquePartitionIdentifier p, const CrateIdentifier c) : UniqueCrateLevelIdentifierBase(p,c) { }; UniqueTimIdentifier(const PartitionIdentifier p, const CrateIdentifier c) : UniqueCrateLevelIdentifierBase(p,c) { }; UniqueTimIdentifier(const std::string & s); UniqueTimIdentifier() {}; // Not necessary: default will do! /* UniqueTimIdentifier & operator=(const UniqueTimIdentifier & other) { this->UniqueCrateLevelIdentifierBase::operator=(other); return *this; }; */ bool operator==(const UniqueTimIdentifier & other) const { return this->UniqueCrateLevelIdentifierBase::operator==(other); }; bool operator!=(const UniqueTimIdentifier & other) const { return this->UniqueCrateLevelIdentifierBase::operator!=(other); }; bool operator<(const UniqueTimIdentifier & other) const { return this->UniqueCrateLevelIdentifierBase::operator<(other); }; operator std::string () const; private: std::string tag() const { return "UTID"; }; }; /// No two rods within the SCT have the same UniqueRodIdentifier. class UniqueRodIdentifier { UniqueCrateIdentifier m_ucid; RodIdentifier m_rid; public: UniqueRodIdentifier(const Sct::Corba::URID & other) : m_ucid(UniqueCrateIdentifier(other.partition, other.crate)), m_rid(other.rod) { }; UniqueRodIdentifier(const UniqueCrateIdentifier c, const RodIdentifier r) : m_ucid(c), m_rid(r) { }; UniqueRodIdentifier(const PartitionIdentifier p, const CrateIdentifier c, const RodIdentifier r) : m_ucid(UniqueCrateIdentifier(p,c)), m_rid(r) { }; /** Constructs from a string encoded URID. throws InvalidArgumentError if the format of URID is not correct */ explicit UniqueRodIdentifier(const std::string & s); UniqueRodIdentifier() {}; public: /// gets upid (="unique partition id") UniquePartitionIdentifier upid() const { return m_ucid.upid(); }; /// gets ucid (="unique crate id") UniqueCrateIdentifier ucid() const { return m_ucid; }; public: /// gets pid (="parition id") PartitionIdentifier partition() const { return m_ucid.partition(); }; /// gets cid (="crate id") RodIdentifier crate() const { return m_ucid.crate(); }; /// gets rid (="rod id") RodIdentifier rod() const { return m_rid; }; /// We can safely rely here on default "operator==", "operator!=" and "operator=" functionality, so no need to define them here. bool operator==(const UniqueRodIdentifier & other) const { return m_rid == other.m_rid && m_ucid == other.m_ucid; }; bool operator!=(const UniqueRodIdentifier & other) const { return m_rid != other.m_rid || m_ucid != other.m_ucid; }; bool operator<(const UniqueRodIdentifier & other) const { return m_ucid < other.m_ucid || m_ucid == other.m_ucid && m_rid < other.m_rid; }; operator std::string () const; private: std::string tag() const { return "URID"; }; }; } inline std::ostream & operator<<(std::ostream & os, const Sct::UniquePartitionIdentifier & upid) { return os << std::string(upid); }; inline std::ostream & operator<<(std::ostream & os, const Sct::UniqueCrateIdentifier & ucid) { return os << std::string(ucid); }; inline std::ostream & operator<<(std::ostream & os, const Sct::UniqueRodIdentifier & urid) { return os << std::string(urid); }; inline std::ostream & operator<<(std::ostream & os, const Sct::UniqueTimIdentifier & utid) { return os << std::string(utid); }; #endif