CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Interval.h
Go to the documentation of this file.
1 #ifndef CondTools_L1Trigger_Interval_h
2 #define CondTools_L1Trigger_Interval_h
3 
4 #include <map>
5 #include <cassert>
6 
7 namespace l1t
8 {
9  /* Template class that will be used to represnt interval from one value to another.
10  * In general this class is not interested in what interval mark means, most of the time
11  * it should be number, time or something similar
12  *
13  * This class requires that TimeType should have defined operator == and < as defined in STL.
14  * It is enforced via sserts that start time is less then end time under provided operator <.
15  * TimeType requires empty constructor.
16  *
17  * Payload should have defined copy constructor and assigment operator.
18  */
19  template<typename TimeType, typename PayloadType>
20  class Interval
21  {
22  public:
23  /* Construncts the class with provided start and end times. Payload is created
24  * with default constructor.
25  */
26  Interval (const TimeType& start, const TimeType& end)
27  : m_start (start), m_end (end), isInvalid (false)
28  { assert (m_start <= m_end); }
29 
30  /* Constructs the class with given start and end times, as well as given payload.
31  */
32  Interval (const TimeType& start, const TimeType& end, const PayloadType& payload)
33  : m_start(start), m_end (end), _payload (payload), isInvalid (false) {}
34 
35  /* Sets the payload to the given one. */
36  void setPayload (const PayloadType& payload) { this->_payload = payload; }
37  /* Returns the payload */
38  const PayloadType& payload () const { return this->_payload; }
39 
40  /* Returns start time */
41  const TimeType & start () const { return this->m_start; }
42  /* Returns end time */
43  const TimeType & end () const { return this->m_end; }
44 
45  /* Static member that will define an invalid interval. Two invalid interfaces are
46  * always considered equal.
47  */
48  static Interval & invalid ();
49 
50  // Operator overloading
51  bool operator== (const Interval<TimeType, PayloadType> & other) const
52  { return (this->isInvalid == true && other.isInvalid == true ) ||
53  (this->start () == other.start ()) && (this->end () == other.end () &&
54  this->isInvalid == other.isInvalid); }
55 
56  bool operator!= (const Interval<TimeType, PayloadType> & other) const
57  { return ! (*this == other); }
58 
59  protected:
60  /* Private data */
63  PayloadType _payload;
64 
65  /* flag that will check if this interval is invalid */
66  bool isInvalid;
67  };
68 
69  /* Manages a list of intervals and provides method to find interval that contains
70  * some value.
71  *
72  * Template parameters are used to manage Interval class, so all requirements to these
73  * parameters comes from Interval class
74  */
75  template<typename TimeType, typename PayloadType>
77  {
78  public:
79  /* Adds one given interval to the list of intervals.
80  */
82  { intervalMap.insert (std::make_pair (interval.start (), interval)); }
83 
84  /* Removes all stored intervals from the list
85  */
86  void clear () { intervalMap.clear (); }
87 
88  /* Returns interval that contaisn given time. If multiple intervals exists
89  * any of them is returned
90  */
91  const Interval<TimeType, PayloadType> & find (const TimeType & time) const;
92 
93  protected:
94  /* Information to store list of intervals */
95  typedef std::map<TimeType, Interval<TimeType, PayloadType> > IntervalMap;
97  };
98 
99 } // namespace
100 
101 // implementation
102 #include "CondTools/L1Trigger/src/Interval.icc"
103 
104 #endif
bool operator!=(const Interval< TimeType, PayloadType > &other) const
Definition: Interval.h:56
const TimeType & start() const
Definition: Interval.h:41
static Interval & invalid()
const PayloadType & payload() const
Definition: Interval.h:38
tuple interval
Definition: MergeJob_cfg.py:20
IntervalMap intervalMap
Definition: Interval.h:96
bool operator==(const Interval< TimeType, PayloadType > &other) const
Definition: Interval.h:51
void addInterval(const Interval< TimeType, PayloadType > &interval)
Definition: Interval.h:81
TimeType
Definition: Time.h:21
Interval(const TimeType &start, const TimeType &end, const PayloadType &payload)
Definition: Interval.h:32
TimeType m_start
Definition: Interval.h:61
void setPayload(const PayloadType &payload)
Definition: Interval.h:36
const TimeType & end() const
Definition: Interval.h:43
std::map< TimeType, Interval< TimeType, PayloadType > > IntervalMap
Definition: Interval.h:95
Interval(const TimeType &start, const TimeType &end)
Definition: Interval.h:26
const Interval< TimeType, PayloadType > & find(const TimeType &time) const
bool isInvalid
Definition: Interval.h:66
TimeType m_end
Definition: Interval.h:62
PayloadType _payload
Definition: Interval.h:63