00001 #ifndef CondTools_L1Trigger_Interval_h
00002 #define CondTools_L1Trigger_Interval_h
00003
00004 #include <map>
00005
00006 namespace l1t
00007 {
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 template<typename TimeType, typename PayloadType>
00019 class Interval
00020 {
00021 public:
00022
00023
00024
00025 Interval (const TimeType& start, const TimeType& end)
00026 : m_start (start), m_end (end), isInvalid (false)
00027 { assert (m_start <= m_end); }
00028
00029
00030
00031 Interval (const TimeType& start, const TimeType& end, const PayloadType& payload)
00032 : m_start(start), m_end (end), _payload (payload), isInvalid (false) {}
00033
00034
00035 void setPayload (const PayloadType& payload) { this->_payload = payload; }
00036
00037 const PayloadType& payload () const { return this->_payload; }
00038
00039
00040 const TimeType & start () const { return this->m_start; }
00041
00042 const TimeType & end () const { return this->m_end; }
00043
00044
00045
00046
00047 static Interval & invalid ();
00048
00049
00050 bool operator== (const Interval<TimeType, PayloadType> & other) const
00051 { return (this->isInvalid == true && other.isInvalid == true ) ||
00052 (this->start () == other.start ()) && (this->end () == other.end () &&
00053 this->isInvalid == other.isInvalid); }
00054
00055 bool operator!= (const Interval<TimeType, PayloadType> & other) const
00056 { return ! (*this == other); }
00057
00058 protected:
00059
00060 TimeType m_start;
00061 TimeType m_end;
00062 PayloadType _payload;
00063
00064
00065 bool isInvalid;
00066 };
00067
00068
00069
00070
00071
00072
00073
00074 template<typename TimeType, typename PayloadType>
00075 class IntervalManager
00076 {
00077 public:
00078
00079
00080 void addInterval (const Interval<TimeType, PayloadType> & interval)
00081 { intervalMap.insert (std::make_pair (interval.start (), interval)); }
00082
00083
00084
00085 void clear () { intervalMap.clear (); }
00086
00087
00088
00089
00090 const Interval<TimeType, PayloadType> & find (const TimeType & time) const;
00091
00092 protected:
00093
00094 typedef std::map<TimeType, Interval<TimeType, PayloadType> > IntervalMap;
00095 IntervalMap intervalMap;
00096 };
00097
00098 }
00099
00100
00101 #include "CondTools/L1Trigger/src/Interval.icc"
00102
00103 #endif