#ifndef __JDETECTOR__JPMTROUTER__ #define __JDETECTOR__JPMTROUTER__ #include "JLang/JObjectID.hh" #include "JDetector/JPMTAddress.hh" #include "JDetector/JPMTIdentifier.hh" #include "JDetector/JDetector.hh" #include "JDetector/JPMTChannel.hh" #include "JTools/JRouter.hh" #include "JLang/JReference.hh" /** * \file * Direct access to PMT in detector data structure. * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { using JLANG::JObjectID; using JLANG::JReference; /** * Router for direct addressing of PMT data in detector data structure. * * This router can be used to directly map the PMT identifier to * the logical address of the PMT (JPMTAddress) in the detector data structure. * * Note that the required memory is determined by the range covered by the PMT identifiers. */ class JPMTRouter : public JReference { typedef JReference JReference_t; public: typedef JDetector::const_iterator const_iterator; /** * Constructor. * * \param detector detector */ JPMTRouter(const JDetector& detector) : JReference_t(detector), router(JPMTAddress()) { for (const_iterator module = detector.begin(); module != detector.end(); ++module) { for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) { router.put(pmt->getID(), JPMTAddress(JModuleAddress(std::distance(detector.begin(), module)), std::distance(module->begin(), pmt))); } } } /** * Get PMT router. * * \return PMT router */ const JPMTRouter& getPMTRouter() const { return static_cast(*this); } /** * Get address of PMT. * * \param id PMT identifier * \return address */ const JPMTAddress& getAddress(const JObjectID& id) const { return router.get(id.getID()); } /** * Get PMT. * * \param address PMT address * \return PMT */ const JPMT& getPMT(const JPMTAddress& address) const { return getReference().getPMT(address); } /** * Get PMT. * * \param id PMT identifier * \return PMT */ const JPMT& getPMT(const JObjectID& id) const { return getReference().getPMT(this->getAddress(id)); } /** * Has PMT. * * \param id PMT identifier * \return true if PMT present; else false */ bool hasPMT(const JObjectID& id) const { return router.has(id.getID()); } /** * Get identifier of PMT. * * \param address PMT address * \return address */ JPMTIdentifier getIdentifier(const JPMTAddress& address) const { return JPMTIdentifier(getModule(address), address.second); } /** * Get identifier of PMT. * * \param id PMT identifier * \return address */ JPMTIdentifier getIdentifier(const JObjectID& id) const { return getIdentifier(this->getAddress(id)); } /** * Get module. * * \param address module address * \return module */ const JModule& getModule(const JModuleAddress& address) const { return getReference().getModule(address); } /** * Get parent module. * * \param id PMT identifier * \return module */ const JModule& getParentModule(const JObjectID& id) const { return getModule(this->getAddress(id)); } /** * Get parent module identifier. * * \param id PMT identifier * \return module identifier */ int getParentModuleID(const JObjectID& id) const { return getParentModule(id).getID(); } /** * Get PMT channel. * * \param address PMT address * \return PMT channel */ JPMTChannel getPMTChannel(const JPMTAddress& address) const { return JPMTChannel(getModule(address).getLocation(), address.second); } /** * Get PMT channel. * * \param id PMT identifier * \return PMT channel */ inline JPMTChannel getPMTChannel(const JObjectID& id) const { return getPMTChannel(getAddress(id)); } /** * Get UTM position of given PMT identifier. * * \param id PMT identifier * \return UTM position */ JUTMPosition getUTMPosition(const JObjectID& id) const { return JUTMPosition(getPMT(id).getPosition() + getReference().getPosition()); } private: JTOOLS::JRouter router; }; } #endif