CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CondTools/L1Trigger/interface/Interval.h

Go to the documentation of this file.
00001 #ifndef CondTools_L1Trigger_Interval_h
00002 #define CondTools_L1Trigger_Interval_h
00003 
00004 #include <map>
00005 #include <cassert>
00006 
00007 namespace l1t
00008 {
00009     /* Template class that will be used to represnt interval from one value to another.
00010      * In general this class is not interested in what interval mark means, most of the time
00011      * it should be number, time or something similar
00012      *
00013      * This class requires that TimeType should have defined operator == and < as defined in STL.
00014      * It is enforced via sserts that start time is less then end time under provided operator <.
00015      * TimeType requires empty constructor.
00016      *
00017      * Payload should have defined copy constructor and assigment operator.
00018      */
00019     template<typename TimeType, typename PayloadType>
00020     class Interval
00021     {
00022     public:
00023         /* Construncts the class with provided start and end times. Payload is created
00024          * with default constructor.
00025          */
00026         Interval (const TimeType& start, const TimeType& end)
00027             : m_start (start), m_end (end), isInvalid (false)
00028         { assert (m_start <= m_end); }
00029 
00030         /* Constructs the class with given start and end times, as well as given payload.
00031          */
00032         Interval (const TimeType& start, const TimeType& end, const PayloadType& payload)
00033             : m_start(start), m_end (end), _payload (payload), isInvalid (false) {}
00034 
00035         /* Sets the payload to the given one. */
00036         void setPayload (const PayloadType& payload) { this->_payload = payload; }
00037         /* Returns the payload */
00038         const PayloadType& payload () const { return this->_payload; }
00039 
00040         /* Returns start time */
00041         const TimeType & start () const { return this->m_start; }
00042         /* Returns end time */
00043         const TimeType & end () const { return this->m_end; }
00044 
00045         /* Static member that will define an invalid interval. Two invalid interfaces are
00046          * always considered equal.
00047          */
00048         static Interval & invalid ();
00049 
00050         // Operator overloading
00051         bool operator== (const Interval<TimeType, PayloadType> & other) const
00052         { return (this->isInvalid == true && other.isInvalid == true ) ||
00053             (this->start () == other.start ()) && (this->end () == other.end () &&
00054                     this->isInvalid == other.isInvalid); }
00055 
00056         bool operator!= (const Interval<TimeType, PayloadType> & other) const
00057         { return ! (*this == other); }
00058 
00059     protected:
00060         /* Private data */
00061         TimeType m_start;
00062         TimeType m_end;
00063         PayloadType _payload;
00064 
00065         /* flag that will check if this interval is invalid */
00066         bool isInvalid;
00067     };
00068 
00069     /* Manages a list of intervals and provides method to find interval that contains
00070      * some value.
00071      *
00072      * Template parameters are used to manage Interval class, so all requirements to these
00073      * parameters comes from Interval class
00074      */
00075     template<typename TimeType, typename PayloadType>
00076     class IntervalManager
00077     {
00078     public:
00079         /* Adds one given interval to the list of intervals.
00080          */
00081         void addInterval (const Interval<TimeType, PayloadType> & interval)
00082         { intervalMap.insert (std::make_pair (interval.start (), interval)); }
00083 
00084         /* Removes all stored intervals from the list
00085          */
00086         void clear () { intervalMap.clear (); }
00087 
00088         /* Returns interval that contaisn given time. If multiple intervals exists
00089          * any of them is returned
00090          */
00091         const Interval<TimeType, PayloadType> & find (const TimeType & time) const;
00092 
00093     protected:
00094         /* Information to store list of intervals */
00095         typedef std::map<TimeType, Interval<TimeType, PayloadType> > IntervalMap;
00096         IntervalMap intervalMap;
00097     };
00098 
00099 } // namespace
00100 
00101 // implementation
00102 #include "CondTools/L1Trigger/src/Interval.icc"
00103 
00104 #endif