Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:25

0001 #ifndef CondCore_CondDB_Types_h
0002 #define CondCore_CondDB_Types_h
0003 //
0004 // Package:     CondDB
0005 //
0006 //
0007 /*
0008    Description: various foundation types for Conditions
0009 */
0010 //
0011 // Author:      Giacomo Govi
0012 // Created:     June 2013
0013 //
0014 
0015 #include <boost/date_time/posix_time/posix_time.hpp>
0016 #include <functional>
0017 //
0018 #include "CondCore/CondDB/interface/Time.h"
0019 
0020 namespace cond {
0021 
0022   struct UserLogInfo {
0023     std::string provenance;
0024     std::string usertext;
0025   };
0026 
0027   typedef enum {
0028     SYNCH_ANY = 0,
0029     SYNCH_VALIDATION,
0030     SYNCH_OFFLINE,
0031     SYNCH_MC,
0032     SYNCH_RUNMC,
0033     SYNCH_HLT,
0034     SYNCH_EXPRESS,
0035     SYNCH_PROMPT,
0036     SYNCH_PCL
0037   } SynchronizationType;
0038 
0039   std::string synchronizationTypeNames(SynchronizationType type);
0040 
0041   SynchronizationType synchronizationTypeFromName(const std::string& name);
0042 
0043   typedef std::string Hash;
0044   static constexpr unsigned int HASH_SIZE = 40;
0045 
0046   // Basic element of the IOV sequence.
0047   struct Iov_t {
0048     Iov_t() : since(time::MAX_VAL), till(time::MIN_VAL), payloadId("") {}
0049     virtual ~Iov_t() = default;
0050     virtual void clear();
0051     bool isValid() const;
0052     bool isValidFor(Time_t target) const;
0053     Time_t since;
0054     Time_t till;
0055     Hash payloadId;
0056   };
0057 
0058   struct Tag_t {
0059     virtual ~Tag_t() = default;
0060     virtual void clear();
0061     std::string name;
0062     std::string payloadType;
0063     TimeType timeType;
0064     SynchronizationType synchronizationType;
0065     Time_t endOfValidity;
0066     Time_t lastValidatedTime;
0067   };
0068 
0069   struct TagInfo_t {
0070     // FIX ME: to be simplyfied, currently keeping the same interface as CondCore/DBCommon/interface/TagInfo.h
0071     TagInfo_t() : name(""), lastInterval() {}
0072     std::string name;
0073     Iov_t lastInterval;
0074     size_t size = 0;
0075     bool isEmpty() const { return lastInterval.since == time::MAX_VAL; }
0076   };
0077 
0078   struct TagMetadata_t {
0079     SynchronizationType synchronizationType;
0080     std::string description;
0081     boost::posix_time::ptime insertionTime;
0082     boost::posix_time::ptime modificationTime;
0083   };
0084 
0085   // temporarely replacement for cond::LogDBEntry
0086   struct LogDBEntry_t {
0087     unsigned long long logId;
0088     std::string destinationDB;
0089     std::string provenance;
0090     std::string usertext;
0091     std::string iovtag;
0092     std::string iovtimetype;
0093     unsigned int payloadIdx;
0094     unsigned long long lastSince;
0095     std::string payloadClass;
0096     std::string payloadToken;
0097     std::string exectime;
0098     std::string execmessage;
0099   };
0100 
0101   struct GTMetadata_t {
0102     Time_t validity;
0103     std::string description;
0104     std::string release;
0105     boost::posix_time::ptime insertionTime;
0106     boost::posix_time::ptime snapshotTime;
0107   };
0108 
0109   class GTEntry_t {
0110   public:
0111     GTEntry_t() : m_data() {}
0112     GTEntry_t(const std::tuple<std::string, std::string, std::string>& gtEntryData) : m_data(gtEntryData) {}
0113     GTEntry_t(const GTEntry_t& rhs) : m_data(rhs.m_data) {}
0114 
0115     GTEntry_t& operator=(const GTEntry_t& rhs) {
0116       m_data = rhs.m_data;
0117       return *this;
0118     }
0119 
0120     const std::string& recordName() const { return std::get<0>(m_data); }
0121     const std::string& recordLabel() const { return std::get<1>(m_data); }
0122     const std::string& tagName() const { return std::get<2>(m_data); }
0123     std::size_t hashvalue() const {
0124       // Derived from CondDB v1 TagMetadata implementation.
0125       // Unique Keys constructed with Record and Labels - allowing for multiple references of the same Tag in a GT
0126       std::hash<std::string> hasher;
0127       std::string key = recordName();
0128       if (!recordLabel().empty())
0129         key = key + "_" + recordLabel();
0130       std::size_t result = hasher(key);
0131       return result;
0132     }
0133     bool operator<(const GTEntry_t& toCompare) const { return this->hashvalue() < toCompare.hashvalue(); }
0134 
0135   private:
0136     std::tuple<std::string, std::string, std::string> m_data;
0137   };
0138 
0139   struct RunInfo_t {
0140     RunInfo_t() : run(0), start(), end() {}
0141     RunInfo_t(const std::tuple<long long unsigned int, boost::posix_time::ptime, boost::posix_time::ptime>& data)
0142         : run(std::get<0>(data)), start(std::get<1>(data)), end(std::get<2>(data)) {}
0143     bool isOnGoing() {
0144       if (run == 0)
0145         return false;
0146       auto now = boost::posix_time::second_clock::universal_time();
0147       return (start < now) && (end == start);
0148     }
0149     Time_t run;
0150     boost::posix_time::ptime start;
0151     boost::posix_time::ptime end;
0152   };
0153 
0154 }  // namespace cond
0155 
0156 #endif