#ifndef __JDETECTOR__JPMTLOGICALADDRESSTABLE__ #define __JDETECTOR__JPMTLOGICALADDRESSTABLE__ #include #include "JTools/JRouter.hh" #include "JDetector/JModuleAddressMap.hh" #include "JDetector/JLocation.hh" #include "JDetector/JPMTIdentifier.hh" /** * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { /** * Lookup table for PMT addresses in detector. */ class JDetectorAddressMap { protected: /** * Default constructor. */ JDetectorAddressMap() : buffer(), router(-1) {} public: /** * Virtual destructor. */ virtual ~JDetectorAddressMap() {} /** * Get default module address map. * * \return module address map */ virtual const JModuleAddressMap& getDefaultModuleAddressMap() const = 0; /** * Get module identifier. * * \param location module location * \return module identifier */ virtual int getModuleID(const JLocation& location) const { return location.getString() * 100 + location.getFloor(); } /** * Get module address map. * * \param id module identifier */ const JModuleAddressMap& get(const int id) const { if (router.has(id)) return buffer[router.get(id)]; else return getDefaultModuleAddressMap(); } /** * Get module address map. * * \param id module identifier * \return module address map */ JModuleAddressMap& get(const int id) { if (!router.has(id)) { buffer.push_back(getDefaultModuleAddressMap()); router.put(id, buffer.size() - 1); } return buffer[router.get(id)]; } /** * Get PMT address translator. * * \param id PMY identifier * \return PMT address translator */ const JPMTAddressTranslator& get(const JPMTIdentifier& id) const { return get(id.getModuleID()).getAddressTranslator(id.getTDC()); } protected: std::vector buffer; JTOOLS::JRouter router; }; } #endif