#ifndef __JCOMPASS__JPOLICY__ #define __JCOMPASS__JPOLICY__ #include #include #include #include "JDetector/JModuleRouter.hh" #include "JDetector/JLocation.hh" /** * \file * * Policy for invalid modules. * \author mdejong */ namespace JCOMPASS {} namespace JPP { using namespace JCOMPASS; } namespace JCOMPASS { using JDETECTOR::JModuleRouter; /** * Auxiliary class to define policy for invalid modules. * * The policy is defined as a map of the identifier of a module to a list of identifiers of valid modules.\n * For invalid modules, the valid modules in the nearest floors in the same string are selected. */ struct JPolicy : public std::map > // identifiers of valid module(s) { /** * Constructor. * * \param router module router * \param __begin begin of list with identifiers of valid modules * \param __end end of list with identifiers of valid modules * \param size minimum number of valid modules in case of an invalid module */ template JPolicy(const JModuleRouter& router, T __begin, T __end, const size_t size = 1) { using namespace std; using namespace JPP; map > zmap; // valid floors per string for (T i = __begin; i != __end; ++i) { if (router.hasModule(*i)) { const JLocation& location = router.getModule(*i); zmap[location.getString()].insert(location.getFloor()); } } map detector; // inverse router for (JModuleRouter::const_iterator module = router->begin(); module != router->end(); ++module) { detector[module->getLocation()] = module->getID(); } for (JModuleRouter::const_iterator module = router->begin(); module != router->end(); ++module) { if (module->getFloor() != 0) { const int id = module->getID(); const int string = module->getString(); if (!zmap[string].empty()) { if (zmap[string].count(module->getFloor()) != 0) { (*this)[id].push_back(id); } else { for (size_t step = 1; (*this)[id].size() < size && (module->getFloor() + (int) step <= *zmap[string].rbegin() || module->getFloor() - (int) step >= *zmap[string]. begin()); ++step) { for (int sign : { -1, +1 }) { const int floor = module->getFloor() + sign * step; if (zmap[string].count(floor) != 0) { (*this)[id].push_back(detector[JLocation(string,floor)]); } } } } } } } } }; } #endif