]>
Commit | Line | Data |
---|---|---|
9e1ceb13 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | ///////////////////////////////////////////////////////////////////// | |
17 | // // | |
18 | // class AliCDBPath // | |
19 | // Path string identifying the object: // | |
20 | // "level0/level1/level2" // | |
21 | // (was: "Detector/DBType/DetSpecType") // | |
22 | // (example: "ZDC/Calib/Pedestals") // | |
23 | // // | |
24 | ///////////////////////////////////////////////////////////////////// | |
25 | ||
26 | #include "AliCDBPath.h" | |
27 | ||
28 | #include <TObjArray.h> | |
29 | #include <TObjString.h> | |
30 | #include <TRegexp.h> | |
31 | ||
32 | #include "AliLog.h" | |
33 | ||
34 | ClassImp(AliCDBPath) | |
35 | ||
36 | //_____________________________________________________________________________ | |
e8d02863 | 37 | AliCDBPath::AliCDBPath() : |
fe12e09c | 38 | TObject(), |
39 | fPath(""), | |
40 | fLevel0(""), | |
41 | fLevel1(""), | |
42 | fLevel2(""), | |
43 | fIsValid(kTRUE), | |
44 | fIsWildcard(kFALSE) | |
e8d02863 | 45 | { |
5078a13f | 46 | // default constructor |
9e1ceb13 | 47 | |
48 | } | |
49 | ||
50 | //_____________________________________________________________________________ | |
51 | AliCDBPath::AliCDBPath(const AliCDBPath& other): | |
fe12e09c | 52 | TObject(other), |
53 | fPath(other.fPath), | |
54 | fLevel0(""), | |
55 | fLevel1(""), | |
56 | fLevel2(""), | |
57 | fIsValid(other.fIsValid), | |
58 | fIsWildcard(other.fIsWildcard) | |
9e1ceb13 | 59 | { |
5078a13f | 60 | // constructor |
61 | Init(); | |
62 | InitPath(); | |
9e1ceb13 | 63 | |
64 | } | |
65 | ||
66 | //_____________________________________________________________________________ | |
67 | AliCDBPath::AliCDBPath(const char* level0, const char* level1, | |
5078a13f | 68 | const char* level2): |
fe12e09c | 69 | TObject(), |
70 | fPath(""), | |
71 | fLevel0(level0), | |
72 | fLevel1(level1), | |
73 | fLevel2(level2), | |
74 | fIsValid(kTRUE), | |
75 | fIsWildcard(kFALSE) | |
9e1ceb13 | 76 | { |
5078a13f | 77 | // constructor |
78 | ||
79 | fPath += level0; | |
80 | fPath += '/'; | |
81 | fPath += level1; | |
82 | fPath += '/'; | |
83 | fPath += level2; | |
84 | ||
85 | if ((IsWord(fLevel0) || fLevel0 == "*") | |
86 | && (IsWord(fLevel1) || fLevel1 == "*") | |
87 | && (IsWord(fLevel2) || fLevel2 == "*")) { | |
88 | ||
89 | fIsValid = kTRUE; | |
90 | } else { | |
91 | fIsValid = kFALSE; | |
92 | AliError(Form("Invalid AliCDBPath <%s/%s/%s>!", | |
93 | level0, level1, level2)); | |
94 | } | |
95 | ||
96 | Init(); | |
9e1ceb13 | 97 | } |
98 | ||
99 | //_____________________________________________________________________________ | |
100 | AliCDBPath::AliCDBPath(const char* path): | |
fe12e09c | 101 | TObject(), |
102 | fPath(path), | |
103 | fLevel0(""), | |
104 | fLevel1(""), | |
105 | fLevel2(""), | |
106 | fIsValid(kTRUE), | |
107 | fIsWildcard(kFALSE) | |
9e1ceb13 | 108 | { |
5078a13f | 109 | // constructor |
9e1ceb13 | 110 | |
5078a13f | 111 | Init(); |
112 | InitPath(); | |
9e1ceb13 | 113 | } |
114 | ||
115 | //_____________________________________________________________________________ | |
116 | AliCDBPath::AliCDBPath(const TString& path): | |
fe12e09c | 117 | TObject(), |
118 | fPath(path), | |
119 | fLevel0(""), | |
120 | fLevel1(""), | |
121 | fLevel2(""), | |
122 | fIsValid(kTRUE), | |
123 | fIsWildcard(kFALSE) | |
9e1ceb13 | 124 | { |
5078a13f | 125 | Init(); |
126 | InitPath(); | |
9e1ceb13 | 127 | } |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | void AliCDBPath::InitPath() { | |
5078a13f | 131 | // sets fLevel0, fLevel1, fLevel2, validity flagss from fPath |
132 | ||
133 | TSubString strippedString = fPath.Strip(TString::kBoth); | |
134 | TString aString(strippedString); | |
135 | strippedString = aString.Strip(TString::kBoth, '/'); | |
136 | ||
137 | TObjArray* anArray = TString(strippedString).Tokenize("/"); | |
138 | Int_t paramCount = anArray->GetEntriesFast(); | |
139 | ||
140 | if (paramCount == 1) { | |
141 | if (fPath == "*") { | |
142 | fLevel0 = "*"; | |
143 | fLevel1 = "*"; | |
144 | fLevel2 = "*"; | |
145 | ||
146 | fIsValid = kTRUE; | |
147 | } else { | |
148 | fIsValid = kFALSE; | |
149 | } | |
150 | ||
151 | } else if (paramCount == 2) { | |
152 | fLevel0 = ((TObjString*) anArray->At(0))->GetString(); | |
153 | TString bString = ((TObjString*) anArray->At(1))->GetString(); | |
154 | ||
155 | if (IsWord(fLevel0) && bString == "*") { | |
156 | fLevel1 = "*"; | |
157 | fLevel2 = "*"; | |
158 | ||
159 | fIsValid = kTRUE; | |
160 | ||
161 | } else { | |
162 | fIsValid = kFALSE; | |
163 | } | |
164 | ||
165 | } else if (paramCount == 3) { | |
166 | fLevel0 = ((TObjString*) anArray->At(0))->GetString(); | |
167 | fLevel1 = ((TObjString*) anArray->At(1))->GetString(); | |
168 | fLevel2 = ((TObjString*) anArray->At(2))->GetString(); | |
169 | ||
170 | if ((IsWord(fLevel0) || fLevel0 == "*") | |
171 | && (IsWord(fLevel1) || fLevel1 == "*") | |
172 | && (IsWord(fLevel2) || fLevel2 == "*")) { | |
173 | ||
174 | fIsValid = kTRUE; | |
175 | } else { | |
176 | fIsValid = kFALSE; | |
177 | } | |
178 | ||
179 | } else { | |
180 | fIsValid = kFALSE; | |
181 | ||
182 | } | |
183 | ||
184 | if (!fIsValid) { | |
185 | AliInfo(Form("Invalid AliCDBPath <%s>!", fPath.Data())); | |
186 | } else { | |
187 | fPath = Form("%s/%s/%s", fLevel0.Data(), fLevel1.Data(), fLevel2.Data()); | |
188 | } | |
189 | ||
190 | delete anArray; | |
191 | ||
192 | Init(); | |
9e1ceb13 | 193 | } |
194 | ||
195 | //_____________________________________________________________________________ | |
196 | AliCDBPath::~AliCDBPath() { | |
5078a13f | 197 | // destructor |
9e1ceb13 | 198 | |
199 | } | |
200 | ||
201 | //_____________________________________________________________________________ | |
202 | Bool_t AliCDBPath::IsWord(const TString& str) { | |
5078a13f | 203 | // check if string is a word |
9e1ceb13 | 204 | |
5078a13f | 205 | TRegexp pattern("^[a-zA-Z0-9_.-]+$"); |
9e1ceb13 | 206 | |
5078a13f | 207 | return str.Contains(pattern); |
9e1ceb13 | 208 | } |
209 | ||
210 | //_____________________________________________________________________________ | |
211 | void AliCDBPath::Init() { | |
5078a13f | 212 | // set fIsWildcard flag |
9e1ceb13 | 213 | |
5078a13f | 214 | fIsWildcard = fPath.MaybeWildcard(); |
9e1ceb13 | 215 | } |
216 | ||
217 | //_____________________________________________________________________________ | |
218 | Bool_t AliCDBPath::Level0Comprises(const TString& str) const { | |
5078a13f | 219 | // check if Level0 is wildcard or is equal to str |
9e1ceb13 | 220 | |
5078a13f | 221 | if (fLevel0 == "*") { |
222 | return kTRUE; | |
223 | } | |
224 | ||
225 | return fLevel0 == str; | |
9e1ceb13 | 226 | } |
227 | ||
228 | //_____________________________________________________________________________ | |
229 | Bool_t AliCDBPath::Level1Comprises(const TString& str) const { | |
5078a13f | 230 | // check if Level1 is wildcard or is equal to str |
9e1ceb13 | 231 | |
5078a13f | 232 | if (fLevel1 == "*") { |
233 | return kTRUE; | |
234 | } | |
9e1ceb13 | 235 | |
5078a13f | 236 | return fLevel1 == str; |
9e1ceb13 | 237 | } |
238 | ||
239 | //_____________________________________________________________________________ | |
240 | Bool_t AliCDBPath::Level2Comprises(const TString& str) const { | |
5078a13f | 241 | // check if Level2 is wildcard or is equal to str |
242 | ||
243 | if (fLevel2 == "*") { | |
244 | return kTRUE; | |
245 | } | |
9e1ceb13 | 246 | |
5078a13f | 247 | return fLevel2 == str; |
9e1ceb13 | 248 | } |
249 | ||
250 | //_____________________________________________________________________________ | |
251 | Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const { | |
5078a13f | 252 | // check if path is wildcard and comprises other |
9e1ceb13 | 253 | |
5078a13f | 254 | return Level0Comprises(other.fLevel0) |
255 | && Level1Comprises(other.fLevel1) | |
256 | && Level2Comprises(other.fLevel2); | |
9e1ceb13 | 257 | } |
4667c116 | 258 | |
259 | //_____________________________________________________________________________ | |
260 | const char* AliCDBPath::GetLevel(Int_t i) const { | |
5078a13f | 261 | // return level i of the path |
262 | ||
263 | switch (i) { | |
264 | case 0: | |
265 | return fLevel0.Data(); | |
266 | break; | |
267 | case 1: | |
268 | return fLevel1.Data(); | |
269 | break; | |
270 | case 2: | |
271 | return fLevel2.Data(); | |
272 | break; | |
273 | default: | |
274 | return 0; | |
275 | } | |
4667c116 | 276 | |
277 | } |