AliRoot Core  3dc7879 (3dc7879)
AliCDBPath.cxx
Go to the documentation of this file.
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 
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 // //
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 //_____________________________________________________________________________
38  TObject(),
39  fPath(""),
40  fLevel0(""),
41  fLevel1(""),
42  fLevel2(""),
43  fIsValid(kTRUE),
44  fIsWildcard(kFALSE)
45 {
46  // default constructor
47 
48 }
49 
50 //_____________________________________________________________________________
52  TObject(other),
53  fPath(other.fPath),
54  fLevel0(""),
55  fLevel1(""),
56  fLevel2(""),
57  fIsValid(other.fIsValid),
58  fIsWildcard(other.fIsWildcard)
59 {
60  // constructor
61  Init();
62  InitPath();
63 
64 }
65 
66 //_____________________________________________________________________________
67 AliCDBPath::AliCDBPath(const char* level0, const char* level1,
68  const char* level2):
69  TObject(),
70  fPath(""),
71  fLevel0(level0),
72  fLevel1(level1),
73  fLevel2(level2),
74  fIsValid(kTRUE),
75  fIsWildcard(kFALSE)
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 //_____________________________________________________________________________
101  TObject(),
102  fPath(path),
103  fLevel0(""),
104  fLevel1(""),
105  fLevel2(""),
106  fIsValid(kTRUE),
107  fIsWildcard(kFALSE)
108 {
109  // constructor
110 
111  Init();
112  InitPath();
113 }
114 
115 //_____________________________________________________________________________
116 AliCDBPath::AliCDBPath(const TString& path):
117  TObject(),
118  fPath(path),
119  fLevel0(""),
120  fLevel1(""),
121  fLevel2(""),
122  fIsValid(kTRUE),
123  fIsWildcard(kFALSE)
124 {
125  Init();
126  InitPath();
127 }
128 
129 //_____________________________________________________________________________
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();
193 }
194 
195 //_____________________________________________________________________________
197  // destructor
198 
199 }
200 
201 //_____________________________________________________________________________
202 Bool_t AliCDBPath::IsWord(const TString& str) {
203  // check if string is a word
204  static const TRegexp pattern("^[a-zA-Z0-9_.-]+$");
205 
206  return str.Contains(pattern);
207 }
208 
209 //_____________________________________________________________________________
211  // set fIsWildcard flag
212 
213  fIsWildcard = fPath.MaybeWildcard();
214 }
215 
216 //_____________________________________________________________________________
217 Bool_t AliCDBPath::Level0Comprises(const TString& str) const {
218  // check if Level0 is wildcard or is equal to str
219 
220  if (fLevel0 == "*") {
221  return kTRUE;
222  }
223 
224  return fLevel0 == str;
225 }
226 
227 //_____________________________________________________________________________
228 Bool_t AliCDBPath::Level1Comprises(const TString& str) const {
229  // check if Level1 is wildcard or is equal to str
230 
231  if (fLevel1 == "*") {
232  return kTRUE;
233  }
234 
235  return fLevel1 == str;
236 }
237 
238 //_____________________________________________________________________________
239 Bool_t AliCDBPath::Level2Comprises(const TString& str) const {
240  // check if Level2 is wildcard or is equal to str
241 
242  if (fLevel2 == "*") {
243  return kTRUE;
244  }
245 
246  return fLevel2 == str;
247 }
248 
249 //_____________________________________________________________________________
250 Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const {
251  // check if path is wildcard and comprises other
252 
253  return Level0Comprises(other.fLevel0)
254  && Level1Comprises(other.fLevel1)
255  && Level2Comprises(other.fLevel2);
256 }
257 
258 //_____________________________________________________________________________
259 const char* AliCDBPath::GetLevel(Int_t i) const {
260  // return level i of the path
261 
262  switch (i) {
263  case 0:
264  return fLevel0.Data();
265  break;
266  case 1:
267  return fLevel1.Data();
268  break;
269  case 2:
270  return fLevel2.Data();
271  break;
272  default:
273  return 0;
274  }
275 
276 }
TString fLevel2
Definition: AliCDBPath.h:64
Bool_t Comprises(const AliCDBPath &other) const
Definition: AliCDBPath.cxx:250
TString fLevel0
Definition: AliCDBPath.h:62
#define TObjArray
Bool_t Level1Comprises(const TString &str) const
Definition: AliCDBPath.cxx:228
const char * path
TString fPath
Definition: AliCDBPath.h:61
Bool_t Level2Comprises(const TString &str) const
Definition: AliCDBPath.cxx:239
const char * GetLevel(Int_t i) const
Definition: AliCDBPath.cxx:259
Bool_t Level0Comprises(const TString &str) const
Definition: AliCDBPath.cxx:217
void InitPath()
Definition: AliCDBPath.cxx:130
#define AliInfo(message)
Definition: AliLog.h:484
virtual ~AliCDBPath()
Definition: AliCDBPath.cxx:196
Bool_t fIsWildcard
Definition: AliCDBPath.h:67
Bool_t fIsValid
Definition: AliCDBPath.h:66
TString fLevel1
Definition: AliCDBPath.h:63
void Init()
Definition: AliCDBPath.cxx:210
#define AliError(message)
Definition: AliLog.h:591
Bool_t IsWord(const TString &str)
Definition: AliCDBPath.cxx:202