#ifndef __JDETECTOR__JMODULEROUTER__ #define __JDETECTOR__JMODULEROUTER__ #include "JDetector/JModuleIdentifier.hh" #include "JDetector/JModuleAddress.hh" #include "JDetector/JDetector.hh" #include "JDetector/JPMTIdentifier.hh" #include "JTools/JRouter.hh" #include "JLang/JReference.hh" /** * \file * Direct access to module in detector data structure. * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { using JLANG::JObjectID; using JLANG::JReference; using JLANG::getUndefinedObjectID; /** * Router for direct addressing of module data in detector data structure. * * This router can be used to directly map the module identifier to * the logical address of the module (JModuleAddress) in the detector data structure. * * Note that the required memory is determined by the range covered by the module identifiers. */ class JModuleRouter : public JReference { typedef JReference JReference_t; public: typedef JDetector::const_iterator const_iterator; /** * Constructor. * * \param detector detector */ JModuleRouter(const JDetector& detector) : JReference_t(detector), router(JModuleAddress(-1)) { for (const_iterator module = detector.begin(); module != detector.end(); ++module) { router.put(module->getID(), JModuleAddress(std::distance(detector.begin(), module))); } } /** * Get module router. * * \return module router */ const JModuleRouter& getModuleRouter() const { return static_cast(*this); } /** * Get address of module. * * \param id module identifier * \return address */ const JModuleAddress& getAddress(const JObjectID& id) const { return router.get(id.getID()); } /** * Get module parameters. * * \param id module identifier * \return module parameters */ const JModule& getModule(const JObjectID& id) const { return getReference().getModule(this->getAddress(id)); } /** * Has module. * * \param id module identifier * \return true if module present; else false */ bool hasModule(const JObjectID& id) const { return router.has(id.getID()); } /** * Get index of module. * * \param id module identifier * \return index */ const int getIndex(const JObjectID& id) const { return getAddress(id).first; } /** * Has PMT. * * \param id PMT identifier * \return true if PMT present; else false */ bool hasPMT(const JPMTIdentifier& id) const { return hasModule(id.getID()) && id.getPMTAddress() >= 0 && id.getPMTAddress() < (int) getModule(id.getID()).size(); } /** * Get PMT parameters. * * \param id PMT identifier * \return PMT parameters */ const JPMT& getPMT(const JPMTIdentifier& id) const { return getModule(id.getID()).getPMT(id.getPMTAddress()); } /** * Get UTM position of given module identifier. * * \param id module identifier * \return UTM position */ JUTMPosition getUTMPosition(const JObjectID& id) const { return JUTMPosition(getModule(id).getPosition() + getReference().getPosition()); } private: JTOOLS::JRouter router; }; } #endif