ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
SGTools
src
SGVersionedKey.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include <cstdio>
6
#include <cstdlib>
7
#include <cstring>
8
#include <iostream>
9
#include <stdexcept>
10
#include <cassert>
11
#include "
SGTools/SGVersionedKey.h
"
12
using namespace
SG
;
13
using namespace
std
;
14
15
VersionedKey::~VersionedKey
() {}
16
17
bool
18
VersionedKey::isVersionedKey
(
const
char
* vkey) {
19
return
(vkey[0]==
separator
() && vkey[3]==
separator
());
20
}
21
22
bool
23
VersionedKey::isVersionedKey
(
const
std::string& vkey) {
24
return
isVersionedKey
(vkey.c_str());
25
}
26
27
bool
28
VersionedKey::isAuto
(
const
std::string& vkey) {
29
return
(vkey.compare(0,4,
VersionedKey::autoVS
())==0);
30
}
31
32
VersionedKey::VersionedKey
(
const
char
*
key
,
unsigned
char
version
) {
33
encode
(std::string(
key
),
version
);
34
}
35
VersionedKey::VersionedKey
(
const
std::string&
key
,
unsigned
char
version
) {
36
encode
(
key
,
version
);
37
}
38
VersionedKey::VersionedKey
(
const
std::string& versionedKey) {
39
copyVK
(versionedKey);
40
}
41
VersionedKey::VersionedKey
(
const
char
* versionedKey) {
42
copyVK
(std::string(versionedKey));
43
}
44
45
void
VersionedKey::decode
(std::string& outKey,
unsigned
char
&
version
)
const
{
46
outKey = this->
key
();
47
version = (
unsigned
char)atoi(
m_versionKey
.substr(1,2).c_str());
48
assert(
version
<= 99);
49
}
50
51
void
VersionedKey::encode
(
const
std::string& inKey,
unsigned
char
version
) {
52
assert(
version
<= 99);
53
char
vers[6];
54
snprintf(vers, 6,
versionFormatString
(),
version
);
55
m_versionKey
= vers + inKey;
56
m_baseKey
= inKey;
57
}
58
59
void
VersionedKey::copyVK
(
const
std::string& inKey) {
60
if
(
isVersionedKey
(inKey)) {
61
m_versionKey
= inKey;
62
m_baseKey
=
m_versionKey
.substr(4);
63
}
else
{
64
encode
(inKey, 0);
//FIXME should autoincrement
65
}
66
}
67
unsigned
char
VersionedKey::version
()
const
{
68
return
(
unsigned
char
) std::stoul(
m_versionKey
.substr(1,2),
nullptr
, 0);
69
}
70
71
const
std::string&
VersionedKey::key
()
const
{
72
return
m_baseKey
;
73
}
74
75
bool
76
VersionedKey::sameKey
(
const
VersionedKey
& vkey)
const
{
77
return
(this->
key
() == vkey.
key
());
78
}
79
80
bool
81
VersionedKey::sameKey
(
const
std::string& baseKey)
const
{
82
return
(this->
key
() == baseKey);
83
}
84
85
bool
86
VersionedKey::sameKey
(
const
char
* baseKey)
const
{
87
return
(this->
key
() == std::string(baseKey));
88
}
89
91
bool
operator <
(
const
SG::VersionedKey
& lhs,
const
SG::VersionedKey
& rhs) {
92
std::string lhskey;
93
unsigned
char
lhsVersion(0);
94
lhs.
decode
(lhskey, lhsVersion);
95
unsigned
char
rhsVersion(0);
96
std::string rhskey;
97
rhs.
decode
(rhskey, rhsVersion);
98
int
keyCompare(strcmp(lhskey.c_str(), rhskey.c_str()));
99
return
( ( keyCompare < 0) ||
100
( (keyCompare == 0) && (lhsVersion < rhsVersion) ) ) ;
101
102
}
operator<
bool operator<(const DataVector< T > &a, const DataVector< T > &b)
Vector ordering relation.
SGVersionedKey.h
defines a StoreGateSvc key with a version number
SG::VersionedKey
a StoreGateSvc key with a version number.
Definition
SGVersionedKey.h:31
SG::VersionedKey::sameKey
bool sameKey(const VersionedKey &vkey) const
compare base keys
Definition
SGVersionedKey.cxx:76
SG::VersionedKey::VersionedKey
VersionedKey(const char *key, unsigned char version)
version must be [0,98], 0 is the default version
Definition
SGVersionedKey.cxx:32
SG::VersionedKey::version
unsigned char version() const
Definition
SGVersionedKey.cxx:67
SG::VersionedKey::isAuto
bool isAuto() const
Definition
SGVersionedKey.h:85
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::copyVK
void copyVK(const std::string &inKey)
Definition
SGVersionedKey.cxx:59
SG::VersionedKey::~VersionedKey
~VersionedKey()
Definition
SGVersionedKey.cxx:15
SG::VersionedKey::autoVS
static const char * autoVS()
Definition
SGVersionedKey.h:101
SG::VersionedKey::separator
static char separator()
Definition
SGVersionedKey.h:95
SG::VersionedKey::VersionedKey
VersionedKey()
default constructor (invalid state, do not use)
Definition
SGVersionedKey.h:90
SG::VersionedKey::encode
void encode(const std::string &inKey, unsigned char version)
Definition
SGVersionedKey.cxx:51
SG::VersionedKey::m_baseKey
std::string m_baseKey
Definition
SGVersionedKey.h:107
SG::VersionedKey::versionFormatString
static const char * versionFormatString()
Definition
SGVersionedKey.h:96
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::VersionedKey::m_versionKey
std::string m_versionKey
the encoded version/key.
Definition
SGVersionedKey.h:106
SG::VersionedKey::key
const std::string & key() const
Definition
SGVersionedKey.cxx:71
SG
Forward declaration.
Definition
CaloCellPacker_400_500.h:32
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0