Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 08:29:55

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