-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathIdPath.cxx
More file actions
221 lines (173 loc) · 4.99 KB
/
IdPath.cxx
File metadata and controls
221 lines (173 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
// Path string identifying the object: //
// (example: "ZDC/Calib/Pedestals") //
#include "CCDB/IdPath.h"
#include <fairlogger/Logger.h> // for LOG
#include <TObjArray.h> // for TObjArray
#include <TObjString.h> // for TObjString
#include <TRegexp.h> // for TRegexp
using namespace o2::ccdb;
ClassImp(IdPath);
IdPath::IdPath() : TObject(), mPath(""), mLevel0(""), mLevel1(""), mLevel2(""), mValid(kTRUE), mWildcard(kFALSE)
{
// default constructor
}
IdPath::IdPath(const IdPath& other)
: TObject(other),
mPath(other.mPath),
mLevel0(""),
mLevel1(""),
mLevel2(""),
mValid(other.mValid),
mWildcard(other.mWildcard)
{
// constructor
init();
InitPath();
}
IdPath::IdPath(const char* level0, const char* level1, const char* level2)
: TObject(), mPath(""), mLevel0(level0), mLevel1(level1), mLevel2(level2), mValid(kTRUE), mWildcard(kFALSE)
{
// constructor
mPath += level0;
mPath += '/';
mPath += level1;
mPath += '/';
mPath += level2;
if ((isWord(mLevel0) || mLevel0 == "*") && (isWord(mLevel1) || mLevel1 == "*") &&
(isWord(mLevel2) || mLevel2 == "*")) {
mValid = kTRUE;
} else {
mValid = kFALSE;
LOG(error) << R"(Invalid Path ")" << level0 << "/" << level1 << "/" << level2 << R"("!)";
}
init();
}
IdPath::IdPath(const char* path)
: TObject(), mPath(path), mLevel0(""), mLevel1(""), mLevel2(""), mValid(kTRUE), mWildcard(kFALSE)
{
// constructor
init();
InitPath();
}
IdPath::IdPath(const TString& path)
: TObject(), mPath(path), mLevel0(""), mLevel1(""), mLevel2(""), mValid(kTRUE), mWildcard(kFALSE)
{
init();
InitPath();
}
void IdPath::InitPath()
{
// sets mLevel0, mLevel1, mLevel2, validity flagss from mPath
TSubString strippedString = mPath.Strip(TString::kBoth);
TString aString(strippedString);
strippedString = aString.Strip(TString::kBoth, '/');
TObjArray* anArray = TString(strippedString).Tokenize("/");
Int_t paramCount = anArray->GetEntriesFast();
if (paramCount == 1) {
if (mPath == "*") {
mLevel0 = "*";
mLevel1 = "*";
mLevel2 = "*";
mValid = kTRUE;
} else {
mValid = kFALSE;
}
} else if (paramCount == 2) {
mLevel0 = ((TObjString*)anArray->At(0))->GetString();
TString bString = ((TObjString*)anArray->At(1))->GetString();
if (isWord(mLevel0) && bString == "*") {
mLevel1 = "*";
mLevel2 = "*";
mValid = kTRUE;
} else {
mValid = kFALSE;
}
} else if (paramCount == 3) {
mLevel0 = ((TObjString*)anArray->At(0))->GetString();
mLevel1 = ((TObjString*)anArray->At(1))->GetString();
mLevel2 = ((TObjString*)anArray->At(2))->GetString();
if ((isWord(mLevel0) || mLevel0 == "*") && (isWord(mLevel1) || mLevel1 == "*") &&
(isWord(mLevel2) || mLevel2 == "*")) {
mValid = kTRUE;
} else {
mValid = kFALSE;
}
} else {
mValid = kFALSE;
}
if (!mValid) {
LOG(info) << R"(Invalid Path ")" << mPath.Data() << R"("!)";
} else {
mPath = Form("%s/%s/%s", mLevel0.Data(), mLevel1.Data(), mLevel2.Data());
}
delete anArray;
init();
}
IdPath::~IdPath() = default;
Bool_t IdPath::isWord(const TString& str)
{
// check if string is a word
TRegexp pattern("^[a-zA-Z0-9_.-]+$");
return str.Contains(pattern);
}
void IdPath::init()
{
// set mWildcard flag
mWildcard = mPath.MaybeWildcard();
}
Bool_t IdPath::doesLevel0Contain(const TString& str) const
{
// check if Level0 is wildcard or is equal to str
if (mLevel0 == "*") {
return kTRUE;
}
return mLevel0 == str;
}
Bool_t IdPath::doesLevel1Contain(const TString& str) const
{
// check if Level1 is wildcard or is equal to str
if (mLevel1 == "*") {
return kTRUE;
}
return mLevel1 == str;
}
Bool_t IdPath::doesLevel2Contain(const TString& str) const
{
// check if Level2 is wildcard or is equal to str
if (mLevel2 == "*") {
return kTRUE;
}
return mLevel2 == str;
}
Bool_t IdPath::isSupersetOf(const IdPath& other) const
{
// check if path is wildcard and comprises other
return doesLevel0Contain(other.mLevel0) && doesLevel1Contain(other.mLevel1) && doesLevel2Contain(other.mLevel2);
}
const char* IdPath::getLevel(Int_t i) const
{
// return level i of the path
switch (i) {
case 0:
return mLevel0.Data();
break;
case 1:
return mLevel1.Data();
break;
case 2:
return mLevel2.Data();
break;
default:
return nullptr;
}
}