#ifndef TGeometryId_hxx_seen #define TGeometryId_hxx_seen #include #include #include #include "EoaCore.hxx" #include "method_deprecated.hxx" namespace COMET { /// Base class for all exceptions associated with the IGeometryId classe. OA_EXCEPTION(EGeomId,EoaCore); /// Invalid MSB or LSB. OA_EXCEPTION(EGeomIdMSBLSB,EGeomId); /// Invalid geometry id. OA_EXCEPTION(EGeomIdInvalid,EGeomId); /// Value out of range. OA_EXCEPTION(EGeomIdOutOfRange,EGeomIdInvalid); class IGeometryId; class IGeomIdManager; } /// Geometry identifier class to uniquely identify a particular volume within /// the detector. This is an opaque type used to index the databases. It /// should be queried using the GetName() method which returns the volume path /// within the current detector geometry. The IGeomIdManager and the /// functions in the COMET::GeomId namespace provide additional ways to query the /// identifier. /// /// Examples: /// /// To set the id to a P0D P0D scintillator bar: /// \code /// IGeometryId id = COMET::GeomId::P0D::Bar(p0duleNumber, xyLayer, bar); /// \endcode /// /// To set the id to a TPC pad: /// \code /// IGeometryId id = COMET::GeomId::TPC::Pad(tpc, half, mm, pad); /// \endcode /// /// Find the detector element: /// \code /// std::string name = geomId.GetName(); /// if (name.find("P0Dule") != std::string::npos) {/* In P0Dule */} /// \endcode /// /// Find a element number (e.g. a MicroMega): /// \code /// std::string name = geomId.GetName(); /// std::size_type mm = name.find("/MM_"); /// if (mm != std::string::npos) { /// std::istringstream in(name.substr(mm+4); /// in >> microMegaNumber; /// } /// \endcode /// /// The ROOT geometry node can be found: /// \code /// IOADatabase::Get().GeomId().CdId(geomId); /// int nodeId = gGeoManager->GetCurrentNodeId(); /// \endcode /// /// The geometry identifier for a particular position. /// \code /// // Return false if x,y,z is an invalid position. /// IOADatabase::Get().GeomId().GetGeometryId(x,y,z,geomId); /// \endcode /// class COMET::IGeometryId { public: IGeometryId(); IGeometryId(const IGeometryId& geom); explicit IGeometryId(int id); virtual ~IGeometryId(); /// Get the internal integer representation const int AsInt() const {return fGeometryId;} /// Check that this is a valid geometry id. This method checks that the /// geometry id is correctly formed, and not that it corresponds to a real /// detector component. const bool IsValid() const; /// Get the geometry path name for this id. This method should be used to /// determine which detector element is represented by the identifier. std::string GetName() const; /// Get the subsystem name. The current values are "CDC", "CTC", "StrawTrk", /// "ECAL", "CosmicVeto", "MuX", "ProtBeamMon", "PiCapSol", "MuTrSol", /// "ColSol", "DetSol", and "node". If the value /// is empty ("node"), then the identifier is a plain ROOT node /// identifier, and you must use the geometry manager to query for the /// specific location. std::string GetSubsystemName() const; /// Get the subsystem index. The values are defined in COMETGeomIdDef.hxx /// and are /// /// * COMET::GeomId::Def::kCDC -- The CDC /// * COMET::GeomId::Def::kCTH -- The Cherenkov Trigger Hodoscope /// * COMET::GeomId::Def::kStrawTrk -- The Straw Tracker /// * COMET::GeomId::Def::kECAL -- The ECAL /// * COMET::GeomId::Def::kCosmicVeto -- The Cosmic Veto /// * COMET::GeomId::Def::kMuX -- The Muon X-ray detector /// * COMET::GeomId::Def::kProtBeamMon -- The Proton Beam Monitor /// * COMET::GeomId::Def::kPiCapSol -- The Pion Capture Solenoid /// * COMET::GeomId::Def::kMuTrSol -- The Muon Tr Sol /// * COMET::GeomId::Def::kColSol -- The Col Tr Sol /// * COMET::GeomId::Def::kDetSol -- The Detector Solenoid /// /// Any other value is invalid. int GetSubsystemId() const; /// Get the volume position for this geometry identifier. This is /// provided as a convenient interface to the /// IGeomIdManager::GetPosition() method. The IGeomIdManager method /// provides return values that flag if the position is not available, and /// it should be preferred. TVector3 GetPosition() const; bool operator <(const COMET::IGeometryId& rhs) const { return AsInt() < rhs.AsInt(); } /// DO NOT USE. This method is deprecated and will be removed in a future /// release. Use the functions provided in the COMETGeomId COMET::GeomId /// namespace to set the IGeometryId fields. void SetField(int val, int msb, int lsb) METHOD_DEPRECATED {SetFieldSafe(val,msb,lsb);} /// DO NOT USE. This method is deprecated and will be removed in a future /// release. Use the functions provided in the COMETGeomId COMET::GeomId /// namespace to get the IGeometryId fields. int GetField(int msb, int lsb) const METHOD_DEPRECATED {return GetFieldSafe(msb,lsb);} protected: /// Set the field in a bit range. The bit range is between 0 /// (lsb) and 31 (msb). Note that to set a single bit, the lsb will equal /// the msb. This class is reserved for internal implementation. void SetFieldSafe(int val, int msb, int lsb); /// Get a field from a bit range. This class is reserved for /// internal implementation. int GetFieldSafe(int msb, int lsb) const; int fGeometryId; ClassDef(IGeometryId, 1) }; bool operator ==(const COMET::IGeometryId& a, const COMET::IGeometryId& b); bool operator !=(const COMET::IGeometryId& a, const COMET::IGeometryId& b); std::ostream& operator<<(std::ostream& s, const COMET::IGeometryId& id); #endif