Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:02

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DD4HEP_IOV_H
0014 #define DD4HEP_IOV_H
0015 
0016 // C/C++ include files
0017 #include <string>
0018 #include <limits>
0019 #include <algorithm>
0020 #include <utility>
0021 #include <cstdint>
0022 
0023 /// Namespace for the AIDA detector description toolkit
0024 namespace dd4hep {
0025 
0026   // Forward declarations
0027   class IOVType;
0028   class IOV;
0029 
0030   /// Class describing the interval of validty type
0031   /**
0032    *
0033    *  \author  M.Frank
0034    *  \version 1.0
0035    *  \ingroup DD4HEP_CONDITIONS
0036    */
0037   class IOVType   {
0038   public:
0039     static constexpr unsigned int UNKNOWN_IOV = ~0x0;
0040     /// integer identifier used internally
0041     unsigned int type = UNKNOWN_IOV;
0042     /// String name
0043     std::string  name;
0044     /// Standard Constructor
0045     IOVType() = default;
0046     /// Standard Destructor
0047     ~IOVType() = default;
0048     /// Copy constructor
0049     IOVType(const IOVType& copy) = default; //: type(copy.type), name(copy.name) {}
0050     /// Move constructor
0051     IOVType(IOVType&& copy) = default;
0052     /// Assignment operator
0053     IOVType& operator=(const IOVType& copy) = default;
0054     /// Move assignment operator
0055     IOVType& operator=(IOVType&& copy) = default;
0056     /// Conversion to string
0057     std::string str() const;
0058   };
0059 
0060   /// Class describing the interval of validty
0061   /**
0062    *
0063    *  \author  M.Frank
0064    *  \version 1.0
0065    *  \ingroup DD4HEP_CONDITIONS
0066    */
0067   class IOV   {
0068   private:
0069     /// Initializing constructor: Does not set reference to IOVType !
0070     explicit IOV() = delete;
0071   public:
0072     /// Key definition. Use fixed width type, though not portable!
0073     using Key_value_type = std::int64_t;
0074     using Key = std::pair<Key_value_type, Key_value_type>;
0075 
0076     static constexpr Key_value_type MIN_KEY = std::numeric_limits<Key_value_type>::min();
0077     static constexpr Key_value_type MAX_KEY = std::numeric_limits<Key_value_type>::max();
0078 
0079     /// Reference to IOV type
0080     const IOVType* iovType = 0;
0081     /// IOV key (if second==first, discrete, otherwise range)
0082     Key            keyData{MIN_KEY,MIN_KEY};
0083     /// Optional user data
0084     int            optData = 0;
0085     /// IOV buffer type: Must be a bitmap!
0086     unsigned int   type    = IOVType::UNKNOWN_IOV;
0087     
0088     /// Initializing constructor
0089     explicit IOV(const IOVType* typ);
0090     /// Specialized copy constructor for range IOVs
0091     explicit IOV(const IOVType* typ, const Key& key);
0092     /// Specialized copy constructor for discrete IOVs
0093     explicit IOV(const IOVType* typ, Key_value_type iov_value);
0094     /// Copy constructor
0095     IOV(const IOV& copy) = default;
0096     /// Move constructor
0097     IOV(IOV&& copy) = default;
0098     /// Standard Destructor
0099     ~IOV() = default;
0100     /// Assignment operator
0101     IOV& operator=(const IOV& c) = default;
0102     /// Move assignment operator
0103     IOV& operator=(IOV&& c) = default;
0104     /// Allow for IOV sorting in maps
0105     bool operator<(const IOV& test)  const;
0106     /// Move the data content: 'from' will be reset to NULL
0107     void move(IOV& from);
0108     /// Create string representation of the IOV
0109     std::string str() const;
0110     /// Check if the IOV corresponds to a range
0111     bool has_range() const             {  return keyData.first != keyData.second;  }
0112     /// Check if the IOV corresponds to a range
0113     bool is_discrete() const           {  return keyData.first == keyData.second;  }
0114     /// Get the local key of the IOV
0115     Key  key() const                   {  return keyData;                          }
0116     /// Set discrete IOV value
0117     void set(const Key& value);
0118     /// Set discrete IOV value
0119     void set(Key_value_type value);
0120     /// Set range IOV value
0121     void set(Key_value_type val_1, Key_value_type val_2);
0122     /// Set keys to unphysical values (LONG_MAX, LONG_MIN)
0123     IOV& reset();
0124     /// Invert the key values (first=second and second=first)
0125     IOV& invert();
0126     /// Set the intersection of this IOV with the argument IOV
0127     void iov_intersection(const IOV& comparator);
0128     /// Set the intersection of this IOV with the argument IOV
0129     void iov_intersection(const IOV::Key& comparator);
0130     /// Set the union of this IOV with the argument IOV
0131     void iov_union(const IOV& comparator);
0132     /// Set the union of this IOV with the argument IOV
0133     void iov_union(const IOV::Key& comparator);
0134 
0135     /// Check for validity containment
0136     /** Check if the caller 'iov' is of the same type and the range 
0137      *  is fully conained by the caller.
0138      */
0139     bool contains(const IOV& iov)  const;
0140     /// Conditions key representing eternity
0141     static IOV forever(const IOVType* typ)
0142     { return IOV(typ, Key(MIN_KEY, MAX_KEY));                             }
0143     /// Conditions key representing eternity
0144     static Key key_forever()
0145     { return Key(MIN_KEY, MAX_KEY);                                       }
0146     /// Check if 2 IOV objects are of the same type
0147     static bool same_type(const IOV& iov, const IOV& test)           {
0148       unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type;
0149       unsigned int typ2 = test.iovType ? test.iovType->type : test.type;
0150       return typ1 == typ2;
0151     }
0152     /// Check if IOV 'test' is fully contained in IOV 'key'
0153     static bool key_is_contained(const Key& key, const Key& test)
0154     {   return key.first >= test.first && key.second <= test.second;      }
0155     /// Same as above, but reverse logic. Gives sometimes more understandable logic.
0156     static bool key_contains_range(const Key& key, const Key& test)
0157     {   return key.first <= test.first && key.second >= test.second;      }
0158     /// Check if IOV 'test' has an overlap on the lower interval edge with IOV 'key'
0159     static bool key_overlaps_lower_end(const Key& key, const Key& test)         
0160     {   return key.first <= test.second && key.first >= test.first;       }
0161     /// Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key'
0162     static bool key_overlaps_higher_end(const Key& key, const Key& test)         
0163     {   return key.second >= test.first && key.second <= test.second;     }
0164     /// Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key'
0165     static bool key_partially_contained(const Key& key, const Key& test)         
0166     {   
0167       return 
0168         (test.first <= key.first  && key.second   >= test.second) || // test fully contained in key
0169         (test.first <= key.first  && key.first    <= test.second) || // test overlaps left edge of key
0170         (test.first <= key.second && key.second   <= test.second);   // test overlaps right edge of key
0171     }
0172     /// Check if IOV 'test' is of same type and is fully contained in iov
0173     static bool full_match(const IOV& iov, const IOV& test)
0174     {   return same_type(iov,test) && key_is_contained(iov.keyData,test.keyData);      }
0175     /// Check if IOV 'test' is of same type and is at least partially contained in iov
0176     static bool partial_match(const IOV& iov, const IOV& test)
0177     {   return same_type(iov,test) && key_partially_contained(iov.keyData,test.keyData);      }
0178   };
0179 
0180   /// Allow for IOV sorting in maps
0181   inline bool IOV::operator<(const IOV& test)  const   {
0182     if ( type > test.type ) return false; // Actually this should never happen!
0183     if ( keyData.first > test.keyData.first ) return false;
0184     if ( keyData.second > test.keyData.second ) return false;
0185     return true;
0186   }
0187 
0188 } /* End namespace dd4hep                   */
0189 #endif // DD4HEP_IOV_H