Skip to content
Snippets Groups Projects
Commit d7ecf7ef authored by Charles Leggett's avatar Charles Leggett
Browse files

add GaudiKernel/EventIDRange class

Adds an EventIDRange class to GaudiKernel, which holds 2 EventIDBase objects

add sort methods to EventIDBase, to sort by Run/Event, Timestamp, and Lumi/Event

See merge request !130
parents d0ae829e 7e419f65
No related branches found
No related tags found
1 merge request!130add GaudiKernel/EventIDRange class
Pipeline #
...@@ -9,11 +9,10 @@ ...@@ -9,11 +9,10 @@
* *
* @author RD Schaffer <R.D.Schaffer@cern.ch> * @author RD Schaffer <R.D.Schaffer@cern.ch>
* @author Paolo Calafiura <pcalafiura@lbl.gov> * @author Paolo Calafiura <pcalafiura@lbl.gov>
* @author Charles Leggett
* *
*/ */
//<<<<<< INCLUDES >>>>>>
#include <iostream> #include <iostream>
#include <stdint.h> #include <stdint.h>
...@@ -34,11 +33,11 @@ public: ...@@ -34,11 +33,11 @@ public:
//@{ //@{
EventIDBase() {}; EventIDBase() {};
EventIDBase(number_type run_number, EventIDBase(number_type run_number,
uint64_t event_number, uint64_t event_number,
number_type time_stamp=0, number_type time_stamp=0,
number_type time_stamp_ns_offset=0, number_type time_stamp_ns_offset=0,
number_type lumi_block=0, number_type lumi_block=0,
number_type bunch_crossing_id=0); number_type bunch_crossing_id=0);
// Use default copy constructor. // Use default copy constructor.
virtual ~EventIDBase(); virtual ~EventIDBase();
//@} //@}
...@@ -91,7 +90,49 @@ public: ...@@ -91,7 +90,49 @@ public:
/// Extraction operators /// Extraction operators
friend std::ostream& operator<<(std::ostream& os, const EventIDBase& rhs); friend std::ostream& operator<<(std::ostream& os, const EventIDBase& rhs);
class SortByTimeStamp {
public:
bool operator() ( const EventIDBase& t1, const EventIDBase& t2 ) const {
if (t1.time_stamp() == t2.time_stamp()) {
return t1.time_stamp_ns_offset() > t2.time_stamp_ns_offset();
} else {
return t1.time_stamp() > t2.time_stamp();
}
}
bool operator() ( const EventIDBase* t1, const EventIDBase* t2 ) const {
return ( SortByTimeStamp()(*t1,*t2) );
}
};
class SortByRunEvent {
public:
bool operator() ( const EventIDBase& t1, const EventIDBase& t2 ) const {
if (t1.run_number() == t2.run_number()) {
return t1.event_number() > t2.event_number();
} else {
return t1.run_number() > t2.run_number();
}
}
bool operator() ( const EventIDBase* t1, const EventIDBase* t2 ) const {
return ( SortByRunEvent()(*t1,*t2) );
}
};
class SortByLumiEvent {
public:
bool operator() ( const EventIDBase& t1, const EventIDBase& t2 ) const {
if (t1.lumi_block() == t2.lumi_block()) {
return t1.event_number() > t2.event_number();
} else {
return t1.lumi_block() > t2.lumi_block();
}
}
bool operator() ( const EventIDBase* t1, const EventIDBase* t2 ) const {
return ( SortByLumiEvent()(*t1,*t2) );
}
};
private: private:
/// run number /// run number
...@@ -115,20 +156,30 @@ private: ...@@ -115,20 +156,30 @@ private:
}; };
inline bool operator<(const EventIDBase& lhs, const EventIDBase& rhs) { inline bool operator<(const EventIDBase& lhs, const EventIDBase& rhs) {
// We are assuming that ALL events will have run and event numbers, // first try ordering by timestamp if both are non-zero
// and never just a time stamp. // then try ordering by lumi/event if both have non-zero lumi
// FIXME: any use for also ordering by lumi-block ? // then order by run/event
return lhs.m_run_number<rhs.m_run_number ||
( lhs.m_run_number==rhs.m_run_number && if (lhs.m_time_stamp != 0 && rhs.m_time_stamp != 0) {
lhs.m_event_number<rhs.m_event_number) ; return (lhs.m_time_stamp < rhs.m_time_stamp);
} else {
if (lhs.m_lumiBlock != 0 && rhs.m_lumiBlock != 0) {
return ( lhs.m_lumiBlock < rhs.m_lumiBlock ||
( lhs.m_lumiBlock == rhs.m_lumiBlock &&
lhs.m_event_number < rhs.m_event_number) );
} else {
return ( lhs.m_run_number<rhs.m_run_number ||
( lhs.m_run_number==rhs.m_run_number &&
lhs.m_event_number<rhs.m_event_number) );
}
}
} }
inline bool operator==(const EventIDBase& lhs, const EventIDBase& rhs) { inline bool operator==(const EventIDBase& lhs, const EventIDBase& rhs) {
// We assume that equality via run/event numbers is sufficient // We assume that equality via run/event numbers is sufficient
return lhs.m_run_number == rhs.m_run_number && return lhs.m_run_number == rhs.m_run_number &&
lhs.m_event_number == rhs.m_event_number; lhs.m_event_number == rhs.m_event_number;
} }
inline bool operator>(const EventIDBase& lhs, const EventIDBase& rhs) { inline bool operator>(const EventIDBase& lhs, const EventIDBase& rhs) {
return !( (lhs < rhs) || (lhs == rhs)); return !( (lhs < rhs) || (lhs == rhs));
...@@ -163,13 +214,4 @@ inline std::ostream& operator<<(std::ostream& os, const EventIDBase& rhs) { ...@@ -163,13 +214,4 @@ inline std::ostream& operator<<(std::ostream& os, const EventIDBase& rhs) {
return os; return os;
} }
//<<<<<< INLINE MEMBER FUNCTIONS >>>>>>
#endif // EVENTINFO_EVENTID_H #endif // EVENTINFO_EVENTID_H
#ifndef GAUDIKERNEL_EVENTIDRANGE_H
#define GAUDIKERNEL_EVENTIDRANGE_H 1
/** **************************************************************************
*
* @file EventIDRange.h
* @brief Event Range object. Holds two EventIDBase instances (start and stop)
*
* @author Charles Leggett
*
*****************************************************************************/
#include "GaudiKernel/EventIDBase.h"
#include <iostream>
#include <string>
#include <sstream>
/**
* @class EventIDRange
* @brief Event ID Range object. Holds two EventIDBases (start and stop)
*/
class EventIDRange {
public:
EventIDRange() {};
EventIDRange( const EventIDBase& start, const EventIDBase& stop );
EventIDRange( const EventIDRange& r ):m_start(r.m_start),m_stop(r.m_stop) {};
EventIDRange& operator= (const EventIDRange& r);
EventIDBase start() const { return m_start; }
EventIDBase stop() const { return m_stop; }
bool isInRange(const EventIDBase& t) const {
return ( t>=m_start && t<m_stop );
}
friend bool operator==(const EventIDRange& lhs, const EventIDRange& rhs);
friend bool operator!=(const EventIDRange& lhs, const EventIDRange& rhs);
friend std::ostream& operator<<(std::ostream& os, const EventIDRange& rhs);
operator std::string() const;
private:
EventIDBase m_start {};
EventIDBase m_stop {};
};
inline bool operator==(const EventIDRange& lhs, const EventIDRange& rhs) {
return lhs.m_start==rhs.m_start &&
lhs.m_stop==rhs.m_stop ;
}
inline bool operator!=(const EventIDRange& lhs, const EventIDRange& rhs) {
return ! (lhs == rhs);
}
inline EventIDRange::operator std::string () const {
std::ostringstream os;
os << "{" << m_start << " - " << m_stop << "}";
return os.str();
}
#endif
#include "GaudiKernel/EventIDRange.h"
/*****************************************************************************
*
* EventIDRange.cpp
*
* Author: Charles Leggett
*
* Validity Range object. Holds two EventIDBases (start and stop)
*
*****************************************************************************/
EventIDRange::EventIDRange( const EventIDBase& start,
const EventIDBase& stop )
: m_start(start), m_stop(stop) {
}
EventIDRange&
EventIDRange::operator= (const EventIDRange& r) {
if (this != &r) {
m_start = r.m_start;
m_stop = r.m_stop;
}
return *this;
}
std::ostream&
operator<< (std::ostream& os, const EventIDRange& rhs) {
os << (std::string) rhs;
return os;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment