#ifndef __JDETECTOR__JLOCATIONROUTER__ #define __JDETECTOR__JLOCATIONROUTER__ #include "JDetector/JLocation.hh" #include "JDetector/JModuleAddress.hh" #include "JDetector/JDetector.hh" #include "JTools/JHashMap.hh" #include "JLang/JReference.hh" /** * \file * Direct access to location in detector data structure. * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { using JLANG::JReference; /** * Router for direct addressing of location data in detector data structure. */ class JLocationRouter : public JReference { typedef JReference JReference_t; public: typedef JDetector::const_iterator const_iterator; /** * Constructor. * * \param detector detector */ JLocationRouter(const JDetector& detector) : JReference_t(detector) { for (const_iterator module = detector.begin(); module != detector.end(); ++module) { router[module->getString()][module->getFloor()] = JModuleAddress(std::distance(detector.begin(), module)); } } /** * Get location router. * * \return location router */ const JLocationRouter& getLocationRouter() const { return static_cast(*this); } /** * Get address of location. * * \param location location * \return address */ const JModuleAddress& getAddress(const JLocation& location) const { return router[location.getString()][location.getFloor()]; } /** * Get module parameters. * * \param location location * \return module parameters */ const JModule& getModule(const JLocation& location) const { return getReference().getModule(this->getAddress(location)); } /** * Has module. * * \param location location * \return true if location present; else false */ bool hasLocation(const JLocation& location) const { return router.has(location.getString()) && router[location.getString()].has(location.getFloor()); } /** * Get index of location. * * \param location location * \return index */ const int getIndex(const JLocation& location) const { return getAddress(location).first; } private: JTOOLS::JHashMap > router; }; } #endif