ATLAS Offline Software
SGVersionedKey.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
10 #ifndef SGTOOLS_VERSIONEDKEY_H
11 #define SGTOOLS_VERSIONEDKEY_H 1
12 #include <iostream>
13 #include <string>
14 class StoreGateSvc; //our friend
15 class SGImplSvc; //our friend
16 namespace SG {
17  template <class T> class ObjectWithVersion;
18 
31  class VersionedKey {
32  friend class ::StoreGateSvc; //call copyVK
33  friend class ::SGImplSvc; //call copyVK
34  public:
36  static bool isVersionedKey(const char *);
38  static bool isVersionedKey(const std::string&);
39 
42  static bool isAuto(const std::string&);
43 
45  VersionedKey(const char* key, unsigned char version);
47  VersionedKey(const std::string& key, unsigned char version);
48 
52  explicit VersionedKey(const char* vkey);
56  explicit VersionedKey(const std::string& vkey);
57 
58  //Defaulted copy and move constructors and assignment operators
59  //since the class only holds strings.
60  VersionedKey(const VersionedKey& rhs) = default;
61  VersionedKey(VersionedKey&& rhs) = default;
62  VersionedKey& operator= (const VersionedKey& rhs) = default;
64 
65  ~VersionedKey();
66 
68  void decode(std::string& outKey, unsigned char& version) const;
69  operator std::string() const { return m_versionKey; }
71  unsigned char version() const;
73  const std::string& key() const;
75  const std::string& rawVersionKey() const {
76  return m_versionKey;
77  }
79  bool sameKey(const VersionedKey& vkey) const;
81  bool sameKey(const std::string& baseKey) const;
83  bool sameKey(const char* baseKey) const;
84  bool isAuto() const { return version() == VersionedKey::autoV(); }
85 
86  private:
87  template <class U> friend class ObjectWithVersion;
90 
91  void encode(const std::string& inKey, unsigned char version);
92  void copyVK(const std::string& inKey);
93 
94  static char separator() {return ';';}
95  static const char* versionFormatString() {return ";%02u;";}
96  static const char* formatString() {return ";%02u;%s";}
97 
98  static unsigned char autoV() { return 99;}
99  static unsigned char defaultV() { return 0;}
100  static const char* autoVS() { return "_99_"; }
101  static const char* defaultVS() { return "_00_"; }
102 
105  std::string m_versionKey;
106  std::string m_baseKey;
107  };
108 } // ns SG
109 
111 bool operator < (const SG::VersionedKey& lhs, const SG::VersionedKey& rhs);
112 
113 namespace SG {
114  inline
115  std::ostream& operator <<(std::ostream& ost, const SG::VersionedKey& k) {
116  return ost << k.rawVersionKey();
117  // return ost.write(k.rawVersionKey(), strlen(k.rawVersionKey()));
118  }
119 }
120 
121 #endif
SG::VersionedKey::isVersionedKey
static bool isVersionedKey(const char *)
quickly determine whether a string has the right format to be a VK
Definition: SGVersionedKey.cxx:18
SG::VersionedKey::VersionedKey
VersionedKey()
default constructor (invalid state, do not use)
Definition: SGVersionedKey.h:89
SG::VersionedKey::defaultV
static unsigned char defaultV()
Definition: SGVersionedKey.h:99
SG::VersionedKey::VersionedKey
VersionedKey(const VersionedKey &rhs)=default
SG::VersionedKey::isAuto
bool isAuto() const
Definition: SGVersionedKey.h:84
python.trigbs_prescaleL1.ost
ost
Definition: trigbs_prescaleL1.py:104
SG::VersionedKey::decode
void decode(std::string &outKey, unsigned char &version) const
sets outKey to point to base key, and version to encoded version (0 is taken to mean default version)...
Definition: SGVersionedKey.cxx:45
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::VersionedKey::version
unsigned char version() const
Definition: SGVersionedKey.cxx:67
SG::VersionedKey::autoVS
static const char * autoVS()
Definition: SGVersionedKey.h:100
SG::VersionedKey::operator=
VersionedKey & operator=(const VersionedKey &rhs)=default
SG::VersionedKey::formatString
static const char * formatString()
Definition: SGVersionedKey.h:96
SG::VersionedKey::defaultVS
static const char * defaultVS()
Definition: SGVersionedKey.h:101
SG::VersionedKey::m_versionKey
std::string m_versionKey
the encoded version/key.
Definition: SGVersionedKey.h:105
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
Atlas.StoreGateSvc
StoreGateSvc
Definition: Atlas.UnixStandardJob.py:25
SG::VersionedKey
a StoreGateSvc key with a version number. Notice that StoreGate does not order multiple instances of ...
Definition: SGVersionedKey.h:31
operator<
bool operator<(const SG::VersionedKey &lhs, const SG::VersionedKey &rhs)
sort according to highest key version
Definition: SGVersionedKey.cxx:91
SG::VersionedKey::versionFormatString
static const char * versionFormatString()
Definition: SGVersionedKey.h:95
SGImplSvc
The Athena Transient Store API.
Definition: SGImplSvc.h:116
SG::VersionedKey::m_baseKey
std::string m_baseKey
Definition: SGVersionedKey.h:106
SG::VersionedKey::encode
void encode(const std::string &inKey, unsigned char version)
Definition: SGVersionedKey.cxx:51
SG::VersionedKey::rawVersionKey
const std::string & rawVersionKey() const
Definition: SGVersionedKey.h:75
SG::VersionedKey::key
const std::string & key() const
Definition: SGVersionedKey.cxx:71
SG::VersionedKey::autoV
static unsigned char autoV()
Definition: SGVersionedKey.h:98
SG::VersionedKey::~VersionedKey
~VersionedKey()
Definition: SGVersionedKey.cxx:15
SG::VersionedKey::VersionedKey
VersionedKey(VersionedKey &&rhs)=default
SG::VersionedKey::sameKey
bool sameKey(const VersionedKey &vkey) const
compare base keys
Definition: SGVersionedKey.cxx:76
SG::VersionedKey::copyVK
void copyVK(const std::string &inKey)
Definition: SGVersionedKey.cxx:59
SG::VersionedKey::separator
static char separator()
Definition: SGVersionedKey.h:94
SG::ObjectWithVersion
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
Definition: SGVersionedKey.h:17
SG::operator<<
std::ostream & operator<<(std::ostream &os, const ArenaAllocatorBase::Stats::Stat &stat)
Format a statistic structure.
Definition: ArenaAllocatorBase.cxx:62
fitman.k
k
Definition: fitman.py:528