#ifndef __JDB__JPRODUCTROUTER__ #define __JDB__JPRODUCTROUTER__ #include #include #include "JDB/JDetectorIntegration_t.hh" #include "JDB/JPBS_t.hh" #include "JDB/JUPI_t.hh" #include "JDB/JPBSSequence.hh" #include "JDB/JLocation_t.hh" /** * \author mdejong */ namespace JDATABASE {} namespace JPP { using namespace JDATABASE; } namespace JDATABASE { /** * Auxiliary class to map %UPI to location in detector. */ struct JProductRouter : public std::map { /** * Constructor. * * \param detector detector integration * \param pbs %PBS sequences */ JProductRouter(const JDetectorIntegration_t& detector, const JPBSSequences& pbs) { for (JDetectorIntegration_t::const_iterator product = detector.begin(); product != detector.end(); ++product) { if (product->is_set()) { for (JPBSSequences::const_iterator i = pbs.begin(); i != pbs.end(); ++i) { if (insert(detector, *product, *i)) { break; } } } } } /** * Get location of product with given %UPI. * * \param upi %UPI * \return location */ JLocation_t getLocation(const JUPI_t& upi) const { const_iterator p = this->find(upi); if (p != this->end()) return p->second; else return JLocation_t(); } private: /** * Insert product. * * \param detector detector integration * \param product product * \param pbs %PBS sequence * \return true if inserted; else false */ bool insert(const JDetectorIntegration_t& detector, const JProductIntegration_t& product, const JPBSSequence& pbs) { using namespace std; if (!pbs.empty()) { JPBSSequence::const_iterator i = pbs.begin(); if (product.content.getPBS() == i->getPBS()) { JLocation_t location; for (JUPI_t upi = product.content.getUPI(); ++i != pbs.end(); ) { const JDetectorIntegration_t::range_type range = detector.find(upi); if (distance(range.first, range.second) == 1) { const JProductIntegration_t& ps = detector[range.first->second]; if (is_optical_module(ps.container.getPBS()) || is_base_module (ps.container.getPBS())) { location.position = ps.position; } else if (is_string (ps.container.getPBS())) { location.floor = ps.position; } else if (is_detector (ps.container.getPBS())) { location.string = ps.position; } upi = ps.container.getUPI(); } else { break; } } if (i == pbs.end()) { std::map::insert(make_pair(product.content.getUPI(), location)); return true; } } } return false; } }; } #endif