]>
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 | { |
9e1ceb13 | 46 | // default constructor |
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 | { |
60 | // constructor | |
61 | Init(); | |
62 | InitPath(); | |
63 | ||
64 | } | |
65 | ||
66 | //_____________________________________________________________________________ | |
67 | AliCDBPath::AliCDBPath(const char* level0, const char* level1, | |
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 | { |
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(); | |
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 | { |
109 | // constructor | |
110 | ||
111 | Init(); | |
112 | InitPath(); | |
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 | { |
125 | Init(); | |
126 | InitPath(); | |
127 | } | |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | void AliCDBPath::InitPath() { | |
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 | ||
e8d02863 | 137 | TObjArray* anArray = TString(strippedString).Tokenize("/"); |
9e1ceb13 | 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 aString = ((TObjString*) anArray->At(1))->GetString(); | |
154 | ||
155 | if (IsWord(fLevel0) && aString == "*") { | |
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 | } | |
187 | ||
188 | delete anArray; | |
189 | ||
190 | Init(); | |
191 | } | |
192 | ||
193 | //_____________________________________________________________________________ | |
194 | AliCDBPath::~AliCDBPath() { | |
195 | // destructor | |
196 | ||
197 | } | |
198 | ||
199 | //_____________________________________________________________________________ | |
200 | Bool_t AliCDBPath::IsWord(const TString& str) { | |
201 | // check if string is a word | |
202 | ||
a00e23f6 | 203 | TRegexp pattern("^[a-zA-Z0-9_.]+$"); |
9e1ceb13 | 204 | |
205 | return str.Contains(pattern); | |
206 | } | |
207 | ||
208 | //_____________________________________________________________________________ | |
209 | void AliCDBPath::Init() { | |
210 | // set fIsWildcard flag | |
211 | ||
212 | fIsWildcard = fPath.MaybeWildcard(); | |
213 | } | |
214 | ||
215 | //_____________________________________________________________________________ | |
216 | Bool_t AliCDBPath::Level0Comprises(const TString& str) const { | |
217 | // check if Level0 is wildcard or is equal to str | |
218 | ||
219 | if (fLevel0 == "*") { | |
220 | return kTRUE; | |
221 | } | |
222 | ||
223 | return fLevel0 == str; | |
224 | } | |
225 | ||
226 | //_____________________________________________________________________________ | |
227 | Bool_t AliCDBPath::Level1Comprises(const TString& str) const { | |
228 | // check if Level1 is wildcard or is equal to str | |
229 | ||
230 | if (fLevel1 == "*") { | |
231 | return kTRUE; | |
232 | } | |
233 | ||
234 | return fLevel1 == str; | |
235 | } | |
236 | ||
237 | //_____________________________________________________________________________ | |
238 | Bool_t AliCDBPath::Level2Comprises(const TString& str) const { | |
239 | // check if Level2 is wildcard or is equal to str | |
240 | ||
241 | if (fLevel2 == "*") { | |
242 | return kTRUE; | |
243 | } | |
244 | ||
245 | return fLevel2 == str; | |
246 | } | |
247 | ||
248 | //_____________________________________________________________________________ | |
249 | Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const { | |
250 | // check if path is wildcard and comprises other | |
251 | ||
252 | return Level0Comprises(other.fLevel0) | |
253 | && Level1Comprises(other.fLevel1) | |
254 | && Level2Comprises(other.fLevel2); | |
255 | } |