Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:29

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_EVENTIDRANGE_H
0012 #define GAUDIKERNEL_EVENTIDRANGE_H 1
0013 
0014 /** **************************************************************************
0015  *
0016  *  @file EventIDRange.h
0017  *  @brief Event Range object. Holds two EventIDBase instances (start and stop)
0018  *
0019  *  @author Charles Leggett
0020  *
0021  *****************************************************************************/
0022 
0023 #include "GaudiKernel/EventIDBase.h"
0024 #include <iostream>
0025 #include <sstream>
0026 #include <string>
0027 
0028 /**
0029  *  @class EventIDRange
0030  *  @brief Event ID Range object. Holds two EventIDBases (start and stop)
0031  */
0032 
0033 class EventIDRange {
0034 public:
0035   EventIDRange();
0036   EventIDRange( const EventIDBase& start, const EventIDBase& stop );
0037   EventIDRange( const EventIDRange& r ) : m_start( r.m_start ), m_stop( r.m_stop ){};
0038   EventIDRange& operator=( const EventIDRange& r );
0039 
0040   EventIDBase start() const { return m_start; }
0041   EventIDBase stop() const { return m_stop; }
0042 
0043   bool isInRange( const EventIDBase& t ) const {                             // return ( t >= m_start && t < m_stop ); }
0044     return ( std::tie( t.m_run_number, t.m_lumi_block, t.m_event_number ) >= // run/lumi larger than run/lumi of start
0045                  std::tie( m_start.m_run_number, m_start.m_lumi_block, m_start.m_event_number ) &&
0046 
0047              std::tie( t.m_run_number, t.m_lumi_block, t.m_event_number ) < // run/lumi smaller than run/lumi of stop
0048                  std::tie( m_stop.m_run_number, m_stop.m_lumi_block, m_stop.m_event_number ) &&
0049 
0050              std::tie( t.m_time_stamp, t.m_time_stamp_ns_offset ) >= // time-stamp larger than time-stamp of start
0051                  std::tie( m_start.m_time_stamp, m_start.m_time_stamp_ns_offset ) &&
0052 
0053              std::tie( t.m_time_stamp, t.m_time_stamp_ns_offset ) < // time-stap smaller than time-tamp of stop
0054                  std::tie( m_stop.m_time_stamp, m_stop.m_time_stamp_ns_offset ) );
0055   }
0056 
0057   static EventIDRange intersect( const EventIDRange& it ) { return it; }
0058   template <typename... T>
0059   static EventIDRange intersect( const EventIDRange& first, const T&... rest ) {
0060     EventIDRange r = intersect( rest... );
0061 
0062     EventIDBase i1 = max( first.start(), r.start() );
0063     EventIDBase i2 = min( first.stop(), r.stop() );
0064 
0065     return EventIDRange( i1, i2 );
0066   }
0067 
0068   friend bool operator==( const EventIDRange& lhs, const EventIDRange& rhs );
0069   friend bool operator!=( const EventIDRange& lhs, const EventIDRange& rhs );
0070 
0071   friend std::ostream& operator<<( std::ostream& os, const EventIDRange& rhs );
0072 
0073   operator std::string() const;
0074 
0075 private:
0076   EventIDBase m_start{};
0077   EventIDBase m_stop{};
0078 };
0079 
0080 inline bool operator==( const EventIDRange& lhs, const EventIDRange& rhs ) {
0081   return lhs.m_start == rhs.m_start && lhs.m_stop == rhs.m_stop;
0082 }
0083 
0084 inline bool operator!=( const EventIDRange& lhs, const EventIDRange& rhs ) { return !( lhs == rhs ); }
0085 
0086 inline EventIDRange::operator std::string() const {
0087   std::ostringstream os;
0088   os << "{" << m_start << " - " << m_stop << "}";
0089   return os.str();
0090 }
0091 
0092 #endif