#ifndef __JTRIGGER__JCLONE__ #define __JTRIGGER__JCLONE__ #include #include "JLang/JClass.hh" #include "JTrigger/JHitToolkit.hh" /** * \author mdejong */ namespace JTRIGGER {} namespace JPP { using namespace JTRIGGER; } namespace JTRIGGER { /** * Clone of a container. * * A JClone object contains a reference to container data and can be used as any normal container. * It comprises in addition an internal iterator which is implemented as mutable data member. * * The methods * - JClone::is_valid, * - JClone::rewind, * - JClone::next, * - JClone::lower_bound, * - JClone::fast_forward and * - JClone::get * * can be used to check, set and access the internal iterator. * * The data in the original container should have been terminated with an appriopriate end marker. */ template class JClone : public JHitToolkit { public: typedef typename JContainer_t::value_type value_type; typedef typename JLANG::JClass::argument_type argument_type; typedef typename JContainer_t::const_iterator const_iterator; typedef typename JContainer_t::const_iterator iterator; using JHitToolkit::getT; using JHitToolkit::getToT; using JHitToolkit::getJHit; using JHitToolkit::getTimeDifference; /** * Default constructor. */ JClone() : JHitToolkit(), __begin(), __end (), __i () {} /** * Constructor. * * \param input input */ JClone(const JContainer_t& input) : JHitToolkit(), __begin(input.begin()), __end (input.end ()), __i (input.begin()) {} /** * Get begin of data. * * \return begin of data */ iterator begin() const { return __begin; } /** * Get end of data. * * \return end of data */ iterator end() const { return __end; } /** * Get size of data. * * \return size of data */ inline unsigned int size() const { return std::distance(__begin, __end); } /** * Check size of data. * * \return true if empty; else false */ inline bool empty() const { return __begin == __end; } /** * Rewind internal iterator. */ inline void rewind() const { __i = __begin; } /** * Check internal iterator. * * \return true if internal iterator not yet at end; else false */ inline bool is_valid() const { return __i != __end; } /** * Increment internal iterator. */ inline void next() const { ++__i; } /** * Get internal iterator. * * \return internal operator */ inline iterator get() const { return __i; } /** * Get time of internal iterator. * * \return time of internal iterator [ns] */ inline double getT() const { return getT(*__i); } /** * Get time-over-threshold of internal iterator. * * \return time-over-threshold of hit [ns] */ inline double getToT() const { return getToT(*__i); } /** * Construct JHit from internal iterator. * * \return hit */ inline JHit getJHit() const { return getJHit(*__i); } /** * Get time difference with respect to given hits. * * \param hit hit * \return time of internal iterator - time hit [ns] */ inline double getTimeDifference(argument_type hit) const { return getTimeDifference(hit, *__i); } /** * Set the internal iterator to the lower bound corresponding to the time of the given hit. * * \param hit hit * \return internal operator */ inline iterator lower_bound(argument_type hit) const { return (__i = std::lower_bound(__begin, __end, hit, this->getToolkit())); } /** * Increment the internal iterator until the lower bound corresponding to the time of the given hit. * * \param hit hit * \return internal operator */ inline iterator fast_forward(argument_type hit) const { while (JHitToolkit::getT(*__i) < JHitToolkit::getT(hit)) { ++__i; } return __i; } protected: iterator __begin; iterator __end; mutable iterator __i; }; } #endif